Fix how get_name() returns Builder names from subclass instanes. (Kevin Quick)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 31 Aug 2004 01:25:53 +0000 (01:25 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 31 Aug 2004 01:25:53 +0000 (01:25 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1050 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
src/engine/SCons/Util.py
test/multi.py

index 47514ea40ea87572f7b4f77e27a8906a84a20051..f1d853006f7ccca0868a21ee810623663705ccb2 100644 (file)
@@ -20,6 +20,11 @@ RELEASE 0.97 - XXX
   - Add an Environment.Dump() method to print the contents of a
     construction environment.
 
+  From Kevin Quick:
+
+  - Fix the Builder name returned from ListBuilders and other instances
+    of subclasses of the BuilderBase class.
+
 
 
 RELEASE 0.96.1 - XXX
index e6e7822094ee3394bcb2a4599e49b9c87466afee..47c9ad2505567de71e4ab19cd7c1235dcb9de3ec 100644 (file)
@@ -308,6 +308,8 @@ def _init_nodes(builder, env, overrides, tlist, slist):
                         raise UserError, "Two different target sets have a target in common: %s"%str(t)
                     else:
                         raise UserError, "Two different builders (%s and %s) were specified for the same target: %s"%(t.builder.get_name(env), builder.get_name(env), str(t))
+                elif isinstance(t.builder, ListBuilder) ^ isinstance(builder, ListBuilder):
+                    raise UserError, "Cannot build same target `%s' as singular and list"%str(t)
             elif t.sources != slist:
                 raise UserError, "Multiple ways to build the same target were specified for: %s" % str(t)
 
@@ -631,9 +633,6 @@ class ListBuilder(SCons.Util.Proxy):
         """
         return self.tlist
 
-    def __cmp__(self, other):
-        return cmp(self.__dict__, other.__dict__)
-
     def get_name(self, env):
         """Attempts to get the name of the Builder."""
 
@@ -767,6 +766,3 @@ class CompositeBuilder(SCons.Util.Proxy):
     def add_action(self, suffix, action):
         self.cmdgen.add_action(suffix, action)
         self.set_src_suffix(self.cmdgen.src_suffixes())
-
-    def __cmp__(self, other):
-        return cmp(self.__dict__, other.__dict__)
index 5a605ec0a392a94bcac67bbfc71f9f53ab56bfcf..bbff6273e86810b7e925dffddc24713a5ef4167f 100644 (file)
@@ -1075,6 +1075,51 @@ class BuilderTestCase(unittest.TestCase):
         assert str(tgt.sources[0]) == 'i0.w', map(str, tgt.sources)
         assert str(tgt.sources[1]) == 'i1.y', map(str, tgt.sources)
 
+    def test_get_name(self):
+        """Test getting name of builder.
+
+        Each type of builder should return it's environment-specific
+        name when queried appropriately.  """
+
+        b1 = SCons.Builder.Builder(action='foo', suffix='.o')
+        b2 = SCons.Builder.Builder(action='foo', suffix='.c')
+        b3 = SCons.Builder.MultiStepBuilder(action='bar',
+                                            src_suffix = '.foo',
+                                            src_builder = b1)
+        b4 = SCons.Builder.Builder(action={})
+        assert isinstance(b4, SCons.Builder.CompositeBuilder)
+        assert isinstance(b4.action, SCons.Action.CommandGeneratorAction)
+        
+        env = Environment(BUILDERS={'bldr1': b1,
+                                    'bldr2': b2,
+                                    'bldr3': b3,
+                                    'bldr4': b4})
+        env2 = Environment(BUILDERS={'B1': b1,
+                                     'B2': b2,
+                                     'B3': b3,
+                                     'B4': b4})
+        assert b1.get_name(env) == 'bldr1', b1.get_name(env2) == 'B1'
+        assert b2.get_name(env) == 'bldr2', b2.get_name(env2) == 'B2'
+        assert b3.get_name(env) == 'bldr3', b3.get_name(env2) == 'B3'
+        assert b4.get_name(env) == 'bldr4', b4.get_name(env2) == 'B4'
+
+        for B in b3.get_src_builders(env):
+            assert B.get_name(env) == 'bldr1'
+        for B in b3.get_src_builders(env2):
+            assert B.get_name(env2) == 'B1'
+
+        tgts = b1(env, target = [outfile, outfile2], source='moo')
+        for t in tgts:
+            assert t.builder.get_name(env) == 'ListBuilder(bldr1)'
+            # The following are not symbolically correct, because the
+            # ListBuilder was only created on behalf of env, so it
+            # would probably be OK if better correctness
+            # env-to-builder mappings caused this to fail in the
+            # future.
+            assert t.builder.get_name(env2) == 'ListBuilder(B1)'
+
+        tgt = b4(env, target = 'moo', source='cow')
+        assert tgt[0].builder.get_name(env) == 'bldr4'
 
 if __name__ == "__main__":
     suite = unittest.makeSuite(BuilderTestCase, 'test_')
index 5636a90d6d894ac08aa8fe9677667b45d439522a..323f5fffc41a70d9f3f2e77365d05dc7aaae2c92 100644 (file)
@@ -1011,6 +1011,11 @@ class Proxy:
         """Retrieve the entire wrapped object"""
         return self.__subject
 
+    def __cmp__(self, other):
+        if issubclass(other.__class__, self.__subject.__class__):
+            return cmp(self.__subject, other)
+        return cmp(self.__dict__, other.__dict__)
+
 # attempt to load the windows registry module:
 can_read_reg = 0
 try:
index 989c6361d2945527a6102b1a13703c0aed624c6a..bc5bc7d481cdd3100c42c936289ae8da21559082 100644 (file)
@@ -369,7 +369,7 @@ test.write('file12b.in', 'file12b.in\n')
 test.run(arguments='file12.out', 
          status=2, 
          stderr="""
-scons: *** Two different builders (ListBuilder(B) and B) were specified for the same target: file12a.out
+scons: *** Cannot build same target `file12a.out' as singular and list
 File "SConstruct", line 11, in ?
 """)