Allow environment substitutions when referencing libraries. (Chad Austin)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 2 Apr 2004 05:15:17 +0000 (05:15 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 2 Apr 2004 05:15:17 +0000 (05:15 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@939 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Scanner/Prog.py
src/engine/SCons/Scanner/ProgTests.py
test/Library.py

index b323e08e9067dcb027cb850ff0b2024ed9487e7f..0e4d4d89c1bb3be3a362e6e436655240c875fc4a 100644 (file)
@@ -14,6 +14,8 @@ RELEASE 0.96 - XXX
 
   - Make the CacheDir() directory if it doesn't already exist.
 
+  - Allow construction variable substitutions in $LIBS specifications.
+
   From Tom Epperly:
 
   - Allow the Java() Builder to take more than one source directory.
index 0100b3dad1905481d07e3a5a6648a61734b203bf..3c45ca28487cdf32acf64a5ae2c826461eedaa41 100644 (file)
@@ -76,6 +76,7 @@ def scan(node, env, libpath = (), fs = SCons.Node.FS.default_fs):
         for pref in map(env.subst, prefix):
             for lib in libs:
                 if SCons.Util.is_String(lib):
+                    lib = env.subst(lib)
                     lib = adjustixes(lib, pref, suf)
                     lib = find_file(lib, libpath, fs.File)
                     if lib:
index 4e1048898a8da240627238f098b2b65aa4860436..f3a275517e7dcb7ddbb065a8c1a831ce8a0f2437 100644 (file)
@@ -71,6 +71,11 @@ class DummyEnvironment:
         del self.Dictionary()[key]
 
     def subst(self, s):
+        try:
+            if s[0] == '$':
+                return self._dict[s[1:]]
+        except IndexError:
+            return ''
         return s
 
     def subst_path(self, path):
@@ -167,6 +172,19 @@ class ProgScanTestCase6(unittest.TestCase):
         deps = s('dummy', env, path)
         assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), map(str, deps)
 
+class ProgScanTestCase7(unittest.TestCase):
+    def runTest(self):
+        env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
+                               LIBS=['foo', '$LIBBAR', '$XYZ'],
+                               LIBPREFIXES=['lib'],
+                               LIBSUFFIXES=['.a'],
+                               LIBBAR='sub/libbar',
+                               XYZ='xyz.other')
+        s = SCons.Scanner.Prog.ProgScan()
+        path = s.path(env)
+        deps = s('dummy', env, path)
+        assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), map(str, deps)
+
 def suite():
     suite = unittest.TestSuite()
     suite.addTest(ProgScanTestCase1())
@@ -174,6 +192,7 @@ def suite():
     suite.addTest(ProgScanTestCase3())
     suite.addTest(ProgScanTestCase5())
     suite.addTest(ProgScanTestCase6())
+    suite.addTest(ProgScanTestCase7())
     if hasattr(types, 'UnicodeType'):
         code = """if 1:
             class ProgScanTestCase4(unittest.TestCase):
index 37641a86e4a23317021a0b4f29e9da4efdf6ef87..f22172c31fffad8c3679e6cde3b3e719b71199a4 100644 (file)
@@ -126,4 +126,32 @@ test.run(arguments = '.')
 test.run(program = test.workpath('prog'),
          stdout = "f1.c\nf2a.c\nf2b.c\nf2c.c\nf3a.c\nf3b.c\nf3c.cpp\nprog.c\n")
 
+# Tests whether you can reference libraries with substitutions.
+
+test.write('SConstruct', r"""
+# nrd = not referenced directly :)
+Library('nrd', 'nrd.c')
+p = Program('uses-nrd', 'uses-nrd.c', NRD='nrd', LIBPATH=['.'], LIBS=['$NRD'])
+Default(p)
+""")
+
+test.write('nrd.c', r"""
+#include <stdio.h>
+void nrd() {
+    puts("nrd");
+}
+""")
+
+test.write('uses-nrd.c', r"""
+void nrd();
+int main() {
+    nrd();
+    return 0;
+}
+""")
+
+test.run()
+test.run(program = test.workpath('uses-nrd'),
+         stdout = "nrd\n")
+
 test.pass_test()