From 772ede31d7a5aed0c72943be9230313de687e0be Mon Sep 17 00:00:00 2001 From: Steven Knight Date: Wed, 17 Oct 2001 16:42:21 +0000 Subject: Portability fixes for tests on Windows Nt. --- src/engine/SCons/Builder.py | 78 ++++++++++++++++++---- src/engine/SCons/BuilderTests.py | 16 +++-- src/engine/SCons/Defaults.py | 68 +++++++++++++++---- src/engine/SCons/Node/FSTests.py | 141 ++++++++++++++++++++++----------------- src/engine/SCons/Sig/MD5.py | 12 +++- src/engine/SCons/UtilTests.py | 32 ++++++--- src/script/scons.py | 5 ++ test/CC.py | 9 ++- test/Command.py | 17 +++-- test/Default.py | 19 +++--- test/Depends.py | 13 ++-- test/ENV.py | 8 +-- test/LINK.py | 9 ++- test/LINKFLAGS.py | 9 ++- test/builderrors.py | 25 ++++--- test/multiline.py | 15 +++-- test/option--.py | 12 ++-- test/option-c.py | 11 +-- test/option-i.py | 11 +-- test/option-j.py | 9 +-- test/option-k.py | 11 +-- test/option-n.py | 12 ++-- test/option-s.py | 10 +-- test/up-to-date.py | 18 ++--- 24 files changed, 375 insertions(+), 195 deletions(-) diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 1f4f555..1e3c9b9 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -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 diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index e84799a..a446f95 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -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") diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index eeaa02a..086c1d5 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -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' + }, + } diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index fc0a0a3..6f2a5a7 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -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 diff --git a/src/engine/SCons/Sig/MD5.py b/src/engine/SCons/Sig/MD5.py index 4004e23..11ba961 100644 --- a/src/engine/SCons/Sig/MD5.py +++ b/src/engine/SCons/Sig/MD5.py @@ -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. diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index bbaf851..7df0c83 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -23,8 +23,10 @@ __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") diff --git a/src/script/scons.py b/src/script/scons.py index b8dc2ff..18347b4 100644 --- a/src/script/scons.py +++ b/src/script/scons.py @@ -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 diff --git a/test/CC.py b/test/CC.py index ce18047..5d2985f 100644 --- a/test/CC.py +++ b/test/CC.py @@ -25,24 +25,27 @@ __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 diff --git a/test/Command.py b/test/Command.py index 5b592b9..c3080cb 100644 --- a/test/Command.py +++ b/test/Command.py @@ -24,14 +24,17 @@ __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") diff --git a/test/Default.py b/test/Default.py index 515a9c0..9155660 100644 --- a/test/Default.py +++ b/test/Default.py @@ -25,43 +25,46 @@ __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']: diff --git a/test/Depends.py b/test/Depends.py index 61ebb0a..03033b1 100644 --- a/test/Depends.py +++ b/test/Depends.py @@ -24,25 +24,28 @@ __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') diff --git a/test/ENV.py b/test/ENV.py index db51327..221e7f9 100644 --- a/test/ENV.py +++ b/test/ENV.py @@ -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() diff --git a/test/LINK.py b/test/LINK.py index f2ac661..6b99976 100644 --- a/test/LINK.py +++ b/test/LINK.py @@ -25,24 +25,27 @@ __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 diff --git a/test/LINKFLAGS.py b/test/LINKFLAGS.py index 06c1482..ff4ee88 100644 --- a/test/LINKFLAGS.py +++ b/test/LINKFLAGS.py @@ -25,24 +25,27 @@ __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 diff --git a/test/builderrors.py b/test/builderrors.py index fad003a..769215a 100644 --- a/test/builderrors.py +++ b/test/builderrors.py @@ -25,8 +25,11 @@ __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") diff --git a/test/multiline.py b/test/multiline.py index dca0b00..7560d55 100644 --- a/test/multiline.py +++ b/test/multiline.py @@ -25,28 +25,31 @@ __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") diff --git a/test/option--.py b/test/option--.py index e9f427a..9fca2bd 100644 --- a/test/option--.py +++ b/test/option--.py @@ -24,29 +24,31 @@ __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'))) diff --git a/test/option-c.py b/test/option-c.py index 76a60e9..0e41ffd 100644 --- a/test/option-c.py +++ b/test/option-c.py @@ -25,25 +25,28 @@ __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") diff --git a/test/option-i.py b/test/option-i.py index 3301396..713655c 100644 --- a/test/option-i.py +++ b/test/option-i.py @@ -25,13 +25,16 @@ __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') diff --git a/test/option-j.py b/test/option-j.py index 80cbcca..3eb0b12 100644 --- a/test/option-j.py +++ b/test/option-j.py @@ -24,10 +24,11 @@ __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""" diff --git a/test/option-k.py b/test/option-k.py index e8fead2..4034d83 100644 --- a/test/option-k.py +++ b/test/option-k.py @@ -25,15 +25,18 @@ __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 = '.') diff --git a/test/option-n.py b/test/option-n.py index cba2e96..0a11101 100644 --- a/test/option-n.py +++ b/test/option-n.py @@ -24,30 +24,32 @@ __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'))) diff --git a/test/option-s.py b/test/option-s.py index fe13fb7..6791786 100644 --- a/test/option-s.py +++ b/test/option-s.py @@ -24,27 +24,29 @@ __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'))) diff --git a/test/up-to-date.py b/test/up-to-date.py index 68df0d4..dd7d86a 100644 --- a/test/up-to-date.py +++ b/test/up-to-date.py @@ -24,29 +24,31 @@ __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() -- cgit v0.12