From fa5bc4fcb9965ab14da0ac78f7f5c7cea7d85ab2 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 18 Oct 2002 01:09:14 +0000 Subject: [PATCH] Win32 test portability. git-svn-id: http://scons.tigris.org/svn/scons/trunk@484 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Action.py | 20 +++++++----- src/engine/SCons/ActionTests.py | 55 +++++++++++++++++++++----------- src/engine/SCons/Node/FSTests.py | 6 ++-- test/Repository/variants.py | 3 +- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index fcd0ec98..06d8dd9f 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -56,6 +56,12 @@ def quote(x): else: return x +def rfile(n): + try: + return n.rfile() + except AttributeError: + return n + if os.name == 'posix': def escape(arg): @@ -393,7 +399,10 @@ class CommandGeneratorAction(ActionBase): return gen_cmd def execute(self, target, source, env): - return self.__generate(target, source, env, 0).execute(target, source, env) + if not SCons.Util.is_List(source): + source = [source] + rsources = map(rfile, source) + return self.__generate(target, source, env, 0).execute(target, rsources, env) def get_contents(self, target, source, env): """Return the signature contents of this action's command line. @@ -430,16 +439,11 @@ class FunctionAction(ActionBase): if not SCons.Util.is_List(target): target = [target] - def rfile(n): - try: - return n.rfile() - except AttributeError: - return n if not SCons.Util.is_List(source): source = [source] - source = map(rfile, source) + rsources = map(rfile, source) - return self.function(target=target, source=source, env=env) + return self.function(target=target, source=rsources, env=env) def get_contents(self, target, source, env): """Return the signature contents of this callable action. diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index ab98d021..2e53bbd4 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -201,22 +201,26 @@ class CommandGeneratorActionTestCase(unittest.TestCase): def f(target, source, env, for_signature, self=self): dummy = env['dummy'] self.dummy = dummy - assert env.subst("$FOO $( bar $) baz") == 'foo baz\nbar ack bar baz', env.subst("$FOO $( bar $) baz") - assert env.subst("$FOO $( bar $) baz", raw=1) == 'foo baz\nbar ack $( bar $) baz', env.subst("$FOO $( bar $) baz", raw=1) - assert env.subst_list("$FOO $( bar $) baz") == [ [ 'foo', 'baz' ], - [ 'bar', 'ack', 'bar', 'baz' ] ], env.subst_list("$FOO $( bar $) baz") - assert env.subst_list("$FOO $( bar $) baz", - raw=1) == [ [ 'foo', 'baz' ], - [ 'bar', 'ack', '$(', 'bar', '$)', 'baz' ] ], env.subst_list("$FOO $( bar $) baz", raw=1) + s = env.subst("$FOO $( bar $) baz") + assert s == 'foo baz\nbar ack bar baz', s + s = env.subst("$FOO $( bar $) baz", raw=1) + assert s == 'foo baz\nbar ack $( bar $) baz', s + s = env.subst_list("$FOO $( bar $) baz") + assert s == [[ 'foo', 'baz' ], [ 'bar', 'ack', 'bar', 'baz' ]], s + s = env.subst_list("$FOO $( bar $) baz", raw=1) + assert s == [[ 'foo', 'baz' ], + [ 'bar', 'ack', '$(', 'bar', '$)', 'baz' ]], s return "$FOO" - def func_action(target, source,env, self=self): + def func_action(target, source, env, self=self): dummy=env['dummy'] - assert env.subst('$foo $( bar $)') == 'bar bar', env.subst('$foo $( bar $)') - assert env.subst('$foo $( bar $)', - raw=1) == 'bar $( bar $)', env.subst('$foo $( bar $)', raw=1) - assert env.subst_list([ '$foo', '$(', 'bar', '$)' ]) == [[ 'bar', 'bar' ]], env.subst_list([ '$foo', '$(', 'bar', '$)' ]) - assert env.subst_list([ '$foo', '$(', 'bar', '$)' ], - raw=1) == [[ 'bar', '$(', 'bar', '$)' ]], env.subst_list([ '$foo', '$(', 'bar', '$)' ], raw=1) + s = env.subst('$foo $( bar $)') + assert s == 'bar bar', s + s = env.subst('$foo $( bar $)', raw=1) + assert s == 'bar $( bar $)', s + s = env.subst_list([ '$foo', '$(', 'bar', '$)' ]) + assert s == [[ 'bar', 'bar' ]], s + s = env.subst_list([ '$foo', '$(', 'bar', '$)' ], raw=1) + assert s == [[ 'bar', '$(', 'bar', '$)' ]], s self.dummy=dummy def f2(target, source, env, for_signature, f=func_action): return f @@ -231,19 +235,32 @@ class CommandGeneratorActionTestCase(unittest.TestCase): self.args = [] try: SCons.Action.SetCommandHandler(ch) - a.execute([],[],env=Environment({ 'FOO' : 'foo baz\nbar ack' , 'dummy':1})) + a.execute([],[],env=Environment({ 'FOO' : 'foo baz\nbar ack', + 'dummy' : 1})) finally: SCons.Action.SetCommandHandler(old_hdl) - assert self.dummy == 1 - assert self.cmd == [ 'foo', 'bar'], self.cmd - assert self.args == [ [ 'foo', 'baz' ], [ 'bar', 'ack' ] ], self.args + assert self.dummy == 1, self.dummy + assert self.cmd == ['foo', 'bar'], self.cmd + assert self.args == [[ 'foo', 'baz' ], [ 'bar', 'ack' ]], self.args b=SCons.Action.CommandGeneratorAction(f2) self.dummy = 0 - b.execute(target=[], source=[], env=Environment({ 'foo' : 'bar','dummy':2 })) + b.execute(target=[], source=[], env=Environment({ 'foo' : 'bar', + 'dummy' : 2 })) assert self.dummy==2, self.dummy del self.dummy + class DummyFile: + def __init__(self, t): + self.t = t + def rfile(self): + self.t.rfile_called = 1 + def f3(target, source, env, for_signature): + return '' + c=SCons.Action.CommandGeneratorAction(f3) + c.execute(target=[], source=DummyFile(self), env=Environment({})) + assert self.rfile_called + def test_get_contents(self): """Test fetching the contents of a command generator Action """ diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 0c7bd696..1610ec69 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -194,7 +194,7 @@ class BuildDirTestCase(unittest.TestCase): # But we do have a file in the Repository assert f3.rexists() # rfile() should point to the source path - assert f3.rfile().path == test.workpath('rep1/src/test2.in'),\ + assert f3.rfile().path == os.path.normpath(test.workpath('rep1/src/test2.in')),\ f3.rfile().path assert f4.srcnode().path == os.path.normpath('src/test2.in'),\ @@ -228,12 +228,12 @@ class BuildDirTestCase(unittest.TestCase): assert not f7.exists() assert f7.rexists() - assert f7.rfile().path == test.workpath('rep1/build/var1/test2.out'),\ + assert f7.rfile().path == os.path.normpath(test.workpath('rep1/build/var1/test2.out')),\ f7.rfile().path assert not f8.exists() assert f8.rexists() - assert f8.rfile().path == test.workpath('rep1/build/var2/test2.out'),\ + assert f8.rfile().path == os.path.normpath(test.workpath('rep1/build/var2/test2.out')),\ f8.rfile().path # Test to see if file_link() works... diff --git a/test/Repository/variants.py b/test/Repository/variants.py index d91235f6..81aa5966 100644 --- a/test/Repository/variants.py +++ b/test/Repository/variants.py @@ -44,11 +44,12 @@ opts = "-Y " + test.workpath('repository') test.write(['repository', 'SConstruct'], r""" OS = ARGUMENTS['OS'] build_os = "#build/" + OS +default_ccflags = Environment()['CCFLAGS'] ccflags = { 'foo' : '-DFOO', 'bar' : '-DBAR', } -env = Environment(CCFLAGS = ccflags[OS], +env = Environment(CCFLAGS = default_ccflags + ' ' + ccflags[OS], CPPPATH = build_os) BuildDir(build_os, 'src') SConscript(build_os + '/SConscript', "env") -- 2.26.2