diff options
author | Steven Knight <knight@baldmt.com> | 2005-08-12 22:08:38 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-08-12 22:08:38 (GMT) |
commit | 055a212a12d75036cdfbaf2b954e39908a2fbac1 (patch) | |
tree | 6117b2ff614672e0d687fd97ede7bddc2ea9ef59 | |
parent | 62b1b28dd7e952eb3d9910feb39fde8f02dd5dfa (diff) | |
download | SCons-055a212a12d75036cdfbaf2b954e39908a2fbac1.zip SCons-055a212a12d75036cdfbaf2b954e39908a2fbac1.tar.gz SCons-055a212a12d75036cdfbaf2b954e39908a2fbac1.tar.bz2 |
Enhance EnsureSConsVersion() to take revision numbers, too. (Amir Szekely)
-rw-r--r-- | doc/man/scons.1 | 15 | ||||
-rw-r--r-- | src/CHANGES.txt | 2 | ||||
-rw-r--r-- | src/engine/SCons/Script/SConscript.py | 34 | ||||
-rw-r--r-- | test/EnsurePythonVersion.py (renamed from test/EnsureVersion.py) | 75 | ||||
-rw-r--r-- | test/EnsureSConsVersion.py | 126 | ||||
-rw-r--r-- | test/LINK/LINKFLAGS.py | 9 | ||||
-rw-r--r-- | test/LINK/SHLINKFLAGS.py | 9 |
7 files changed, 182 insertions, 88 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 6e690a2..cb58f68 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -3096,17 +3096,24 @@ EnsurePythonVersion(2,2) '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .TP -.RI EnsureSConsVersion( major ", " minor ) +.RI EnsureSConsVersion( major ", " minor ", [" revision ]) .TP -.RI env.EnsureSConsVersion( major ", " minor ) +.RI env.EnsureSConsVersion( major ", " minor ", [" revision ]) Ensure that the SCons version is at least -.IR major . minor . +.IR major.minor , +or +.IR major.minor.revision . +if +.I revision +is specified. 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) +EnsureSConsVersion(0,14) + +EnsureSConsVersion(0,96,90) .EE '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 9ef394c..88b202b 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -587,6 +587,8 @@ RELEASE 0.97 - XXX - When calling the resource compiler on MinGW, add --include-dir and the source directory so it finds the source file. + - Update EnsureSConsVersion() to support revision numbers. + From Greg Ward: - Fix a misplaced line in the man page. diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index af9d492..ef77355 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -306,14 +306,20 @@ class SConsEnvironment(SCons.Environment.Base): in 'v_major' and 'v_minor', and 0 otherwise.""" return (major > v_major or (major == v_major and minor > v_minor)) - def _get_major_minor(self, version_string): - """Split a version string into major and minor parts. This - is complicated by the fact that a version string can be something - like 3.2b1.""" + def _get_major_minor_revision(self, version_string): + """Split a version string into major, minor and (optionally) + revision parts. + + This is complicated by the fact that a version string can be + something like 3.2b1.""" version = string.split(string.split(version_string, ' ')[0], '.') v_major = int(version[0]) v_minor = int(re.match('\d+', version[1]).group()) - return v_major, v_minor + if len(version) >= 3: + v_revision = int(re.match('\d+', version[2]).group()) + else: + v_revision = 0 + return v_major, v_minor, v_revision def _get_SConscript_filenames(self, ls, kw): """ @@ -400,20 +406,26 @@ class SConsEnvironment(SCons.Environment.Base): def Default(self, *targets): SCons.Script._Set_Default_Targets(self, targets) - def EnsureSConsVersion(self, major, minor): + def EnsureSConsVersion(self, major, minor, revision=0): """Exit abnormally if the SCons version is not late enough.""" - v_major, v_minor = self._get_major_minor(SCons.__version__) - if self._exceeds_version(major, minor, v_major, v_minor): - print "SCons %d.%d or greater required, but you have SCons %s" %(major,minor,SCons.__version__) + scons_ver = self._get_major_minor_revision(SCons.__version__) + if scons_ver < (major, minor, revision): + if revision: + scons_ver_string = '%d.%d.%d' % (major, minor, revision) + else: + scons_ver_string = '%d.%d' % (major, minor) + print "SCons %s or greater required, but you have SCons %s" % \ + (scons_ver_string, SCons.__version__) sys.exit(2) def EnsurePythonVersion(self, major, minor): """Exit abnormally if the Python version is not late enough.""" try: v_major, v_minor, v_micro, release, serial = sys.version_info + python_ver = (v_major, v_minor) except AttributeError: - v_major, v_minor = self._get_major_minor(sys.version) - if self._exceeds_version(major, minor, v_major, v_minor): + python_ver = self._get_major_minor_revision(sys.version)[:2] + if python_ver < (major, minor): 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) diff --git a/test/EnsureVersion.py b/test/EnsurePythonVersion.py index 0abe082..af59b52 100644 --- a/test/EnsureVersion.py +++ b/test/EnsurePythonVersion.py @@ -28,75 +28,20 @@ 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 -env = Environment() -EnsurePythonVersion(0,0) -env.EnsureSConsVersion(0,0) -sys.exit(0) -""") - - test.run() - - test.write('SConstruct', """ -import sys -env = Environment() -EnsurePythonVersion(0,0) -env.EnsureSConsVersion(1,0) -sys.exit(0) -""") - - test.run(status=2) - - test.write('SConstruct', """ -import sys -env = Environment() +test.write('SConstruct', """\ EnsurePythonVersion(0,0) -env.EnsureSConsVersion(2,0) -sys.exit(0) +Exit(0) """) - test.run(status=2) - - test.write('SConstruct', """ -import sys -env = Environment() -env.EnsurePythonVersion(0,0) -EnsureSConsVersion(2000,0) -sys.exit(0) -""") - - test.run(status=2) +test.run() - test.write('SConstruct', """ -import sys +test.write('SConstruct', """\ EnsurePythonVersion(2000,0) -EnsureSConsVersion(2000,0) -sys.exit(0) +Exit(0) """) - test.run(status=2) +test.run(status=2) test.write('SConstruct', """\ import sys @@ -106,7 +51,7 @@ except AttributeError: pass sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n' EnsurePythonVersion(1,3) -sys.exit(0) +Exit(0) """) test.run() @@ -119,7 +64,7 @@ except AttributeError: pass sys.version = '2.3+ (#0, Feb 24 2003, 19:13:11)\\n' EnsurePythonVersion(2,2) -sys.exit(0) +Exit(0) """) test.run() @@ -132,7 +77,7 @@ except AttributeError: pass sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n' EnsurePythonVersion(2,3) -sys.exit(0) +Exit(0) """) test.run() @@ -145,7 +90,7 @@ except AttributeError: pass sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n' EnsurePythonVersion(2,4) -sys.exit(0) +Exit(0) """) test.run(status=2) diff --git a/test/EnsureSConsVersion.py b/test/EnsureSConsVersion.py new file mode 100644 index 0000000..287dfa7 --- /dev/null +++ b/test/EnsureSConsVersion.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# 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', """\ +env = Environment() +env.EnsureSConsVersion(0,0) +Exit(0) +""") + + test.run() + + test.write('SConstruct', """\ +env = Environment() +env.EnsureSConsVersion(1,0) +Exit(0) +""") + + test.run(status=2) + + test.write('SConstruct', """\ +env = Environment() +env.EnsureSConsVersion(2,0) +Exit(0) +""") + + test.run(status=2) + + test.write('SConstruct', """\ +EnsureSConsVersion(2000,0) +Exit(0) +""") + + test.run(status=2) + + + +test.write('SConstruct', """\ +import SCons +SCons.__version__ = '0.33.2' +EnsureSConsVersion(0,33) +""") + +test.run() + +test.write('SConstruct', """\ +import SCons +SCons.__version__ = '0.33.2' +EnsureSConsVersion(0,33,0) +""") + +test.run() + +test.write('SConstruct', """\ +import SCons +SCons.__version__ = '0.33.2' +EnsureSConsVersion(0,33,1) +""") + +test.run() + +test.write('SConstruct', """\ +import SCons +SCons.__version__ = '0.33.2' +EnsureSConsVersion(0,33,2) +""") + +test.run() + +test.write('SConstruct', """\ +import SCons +SCons.__version__ = '0.33.2' +EnsureSConsVersion(0,33,3) +""") + +test.run(status=2) + +test.write('SConstruct', """\ +import SCons +SCons.__version__ = '0.33.2' +EnsureSConsVersion(0,34) +""") + +test.run(status=2) + +test.write('SConstruct', """\ +import SCons +SCons.__version__ = '0.33.2' +EnsureSConsVersion(1,0) +""") + +test.run(status=2) + + + +test.pass_test() diff --git a/test/LINK/LINKFLAGS.py b/test/LINK/LINKFLAGS.py index 047ddc7..9a6ef1c 100644 --- a/test/LINK/LINKFLAGS.py +++ b/test/LINK/LINKFLAGS.py @@ -39,13 +39,14 @@ test.write("wrapper.py", import string import sys open('%s', 'wb').write("wrapper.py\\n") -os.system(string.join(sys.argv[1:], " ")) +args = filter(lambda s: s != 'fake_link_flag', sys.argv[1:]) +os.system(string.join(args, " ")) """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) test.write('SConstruct', """ foo = Environment() -link = foo.subst("$LINK") -bar = Environment(LINK = '', LINKFLAGS = r'%s wrapper.py ' + link) +bar = Environment(LINK = foo.subst(r'%s wrapper.py $LINK'), + LINKFLAGS = foo.subst('$LINKFLAGS fake_link_flag')) foo.Program(target = 'foo', source = 'foo.c') bar.Program(target = 'bar', source = 'bar.c') """ % python) @@ -73,7 +74,7 @@ main(int argc, char *argv[]) test.run(arguments = 'foo' + _exe) -test.fail_test(os.path.exists(test.workpath('wrapper.out'))) +test.must_not_exist(test.workpath('wrapper.out')) test.run(arguments = 'bar' + _exe) diff --git a/test/LINK/SHLINKFLAGS.py b/test/LINK/SHLINKFLAGS.py index 88e2442..c9ecf21 100644 --- a/test/LINK/SHLINKFLAGS.py +++ b/test/LINK/SHLINKFLAGS.py @@ -40,13 +40,14 @@ test.write("wrapper.py", import string import sys open('%s', 'wb').write("wrapper.py\\n") -os.system(string.join(sys.argv[1:], " ")) +args = filter(lambda s: s != 'fake_shlink_flag', sys.argv[1:]) +os.system(string.join(args, " ")) """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) test.write('SConstruct', """ foo = Environment() -bar = Environment(SHLINK = '', - SHLINKFLAGS = foo.subst(r'%s wrapper.py $SHLINK $SHLINKFLAGS')) +bar = Environment(SHLINK = foo.subst(r'%s wrapper.py $SHLINK'), + SHLINKFLAGS = foo.subst('$SHLINKFLAGS fake_shlink_flag')) foo.SharedLibrary(target = 'foo', source = 'foo.c') bar.SharedLibrary(target = 'bar', source = 'bar.c') """ % python) @@ -75,7 +76,7 @@ test() test.run(arguments = lib_ + 'foo' + _shlib) -test.fail_test(os.path.exists(test.workpath('wrapper.out'))) +test.must_not_exist(test.workpath('wrapper.out')) test.run(arguments = lib_ + 'bar' + _shlib) |