Commits

Gary Oberbrunner committed 5667155

Fix nested LIBPATH expansion by flattening sequences in subst_path.

Patch from Alexey Klimkin; fixes issue #2660.

  • Participants
  • Parent commits bb567fa

Comments (0)

Files changed (4)

File src/CHANGES.txt

 
 RELEASE 2.X.X - 
 
+  From Alexey Klimkin:
+    - Fix nested LIBPATH expansion by flattening sequences in subst_path.
+
   From eyan on Bitbucket:
     - Print target name with command execution time with --debug=time
 

File src/engine/SCons/EnvironmentTests.py

         x = s("${_concat(PRE, LIST, SUF, __env__)}")
         assert x == 'preasuf prebsuf', x
 
+    def test_concat_nested(self):
+        "Test _concat() on a nested substitution strings."
+        e = self.TestEnvironment(PRE='pre', SUF='suf',
+                                 L1=['a', 'b'],
+                                 L2=['c', 'd'],
+                                 L3=['$L2'])
+        x = e.subst('$( ${_concat(PRE, L1, SUF, __env__)} $)')
+        assert x == 'preasuf prebsuf', x
+        e.AppendUnique(L1 = ['$L2'])
+        x = e.subst('$( ${_concat(PRE, L1, SUF, __env__)} $)')
+        assert x == 'preasuf prebsuf precsuf predsuf', x
+        e.AppendUnique(L1 = ['$L3'])
+        x = e.subst('$( ${_concat(PRE, L1, SUF, __env__)} $)')
+        assert x == 'preasuf prebsuf precsuf predsuf precsuf predsuf', x
+
     def test_gvars(self):
         """Test the Environment gvars() method"""
         env = self.TestEnvironment(XXX = 'x', YYY = 'y', ZZZ = 'z')

File src/engine/SCons/PathList.py

                 value = env.subst(value, target=target, source=source,
                                   conv=node_conv)
                 if SCons.Util.is_Sequence(value):
-                    result.extend(value)
-                    continue
-                    
+                    result.extend(SCons.Util.flatten(value))
+                elif value:
+                    result.append(value)
             elif type == TYPE_OBJECT:
                 value = node_conv(value)
-            if value:
+                if value:
+                    result.append(value)
+            elif value:
                 result.append(value)
         return tuple(result)
 

File src/engine/SCons/PathListTests.py

                 return s
 
         self.env = FakeEnvironment(AAA = 'aaa', NULL = '')
+        from SCons.Environment import Environment
+        self.env = Environment(AAA = 'aaa', NULL = '')
 
     def test_node(self):
         """Test the subst_path() method on a Node
 
         assert result == ('aaa',), result
 
+    def test_list_of_lists(self):
+        """Test the subst_path() method on substitution of nested lists.
+        """
+        pl = SCons.PathList.PathList((['$AAA', '$AAA'], '$NULL'))
+        result = pl.subst_path(self.env, 'y', 'z')
+        assert result == ('aaa', 'aaa'), result
+
+    def test_subst_nested(self):
+        """Test the subst_path() method on nested substitution of strings.
+        """
+        self.env.Append(L1 = ['a', 'b'],
+                        L2 = ['c', 'd'],
+                        L3 = ['$L2'])
+        pl = SCons.PathList.PathList(['$L1'])
+        result = pl.subst_path(self.env, 'y', 'z')
+        assert result == ('a', 'b'), result
+        self.env.Append(L1 = ['$L2'])
+        pl = SCons.PathList.PathList(['$L1'])
+        result = pl.subst_path(self.env, 'y', 'z')
+        assert result == ('a', 'b', 'c', 'd'), result
+        self.env.Append(L1 = ['$L3'])
+        pl = SCons.PathList.PathList(['$L1'])
+        result = pl.subst_path(self.env, 'y', 'z')
+        assert result == ('a', 'b', 'c', 'd', 'c', 'd'), result
+
+    def test_another_env(self):
+        """Test the subst_path does lazy evaluation.
+        """
+        pl = SCons.PathList.PathList(('$AAA', '$NULL'))
+        result = pl.subst_path(self.env, 'y', 'z')
+        assert result == ('aaa',), result
+        e = self.env.Clone(AAA = 'bbb')
+        result = pl.subst_path(e, 'y', 'z')
+        assert result == ('bbb',), result
 
 class PathListCacheTestCase(unittest.TestCase):