Portability fixes for tests on Windows Nt.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 17 Oct 2001 16:42:21 +0000 (16:42 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 17 Oct 2001 16:42:21 +0000 (16:42 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@102 fdb21ef1-2011-0410-befe-b5e4ea1792b1

24 files changed:
src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
src/engine/SCons/Defaults.py
src/engine/SCons/Node/FSTests.py
src/engine/SCons/Sig/MD5.py
src/engine/SCons/UtilTests.py
src/script/scons.py
test/CC.py
test/Command.py
test/Default.py
test/Depends.py
test/ENV.py
test/LINK.py
test/LINKFLAGS.py
test/builderrors.py
test/multiline.py
test/option--.py
test/option-c.py
test/option-i.py
test/option-j.py
test/option-k.py
test/option-n.py
test/option-s.py
test/up-to-date.py

index 1f4f555f37529a214563a74abad1483f92f1c9e6..1e3c9b9aa494f39e2c15b578a106d1f5865bbf35 100644 (file)
@@ -32,6 +32,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 
 import os
+import os.path
 import SCons.Node.FS
 from SCons.Util import PathList, scons_str2nodes, scons_subst
 import string
@@ -39,6 +40,62 @@ import types
 
 
 
+if os.name == 'posix':
+
+    def spawn(cmd, args, env):
+        pid = os.fork()
+        if not pid:
+            # Child process.
+            os.execvpe(cmd, args, env)
+        else:
+            # Parent process.
+            pid, stat = os.waitpid(pid, 0)
+            ret = stat >> 8
+           return ret
+
+elif os.name == 'nt':
+
+    def pathsearch(cmd, env):
+       # In order to deal with the fact that 1.5.2 doesn't have
+       # os.spawnvpe(), roll our own PATH search.
+       if os.path.isabs(cmd):
+           if not os.path.exists(cmd):
+               exts = env['PATHEXT']
+               if type(exts) != type([]):
+                   exts = string.split(exts, os.pathsep)
+               for e in exts:
+                   f = cmd + e
+                   if os.path.exists(f):
+                       return f
+       else:
+           path = env['PATH']
+           if type(path) != type([]):
+               path = string.split(path, os.pathsep)
+           exts = env['PATHEXT']
+           if type(exts) != type([]):
+               exts = string.split(exts, os.pathsep)
+           pairs = []
+           for dir in path:
+               for e in [None] + exts:
+                   pairs.append(dir, e)
+           for dir, ext in pairs:
+               f = os.path.join(dir, cmd)
+               if not ext is None:
+                   f = f + ext
+               if os.path.exists(f):
+                   return f
+       return cmd
+
+    def spawn(cmd, args, env):
+        try:
+           ret = os.spawnvpe(os.P_WAIT, cmd, args, env)
+       except AttributeError:
+           cmd = pathsearch(cmd, env)
+           ret = os.spawnve(os.P_WAIT, cmd, args, env)
+        return ret
+
+
+
 def Builder(**kw):
     """A factory for builder objects."""
     if kw.has_key('builders'):
@@ -230,20 +287,13 @@ class CommandAction(ActionBase):
            self.show(cmd)
        ret = 0
        if execute_actions:
-           pid = os.fork()
-           if not pid:
-               # Child process.
-               args = string.split(cmd)
-               try:
-                   ENV = kw['env']['ENV']
-               except:
-                   import SCons.Defaults
-                   ENV = SCons.Defaults.ConstructionEnvironment['ENV']
-               os.execvpe(args[0], args, ENV)
-           else:
-               # Parent process.
-               pid, stat = os.waitpid(pid, 0)
-               ret = stat >> 8
+            args = string.split(cmd)
+            try:
+                ENV = glob['ENV']
+            except:
+                import SCons.Defaults
+                ENV = SCons.Defaults.ConstructionEnvironment['ENV']
+           ret = spawn(args[0], args, ENV)
        return ret
 
 
index e84799aaeadf74e2019b6702f04c65b0b9373299..a446f951c2bd090a3886b9e7e4eb4eeeb20e9163 100644 (file)
@@ -111,7 +111,9 @@ class BuilderTestCase(unittest.TestCase):
        containing one of each.
        """
 
-       cmd1 = "python %s %s xyzzy" % (act_py, outfile)
+       python = sys.executable
+
+       cmd1 = r'%s %s %s xyzzy' % (python, act_py, outfile)
 
        builder = SCons.Builder.Builder(action = cmd1)
        r = builder.execute()
@@ -119,7 +121,7 @@ class BuilderTestCase(unittest.TestCase):
        c = test.read(outfile, 'r')
        assert c == "act.py: xyzzy\n", c
 
-       cmd2 = "python %s %s $target" % (act_py, outfile)
+       cmd2 = r'%s %s %s $target' % (python, act_py, outfile)
 
        builder = SCons.Builder.Builder(action = cmd2)
        r = builder.execute(target = 'foo')
@@ -127,7 +129,7 @@ class BuilderTestCase(unittest.TestCase):
        c = test.read(outfile, 'r')
        assert c == "act.py: foo\n", c
 
-       cmd3 = "python %s %s ${targets}" % (act_py, outfile)
+       cmd3 = r'%s %s %s ${targets}' % (python, act_py, outfile)
 
        builder = SCons.Builder.Builder(action = cmd3)
        r = builder.execute(target = ['aaa', 'bbb'])
@@ -135,7 +137,7 @@ class BuilderTestCase(unittest.TestCase):
        c = test.read(outfile, 'r')
        assert c == "act.py: aaa bbb\n", c
 
-       cmd4 = "python %s %s $sources" % (act_py, outfile)
+       cmd4 = r'%s %s %s $sources' % (python, act_py, outfile)
 
        builder = SCons.Builder.Builder(action = cmd4)
        r = builder.execute(source = ['one', 'two'])
@@ -143,7 +145,7 @@ class BuilderTestCase(unittest.TestCase):
        c = test.read(outfile, 'r')
        assert c == "act.py: one two\n", c
 
-       cmd4 = "python %s %s ${sources[:2]}" % (act_py, outfile)
+       cmd4 = r'%s %s %s ${sources[:2]}' % (python, act_py, outfile)
 
        builder = SCons.Builder.Builder(action = cmd4)
        r = builder.execute(source = ['three', 'four', 'five'])
@@ -151,7 +153,7 @@ class BuilderTestCase(unittest.TestCase):
        c = test.read(outfile, 'r')
        assert c == "act.py: three four\n", c
 
-       cmd5 = "python %s %s $target XYZZY" % (act_py, outfile)
+       cmd5 = r'%s %s %s $target XYZZY' % (python, act_py, outfile)
 
        builder = SCons.Builder.Builder(action = cmd5)
        r = builder.execute(target = 'out5', env = {'ENV' : {'XYZZY' : 'xyzzy'}})
@@ -190,7 +192,7 @@ class BuilderTestCase(unittest.TestCase):
        c = test.read(outfile, 'r')
        assert c == "class1b\n", c
 
-       cmd2 = "python %s %s syzygy" % (act_py, outfile)
+       cmd2 = r'%s %s %s syzygy' % (python, act_py, outfile)
 
        def function2(kw):
            open(kw['out'], 'a').write("function2\n")
index eeaa02a83e9c436ee14d874e764607e975ab7583..086c1d55188ddae9d61fc0c17e7ca7571e8811e3 100644 (file)
@@ -33,30 +33,70 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 
 
+import os
 import SCons.Builder
 
 
 
+if os.name == 'posix':
+
+    object_suffix = '.o'
+    program_suffix = None
+    library_prefix = 'lib'
+    library_suffix = '.a'
+
+elif os.name == 'nt':
+
+    object_suffix = '.obj'
+    program_suffix = '.exe'
+    library_prefix = None
+    library_suffix = '.lib'
+
+
+
 Object = SCons.Builder.Builder(name = 'Object',
-                               action = '$CC $CCFLAGS -c -o $target $sources',
-                               src_suffix='.c',
-                               suffix='.o')
+                               action = '$CCCOM',
+                               suffix = object_suffix,
+                               src_suffix = '.c')
 
 Program = SCons.Builder.Builder(name = 'Program',
-                                action = '$LINK $LINKFLAGS -o $target $sources',
+                                action = '$LINKCOM',
+                                suffix = program_suffix,
                                 builders = [ Object ])
 
 Library = SCons.Builder.Builder(name = 'Library',
                                 action = 'ar r $target $sources\nranlib $target',
-                                prefix = 'lib',
-                                suffix = '.a',
+                                prefix = library_prefix,
+                                suffix = library_suffix,
                                 builders = [ Object ])
 
-ConstructionEnvironment = {
-       'CC' : 'cc',
-       'CCFLAGS' : '',
-       'LINK' : '$CC',
-       'LINKFLAGS' : '',
-       'BUILDERS' : [Object, Program, Library],
-       'ENV' : { 'PATH' : '/usr/local/bin:/bin:/usr/bin' },
-}
+
+
+if os.name == 'posix':
+
+    ConstructionEnvironment = {
+        'CC'        : 'cc',
+        'CCFLAGS'   : '',
+        'CCCOM'     : '$CC $CCFLAGS -c -o $target $sources',
+        'LINK'      : '$CC',
+        'LINKFLAGS' : '',
+        'LINKCOM'   : '$LINK $LINKFLAGS -o $target $sources',
+        'BUILDERS'  : [Object, Program, Library],
+        'ENV'       : { 'PATH' : '/usr/local/bin:/bin:/usr/bin' },
+    }
+
+elif os.name == 'nt':
+
+    ConstructionEnvironment = {
+        'CC'        : 'cl',
+        'CCFLAGS'   : '/nologo',
+        'CCCOM'     : '$CC $CCFLAGS /c $sources /Fo$target',
+        'LINK'      : 'link',
+        'LINKFLAGS' : '',
+        'LINKCOM'   : '$LINK $LINKFLAGS /out:$target $sources',
+        'BUILDERS'  : [Object, Program, Library],
+        'ENV'       : {
+                        'PATH'    : r'C:\Python20;C:\WINNT\system32;C:\WINNT;C:\Program Files\Microsoft Visual Studio\VC98\Bin\;',
+                        'PATHEXT' : '.COM;.EXE;.BAT;.CMD'
+                      },
+    }
index fc0a0a30978ffe6a4a89df53c1824726545459b7..6f2a5a7535bdd2c029093ebb57edcb7fcc2f9283 100644 (file)
@@ -24,6 +24,7 @@
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
+import string
 import sys
 import unittest
 
@@ -69,70 +70,90 @@ class FSTestCase(unittest.TestCase):
 
         fs = SCons.Node.FS.FS()
 
-        def Dir_test(lpath, path, abspath, up_path, fileSys=fs):
-            dir = fileSys.Dir(lpath)
-            assert dir.path == path, "Dir.path %s != expected path %s" % \
-                   (dir.path, path)
-            assert str(dir) == path, "str(dir) %s != expected path %s" % \
-                   (str(dir), path)
-            assert dir.abspath == abspath, "Dir.abspath %s != expected abs. path %s" % \
-                   (dir.abspath, path)
-            assert dir.up().path == up_path, "Dir.up().path %s != expected parent path %s" % \
-                   (dir.up().path, up_path)
-
-        Dir_test('foo',         'foo/',         sub_dir_foo,            '.')
-        Dir_test('foo/bar',     'foo/bar/',     sub_dir_foo_bar,        'foo/')
-        Dir_test('/foo',        '/foo/',        '/foo/',                '/')
-        Dir_test('/foo/bar',    '/foo/bar/',    '/foo/bar/',            '/foo/')
-        Dir_test('..',          sub,            sub,                    wp)
-        Dir_test('foo/..',      '.',            sub_dir,                sub)
-        Dir_test('../foo',      sub_foo,        sub_foo,                sub)
-        Dir_test('.',           '.',            sub_dir,                sub)
-        Dir_test('./.',         '.',            sub_dir,                sub)
-        Dir_test('foo/./bar',   'foo/bar/',     sub_dir_foo_bar,        'foo/')
-
         d1 = fs.Dir('d1')
 
         f1 = fs.File('f1', directory = d1)
 
-        assert d1.current() == 0
-        assert f1.current() == 0
-
-        assert f1.path == 'd1/f1', "f1.path %s != d1/f1" % f1.path
-        assert str(f1) == 'd1/f1', "str(f1) %s != d1/f1" % str(f1)
-
-        try:
-            f2 = fs.File('f1/f2', directory = d1)
-        except TypeError, x:
-           assert str(x) == "Tried to lookup File 'd1/f1' as a Dir.", x
-        except:
-            raise
-
-        try:
-            dir = fs.Dir('d1/f1')
-        except TypeError, x:
-           assert str(x) == "Tried to lookup File 'd1/f1' as a Dir.", x
-        except:
-            raise
-
-       try:
-           f2 = fs.File('d1')
-       except TypeError, x:
-           assert str(x) == "Tried to lookup Dir 'd1/' as a File.", x
-       except:
-           raise
-
-       # Test Dir.children()
-       dir = fs.Dir('ddd')
-       fs.File('ddd/f1')
-       fs.File('ddd/f2')
-       fs.File('ddd/f3')
-       fs.Dir('ddd/d1')
-       fs.Dir('ddd/d1/f4')
-       fs.Dir('ddd/d1/f5')
-       kids = map(lambda x: x.path, dir.children())
-       kids.sort()
-       assert kids == ['ddd/d1/', 'ddd/f1', 'ddd/f2', 'ddd/f3']
+        d1_f1 = os.path.join('d1', 'f1')
+        assert f1.path == d1_f1, "f1.path %s != %s" % (f1.path, d1_f1)
+        assert str(f1) == d1_f1, "str(f1) %s != %s" % (str(f1), d1_f1)
+
+        seps = [os.sep]
+        if os.sep != '/':
+            seps = seps + ['/']
+
+        for sep in seps:
+
+            def Dir_test(lpath, path, abspath, up_path, fileSys=fs, s=sep):
+                dir = fileSys.Dir(string.replace(lpath, '/', s))
+
+               if os.sep != '/':
+                    path = string.replace(path, '/', os.sep)
+                    abspath = string.replace(abspath, '/', os.sep)
+                    up_path = string.replace(up_path, '/', os.sep)
+
+                assert dir.path == path, \
+                       "dir.path %s != expected path %s" % \
+                       (dir.path, path)
+                assert str(dir) == path, \
+                       "str(dir) %s != expected path %s" % \
+                       (str(dir), path)
+                assert dir.abspath == abspath, \
+                       "dir.abspath %s != expected absolute path %s" % \
+                       (dir.abspath, abspath)
+                assert dir.up().path == up_path, \
+                       "dir.up().path %s != expected parent path %s" % \
+                       (dir.up().path, up_path)
+
+            Dir_test('foo',         'foo/',        sub_dir_foo,       '.')
+            Dir_test('foo/bar',     'foo/bar/',    sub_dir_foo_bar,   'foo/')
+            Dir_test('/foo',        '/foo/',       '/foo/',           '/')
+            Dir_test('/foo/bar',    '/foo/bar/',   '/foo/bar/',       '/foo/')
+            Dir_test('..',          sub,           sub,               wp)
+            Dir_test('foo/..',      '.',           sub_dir,           sub)
+            Dir_test('../foo',      sub_foo,       sub_foo,           sub)
+            Dir_test('.',           '.',           sub_dir,           sub)
+            Dir_test('./.',         '.',           sub_dir,           sub)
+            Dir_test('foo/./bar',   'foo/bar/',    sub_dir_foo_bar,   'foo/')
+
+            try:
+                f2 = fs.File(string.join(['f1', 'f2'], sep), directory = d1)
+            except TypeError, x:
+               assert str(x) == ("Tried to lookup File '%s' as a Dir." %
+                                 d1_f1), x
+            except:
+                raise
+
+            try:
+                dir = fs.Dir(string.join(['d1', 'f1'], sep))
+            except TypeError, x:
+               assert str(x) == ("Tried to lookup File '%s' as a Dir." %
+                                 d1_f1), x
+            except:
+                raise
+
+            try:
+                f2 = fs.File('d1')
+            except TypeError, x:
+                assert str(x) == ("Tried to lookup Dir '%s' as a File." %
+                                 os.path.join('d1', '')), x
+            except:
+               raise
+
+            # Test Dir.children()
+            dir = fs.Dir('ddd')
+            fs.File(string.join(['ddd', 'f1'], sep))
+            fs.File(string.join(['ddd', 'f2'], sep))
+            fs.File(string.join(['ddd', 'f3'], sep))
+            fs.Dir(string.join(['ddd', 'd1'], sep))
+            fs.Dir(string.join(['ddd', 'd1', 'f4'], sep))
+            fs.Dir(string.join(['ddd', 'd1', 'f5'], sep))
+            kids = map(lambda x: x.path, dir.children())
+            kids.sort()
+            assert kids == [os.path.join('ddd', 'd1', ''),
+                           os.path.join('ddd', 'f1'),
+                           os.path.join('ddd', 'f2'),
+                           os.path.join('ddd', 'f3')]
 
         # Test for sub-classing of node building.
         global built_it
index 4004e233eedf41c7c6aaf7db58c177edb2bf3e80..11ba96106b5852edea7f0f735da0a7fc176a5269 100644 (file)
@@ -30,9 +30,19 @@ utility.
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import md5
+import imp
 import string
 
+# Force Python to load the builtin "md5" module.  If we do this with a
+# normal import statement, then case-insensitive systems (Win32) get
+# confused and thinks there's a case mismatch with *this* MD5.py module.
+file, name, desc = imp.find_module('md5')
+try:
+    md5 = imp.load_module('md5', file, name, desc)
+finally:
+    if file:
+        file.close()
+
 def current(new, old):
     """Return whether a new signature is up-to-date with
     respect to an old signature.
index bbaf851f5d4fd2b569d9cb47c166cc80fc4deac6..7df0c83b1dab3aa58da22a3403bd776ce0b8f25c 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import sys
+import os
 import os.path
+import string
+import sys
 import unittest
 import SCons.Node
 import SCons.Node.FS
@@ -83,35 +85,43 @@ class UtilTestCase(unittest.TestCase):
                                                           "/bar/ack.cpp",
                                                           "../foo/ack.c" ]))
 
