Fix so Nodes don't get removed by ListBuilder after they're built.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 28 Jan 2002 12:45:30 +0000 (12:45 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 28 Jan 2002 12:45:30 +0000 (12:45 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@227 fdb21ef1-2011-0410-befe-b5e4ea1792b1

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

index bcaf1a0af4f061ceeff956a76672f65a01ec213f..9dc2105a3ddb80e2c25abf59707e41b72fb742ea 100644 (file)
@@ -52,6 +52,17 @@ class NoneBuilder(Builder):
         apply(Builder.execute, (self,), kw)
         return None
 
+class ListBuilder(Builder):
+    def __init__(self, *nodes):
+        self.nodes = nodes
+    def execute(self, **kw):
+        if hasattr(self, 'status'):
+            return self.status
+        for n in self.nodes:
+            n.remove()
+        kw['target'] = self.nodes[0]
+        self.status = apply(Builder.execute, (self,), kw)
+
 class FailBuilder:
     def execute(self, **kw):
         return 1
@@ -117,8 +128,13 @@ class NodeTestCase(unittest.TestCase):
         global built_it
 
         class MyNode(SCons.Node.Node):
+            def __init__(self, **kw):
+                apply(SCons.Node.Node.__init__, (self,), kw)
+                self.remove_count = 0
             def __str__(self):
                 return self.path
+            def remove(self):
+                self.remove_count= self.remove_count+ 1
        # Make sure it doesn't blow up if no builder is set.
         node = MyNode()
        node.build()
@@ -147,6 +163,41 @@ class NodeTestCase(unittest.TestCase):
         assert str(built_target) == "qqq", str(built_target)
         assert built_source == ["rrr", "sss"], built_source
 
+        fff = MyNode()
+        ggg = MyNode()
+        lb = ListBuilder(fff, ggg)
+        e = Environment()
+        fff.builder_set(lb)
+        fff.env_set(e)
+        fff.path = "fff"
+        ggg.builder_set(lb)
+        ggg.env_set(e)
+        ggg.path = "ggg"
+        fff.sources = ["hhh", "iii"]
+        ggg.sources = ["hhh", "iii"]
+
+        built_it = None
+        fff.build()
+        assert built_it
+        ggg.build()
+        assert ggg.remove_count== 1, ggg.remove_count
+        assert type(built_target) == type(MyNode()), type(built_target)
+        assert str(built_target) == "fff", str(built_target)
+        assert built_source == ["hhh", "iii"], built_source
+
+        delattr(lb, 'status')
+        fff.remove_count = 0
+        ggg.remove_count = 0
+
+        built_it = None
+        ggg.build()
+        #assert built_it
+        fff.build()
+        assert fff.remove_count== 1, fff.remove_count
+        assert type(built_target) == type(MyNode()), type(built_target)
+        assert str(built_target) == "fff", str(built_target)
+        assert built_source == ["hhh", "iii"], built_source
+
     def test_builder_set(self):
        """Test setting a Node's Builder
        """
index 02c14bba1775a718885676735bdf9334cff3745b..504c6d1fcbc16143fc7b3ad509fb46f0d0c25f5b 100644 (file)
@@ -76,16 +76,22 @@ class Node:
         """Actually build the node.   Return the status from the build."""
        if not self.builder:
            return None
-        if not self.precious:
-            self.remove()
         try:
-            stat = self.builder.execute(env = self.env.Dictionary(),
-                                        target = self, source = self.sources)
-        except:
-            raise BuildError(self, "Exception",
-                             sys.exc_type,
-                             sys.exc_value,
-                             sys.exc_traceback)
+            # If this Builder instance has already been called,
+            # there will already be an associated status.
+            stat = self.builder.status
+        except AttributeError:
+            if not self.precious:
+                self.remove()
+            try:
+                stat = self.builder.execute(env = self.env.Dictionary(),
+                                            target = self,
+                                            source = self.sources)
+            except:
+                raise BuildError(self, "Exception",
+                                 sys.exc_type,
+                                 sys.exc_value,
+                                 sys.exc_traceback)
         if stat:
             raise BuildError(node = self, errstr = "Error %d" % stat)