Commits

Anonymous committed f47e63b

Portability fixes for tests on Windows Nt.

  • Participants
  • Parent commits f1279e5

Comments (0)

Files changed (24)

File src/engine/SCons/Builder.py

 
 
 import os
+import os.path
 import SCons.Node.FS
 from SCons.Util import PathList, scons_str2nodes, scons_subst
 import string
 
 
 
+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'):
 	    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
 
 

File src/engine/SCons/BuilderTests.py

 	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()
 	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')
 	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'])
 	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'])
 	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'])
 	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'}})
 	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")

File src/engine/SCons/Defaults.py

 
 
 
+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'
+                      },
+    }

File src/engine/SCons/Node/FSTests.py

 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
+import string
 import sys
 import unittest
 
 
         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
+        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)
 
-        assert f1.path == 'd1/f1', "f1.path %s != d1/f1" % f1.path
-        assert str(f1) == 'd1/f1', "str(f1) %s != d1/f1" % str(f1)
+        seps = [os.sep]
+        if os.sep != '/':
+            seps = seps + ['/']
 
-        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
+        for sep in seps:
 
-        try:
-            dir = fs.Dir('d1/f1')
-        except TypeError, x:
-	    assert str(x) == "Tried to lookup File 'd1/f1' as a Dir.", x
-        except:
-            raise
+            def Dir_test(lpath, path, abspath, up_path, fileSys=fs, s=sep):
+                dir = fileSys.Dir(string.replace(lpath, '/', s))
 
-	try:
-	    f2 = fs.File('d1')
-	except TypeError, x:
-	    assert str(x) == "Tried to lookup Dir 'd1/' as a File.", x
-	except:
-	    raise
+		if os.sep != '/':
+                    path = string.replace(path, '/', os.sep)
+                    abspath = string.replace(abspath, '/', os.sep)
+                    up_path = string.replace(up_path, '/', os.sep)
 
-	# 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']
+                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

File src/engine/SCons/Sig/MD5.py

 
 __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.

File src/engine/SCons/UtilTests.py

 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
+import os
+import os.path
+import string
 import sys
-import os.path
 import unittest
 import SCons.Node
 import SCons.Node.FS
                                                           "/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")
 
 
 

File src/script/scons.py

 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
 __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

File test/Command.py

 
 __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()
 """)
 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")
 

File test/Default.py

 __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']:
 

File test/Depends.py

 
 __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')
 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')
 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()
 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()

File test/LINK.py

 __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

File test/LINKFLAGS.py

 __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

File test/builderrors.py

 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
+import sys
 import TestSCons
 
+python = sys.executable
+
 test = TestSCons.TestSCons()
 
 test.subdir('one', 'two', 'three')
 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")
 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")
 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")

File test/multiline.py

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

File test/option--.py

 
 __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')))

File test/option-c.py

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

File test/option-i.py

 __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)
 """)
 
 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')

File test/option-j.py

 
 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
-import TestSCons
 import string
 import sys
+import TestSCons
 
+python = sys.executable
 
 try:
     import threading
 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()))
 
 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"""

File test/option-k.py

 __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)
 """)
 
 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 = '.')
 

File test/option-n.py

 
 __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')))

File test/option-s.py

 
 __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')))

File test/up-to-date.py

 
 __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")
 
 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()