summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2005-01-05 21:26:41 (GMT)
committerSteven Knight <knight@baldmt.com>2005-01-05 21:26:41 (GMT)
commit7065ee43b7f6828f0f1b91148db074aea759a44d (patch)
treecb64e69f33383e176fded537d24649dda29c566c /src
parent0e0a0aeaba0c7f6188370fe08304f807af798a9c (diff)
downloadSCons-7065ee43b7f6828f0f1b91148db074aea759a44d.zip
SCons-7065ee43b7f6828f0f1b91148db074aea759a44d.tar.gz
SCons-7065ee43b7f6828f0f1b91148db074aea759a44d.tar.bz2
Use AppendUnique() in ParseConfig(). Provide a unique=0 keyword argument in case someone has a reason to need to allow duplicates.
Diffstat (limited to 'src')
-rw-r--r--src/CHANGES.txt4
-rw-r--r--src/RELEASE.txt4
-rw-r--r--src/engine/SCons/Environment.py14
-rw-r--r--src/engine/SCons/EnvironmentTests.py58
4 files changed, 59 insertions, 21 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 523ace9..ff2dd71 100644
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -163,6 +163,10 @@ RELEASE 0.97 - XXX
it much simpler to support aliases like "clean" that just invoke
an arbitrary action).
+ - Have env.ParseConfig() use AppendUnique() by default to suppress
+ duplicate entries from multiple calls. Add a "unique" keyword
+ argument to allow the old behavior to be specified.
+
From Wayne Lee:
- Avoid "maximum recursion limit" errors when removing $(-$) pairs
diff --git a/src/RELEASE.txt b/src/RELEASE.txt
index 948085a..2ace3c5 100644
--- a/src/RELEASE.txt
+++ b/src/RELEASE.txt
@@ -33,6 +33,10 @@ RELEASE 0.97 - XXX
variable, instead of returning them (the same way it handles
the -l option).
+ - By default, the ParseConfig() method now avoids adding duplicate
+ entries to construction variables. The old behavior may be
+ specified using a new "unique=0" keyword argument.
+
- When compiling with Microsoft Visual Studio, SCons no longer
adds the ATL and MFC directories to the INCLUDE and LIB
environment variables by default. If you want these directories
diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py
index 6f8e30c..c98c7aa 100644
--- a/src/engine/SCons/Environment.py
+++ b/src/engine/SCons/Environment.py
@@ -686,7 +686,7 @@ class Base(SubstitutionEnvironment):
"""
kw = copy_non_reserved_keywords(kw)
for key, val in kw.items():
- if not self._dict.has_key(key):
+ if not self._dict.has_key(key) or not self._dict[key]:
self._dict[key] = val
elif SCons.Util.is_Dict(self._dict[key]) and \
SCons.Util.is_Dict(val):
@@ -786,7 +786,7 @@ class Base(SubstitutionEnvironment):
if name[:len(prefix)] == prefix and name[-len(suffix):] == suffix:
return path
- def ParseConfig(self, command, function=None):
+ def ParseConfig(self, command, function=None, unique=1):
"""
Use the specified function to parse the output of the command
in order to modify the current environment. The 'command' can
@@ -800,7 +800,7 @@ class Base(SubstitutionEnvironment):
"""
# the default parse function
- def parse_conf(env, output, fs=self.fs):
+ def parse_conf(env, output, fs=self.fs, unique=unique):
dict = {
'ASFLAGS' : [],
'CCFLAGS' : [],
@@ -853,7 +853,11 @@ class Base(SubstitutionEnvironment):
dict['LINKFLAGS'].append(arg)
else:
dict['CCFLAGS'].append(arg)
- apply(env.Append, (), dict)
+ if unique:
+ appender = env.AppendUnique
+ else:
+ appender = env.Append
+ apply(appender, (), dict)
if function is None:
function = parse_conf
@@ -979,7 +983,7 @@ class Base(SubstitutionEnvironment):
"""
kw = copy_non_reserved_keywords(kw)
for key, val in kw.items():
- if not self._dict.has_key(key):
+ if not self._dict.has_key(key) or not self._dict[key]:
self._dict[key] = val
elif SCons.Util.is_Dict(self._dict[key]) and \
SCons.Util.is_Dict(val):
diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py
index 2e65ac1..b34657a 100644
--- a/src/engine/SCons/EnvironmentTests.py
+++ b/src/engine/SCons/EnvironmentTests.py
@@ -1216,19 +1216,26 @@ def exists(env):
AAA3 = 'a3',
BBB1 = ['b1'],
BBB2 = ['b2'],
- BBB3 = ['b3'])
+ BBB3 = ['b3'],
+ CCC1 = '',
+ CCC2 = '')
env.AppendUnique(AAA1 = 'a1',
AAA2 = ['a2'],
AAA3 = ['a3', 'b', 'c', 'a3'],
BBB1 = 'b1',
BBB2 = ['b2'],
- BBB3 = ['b3', 'c', 'd', 'b3'])
+ BBB3 = ['b3', 'c', 'd', 'b3'],
+ CCC1 = 'c1',
+ CCC2 = ['c2'])
+
assert env['AAA1'] == 'a1a1', env['AAA1']
assert env['AAA2'] == ['a2'], env['AAA2']
assert env['AAA3'] == ['a3', 'b', 'c'], env['AAA3']
assert env['BBB1'] == ['b1'], env['BBB1']
assert env['BBB2'] == ['b2'], env['BBB2']
assert env['BBB3'] == ['b3', 'c', 'd'], env['BBB3']
+ assert env['CCC1'] == 'c1', env['CCC1']
+ assert env['CCC2'] == ['c2'], env['CCC2']
def test_Copy(self):
"""Test construction Environment copying
@@ -1435,20 +1442,27 @@ def exists(env):
LIBS='',
LINKFLAGS=[''],
CCFLAGS=[''])
- save_command = []
orig_popen = os.popen
- def my_popen(command, save_command=save_command):
- save_command.append(command)
- class fake_file:
- def read(self):
- return "-I/usr/include/fum -I bar -X\n" + \
- "-L/usr/fax -L foo -lxxx -l yyy " + \
- "-Wa,-as -Wl,-link -Wp,-cpp abc " + \
- "-pthread -framework Carbon " + \
- "-mno-cygwin -mwindows"
- return fake_file()
+ class my_popen:
+ def __init__(self, save_command, output):
+ self.save_command = save_command
+ self.output = output
+ def __call__(self, command):
+ self.save_command.append(command)
+ class fake_file:
+ def __init__(self, output):
+ self.output = output
+ def read(self):
+ return self.output
+ return fake_file(self.output)
try:
- os.popen = my_popen
+ save_command = []
+ os.popen = my_popen(save_command,
+ "-I/usr/include/fum -I bar -X\n" + \
+ "-L/usr/fax -L foo -lxxx -l yyy " + \
+ "-Wa,-as -Wl,-link -Wp,-cpp abc " + \
+ "-pthread -framework Carbon " + \
+ "-mno-cygwin -mwindows")
env.ParseConfig("fake $COMMAND")
assert save_command == ['fake command'], save_command
assert env['ASFLAGS'] == ['assembler', '-Wa,-as'], env['ASFLAGS']
@@ -1458,6 +1472,12 @@ def exists(env):
assert env['LIBS'] == ['xxx', 'yyy', env.File('abc')], env['LIBS']
assert env['LINKFLAGS'] == ['', '-Wl,-link', '-pthread', '-framework', 'Carbon', '-mno-cygwin', '-mwindows'], env['LINKFLAGS']
assert env['CCFLAGS'] == ['', '-X', '-pthread', '-mno-cygwin'], env['CCFLAGS']
+
+ os.popen = my_popen([], "-Ibar")
+ env.ParseConfig("fake2")
+ assert env['CPPPATH'] == ['string', '/usr/include/fum', 'bar'], env['CPPPATH']
+ env.ParseConfig("fake2", unique=0)
+ assert env['CPPPATH'] == ['string', '/usr/include/fum', 'bar', 'bar'], env['CPPPATH']
finally:
os.popen = orig_popen
@@ -1706,19 +1726,25 @@ f5: \
AAA3 = 'a3',
BBB1 = ['b1'],
BBB2 = ['b2'],
- BBB3 = ['b3'])
+ BBB3 = ['b3'],
+ CCC1 = '',
+ CCC2 = '')
env.PrependUnique(AAA1 = 'a1',
AAA2 = ['a2'],
AAA3 = ['a3', 'b', 'c', 'a3'],
BBB1 = 'b1',
BBB2 = ['b2'],
- BBB3 = ['b3', 'b', 'c', 'b3'])
+ BBB3 = ['b3', 'b', 'c', 'b3'],
+ CCC1 = 'c1',
+ CCC2 = ['c2'])
assert env['AAA1'] == 'a1a1', env['AAA1']
assert env['AAA2'] == ['a2'], env['AAA2']
assert env['AAA3'] == ['b', 'c', 'a3'], env['AAA3']
assert env['BBB1'] == ['b1'], env['BBB1']
assert env['BBB2'] == ['b2'], env['BBB2']
assert env['BBB3'] == ['b', 'c', 'b3'], env['BBB3']
+ assert env['CCC1'] == 'c1', env['CCC1']
+ assert env['CCC2'] == ['c2'], env['CCC2']
def test_Replace(self):
"""Test replacing construction variables in an Environment