From: stevenknight Date: Wed, 15 Sep 2004 21:35:19 +0000 (+0000) Subject: Return real builder names from the default, environment-less builders like MkdirBuild... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cc7da8aa9aa3309bcca442633b197e438f32af13;p=scons.git Return real builder names from the default, environment-less builders like MkdirBuilder, DefaultSCCSBuilder and DefaultRCSBuilder. (Kevin Quick) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1074 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 4064121e..bb18b312 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -75,6 +75,9 @@ RELEASE 0.97 - XXX - Fix a stack trace when a suffix selection dictionary is passed an empty source file list. + - Allow optional names to be attached to Builders, for default + Builders that don't get attached to construction environments. + From Christoph Wiedemann: - Add an Environment.SetDefault() method that only sets values if diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 1f3c60d5..543ca8ec 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -407,6 +407,7 @@ class BuilderBase: multi = 0, env = None, single_source = 0, + name = None, **overrides): if __debug__: logInstanceCreation(self, 'BuilderBase') self.action = SCons.Action.Action(action) @@ -436,6 +437,11 @@ class BuilderBase: self.emitter = emitter + # Optional Builder name should only be used for Builders + # that don't get attached to construction environments. + if name: + self.name = name + def __nonzero__(self): raise InternalError, "Do not test for the Node.builder attribute directly; use Node.has_builder() instead" @@ -444,13 +450,17 @@ class BuilderBase: Look at the BUILDERS variable of env, expecting it to be a dictionary containing this Builder, and return the key of the - dictionary.""" + dictionary. If there's no key, then return a directly-configured + name (if there is one) or the name of the class (by default).""" try: index = env['BUILDERS'].values().index(self) return env['BUILDERS'].keys()[index] except (AttributeError, KeyError, ValueError): - return str(self.__class__) + try: + return self.name + except AttributeError: + return str(self.__class__) 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 913e6d4f..e4647f5f 100644 --- a/src/engine/SCons/BuilderTests.py +++ b/src/engine/SCons/BuilderTests.py @@ -1236,7 +1236,7 @@ class BuilderTestCase(unittest.TestCase): def test_get_name(self): """Test getting name of builder. - Each type of builder should return it's environment-specific + Each type of builder should return its environment-specific name when queried appropriately. """ b1 = SCons.Builder.Builder(action='foo', suffix='.o') @@ -1245,6 +1245,8 @@ class BuilderTestCase(unittest.TestCase): src_suffix = '.foo', src_builder = b1) b4 = SCons.Builder.Builder(action={}) + b5 = SCons.Builder.Builder(action='foo', name='builder5') + b6 = SCons.Builder.Builder(action='foo') assert isinstance(b4, SCons.Builder.CompositeBuilder) assert isinstance(b4.action, SCons.Action.CommandGeneratorAction) @@ -1256,10 +1258,18 @@ class BuilderTestCase(unittest.TestCase): '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' + assert b1.get_name(env) == 'bldr1', b1.get_name(env) + assert b2.get_name(env) == 'bldr2', b2.get_name(env) + assert b3.get_name(env) == 'bldr3', b3.get_name(env) + assert b4.get_name(env) == 'bldr4', b4.get_name(env) + assert b5.get_name(env) == 'builder5', b5.get_name(env) + assert b6.get_name(env) == 'SCons.Builder.BuilderBase', b6.get_name(env) + assert b1.get_name(env2) == 'B1', b1.get_name(env2) + assert b2.get_name(env2) == 'B2', b2.get_name(env2) + assert b3.get_name(env2) == 'B3', b3.get_name(env2) + assert b4.get_name(env2) == 'B4', b4.get_name(env2) + assert b5.get_name(env2) == 'builder5', b5.get_name(env2) + assert b6.get_name(env2) == 'SCons.Builder.BuilderBase', b6.get_name(env2) for B in b3.get_src_builders(env): assert B.get_name(env) == 'bldr1' diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index b59c375e..7f60c7b6 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -193,7 +193,8 @@ def get_MkdirBuilder(): # calling SCons.Defaults.DefaultEnvironment() when necessary. MkdirBuilder = SCons.Builder.Builder(action = Mkdir, env = None, - explain = None) + explain = None, + name = "MkdirBuilder") return MkdirBuilder def CacheRetrieveFunc(target, source, env): @@ -261,7 +262,8 @@ def get_DefaultSCCSBuilder(): # "env" will get filled in by Executor.get_build_env() # calling SCons.Defaults.DefaultEnvironment() when necessary. DefaultSCCSBuilder = SCons.Builder.Builder(action = '$SCCSCOM', - env = None) + env = None, + name = "DefaultSCCSBuilder") return DefaultSCCSBuilder def get_DefaultRCSBuilder(): @@ -271,7 +273,8 @@ def get_DefaultRCSBuilder(): # "env" will get filled in by Executor.get_build_env() # calling SCons.Defaults.DefaultEnvironment() when necessary. DefaultRCSBuilder = SCons.Builder.Builder(action = '$RCS_COCOM', - env = None) + env = None, + name = "DefaultRCSBuilder") return DefaultRCSBuilder #