summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-08-31 01:25:53 (GMT)
committerSteven Knight <knight@baldmt.com>2004-08-31 01:25:53 (GMT)
commitc0c32fb930d47c02fcdceea5d1759a35c4a92025 (patch)
tree6a1b17647873df7fab2d197e016225f592657a63
parentf09896916e7eb4fbd1d334d22e99e6b8d8a64696 (diff)
downloadSCons-c0c32fb930d47c02fcdceea5d1759a35c4a92025.zip
SCons-c0c32fb930d47c02fcdceea5d1759a35c4a92025.tar.gz
SCons-c0c32fb930d47c02fcdceea5d1759a35c4a92025.tar.bz2
Fix how get_name() returns Builder names from subclass instanes. (Kevin Quick)
-rw-r--r--src/CHANGES.txt5
-rw-r--r--src/engine/SCons/Builder.py8
-rw-r--r--src/engine/SCons/BuilderTests.py45
-rw-r--r--src/engine/SCons/Util.py5
-rw-r--r--test/multi.py2
5 files changed, 58 insertions, 7 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 47514ea..f1d8530 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 e6e7822..47c9ad2 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 5a605ec..bbff627 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 5636a90..323f5ff 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 989c636..bc5bc7d 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 ?
""")