Refactor path-substitution logic into an Environment method.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 5 Mar 2004 08:51:01 +0000 (08:51 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 5 Mar 2004 08:51:01 +0000 (08:51 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@914 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Defaults.py
src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py
src/engine/SCons/Scanner/CTests.py
src/engine/SCons/Scanner/FortranTests.py
src/engine/SCons/Scanner/ProgTests.py
src/engine/SCons/Scanner/ScannerTests.py
src/engine/SCons/Scanner/__init__.py

index bf6d59f86ab16e1c41d7cbb397de18ec31a9a8b3..78103ef83989c759d52573e386b8005579de2fc1 100644 (file)
@@ -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
 
index c6bc2a995729ec64a4170dc164c9c5ed843c1868..2235ace4a1fe8034b375775597206eb3250213e8 100644 (file)
@@ -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.
index a5cf171691d576ef5481be02c289c41ff5469845..45f5fdbc781c991de2f5d1562ecc377b1d4bd995 100644 (file)
@@ -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
         """
index 253af88543e97a0a4a0c11c207d7fb255704f72d..abb72a4444a9a9fb2048ac0154a1d224afdd550b 100644 (file)
@@ -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)
 
index a719765ecfb2f19e2ccc2d50461fa7e470505f0c..e69f99e754135381bdac6b3e386dd602687f8f0b 100644 (file)
@@ -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)
index 9f178f88774d9931c88d8a782916a3b74b43708e..4e1048898a8da240627238f098b2b65aa4860436 100644 (file)
@@ -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()
index 3d72bd236c3fa854d4169602cc66939cb6714e4e..169c74c89ca3109e0a2cf8e31efcfe35ede78ce2 100644 (file)
@@ -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):
index 4bf8b6cf305722b2f3efdc91dd1054aa33f42e43..dc9abc381027d48e43d7a791693dc0128a555cbe 100644 (file)
@@ -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))