summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2003-07-21 12:03:33 (GMT)
committerSteven Knight <knight@baldmt.com>2003-07-21 12:03:33 (GMT)
commitd77bd9aa09a469f734d52951f09ec8b649d33482 (patch)
treeafaf9d46954b81e86194f5201dd87e0a640c4fd4
parentcf7a4545126e4fe5a0c36c0c26b74980d1c06c9a (diff)
downloadSCons-d77bd9aa09a469f734d52951f09ec8b649d33482.zip
SCons-d77bd9aa09a469f734d52951f09ec8b649d33482.tar.gz
SCons-d77bd9aa09a469f734d52951f09ec8b649d33482.tar.bz2
Support specifying a list of tools when calling env.Copy(). (Chad Austin)
-rw-r--r--doc/man/scons.19
-rw-r--r--src/CHANGES.txt4
-rw-r--r--src/engine/SCons/Environment.py18
-rw-r--r--src/engine/SCons/EnvironmentTests.py19
4 files changed, 45 insertions, 5 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index 7c93e0e..7be2a37 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 37e36a8..b7a0506 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 cbf7a7c..47d2e24 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 080c0d9..e71ee0d 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