Use AppendUnique() in ParseConfig(). Provide a unique=0 keyword argument in case...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 5 Jan 2005 21:26:41 +0000 (21:26 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Wed, 5 Jan 2005 21:26:41 +0000 (21:26 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1206 fdb21ef1-2011-0410-befe-b5e4ea1792b1

doc/man/scons.1
src/CHANGES.txt
src/RELEASE.txt
src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py
test/ParseConfig.py

index 417ced446eb8340cfb975590589806a95f32bf0d..38a3822c22f0f99ddc847a65b92475f109cbef8e 100644 (file)
@@ -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
index 523ace9216daeaaa478e66a0b0e3633ca990f307..ff2dd71865f06ed08e3e4c35ee7da3d5461bbecf 100644 (file)
@@ -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
index 948085afd29bc8eb54c4a8dc3b0dde0ae9c92423..2ace3c5d4dfae1795241b2919e75653db4eaa811 100644 (file)
@@ -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
index 6f8e30cff9b7fee0acb38f58416688e519cb95e3..c98c7aa145be4eff4100249d14322345e2486b57 100644 (file)
@@ -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):
index 2e65ac122810de21ed71a2a4c7d7786d8d57e361..b34657afdd08fffb4eac5f63f5a3c80294ca3b20 100644 (file)
@@ -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
index c70bc3cca2e1e677730962c93d906325efee82f4..1ab27c4f914e11e61b95a7cbbbd2bcc41e71b130 100644 (file)
@@ -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")