Environment infrastructure for special variable handling.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 18 Sep 2005 01:26:47 +0000 (01:26 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 18 Sep 2005 01:26:47 +0000 (01:26 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1345 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py

index 847b130d528ed15c35116e0db543a38478170a90..57066c178424e9c9d528526fd63198cb1024608d 100644 (file)
@@ -147,6 +147,23 @@ def copy_non_reserved_keywords(dict):
             del result[k]
     return result
 
+def _set_reserved(env, key, value):
+    msg = "Ignoring attempt to set reserved variable `%s'" % key
+    SCons.Warnings.warn(SCons.Warnings.ReservedVariableWarning, msg)
+
+def _set_BUILDERS(env, key, value):
+    try:
+        bd = env._dict[key]
+        for k in bd.keys():
+            del bd[k]
+    except KeyError:
+        env._dict[key] = BuilderDict(kwbd, env)
+    env._dict[key].update(value)
+
+def _set_SCANNERS(env, key, value):
+    env._dict[key] = value
+    env.scanner_map_delete()
+
 class BuilderWrapper:
     """Wrapper class that associates an environment with a Builder at
     instantiation."""
@@ -255,6 +272,16 @@ class SubstitutionEnvironment:
         self.ans = SCons.Node.Alias.default_ans
         self.lookup_list = SCons.Node.arg2nodes_lookups
         self._dict = kw.copy()
+        self._init_special()
+
+    def _init_special(self):
+        """Initial the dispatch table for special handling of
+        special construction variables."""
+        self._special = {}
+        for key in reserved_construction_var_names:
+            self._special[key] = _set_reserved
+        self._special['BUILDERS'] = _set_BUILDERS
+        self._special['SCANNERS'] = _set_SCANNERS
 
     def __cmp__(self, other):
         return cmp(self._dict, other._dict)
@@ -268,20 +295,9 @@ class SubstitutionEnvironment:
 
     def __setitem__(self, key, value):
         "__cache_reset__"
-        if key in reserved_construction_var_names:
-            SCons.Warnings.warn(SCons.Warnings.ReservedVariableWarning,
-                                "Ignoring attempt to set reserved variable `%s'" % key)
-        elif key == 'BUILDERS':
-            try:
-                bd = self._dict[key]
-                for k in bd.keys():
-                    del bd[k]
-            except KeyError:
-                self._dict[key] = BuilderDict(kwbd, self)
-            self._dict[key].update(value)
-        elif key == 'SCANNERS':
-            self._dict[key] = value
-            self.scanner_map_delete()
+        special = self._special.get(key)
+        if special:
+            special(self, key, value)
         else:
             if not SCons.Util.is_valid_construction_var(key):
                 raise SCons.Errors.UserError, "Illegal construction variable `%s'" % key
@@ -489,6 +505,7 @@ class Base(SubstitutionEnvironment):
         self.ans = SCons.Node.Alias.default_ans
         self.lookup_list = SCons.Node.arg2nodes_lookups
         self._dict = our_deepcopy(SCons.Defaults.ConstructionEnvironment)
+        self._init_special()
 
         self._dict['BUILDERS'] = BuilderDict(self._dict['BUILDERS'], self)
 
@@ -501,12 +518,10 @@ class Base(SubstitutionEnvironment):
         self._dict['PLATFORM'] = str(platform)
         platform(self)
 
-        # Apply the passed-in variables before calling the tools,
-        # because they may use some of them:
+        # Apply the passed-in variables and customizable options to the
+        # environment before calling the tools, because they may use
+        # some of them during initialization.
         apply(self.Replace, (), kw)
-        
-        # Update the environment with the customizable options
-        # before calling the tools, since they may use some of the options: 
         if options:
             options.Update(self)
 
@@ -516,13 +531,10 @@ class Base(SubstitutionEnvironment):
                 tools = ['default']
         apply_tools(self, tools, toolpath)
 
-        # Reapply the passed in variables after calling the tools,
-        # since they should overide anything set by the tools:
+        # Now re-apply the passed-in variables and customizable options
+        # to the environment, since the values the user set explicitly
+        # should override any values set by the tools.
         apply(self.Replace, (), kw)
-
-        # Update the environment with the customizable options
-        # after calling the tools, since they should override anything
-        # set by the tools:
         if options:
             options.Update(self)
 
index 495fab0e19d0e5fcd552d8b21b807f6ce67c3865..55dfb3a8e1f096a57deb670da1f9096d0f0186dc 100644 (file)
@@ -1211,7 +1211,7 @@ def exists(env):
         assert env['CCC2'] == ['c2'], env['CCC2']
 
     def test_Copy(self):
-        """Test construction Environment copying
+        """Test construction environment copying
 
         Update the copy independently afterwards and check that
         the original remains intact (that is, no dangling