+        if os.sep == '/':
+            def cvt(str):
+                return str
+        else:
+            def cvt(str):
+                return string.replace(str, '/', os.sep)
+
+
         newcom = scons_subst("test $targets $sources", loc, {})
-       assert newcom == "test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp /bar/ack.cpp ../foo/ack.c"
+        assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp /bar/ack.cpp ../foo/ack.c")
 
         newcom = scons_subst("test ${targets[:]} ${sources[0]}", loc, {})
-       assert newcom == "test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp"
+        assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp")
 
         newcom = scons_subst("test ${targets[1:]}v", loc, {})
-       assert newcom == "test /bar/baz.obj ../foo/baz.objv"
+        assert newcom == cvt("test /bar/baz.obj ../foo/baz.objv")
 
         newcom = scons_subst("test $target", loc, {})
-       assert newcom == "test foo/bar.exe"
+        assert newcom == cvt("test foo/bar.exe")
 
         newcom = scons_subst("test $target$source[0]", loc, {})
-       assert newcom == "test foo/bar.exe[0]"
+        assert newcom == cvt("test foo/bar.exe[0]")
 
         newcom = scons_subst("test ${target.file}", loc, {})
-       assert newcom == "test bar.exe"
+        assert newcom == cvt("test bar.exe")
 
         newcom = scons_subst("test ${target.filebase}", loc, {})
