summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2002-05-06 15:06:09 (GMT)
committerSteven Knight <knight@baldmt.com>2002-05-06 15:06:09 (GMT)
commit7f24756809ba8ae0c2aa27e8ba8f906b7fef1d3d (patch)
tree3528f6acc866caea337cdd897b31f85ae36a049e
parente6e85a842cb066639048a6344db51b747eaf4245 (diff)
downloadSCons-7f24756809ba8ae0c2aa27e8ba8f906b7fef1d3d.zip
SCons-7f24756809ba8ae0c2aa27e8ba8f906b7fef1d3d.tar.gz
SCons-7f24756809ba8ae0c2aa27e8ba8f906b7fef1d3d.tar.bz2
Add Append() and Replace() functions. (Zed Shaw)
-rw-r--r--doc/man/scons.126
-rw-r--r--src/CHANGES.txt8
-rw-r--r--src/engine/SCons/Environment.py36
-rw-r--r--src/engine/SCons/EnvironmentTests.py34
4 files changed, 84 insertions, 20 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1
index a716147..c60cf17 100644
--- a/doc/man/scons.1
+++ b/doc/man/scons.1
@@ -995,12 +995,32 @@ env.Alias('install', ['/usr/local/bin', '/usr/local/lib'])
.EE
.TP
-.RI Update( key = val ", [...])"
-Updates the contents of an environment
+.RI Replace( key = val ", [...])"
+Replaces construction variables in the Environment
with the specified keyword arguments.
+(Note: "Update()" is a deprecated synonym for this method.)
.ES
-env.Update(CCFLAGS = '-g', FOO = 'foo.xxx')
+env.Replace(CCFLAGS = '-g', FOO = 'foo.xxx')
+.EE
+
+.TP
+.RI Append( key = val ", [...])"
+Appends the specified keyword arguments
+to the construction variables in the environment.
+If the Environment does not have
+the specified construction variable,
+it is simply added to the environment.
+If the values of the construction variable
+and the keyword argument are the same type,
+then the two values will be simply added together.
+Otherwise, the construction variable
+and the value of the keyword argument
+are both coerced to lists,
+and the lists are added together.
+
+.ES
+env.Append(CCFLAGS = ' -g', FOO = ['foo.yyy'])
.EE
.SS Construction Variables
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 1912edb..391da3c 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -10,6 +10,14 @@
RELEASE 0.08 -
+ From Zed Shaw:
+
+ - Add an Append() method to Environments, to append values to
+ construction variables.
+
+ - Change the name of Update() to Replace(). Keep Update() as a
+ deprecated synonym, at least for now.
+
RELEASE 0.07 - Thu, 2 May 2002 13:37:16 -0500
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index b0d1457..432c394 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -95,7 +95,7 @@ class Environment:
def __init__(self, **kw):
self.fs = SCons.Node.FS.default_fs
self._dict = our_deepcopy(SCons.Defaults.ConstructionEnvironment)
- apply(self.Update, (), kw)
+ apply(self.Replace, (), kw)
#
# self.autogen_vars is a tuple of tuples. Each inner tuple
@@ -141,17 +141,22 @@ class Environment:
"""
clone = copy.copy(self)
clone._dict = our_deepcopy(self._dict)
- apply(clone.Update, (), kw)
+ apply(clone.Replace, (), kw)
return clone
def Scanners(self):
pass # XXX
def Update(self, **kw):
- """Update an existing construction Environment with new
- construction variables and/or values.
- """
- self._dict.update(our_deepcopy(kw))
+ """A deprecated synonym for Replace().
+ """
+ apply(self.Replace, (), kw)
+
+ def Replace(self, **kw):
+ """Replace existing construction variables in an Environment
+ with new construction variables and/or values.
+ """
+ self._dict.update(our_deepcopy(kw))
if self._dict.has_key('BUILDERS') and \
not SCons.Util.is_List(self._dict['BUILDERS']):
self._dict['BUILDERS'] = [self._dict['BUILDERS']]
@@ -188,6 +193,25 @@ class Environment:
for s in self._dict['SCANNERS']:
setattr(self, s.name, s)
+ def Append(self, **kw):
+ """Append 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 type(self._dict[key]) is type(kw[key]):
+ self._dict[key] = self._dict[key] + kw[key]
+ else:
+ l1 = self._dict[key]
+ if not SCons.Util.is_List(l1):
+ l1 = [l1]
+ l2 = kw[key]
+ if not SCons.Util.is_List(l2):
+ l2 = [l2]
+ self._dict[key] = l1 + l2
+
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 24db460..d1c5aa8 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -88,7 +88,7 @@ class EnvironmentTestCase(unittest.TestCase):
built_it = {}
env3 = Environment()
- env3.Update(BUILDERS = [b1, b2])
+ env3.Replace(BUILDERS = [b1, b2])
env3.builder1.execute(target = 'out1')
env3.builder2.execute(target = 'out2')
env3.builder1.execute(target = 'out3')
@@ -124,7 +124,7 @@ class EnvironmentTestCase(unittest.TestCase):
scanned_it = {}
env3 = Environment()
- env3.Update(SCANNERS = [s1, s2])
+ env3.Replace(SCANNERS = [s1, s2])
env3.scanner1.scan(filename = 'out1')
env3.scanner2.scan(filename = 'out2')
env3.scanner1.scan(filename = 'out3')
@@ -152,7 +152,7 @@ class EnvironmentTestCase(unittest.TestCase):
env1 = Environment(XXX = 'x', YYY = 'y')
env2 = env1.Copy()
env1copy = env1.Copy()
- env2.Update(YYY = 'yyy')
+ env2.Replace(YYY = 'yyy')
assert env1 != env2
assert env1 == env1copy
@@ -240,15 +240,27 @@ class EnvironmentTestCase(unittest.TestCase):
for tnode in tgt:
assert tnode.builder == InstallBuilder
- def test_Update(self):
- """Test updating an Environment with new construction variables
+ def test_Replace(self):
+ """Test replacing construction variables in an Environment
- After creation of the Environment, of course.
- """
- env1 = Environment(AAA = 'a', BBB = 'b')
- env1.Update(BBB = 'bbb', CCC = 'ccc')
- env2 = Environment(AAA = 'a', BBB = 'bbb', CCC = 'c')
- assert env1 != env2
+ After creation of the Environment, of course.
+ """
+ env1 = Environment(AAA = 'a', BBB = 'b')
+ env1.Replace(BBB = 'bbb', CCC = 'ccc')
+ env2 = Environment(AAA = 'a', BBB = 'bbb', CCC = 'ccc')
+ assert env1 == env2
+
+ def test_Append(self):
+ """Test appending to construction variables in an Environment
+ """
+ env1 = Environment(AAA = 'a', BBB = 'b', CCC = 'c',
+ DDD = ['d'], EEE = ['e'], FFF = ['f'])
+ env1.Append(BBB = 'B', CCC = ['C'], EEE = 'E', FFF = ['F'],
+ GGG = 'g', HHH = ['h'])
+ env2 = Environment(AAA = 'a', BBB = 'bB', CCC = ['c', 'C'],
+ DDD = ['d'], EEE = ['e', 'E'], FFF = ['f', 'F'],
+ GGG = 'g', HHH = ['h'])
+ assert env1 == env2
def test_Depends(self):
"""Test the explicit Depends method."""