summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2002-08-26 04:10:41 (GMT)
committerSteven Knight <knight@baldmt.com>2002-08-26 04:10:41 (GMT)
commitcff75e572311356bfd6d80c460c1140492a35073 (patch)
treefcdf14cc3aff099936e069fe6f45ef01da89f43c /src/engine
parent62446cb66567e967e1af2b6a0c152fdeb98508c8 (diff)
downloadSCons-cff75e572311356bfd6d80c460c1140492a35073.zip
SCons-cff75e572311356bfd6d80c460c1140492a35073.tar.gz
SCons-cff75e572311356bfd6d80c460c1140492a35073.tar.bz2
Add a Prepend() method to Environments. (Chad Austin)
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Environment.py18
-rw-r--r--src/engine/SCons/EnvironmentTests.py28
2 files changed, 46 insertions, 0 deletions
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 4a86ae6..47ab58b 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -269,6 +269,24 @@ class Environment:
self._dict[key] = self._dict[key] + kw[key]
self.__updateBuildersAndScanners()
+ def Prepend(self, **kw):
+ """Prepend values to existing construction variables
+ in an Environment.
+ """
+ kw = our_deepcopy(kw)
+ for key in kw.keys():
+ if not self._dict.has_key(key):
+ self._dict[key] = kw[key]
+ elif SCons.Util.is_List(self._dict[key]) and not \
+ SCons.Util.is_List(kw[key]):
+ self._dict[key] = [ kw[key] ] + self._dict[key]
+ elif SCons.Util.is_List(kw[key]) and not \
+ SCons.Util.is_List(self._dict[key]):
+ self._dict[key] = kw[key] + [ self._dict[key] ]
+ else:
+ self._dict[key] = kw[key] + self._dict[key]
+ self.__updateBuildersAndScanners()
+
def Depends(self, target, dependency):
"""Explicity specify that 'target's depend on 'dependency'."""
tlist = SCons.Node.arg2nodes(target, self.fs.File)
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index eefb605..8154990 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -345,6 +345,34 @@ class EnvironmentTestCase(unittest.TestCase):
except:
raise
+ def test_Prepend(self):
+ """Test prepending to construction variables in an Environment
+ """
+ import UserList
+ UL = UserList.UserList
+ env1 = Environment(AAA = 'a', BBB = 'b', CCC = 'c', DDD = 'd',
+ EEE = ['e'], FFF = ['f'], GGG = ['g'], HHH = ['h'],
+ III = UL(['i']), JJJ = UL(['j']),
+ KKK = UL(['k']), LLL = UL(['l']))
+ env1.Prepend(BBB = 'B', CCC = ['C'], DDD = UL(['D']),
+ FFF = 'F', GGG = ['G'], HHH = UL(['H']),
+ JJJ = 'J', KKK = ['K'], LLL = UL(['L']))
+ env2 = Environment(AAA = 'a', BBB = 'Bb',
+ CCC = ['C', 'c'], DDD = UL(['D', 'd']),
+ EEE = ['e'], FFF = ['F', 'f'],
+ GGG = ['G', 'g'], HHH = UL(['H', 'h']),
+ III = UL(['i']), JJJ = UL(['J', 'j']),
+ KKK = UL(['K', 'k']), LLL = UL(['L', 'l']))
+ assert env1 == env2, diff_env(env1, env2)
+
+ env3 = Environment(X = {'x' : 7})
+ try:
+ env3.Prepend(X = {'x' : 8})
+ except TypeError:
+ pass
+ except:
+ raise
+
def test_Depends(self):
"""Test the explicit Depends method."""
env = Environment()