-       assert newcom == "test bar"
+        assert newcom == cvt("test bar")
 
         newcom = scons_subst("test ${target.suffix}", loc, {})
-       assert newcom == "test .exe"
+        assert newcom == cvt("test .exe")
 
         newcom = scons_subst("test ${target.base}", loc, {})
-       assert newcom == "test foo/bar"
+        assert newcom == cvt("test foo/bar")
 
         newcom = scons_subst("test ${target.dir}", loc, {})
-       assert newcom == "test foo"
+        assert newcom == cvt("test foo")
 
 
 
index b8dc2ff705dc37036338439696d9a49c5c1bfb78..18347b47bdfd3a16dd73a4f7f21bdc15518ffe72 100644 (file)
@@ -33,6 +33,11 @@ import string
 import sys
 import traceback
 
+# Strip the script directory from sys.path() so on case-insensitive
+# (WIN32) systems Python doesn't think that the "scons" script is the
+# "SCons" package.
+sys.path = sys.path[1:]
+
 import SCons.Node
 import SCons.Node.FS
 import SCons.Job
index ce18047ab252fb0fa969bdca3e708ebd16be6caa..5d2985f694d174d706cb3e26a7fe8d47f876f138 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.write("ccwrapper.py",
 """import os
 import string
 import sys
-open('%s', 'w').write("ccwrapper.py\\n")
+open('%s', 'wb').write("ccwrapper.py\\n")
 os.system(string.join(["cc"] + sys.argv[1:], " "))
 """ % test.workpath('ccwrapper.out'))
 
 test.write('SConstruct', """
 foo = Environment()
-bar = Environment(CC = 'python ccwrapper.py')
+bar = Environment(CC = r'%s ccwrapper.py')
 foo.Program(target = 'foo', source = 'foo.c')
 bar.Program(target = 'bar', source = 'bar.c')
-""")
+""" % python)
 
 test.write('foo.c', """
 int
