If we added a temporary builder to a Node while calling the emitter, don't remove...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 4 May 2003 18:26:04 +0000 (18:26 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 4 May 2003 18:26:04 +0000 (18:26 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@671 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py

index 22b177e973be8659291cd80006e3fa59a3fd2afe..19cbe27316299155cd7c6d231bf8197e3a2c0431 100644 (file)
@@ -306,11 +306,14 @@ class BuilderBase:
         
             target, source = self.emitter(target=tlist, source=slist, env=env)
 
-            # Now delete the temporary builders that we attached to the
+            # Now delete the temporary builders that we attached to any
             # new targets, so that _init_nodes() doesn't do weird stuff
             # to them because it thinks they already have builders.
             for t in new_targets:
-                t.builder = None
+                if t.builder is self:
+                    # Only delete the temporary builder if the emitter
+                    # didn't change it on us.
+                    t.builder = None
 
             # Have to call arg2nodes yet again, since it is legal for
             # emitters to spit out strings as well as Node instances.
index 02c570c178098c46aa0cdc035a929b044d0b775a..c71f18fd2fddde9c53a3d1769539903efa654ba8 100644 (file)
@@ -637,6 +637,25 @@ class BuilderTestCase(unittest.TestCase):
                                         node_factory=MyNode)
         assert builder2 == builder2a, repr(builder2.__dict__) + "\n" + repr(builder2a.__dict__)
 
+        # Test that, if an emitter sets a builder on the passed-in
+        # targets and passes back new targets, the new builder doesn't
+        # get overwritten.
+        new_builder = SCons.Builder.Builder(action='new')
+        node = MyNode('foo8')
+        new_node = MyNode('foo8.new')
+        def emit3(target, source, env, nb=new_builder, nn=new_node):
+            for t in target:
+                t.builder = nb
+            return [nn], source
+            
+        builder3=SCons.Builder.Builder(action='foo',
+                                       emitter=emit3,
+                                       node_factory=MyNode)
+        tgt = builder3(env, target=node, source='bar')
+        assert tgt is new_node, tgt
+        assert tgt.builder is builder3, tgt.builder
+        assert node.builder is new_builder, node.builder
+
     def test_no_target(self):
         """Test deducing the target from the source."""