diff options
author | Steven Knight <knight@baldmt.com> | 2005-01-05 21:26:41 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2005-01-05 21:26:41 (GMT) |
commit | 1344c9c2297d5e0931bfcd15a853b13d8e5caf34 (patch) | |
tree | cb64e69f33383e176fded537d24649dda29c566c | |
parent | afb25b009ee74ade18a9a5b65e62f2ad5b773739 (diff) | |
download | SCons-1344c9c2297d5e0931bfcd15a853b13d8e5caf34.zip SCons-1344c9c2297d5e0931bfcd15a853b13d8e5caf34.tar.gz SCons-1344c9c2297d5e0931bfcd15a853b13d8e5caf34.tar.bz2 |
Use AppendUnique() in ParseConfig(). Provide a unique=0 keyword argument in case someone has a reason to need to allow duplicates.
-rw-r--r-- | doc/man/scons.1 | 20 | ||||
-rw-r--r-- | src/CHANGES.txt | 4 | ||||
-rw-r--r-- | src/RELEASE.txt | 4 | ||||
-rw-r--r-- | src/engine/SCons/Environment.py | 14 | ||||
-rw-r--r-- | src/engine/SCons/EnvironmentTests.py | 58 | ||||
-rw-r--r-- | test/ParseConfig.py | 25 |
6 files changed, 91 insertions, 34 deletions
diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 417ced4..38a3822 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -3266,7 +3266,7 @@ Returns a list of the target Node or Nodes. '\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .TP -.RI env.ParseConfig( command ", [" function ]) +.RI env.ParseConfig( command ", [" function ", " unique ]) Calls the specified .I function to modify the environment as specified by the output of @@ -3277,15 +3277,25 @@ expects the output of a typical .I *-config command (for example, .BR gtk-config ) -and parses the returned +and adds the options +to the appropriate construction variables. +By default, +duplicate values are not +added to any construction variables; +you can specify +.B unique=0 +to allow duplicate +values to be added. + +By default, .BR -L , .BR -l , .BR -Wa , .BR -Wl , .BR -Wp , .B -I -and other options -into the +and other options, +are add to the .BR LIBPATH , .BR LIBS , .BR ASFLAGS , @@ -3294,7 +3304,7 @@ into the .B CPPPATH and .B CCFLAGS -variables, +construction variables, respectively. A returned .B -pthread 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 diff --git a/test/ParseConfig.py b/test/ParseConfig.py index c70bc3c..1ab27c4 100644 --- a/test/ParseConfig.py +++ b/test/ParseConfig.py @@ -30,40 +30,49 @@ import sys 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") |