index 5b592b977dee88d415c224b46a7e664adb4b1e15..c3080cbc53c7f49f9c3998f6facb230d49808109 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.write('build.py', r"""
 import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read()
+file = open(sys.argv[1], 'wb')
 file.write(contents)
 file.close()
 """)
@@ -39,14 +42,14 @@ file.close()
 test.write('SConstruct', """
 env = Environment()
 env.Command(target = 'f1.out', source = 'f1.in',
-               action = "python build.py $target $sources")
+            action = r'%s build.py $target $sources')
 env.Command(target = 'f2.out', source = 'f2.in',
-               action = "python build.py temp2 $sources\\npython build.py $target temp2")
+            action = r'%s' + " build.py temp2 $sources\\n" + r'%s' + " build.py $target temp2")
 env.Command(target = 'f3.out', source = 'f3.in',
-               action = ["python build.py temp3 $sources",
-                         "python build.py $target temp3"])
+            action = [r'%s build.py temp3 $sources',
+                      r'%s build.py $target temp3'])
 # Eventually, add ability to do execute Python code.
-""")
+""" % (python, python, python, python, python))
 
 test.write('f1.in', "f1.in\n")
 
index 515a9c0b49481ef15148b14d9bc0bbeb9ee2ad4a..9155660d09dc41819937f7e4bd2acca93b1fb497 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.subdir('one', 'two', 'three')
 
 test.write('build.py', r"""
 import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read()
