summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/man/scons.138
-rw-r--r--src/CHANGES.txt2
-rw-r--r--src/engine/SCons/Script/SConscript.py25
-rw-r--r--test/EnsureVersion.py79
4 files changed, 143 insertions, 1 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index 7a9790a..b090ff6 100644
--- a/doc/man/scons.1
+++ b/doc/man/scons.1
@@ -2188,7 +2188,43 @@ can be a relative or absolute path.
is an optional directory that will be used as the parent directory.
.TP
-.RI FindFile( file ", "
+.RI FindFile( file ", " dirs )
+Search for
+.I file
+in the path specified by
+.IR dirs .
+.I file
+may be a list of file names or a single file name. In addition to searching
+for files that exist in the filesytem, this function also searches for
+derived files that have not yet been built.
+
+.ES
+foo = FindFile('foo', ['dir1', 'dir2'])
+.EE
+
+.TP
+.RI EnsurePythonVersion( major ", " minor )
+Ensure that the Python version is at least
+.IR major . minor .
+This function will
+print out an error message and exit SCons with a non-zero exit code if the
+actual Python version is not late enough.
+
+.ES
+EnsurePythonVersion(2,2)
+.EE
+
+.TP
+.RI EnsureSConsVersion( major ", " minor )
+Ensure that the SCons version is at least
+.IR major . minor .
+This function will
+print out an error message and exit SCons with a non-zero exit code if the
+actual SCons version is not late enough.
+
+.ES
+EnsureSConsVersion(0,9)
+.EE
.TP
.RI Export( vars )
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 8d6bad5..e227920 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -90,6 +90,8 @@ RELEASE 0.09 -
- Fix dependency scans when $LIBS is overridden.
+ - Add EnsurePythonVersion() and EnsureSConsVersion() functions.
+
From sam th:
- Dynamically check for the existence of utilities with which to
diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py
index 9ecd3d7..cb20ae9 100644
--- a/src/engine/SCons/Script/SConscript.py
+++ b/src/engine/SCons/Script/SConscript.py
@@ -41,6 +41,7 @@ import SCons.Tool
import SCons.Util
import SCons.Sig
import SCons.Options
+import SCons
import os
import os.path
@@ -268,6 +269,28 @@ class Options(SCons.Options.Options):
def Update(self, env):
return SCons.Options.Options.Update(self, env, arguments)
+def CheckVersion(major,minor,version_string):
+ """Return 0 if 'major' and 'minor' are greater than the version
+ in 'version_string', and 1 otherwise."""
+ version = string.split(string.split(version_string, ' ')[0], '.')
+ if major > int(version[0]) or (major == int(version[0]) and minor > int(version[1])):
+ return 0
+ else:
+ return 1
+
+def EnsureSConsVersion(major, minor):
+ """Exit abnormally if the SCons version is not late enough."""
+ if not CheckVersion(major,minor,SCons.__version__):
+ print "SCons %d.%d or greater required, but you have SCons %s" %(major,minor,SCons.__version__)
+ sys.exit(2)
+
+def EnsurePythonVersion(major, minor):
+ """Exit abnormally if the Python version is not late enough."""
+ if not CheckVersion(major,minor,sys.version):
+ v = string.split(sys.version, " ", 1)[0]
+ print "Python %d.%d or greater required, but you have Python %s" %(major,minor,v)
+ sys.exit(2)
+
def BuildDefaultGlobals():
"""
Create a dictionary containing all the default globals for
@@ -282,6 +305,8 @@ def BuildDefaultGlobals():
globals['CScan'] = SCons.Defaults.CScan
globals['Default'] = Default
globals['Dir'] = SCons.Node.FS.default_fs.Dir
+ globals['EnsurePythonVersion'] = EnsurePythonVersion
+ globals['EnsureSConsVersion'] = EnsureSConsVersion
globals['Environment'] = SCons.Environment.Environment
globals['Export'] = Export
globals['File'] = SCons.Node.FS.default_fs.File
diff --git a/test/EnsureVersion.py b/test/EnsureVersion.py
new file mode 100644
index 0000000..e5c3a11
--- /dev/null
+++ b/test/EnsureVersion.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2001, 2002 Steven Knight
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+import SCons
+
+if SCons.__version__ == "__VERSION__":
+
+ test.write('SConstruct', """
+import sys
+EnsurePythonVersion(0,0)
+sys.exit(0)
+""")
+
+ test.run()
+
+ test.write('SConstruct', """
+import sys
+EnsurePythonVersion(2000,0)
+sys.exit(0)
+""")
+
+ test.run(status=2)
+
+else:
+ test.write('SConstruct', """
+import sys
+EnsurePythonVersion(0,0)
+EnsureSConsVersion(0,0)
+sys.exit(0)
+""")
+
+ test.run()
+
+ test.write('SConstruct', """
+import sys
+EnsurePythonVersion(0,0)
+EnsureSConsVersion(2000,0)
+sys.exit(0)
+""")
+
+ test.run(status=2)
+
+ test.write('SConstruct', """
+import sys
+EnsurePythonVersion(2000,0)
+EnsureSConsVersion(2000,0)
+sys.exit(0)
+""")
+
+ test.run(status=2)
+
+test.pass_test()