From 766298bef9fe77e8693785122f7aa523d81fff27 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 21 Jul 2003 12:03:33 +0000 Subject: [PATCH] Support specifying a list of tools when calling env.Copy(). (Chad Austin) git-svn-id: http://scons.tigris.org/svn/scons/trunk@741 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 9 +++++++++ src/CHANGES.txt | 4 ++++ src/engine/SCons/Environment.py | 18 +++++++++++++----- src/engine/SCons/EnvironmentTests.py | 19 +++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 7c93e0e3..7be2a376 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -1791,6 +1791,15 @@ env2 = env.Copy() env3 = env.Copy(CCFLAGS = '-g') .EE +Additionally, a list of tools may be specified, as in the Environment +constructor: + +.ES +def MyTool(env): env['FOO'] = 'bar' +env4 = env.Copy(tools = ['msvc', MyTool]) +.EE + + .TP .RI CVS( repository ", " module ) A factory function that diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 37e36a84..b7a05068 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -10,6 +10,10 @@ RELEASE 0.XX - XXX + From Chad Austin: + + - Support specifying a list of tools when calling Environment.Copy(). + From Steven Knight: - Tighten up the scons -H help output. diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index cbf7a7c5..47d2e243 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -83,6 +83,13 @@ def our_deepcopy(x): copy = x return copy +def apply_tools(env, tools): + if tools: + for tool in tools: + if SCons.Util.is_String(tool): + tool = SCons.Tool.Tool(tool) + tool(env) + class BuilderWrapper: """Wrapper class that associates an environment with a Builder at instantiation.""" @@ -183,10 +190,7 @@ class Environment: if tools is None: tools = ['default'] - for tool in tools: - if SCons.Util.is_String(tool): - tool = SCons.Tool.Tool(tool) - tool(self) + apply_tools(self, tools) # Reapply the passed in variables after calling the tools, # since they should overide anything set by the tools: @@ -204,7 +208,7 @@ class Environment: def Builders(self): pass # XXX - def Copy(self, **kw): + def Copy(self, tools=None, **kw): """Return a copy of a construction Environment. The copy is like a Python "deep copy"--that is, independent copies are made recursively of each objects--except that @@ -219,6 +223,10 @@ class Environment: clone._dict['BUILDERS'] = BuilderDict(cbd, clone) except KeyError: pass + + apply_tools(clone, tools) + + # Apply passed-in variables after the new tools. apply(clone.Replace, (), kw) return clone diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 080c0d93..e71ee0df 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -290,6 +290,25 @@ class EnvironmentTestCase(unittest.TestCase): assert hasattr(env2, 'b2'), "env2.b2 was not set" assert env2.b2.env == env2, "b2.env doesn't point to env2" + # Ensure that specifying new tools in a copied environment + # works. + def foo(env): env['FOO'] = 1 + def bar(env): env['BAR'] = 2 + def baz(env): env['BAZ'] = 3 + env1 = Environment(tools=[foo]) + env2 = env1.Copy() + env3 = env1.Copy(tools=[bar, baz]) + + assert env1.get('FOO') is 1 + assert env1.get('BAR') is None + assert env1.get('BAZ') is None + assert env2.get('FOO') is 1 + assert env2.get('BAR') is None + assert env2.get('BAZ') is None + assert env3.get('FOO') is 1 + assert env3.get('BAR') is 2 + assert env3.get('BAZ') is 3 + def test_Dictionary(self): """Test retrieval of known construction variables -- 2.26.2