"""
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):
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
"""
# 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' : [],
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
"""
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):
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
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']
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
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
import TestCmd
import TestSCons
+python = TestSCons.python
+
test = TestSCons.TestSCons()
-test_config = test.workpath('test-config')
+test_config1 = test.workpath('test-config1')
+test_config2 = test.workpath('test-config2')
# 'abc' is supposed to be a static lib; it is included in LIBS as a
# File node.
# It used to be returned as the 'static_libs' output of ParseConfig.
-test.write('test-config', """#! /usr/bin/env python
+test.write(test_config1, """\
print "-I/usr/include/fum -Ibar -X"
print "-L/usr/fax -Lfoo -lxxx abc"
""")
+test.write(test_config2, """\
+print "-L foo -L lib_dir"
+""")
+
test.write('SConstruct', """
env = Environment(CPPPATH = [], LIBPATH = [], LIBS = [], CCFLAGS = '')
-env.ParseConfig([r"%s", r"%s", "--libs --cflags"])
+env.ParseConfig([r"%(python)s", r"%(test_config1)s", "--libs --cflags"])
+env.ParseConfig([r"%(python)s", r"%(test_config2)s", "--libs --cflags"])
print env['CPPPATH']
print env['LIBPATH']
print map(lambda x: str(x), env['LIBS'])
print env['CCFLAGS']
-""" % (TestSCons.python, test_config))
+""" % locals())
test.write('SConstruct2', """
env = Environment(CPPPATH = [], LIBPATH = [], LIBS = [], CCFLAGS = '',
- PYTHON = '%s')
-env.ParseConfig(r"$PYTHON %s --libs --cflags")
+ PYTHON = '%(python)s')
+env.ParseConfig(r"$PYTHON %(test_config1)s --libs --cflags")
+env.ParseConfig(r"$PYTHON %(test_config2)s --libs --cflags")
print env['CPPPATH']
print env['LIBPATH']
print map(lambda x: str(x), env['LIBS'])
print env['CCFLAGS']
-""" % (TestSCons.python, test_config))
+""" % locals())
good_stdout = test.wrap_stdout(read_str = """\
['/usr/include/fum', 'bar']
-['/usr/fax', 'foo']
+['/usr/fax', 'foo', 'lib_dir']
['xxx', 'abc']
['-X']
""", build_str = "scons: `.' is up to date.\n")