From 92679290ece0dc886840276c90c94ed91b2a949d Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 2 Apr 2004 05:15:17 +0000 Subject: [PATCH] Allow environment substitutions when referencing libraries. (Chad Austin) git-svn-id: http://scons.tigris.org/svn/scons/trunk@939 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/CHANGES.txt | 2 ++ src/engine/SCons/Scanner/Prog.py | 1 + src/engine/SCons/Scanner/ProgTests.py | 19 ++++++++++++++++++ test/Library.py | 28 +++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index b323e08e..0e4d4d89 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -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. diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index 0100b3da..3c45ca28 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -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: diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py index 4e104889..f3a27551 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -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): diff --git a/test/Library.py b/test/Library.py index 37641a86..f22172c3 100644 --- a/test/Library.py +++ b/test/Library.py @@ -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 +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() -- 2.26.2