Support specifying a list of tools when calling env.Copy(). (Chad Austin)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 21 Jul 2003 12:03:33 +0000 (12:03 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 21 Jul 2003 12:03:33 +0000 (12:03 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@741 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py

index 7c93e0e39339a496993a6bc970d2bde92d31295e..7be2a37605e4709ca35fbea032b9c57f401bae65 100644 (file)
@@ -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
index 37e36a84cdc913e0bf425aee6bbac7881c07302e..b7a050688fc3a8f22307631c0f1a44fab21c86d0 100644 (file)
 
 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.
index cbf7a7c564b80d28d0b8581613ca57579a842103..47d2e243d7ffc79433020af49b4b002c751b4a96 100644 (file)
@@ -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
 
index 080c0d934d1f39af534a92642bc3597c2f395ad8..e71ee0df046dd504ac7820eef9e2719c43a64abf 100644 (file)
@@ -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