From 528e58d691c793c8b1fb10e9fd974e8f7d6bf088 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Tue, 31 Aug 2004 01:25:53 +0000 Subject: [PATCH] Fix how get_name() returns Builder names from subclass instanes. (Kevin Quick) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1050 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 5 ++++ src/engine/SCons/Builder.py | 8 ++---- src/engine/SCons/BuilderTests.py | 45 ++++++++++++++++++++++++++++++++ src/engine/SCons/Util.py | 5 ++++ test/multi.py | 2 +- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 47514ea4..f1d85300 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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 diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index e6e78220..47c9ad25 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -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__) diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py index 5a605ec0..bbff6273 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -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_') diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 5636a90d..323f5fff 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -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: diff --git a/test/multi.py b/test/multi.py index 989c6361..bc5bc7d4 100644 --- a/test/multi.py +++ b/test/multi.py @@ -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 ? """) -- 2.26.2