summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-03-05 08:51:01 (GMT)
committerSteven Knight <knight@baldmt.com>2004-03-05 08:51:01 (GMT)
commitbb42c27bfa1a4208fc3cdc7b583b8093305fc4c0 (patch)
tree40bbe3ce2769d5fc3c9b201a13a59f5c6ebf12e7 /src/engine/SCons
parentc6a5a383c8771988bc829ef90111afc4db03cc5f (diff)
downloadSCons-bb42c27bfa1a4208fc3cdc7b583b8093305fc4c0.zip
SCons-bb42c27bfa1a4208fc3cdc7b583b8093305fc4c0.tar.gz
SCons-bb42c27bfa1a4208fc3cdc7b583b8093305fc4c0.tar.bz2
Refactor path-substitution logic into an Environment method.
Diffstat (limited to 'src/engine/SCons')
-rw-r--r--src/engine/SCons/Defaults.py38
-rw-r--r--src/engine/SCons/Environment.py13
-rw-r--r--src/engine/SCons/EnvironmentTests.py11
-rw-r--r--src/engine/SCons/Scanner/CTests.py5
-rw-r--r--src/engine/SCons/Scanner/FortranTests.py5
-rw-r--r--src/engine/SCons/Scanner/ProgTests.py5
-rw-r--r--src/engine/SCons/Scanner/ScannerTests.py4
-rw-r--r--src/engine/SCons/Scanner/__init__.py10
8 files changed, 59 insertions, 32 deletions
diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py
index bf6d59f..78103ef 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 c6bc2a9..2235ace 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 a5cf171..45f5fdb 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 253af88..abb72a4 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 a719765..e69f99e 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 9f178f8..4e10488 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 3d72bd2..169c74c 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 4bf8b6c..dc9abc3 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))