From: stevenknight Date: Thu, 10 Oct 2002 12:49:15 +0000 (+0000) Subject: Add Python and SCons version checking functions. (Anthony Roach) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a192198fdbbc8b5833fb94a7b35f59fb42ae1037;p=scons.git Add Python and SCons version checking functions. (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@478 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 7a9790aa..b090ff6b 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 8d6bad5c..e227920e 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 9ecd3d78..cb20ae9f 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 00000000..e5c3a114 --- /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()