From 46043901f7a93385e5bb2d3243073bd6c5634ca8 Mon Sep 17 00:00:00 2001 From: Gary Oberbrunner Date: Sat, 6 Oct 2012 17:54:14 -0400 Subject: Fix nested LIBPATH expansion by flattening sequences in subst_path. Patch from Alexey Klimkin; fixes issue #2660. --- src/CHANGES.txt | 3 +++ src/engine/SCons/EnvironmentTests.py | 15 +++++++++++++++ src/engine/SCons/PathList.py | 10 ++++++---- src/engine/SCons/PathListTests.py | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index c903ece..ca6c5df 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -6,6 +6,9 @@ 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 diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 9237c8a..45cf876 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -1440,6 +1440,21 @@ def exists(env): 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') diff --git a/src/engine/SCons/PathList.py b/src/engine/SCons/PathList.py index 870c195..f3de57c 100644 --- a/src/engine/SCons/PathList.py +++ b/src/engine/SCons/PathList.py @@ -131,12 +131,14 @@ class _PathList(object): 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) diff --git a/src/engine/SCons/PathListTests.py b/src/engine/SCons/PathListTests.py index 212c761..e83fc50 100644 --- a/src/engine/SCons/PathListTests.py +++ b/src/engine/SCons/PathListTests.py @@ -48,6 +48,8 @@ class subst_pathTestCase(unittest.TestCase): 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 @@ -120,6 +122,40 @@ class subst_pathTestCase(unittest.TestCase): 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): -- cgit v0.12