+file = open(sys.argv[1], 'wb')
 file.write(contents)
 file.close()
 """)
 
 test.write(['one', 'SConstruct'], """
-B = Builder(name = 'B', action = "python ../build.py $target $sources")
+B = Builder(name = 'B', action = r'%s ../build.py $target $sources')
 env = Environment(BUILDERS = [B])
 env.B(target = 'foo.out', source = 'foo.in')
 env.B(target = 'bar.out', source = 'bar.in')
 Default('foo.out')
-""")
+""" % python)
 
 test.write(['two', 'SConstruct'], """
-B = Builder(name = 'B', action = "python ../build.py $target $sources")
+B = Builder(name = 'B', action = r'%s ../build.py $target $sources')
 env = Environment(BUILDERS = [B])
 env.B(target = 'foo.out', source = 'foo.in')
 env.B(target = 'bar.out', source = 'bar.in')
 Default('foo.out', 'bar.out')
-""")
+""" % python)
 
 test.write(['three', 'SConstruct'], """
-B = Builder(name = 'B', action = "python ../build.py $target $sources")
+B = Builder(name = 'B', action = r'%s ../build.py $target $sources')
 env = Environment(BUILDERS = [B])
 env.B(target = 'foo.out', source = 'foo.in')
 env.B(target = 'bar.out', source = 'bar.in')
 Default('foo.out bar.out')
-""")
+""" % python)
 
 for dir in ['one', 'two', 'three']:
 
index 61ebb0af9cfa682b3946e1baf88159d09ceac896..03033b1745ee296cd527f25ef2c7026089e6dfd3 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.subdir('subdir')
 
 test.write('build.py', r"""
 import sys
-contents = open(sys.argv[2], 'r').read() + open(sys.argv[3], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read() + open(sys.argv[3], 'rb').read()
+file = open(sys.argv[1], 'wb')
 file.write(contents)
 file.close()
 """)
 
 test.write('SConstruct', """
 Foo = Builder(name = "Foo",
-         action = "python build.py $target $sources subdir/foo.dep")
+              action = "%s build.py $target $sources subdir/foo.dep")
 Bar = Builder(name = "Bar",
-         action = "python build.py $target $sources subdir/bar.dep")
+              action = "%s build.py $target $sources subdir/bar.dep")
 env = Environment(BUILDERS = [Foo, Bar])
 env.Depends(target = ['f1.out', 'f2.out'], dependency = 'subdir/foo.dep')
 env.Depends(target = 'f3.out', dependency = 'subdir/bar.dep')
@@ -50,7 +53,7 @@ env.Foo(target = 'f1.out', source = 'f1.in')
 env.Foo(target = 'f2.out', source = 'f2.in')
 env.Bar(target = 'f3.out', source = 'f3.in')
 Conscript('subdir/SConscript')
-""")
+""" % (python, python))
 
 test.write(['subdir', 'SConscript'], """
 env.Depends(target = 'f4.out', dependency = 'bar.dep')
