Refactor the Builder execute() interface to take Nodes, not string names of targets...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Dec 2001 01:53:48 +0000 (01:53 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Dec 2001 01:53:48 +0000 (01:53 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@132 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py

index 983e32f471ee58d3f58d57391f1e23079856ac52..1525804c0e1a30cbd2874e6874fa747733bd36d3 100644 (file)
@@ -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):
index 4c6ad1f4134afd38b0ec0fe34e05cff7b2109440..9143a5f0f0653cb514ef6f6cdb699d63aae03c55 100644 (file)
@@ -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,
index 2eba47ebfe9fc285e32fb480315342d4525af038..a3590a1c8b604f342f38860220e9419872813a05 100644 (file)
@@ -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):
index 83663dc334d545db5dae160bbd69a56d55289d67..8b1ef55a37f8ac19af12e537a204b59ca7768900 100644 (file)
@@ -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