From 7d777b10662c6fb7d0b857cc6ee14feeb6f96c29 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 5 Mar 2004 08:51:01 +0000 Subject: [PATCH] Refactor path-substitution logic into an Environment method. git-svn-id: http://scons.tigris.org/svn/scons/trunk@914 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Defaults.py | 38 ++++++++++-------------- src/engine/SCons/Environment.py | 13 ++++++++ src/engine/SCons/EnvironmentTests.py | 11 +++++++ src/engine/SCons/Scanner/CTests.py | 5 ++++ src/engine/SCons/Scanner/FortranTests.py | 5 ++++ src/engine/SCons/Scanner/ProgTests.py | 5 ++++ src/engine/SCons/Scanner/ScannerTests.py | 4 +++ src/engine/SCons/Scanner/__init__.py | 10 +------ 8 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index bf6d59f8..78103ef8 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -147,38 +147,30 @@ def _concat(prefix, list, suffix, env, f=lambda x: x): if not list: return list - if not SCons.Util.is_List(list): - list = [list] - - def subst(x, env = env): - if SCons.Util.is_String(x): - return env.subst(x) - else: - return x - - list = map(subst, list) - - list = f(list) + list = f(env.subst_path(list)) ret = [] # ensure that prefix and suffix are strings - prefix = str(prefix) - suffix = str(suffix) + prefix = str(env.subst(prefix, SCons.Util.SUBST_RAW)) + suffix = str(env.subst(suffix, SCons.Util.SUBST_RAW)) for x in list: x = str(x) - if prefix and prefix[-1] == ' ': - ret.append(prefix[:-1]) - ret.append(x) - else: - ret.append(prefix+x) + if prefix: + if prefix[-1] == ' ': + ret.append(prefix[:-1]) + elif x[:len(prefix)] != prefix: + x = prefix + x - if suffix and suffix[0] == ' ': - ret.append(suffix[1:]) - else: - ret[-1] = ret[-1]+suffix + ret.append(x) + + if suffix: + if suffix[0] == ' ': + ret.append(suffix[1:]) + elif x[-len(suffix):] != suffix: + ret[-1] = ret[-1]+suffix return ret diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index c6bc2a99..2235ace4 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -392,6 +392,19 @@ class Base: the documentation for that function.""" return SCons.Util.scons_subst_list(string, self, raw, target, source, dict) + def subst_path(self, path): + """Substitute a path list.""" + + if not SCons.Util.is_List(path): + path = [path] + + r = [] + for p in path: + if SCons.Util.is_String(p): + p = self.subst(p) + r.append(p) + return r + def _update(self, dict): """Update an environment's values directly, bypassing the normal checks that occur when users try to set items. diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index a5cf1716..45f5fdbc 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -416,6 +416,17 @@ class EnvironmentTestCase(unittest.TestCase): subst = env.subst_list('$FOO', call=None) assert subst is bar, subst + def test_subst_path(self): + """Test substituting a path list + """ + env = Environment(FOO='foo', BAR='bar') + + r = env.subst_path('$FOO') + assert r == ['foo'], r + + r = env.subst_path(['$FOO', 'xxx', '$BAR']) + assert r == ['foo', 'xxx', 'bar'], r + def test_Builder_calls(self): """Test Builder calls through different environments """ diff --git a/src/engine/SCons/Scanner/CTests.py b/src/engine/SCons/Scanner/CTests.py index 253af885..abb72a44 100644 --- a/src/engine/SCons/Scanner/CTests.py +++ b/src/engine/SCons/Scanner/CTests.py @@ -182,6 +182,11 @@ class DummyEnvironment: def subst(self, arg): return arg + def subst_path(self, path): + if type(path) != type([]): + path = [path] + return map(self.subst, path) + def has_key(self, key): return self.Dictionary().has_key(key) diff --git a/src/engine/SCons/Scanner/FortranTests.py b/src/engine/SCons/Scanner/FortranTests.py index a719765e..e69f99e7 100644 --- a/src/engine/SCons/Scanner/FortranTests.py +++ b/src/engine/SCons/Scanner/FortranTests.py @@ -163,6 +163,11 @@ class DummyEnvironment: def subst(self, arg): return arg + def subst_path(self, path): + if type(path) != type([]): + path = [path] + return map(self.subst, path) + def deps_match(self, deps, headers): scanned = map(os.path.normpath, map(str, deps)) expect = map(os.path.normpath, headers) diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py index 9f178f88..4e104889 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -73,6 +73,11 @@ class DummyEnvironment: def subst(self, s): return s + def subst_path(self, path): + if type(path) != type([]): + path = [path] + return map(self.subst, path) + def deps_match(deps, libs): deps=map(str, deps) deps.sort() diff --git a/src/engine/SCons/Scanner/ScannerTests.py b/src/engine/SCons/Scanner/ScannerTests.py index 3d72bd23..169c74c8 100644 --- a/src/engine/SCons/Scanner/ScannerTests.py +++ b/src/engine/SCons/Scanner/ScannerTests.py @@ -35,6 +35,10 @@ class DummyEnvironment(UserDict.UserDict): self.data.update(kw) def subst(self, strSubst): return strSubst + def subst_path(self, path): + if type(path) != type([]): + path = [path] + return map(self.subst, path) class FindPathDirsTestCase(unittest.TestCase): def test_FindPathDirs(self): diff --git a/src/engine/SCons/Scanner/__init__.py b/src/engine/SCons/Scanner/__init__.py index 4bf8b6cf..dc9abc38 100644 --- a/src/engine/SCons/Scanner/__init__.py +++ b/src/engine/SCons/Scanner/__init__.py @@ -55,15 +55,7 @@ class FindPathDirs: except KeyError: return () - if not SCons.Util.is_List(path): - path = [path] - r = [] - for p in path: - if SCons.Util.is_String(p): - p = env.subst(p) - r.append(p) - - return tuple(self.fs.Rsearchall(r, + return tuple(self.fs.Rsearchall(env.subst_path(path), must_exist = 0, clazz = SCons.Node.FS.Dir, cwd = dir)) -- 2.26.2