index db513273b40f2719926640683feb8eec1c0dd48e..221e7f9655ad3db59a4dfd2d0f02673bb31da058 100644 (file)
@@ -50,8 +50,8 @@ bin2.Bld(target = 'bin2.out', source = 'input')
 test.write(bin1_build_py,
 """#!/usr/bin/env python
 import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read()
+file = open(sys.argv[1], 'wb')
 file.write("bin1/build.py\\n")
 file.write(contents)
 file.close()
@@ -61,8 +61,8 @@ os.chmod(bin1_build_py, 0755)
 test.write(bin2_build_py,
 """#!/usr/bin/env python
 import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read()
+file = open(sys.argv[1], 'wb')
 file.write("bin2/build.py\\n")
 file.write(contents)
 file.close()
index f2ac661de3ffad0740e9c66af2af9fd7c4c09603..6b9997663fe56d301e90768bc044ef823c4170ac 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.write("ccwrapper.py",
 """import os
 import string
 import sys
-open('%s', 'w').write("ccwrapper.py\\n")
+open('%s', 'wb').write("ccwrapper.py\\n")
 os.system(string.join(["cc"] + sys.argv[1:], " "))
 """ % test.workpath('ccwrapper.out'))
 
 test.write('SConstruct', """
 foo = Environment()
-bar = Environment(LINK = 'python ccwrapper.py')
+bar = Environment(LINK = r'%s ccwrapper.py')
 foo.Program(target = 'foo', source = 'foo.c')
 bar.Program(target = 'bar', source = 'bar.c')
-""")
+""" % python)
 
 test.write('foo.c', """
 int
index 06c148238a76e20903fdc4ee61607643bddeedc6..ff4ee880ed85c3f1e232f4db1811ff9d87684605 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.write("ccwrapper.py",
 """import os
 import string
 import sys
-open('%s', 'w').write("ccwrapper.py\\n")
+open('%s', 'wb').write("ccwrapper.py\\n")
 os.system(string.join(["cc"] + sys.argv[1:], " "))
 """ % test.workpath('ccwrapper.out'))
 
 test.write('SConstruct', """
 foo = Environment()
-bar = Environment(LINK = '', LINKFLAGS = 'python ccwrapper.py')
+bar = Environment(LINK = '', LINKFLAGS = r'%s ccwrapper.py')
 foo.Program(target = 'foo', source = 'foo.c')
 bar.Program(target = 'bar', source = 'bar.c')
-""")
+""" % python)
 
 test.write('foo.c', """
 int
index fad003abfd6ccfe9b58c7aaa6af619583e77e3e3..769215a9f0135b60b6c6e1e62cb6347abf7578a1 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.subdir('one', 'two', 'three')
@@ -35,21 +38,21 @@ test.write('build.py', r"""
 import sys
 exitval = int(sys.argv[1])
 if exitval == 0:
-    contents = open(sys.argv[3], 'r').read()
-    file = open(sys.argv[2], 'w')
+    contents = open(sys.argv[3], 'rb').read()
+    file = open(sys.argv[2], 'wb')
     file.write(contents)
     file.close()
 sys.exit(exitval)
 """)
 
 test.write(['one', 'SConstruct'], """
-B0 = Builder(name = 'B0', action = "python ../build.py 0 $target $sources")
-B1 = Builder(name = 'B1', action = "python ../build.py 1 $target $sources")
+B0 = Builder(name = 'B0', action = r'%s ../build.py 0 $target $sources')
+B1 = Builder(name = 'B1', action = r'%s ../build.py 1 $target $sources')
 env = Environment(BUILDERS = [B0, B1])
 env.B1(target = 'f1.out', source = 'f1.in')
 env.B0(target = 'f2.out', source = 'f2.in')
 env.B0(target = 'f3.out', source = 'f3.in')
-""")
+""" % (python, python))
 
 test.write(['one', 'f1.in'], "one/f1.in\n")
 test.write(['one', 'f2.in'], "one/f2.in\n")
@@ -63,13 +66,13 @@ test.fail_test(os.path.exists(test.workpath('f2.out')))
 test.fail_test(os.path.exists(test.workpath('f3.out')))
 
 test.write(['two', 'SConstruct'], """
-B0 = Builder(name = 'B0', action = "python ../build.py 0 $target $sources")
-B1 = Builder(name = 'B1', action = "python ../build.py 1 $target $sources")
+B0 = Builder(name = 'B0', action = r'%s ../build.py 0 $target $sources')
+B1 = Builder(name = 'B1', action = r'%s ../build.py 1 $target $sources')
 env = Environment(BUILDERS = [B0, B1])
 env.B0(target = 'f1.out', source = 'f1.in')
 env.B1(target = 'f2.out', source = 'f2.in')
 env.B0(target = 'f3.out', source = 'f3.in')
-""")
+""" % (python, python))
 
 test.write(['two', 'f1.in'], "two/f1.in\n")
 test.write(['two', 'f2.in'], "two/f2.in\n")
@@ -83,13 +86,13 @@ test.fail_test(os.path.exists(test.workpath('f2.out')))
 test.fail_test(os.path.exists(test.workpath('f3.out')))
 
 test.write(['three', 'SConstruct'], """
-B0 = Builder(name = 'B0', action = "python ../build.py 0 $target $sources")
-B1 = Builder(name = 'B1', action = "python ../build.py 1 $target $sources")
+B0 = Builder(name = 'B0', action = r'%s ../build.py 0 $target $sources')
+B1 = Builder(name = 'B1', action = r'%s ../build.py 1 $target $sources')
 env = Environment(BUILDERS = [B0, B1])
 env.B0(target = 'f1.out', source = 'f1.in')
 env.B0(target = 'f2.out', source = 'f2.in')
 env.B1(target = 'f3.out', source = 'f3.in')
-""")
+""" % (python, python))
 
 test.write(['three', 'f1.in'], "three/f1.in\n")
 test.write(['three', 'f2.in'], "three/f2.in\n")
index dca0b00ffcf69d520f717047d663641a5f0ae8e9..7560d5594ddf61ce43dd7cd8d263f57ca9feba79 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os.path
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.write('build.py', r"""
 import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read()
