Commits

Anonymous committed 71820d1

Enhance EnsureSConsVersion() to take revision numbers, too. (Amir Szekely)

Comments (0)

Files changed (8)

 
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
-.RI EnsureSConsVersion( major ", " minor )
-.TP
-.RI env.EnsureSConsVersion( major ", " minor )
+.RI EnsureSConsVersion( major ", " minor ", [" revision ])
+.TP
+.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
 
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
   - 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.

src/engine/SCons/Script/SConscript.py

         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):
         """
     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)

test/EnsurePythonVersion.py

+#!/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()
+
+
+test.write('SConstruct', """\
+EnsurePythonVersion(0,0)
+Exit(0)
+""")
+
+test.run()
+
+test.write('SConstruct', """\
+EnsurePythonVersion(2000,0)
+Exit(0)
+""")
+
+test.run(status=2)
+
+test.write('SConstruct', """\
+import sys
+try:
+    delattr(sys, 'version_info')
+except AttributeError:
+    pass
+sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n'
+EnsurePythonVersion(1,3)
+Exit(0)
+""")
+
+test.run()
+
+test.write('SConstruct', """\
+import sys
+try:
+    delattr(sys, 'version_info')
+except AttributeError:
+    pass
+sys.version = '2.3+ (#0, Feb 24 2003, 19:13:11)\\n'
+EnsurePythonVersion(2,2)
+Exit(0)
+""")
+
+test.run()
+
+test.write('SConstruct', """\
+import sys
+try:
+    delattr(sys, 'version_info')
+except AttributeError:
+    pass
+sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n'
+EnsurePythonVersion(2,3)
+Exit(0)
+""")
+
+test.run()
+
+test.write('SConstruct', """\
+import sys
+try:
+    delattr(sys, 'version_info')
+except AttributeError:
+    pass
+sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n'
+EnsurePythonVersion(2,4)
+Exit(0)
+""")
+
+test.run(status=2)
+
+
+
+test.pass_test()

test/EnsureSConsVersion.py

+#!/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()

test/EnsureVersion.py

-#!/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', """
-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()
-EnsurePythonVersion(0,0)
-env.EnsureSConsVersion(2,0)
-sys.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.write('SConstruct', """
-import sys
-EnsurePythonVersion(2000,0)
-EnsureSConsVersion(2000,0)
-sys.exit(0)
-""")
-
-    test.run(status=2)
-
-test.write('SConstruct', """\
-import sys
-try:
-    delattr(sys, 'version_info')
-except AttributeError:
-    pass
-sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n'
-EnsurePythonVersion(1,3)
-sys.exit(0)
-""")
-
-test.run()
-
-test.write('SConstruct', """\
-import sys
-try:
-    delattr(sys, 'version_info')
-except AttributeError:
-    pass
-sys.version = '2.3+ (#0, Feb 24 2003, 19:13:11)\\n'
-EnsurePythonVersion(2,2)
-sys.exit(0)
-""")
-
-test.run()
-
-test.write('SConstruct', """\
-import sys
-try:
-    delattr(sys, 'version_info')
-except AttributeError:
-    pass
-sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n'
-EnsurePythonVersion(2,3)
-sys.exit(0)
-""")
-
-test.run()
-
-test.write('SConstruct', """\
-import sys
-try:
-    delattr(sys, 'version_info')
-except AttributeError:
-    pass
-sys.version = '2.3b1 (#0, Feb 24 2003, 19:13:11)\\n'
-EnsurePythonVersion(2,4)
-sys.exit(0)
-""")
-
-test.run(status=2)
-
-
-
-test.pass_test()

test/LINK/LINKFLAGS.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)
 
 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)
 

test/LINK/SHLINKFLAGS.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)
 
 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)