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
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.
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
"""
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)
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)
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()
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):
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))