From: stevenknight Date: Tue, 11 Dec 2001 01:53:48 +0000 (+0000) Subject: Refactor the Builder execute() interface to take Nodes, not string names of targets... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8abc156d00ba1a0aacf262b052f2cdf67412fd24;p=scons.git Refactor the Builder execute() interface to take Nodes, not string names of targets and sources. git-svn-id: http://scons.tigris.org/svn/scons/trunk@132 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 983e32f4..1525804c 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -347,17 +347,17 @@ class ActionBase: if kw.has_key('target'): t = kw['target'] del kw['target'] - if type(t) is type(""): + if not type(t) is types.ListType: t = [t] - dict['TARGETS'] = PathList(map(os.path.normpath, t)) + dict['TARGETS'] = PathList(map(os.path.normpath, map(str, t))) if dict['TARGETS']: dict['TARGET'] = dict['TARGETS'][0] if kw.has_key('source'): s = kw['source'] del kw['source'] - if type(s) is type(""): + if not type(s) is types.ListType: s = [s] - dict['SOURCES'] = PathList(map(os.path.normpath, s)) + dict['SOURCES'] = PathList(map(os.path.normpath, map(str, s))) dict.update(kw) @@ -408,6 +408,13 @@ class FunctionAction(ActionBase): # if print_actions: # XXX: WHAT SHOULD WE PRINT HERE? if execute_actions: + if kw.has_key('target'): + if type(kw['target']) is types.ListType: + kw['target'] = map(str, kw['target']) + else: + kw['target'] = str(kw['target']) + if kw.has_key('source'): + kw['source'] = map(str, kw['source']) return apply(self.function, (), kw) def get_contents(self, **kw): diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 4c6ad1f4..9143a5f0 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -171,6 +171,21 @@ class BuilderTestCase(unittest.TestCase): c = test.read(outfile, 'r') assert c == "act.py: 'out5' 'XYZZY'\nact.py: 'xyzzy'\n", c + class Obj: + def __init__(self, str): + self._str = str + def __str__(self): + return self._str + + cmd6 = r'%s %s %s ${TARGETS[1]} $TARGET ${SOURCES[:2]}' % (python, act_py, outfile) + + builder = SCons.Builder.Builder(action = cmd6) + r = builder.execute(target = [Obj('111'), Obj('222')], + source = [Obj('333'), Obj('444'), Obj('555')]) + assert r == 0 + c = test.read(outfile, 'r') + assert c == "act.py: '222' '111' '333' '444'\n", c + cmd7 = '%s %s %s one\n\n%s %s %s two' % (python, act_py, outfile, python, act_py, outfile) expect7 = '%s %s %s one\n%s %s %s two\n' % (python, act_py, outfile, diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index 2eba47eb..a3590a1c 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -90,7 +90,8 @@ class NodeTestCase(unittest.TestCase): node.sources = ["yyy", "zzz"] node.build() assert built_it - assert built_target == "xxx", built_target + assert type(built_target) == type(MyNode()), type(built_target) + assert str(built_target) == "xxx", str(built_target) assert built_source == ["yyy", "zzz"], built_source def test_builder_set(self): diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 83663dc3..8b1ef55a 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -71,9 +71,8 @@ class Node: """Actually build the node. Return the status from the build.""" if not self.builder: return None - sources = map(lambda x: str(x), self.sources) stat = self.builder.execute(env = self.env.Dictionary(), - target = str(self), source = sources) + target = self, source = self.sources) if stat != 0: raise BuildError(node = self, stat = stat) return stat