+file = open(sys.argv[1], 'wb')
 file.write(contents)
 file.close()
 sys.exit(0)
 """)
 
 test.write('SConstruct', """
-B1 = Builder(name = 'B1', action = ["python build.py .temp $sources",
-                                   "python build.py $targets .temp"])
-B2 = Builder(name = 'B2', action = "python build.py .temp $sources\\npython build.py $targets .temp")
+B1 = Builder(name = 'B1', action = [r'%s build.py .temp $sources',
+                                    r'%s build.py $targets .temp'])
+B2 = Builder(name = 'B2', action = r'%s' + " build.py .temp $sources\\n" + r'%s' + " build.py $targets .temp")
 env = Environment(BUILDERS = [B1, B2])
 env.B1(target = 'foo1.out', source = 'foo1.in')
 env.B2(target = 'foo2.out', source = 'foo2.in')
 env.B1(target = 'foo3.out', source = 'foo3.in')
-""")
+""" % (python, python, python, python))
 
 test.write('foo1.in', "foo1.in\n")
 
index e9f427a1d2d57e7c657f3c55069386e5a3a651b9..9fca2bd97adff2ea941a38d96f17fcf9f7011bea 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import TestSCons
 import os.path
 import string
 import sys
+import TestSCons
+
+python = sys.executable
 
 test = TestSCons.TestSCons()
 
 test.write('build.py', r"""
 import sys
-file = open(sys.argv[1], 'w')
+file = open(sys.argv[1], 'wb')
 file.write("build.py: %s\n" % sys.argv[1])
 file.close()
 """)
 
 test.write('SConstruct', """
 MyBuild = Builder(name = "MyBuild",
-                 action = "python build.py $targets")
+                  action = r'%s build.py $targets')
 env = Environment(BUILDERS = [MyBuild])
 env.MyBuild(target = '-f1.out', source = 'f1.in')
 env.MyBuild(target = '-f2.out', source = 'f2.in')
-""")
+""" % python)
 
-expect = "python build.py -f1.out\npython build.py -f2.out\n"
+expect = "%s build.py -f1.out\n%s build.py -f2.out\n" % (python, python)
 
 test.run(arguments = '-- -f1.out -f2.out', stdout = expect)
 test.fail_test(not os.path.exists(test.workpath('-f1.out')))
index 76a60e95a12ccd5332c44eb1fbbc8e102951c277..0e41ffd6f053941dd24add5cf5400e4556312083 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os.path
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.write('build.py', r"""
 import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read()
+file = open(sys.argv[1], 'wb')
 file.write(contents)
 file.close()
 """)
 
 test.write('SConstruct', """
-B = Builder(name = 'B', action = "python build.py $targets $sources")
+B = Builder(name = 'B', action = r'%s build.py $targets $sources')
 env = Environment(BUILDERS = [B])
 env.B(target = 'foo1.out', source = 'foo1.in')
 env.B(target = 'foo2.out', source = 'foo2.in')
 env.B(target = 'foo3.out', source = 'foo3.in')
-""")
+""" % python)
 
 test.write('foo1.in', "foo1.in\n")
 
index 3301396d0b394a5fda4a8f79749d822adf68d063..713655c4eae23e05da761c4c3d4e90f4164eda21 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os.path
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.write('succeed.py', r"""
 import sys
-file = open(sys.argv[1], 'w')
+file = open(sys.argv[1], 'wb')
 file.write("succeed.py: %s\n" % sys.argv[1])
 file.close()
 sys.exit(0)
@@ -43,14 +46,14 @@ sys.exit(1)
 """)
 
 test.write('SConstruct', """
-Succeed = Builder(name = "Succeed", action = "python succeed.py $targets")
-Fail = Builder(name = "Fail", action = "python fail.py $targets")
+Succeed = Builder(name = "Succeed", action = r'%s succeed.py $targets')
+Fail = Builder(name = "Fail", action = r'%s fail.py $targets')
 env = Environment(BUILDERS = [Succeed, Fail])
 env.Fail(target = 'aaa.1', source = 'aaa.in')
 env.Succeed(target = 'aaa.out', source = 'aaa.1')
 env.Fail(target = 'bbb.1', source = 'bbb.in')
 env.Succeed(target = 'bbb.out', source = 'bbb.1')
-""")
+""" % (python, python))
 
 test.run(arguments = 'aaa.1 aaa.out bbb.1 bbb.out',
          stderr = 'scons: *** [aaa.1] Error 1\n')
index 80cbccacedb3416d6bd6fa6c0eca6e9a415dc3fc..3eb0b12d95a7216f5e3e11ebdb4316937ae16ebf 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import TestSCons
 import string
 import sys
+import TestSCons
 
+python = sys.executable
 
 try:
     import threading
@@ -43,7 +44,7 @@ test = TestSCons.TestSCons()
 test.write('build.py', r"""
 import time
 import sys
-file = open(sys.argv[1], 'w')
+file = open(sys.argv[1], 'wb')
 file.write(str(time.time()) + '\n')
 time.sleep(1)
 file.write(str(time.time()))
@@ -52,11 +53,11 @@ file.close()
 
 test.write('SConstruct', """
 MyBuild = Builder(name = "MyBuild",
-                 action = "python build.py $targets")
+                  action = r'%s build.py $targets')
 env = Environment(BUILDERS = [MyBuild])
 env.MyBuild(target = 'f1', source = 'f1.in')
 env.MyBuild(target = 'f2', source = 'f2.in')
-""")
+""" % python)
 
 def RunTest(args, extra):
     """extra is used to make scons rebuild the output file"""
index e8fead2363a500330d25a97d03fd4f1d84912bcf..4034d831ea0db57335f109eed83d070b7563d1cc 100644 (file)
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os.path
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.pass_test()       #XXX Short-circuit until this is supported.
 
 test.write('succeed.py', r"""
 import sys
-file = open(sys.argv[1], 'w')
+file = open(sys.argv[1], 'wb')
 file.write("succeed.py: %s\n" % sys.argv[1])
 file.close()
 sys.exit(0)
@@ -45,13 +48,13 @@ sys.exit(1)
 """)
 
 test.write('SConstruct', """
-Succeed = Builder(name = "Succeed", action = "python succeed.py $targets")
-Fail = Builder(name = "Fail", action = "python fail.py $targets")
+Succeed = Builder(name = "Succeed", action = r'%s succeed.py $targets')
+Fail = Builder(name = "Fail", action = r'%s fail.py $targets')
 env = Environment(BUILDERS = [Succeed, Fail])
 env.Fail(target = 'aaa.1', source = 'aaa.in')
 env.Succeed(target = 'aaa.out', source = 'aaa.1')
 env.Succeed(target = 'bbb.out', source = 'bbb.in')
-""")
+""" % (python, python))
 
 test.run(arguments = '.')
 
index cba2e96662e75e299893ec55681d9e8c7f08f66d..0a111010c2e35196f7edd06d4f60252dadfb0cf0 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import TestSCons
 import os.path
 import string
 import sys
+import TestSCons
+
+python = sys.executable
 
 test = TestSCons.TestSCons()
 
 test.write('build.py', r"""
 import sys
-file = open(sys.argv[1], 'w')
+file = open(sys.argv[1], 'wb')
 file.write("build.py: %s\n" % sys.argv[1])
 file.close()
 """)
 
 test.write('SConstruct', """
 MyBuild = Builder(name = "MyBuild",
-                 action = "python build.py $targets")
+                  action = r'%s build.py $targets')
 env = Environment(BUILDERS = [MyBuild])
 env.MyBuild(target = 'f1.out', source = 'f1.in')
 env.MyBuild(target = 'f2.out', source = 'f2.in')
-""")
+""" % python)
 
 args = 'f1.out f2.out'
-expect = "python build.py f1.out\npython build.py f2.out\n"
+expect = "%s build.py f1.out\n%s build.py f2.out\n" % (python, python)
 
 test.run(arguments = args, stdout = expect)
 test.fail_test(not os.path.exists(test.workpath('f1.out')))
index fe13fb7ee83d9f808eee49046083008bc449e825..6791786e8e293708522c256dfef1561d93597ce6 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import TestSCons
 import os.path
 import string
 import sys
+import TestSCons
+
+python = sys.executable
 
 test = TestSCons.TestSCons()
 
 test.write('build.py', r"""
 import sys
-file = open(sys.argv[1], 'w')
+file = open(sys.argv[1], 'wb')
 file.write("build.py: %s\n" % sys.argv[1])
 file.close()
 """)
 
 test.write('SConstruct', """
 MyBuild = Builder(name = "MyBuild",
-                 action = "python build.py $target")
+                  action = r'%s build.py $target')
 env = Environment(BUILDERS = [MyBuild])
 env.MyBuild(target = 'f1.out', source = 'f1.in')
 env.MyBuild(target = 'f2.out', source = 'f2.in')
-""")
+""" % python)
 
 test.run(arguments = '-s f1.out f2.out', stdout = "")
 test.fail_test(not os.path.exists(test.workpath('f1.out')))
index 68df0d436f0c4ea3cbbb8e097a0b2747b0c58fe1..dd7d86af060b31b20d9a093698b9439c5d5a24bd 100644 (file)
 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import TestSCons
 import os.path
 import string
 import sys
+import TestSCons
+
+python = sys.executable
 
 test = TestSCons.TestSCons()
 
 test.write('build.py', r"""
 import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read()
+file = open(sys.argv[1], 'wb')
 file.write(contents)
 file.close()
 """)
 
 test.write('SConstruct', """
-B = Builder(name = "B", action = "python build.py $targets $sources")
+B = Builder(name = "B", action = r'%s build.py $targets $sources')
 env = Environment(BUILDERS = [B])
 env.B(target = 'f1.out', source = 'f1.in')
 env.B(target = 'f2.out', source = 'f2.in')
 env.B(target = 'f3.out', source = 'f3.in')
 env.B(target = 'f4.out', source = 'f4.in')
-""")
+""" % python)
 
 test.write('f1.in', "f1.in\n")
 test.write('f2.in', "f2.in\n")
@@ -57,10 +59,10 @@ test.run(arguments = 'f1.out f3.out')
 
 test.run(arguments = 'f1.out f2.out f3.out f4.out', stdout =
 """scons: "f1.out" is up to date.
-python build.py f2.out f2.in
+%s build.py f2.out f2.in
 scons: "f3.out" is up to date.
-python build.py f4.out f4.in
-""")
+%s build.py f4.out f4.in
+""" % (python, python))
 
 test.pass_test()