From: stevenknight Date: Sun, 9 Nov 2003 06:41:02 +0000 (+0000) Subject: Allow LIBS to be a single element, not a list, and allow it to contain File nodes. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4add1d221c0db751d4b44dc6e85efe9c89ed8fec;p=scons.git Allow LIBS to be a single element, not a list, and allow it to contain File nodes. git-svn-id: http://scons.tigris.org/svn/scons/trunk@843 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 06ef176a..504fadfd 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -22,6 +22,11 @@ RELEASE 0.95 - XXX - Fix looking up a naked drive letter as a directory (Dir('C:')). + - Support using File nodes in the LIBS construction variable. + + - Allow the LIBS construction variable to be a single string or File + node, not a list, when only one library is needed. + RELEASE 0.94 - Fri, 07 Nov 2003 05:29:48 -0600 diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index aaa1abaa..c75c7c75 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -195,6 +195,8 @@ def _stripixes(prefix, list, suffix, stripprefix, stripsuffix, env, c=_concat): def f(list, sp=stripprefix, ss=stripsuffix): ret = [] for l in list: + if not SCons.Util.is_String(l): + l = str(l) if l[:len(sp)] == sp: l = l[len(sp):] if l[-len(ss):] == ss: diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index 6145ce06..650d26a1 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -60,6 +60,8 @@ def scan(node, env, libpath = (), fs = SCons.Node.FS.default_fs): return [] if SCons.Util.is_String(libs): libs = string.split(libs) + elif not SCons.Util.is_List(libs): + libs = [libs] try: prefix = env.Dictionary('LIBPREFIXES') @@ -75,8 +77,15 @@ def scan(node, env, libpath = (), fs = SCons.Node.FS.default_fs): except KeyError: suffix = [ '' ] + find_file = SCons.Node.FS.find_file ret = [] for suf in map(env.subst, suffix): for pref in map(env.subst, prefix): - ret.extend(map(lambda x, s=suf, p=pref: p + x + s, libs)) - return SCons.Node.FS.find_files(ret, libpath, fs.File) + for lib in libs: + if SCons.Util.is_String(lib): + f = find_file(pref + lib + suf, libpath, fs.File) + if f: + ret.append(f) + else: + ret.append(lib) + return ret diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py index 98d9c785..9162b8e6 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -30,6 +30,7 @@ import types import unittest import TestCmd +import SCons.Node.FS import SCons.Scanner.Prog test = TestCmd.TestCmd(workdir = '') @@ -90,6 +91,30 @@ class ProgScanTestCase1(unittest.TestCase): deps = s('dummy', env, path) assert deps_match(deps, ['l1.lib']), map(str, deps) + env = DummyEnvironment(LIBPATH=[ test.workpath("") ], + LIBS='l1') + s = SCons.Scanner.Prog.ProgScan() + path = s.path(env) + deps = s('dummy', env, path) + assert deps_match(deps, ['l1.lib']), map(str, deps) + + f1 = SCons.Node.FS.default_fs.File(test.workpath('f1')) + env = DummyEnvironment(LIBPATH=[ test.workpath("") ], + LIBS=[f1]) + s = SCons.Scanner.Prog.ProgScan() + path = s.path(env) + deps = s('dummy', env, path) + assert deps[0] is f1, deps + + f2 = SCons.Node.FS.default_fs.File(test.workpath('f1')) + env = DummyEnvironment(LIBPATH=[ test.workpath("") ], + LIBS=f2) + s = SCons.Scanner.Prog.ProgScan() + path = s.path(env) + deps = s('dummy', env, path) + assert deps[0] is f2, deps + + class ProgScanTestCase2(unittest.TestCase): def runTest(self): env = DummyEnvironment(LIBPATH=map(test.workpath, diff --git a/test/LIBS.py b/test/LIBS.py index c9bcecdd..c3125c7e 100644 --- a/test/LIBS.py +++ b/test/LIBS.py @@ -29,21 +29,32 @@ import sys if sys.platform == 'win32': _exe = '.exe' + bar_lib = 'bar.lib' else: _exe = '' + bar_lib = 'libbar.a' test = TestSCons.TestSCons() test.subdir('sub1', 'sub2') -foo_exe = test.workpath('foo' + _exe) +foo1_exe = test.workpath('foo1' + _exe) +foo2_exe = test.workpath('foo2' + _exe) +foo3_exe = test.workpath('foo3' + _exe) +foo4_exe = test.workpath('foo4' + _exe) test.write('SConstruct', """ env = Environment(LIBS=['bar'], LIBPATH = '.') -env.Program(target='foo', source='foo.c') +env.Program(target='foo1', source='foo1.c') +env2 = Environment(LIBS=[File(r'%s')], LIBPATH = '.') +env2.Program(target='foo2', source='foo2.c') +env3 = Environment(LIBS='bar', LIBPATH = '.') +env3.Program(target='foo3', source='foo3.c') +env4 = Environment(LIBS=File(r'%s'), LIBPATH = '.') +env4.Program(target='foo4', source='foo4.c') SConscript('sub1/SConscript', 'env') SConscript('sub2/SConscript', 'env') -""") +""" % (bar_lib, bar_lib)) test.write(['sub1', 'SConscript'], r""" Import('env') @@ -57,7 +68,7 @@ lib = env.Library(target='baz', source='baz.c') env.Install('..', lib) """) -test.write('foo.c', r""" +foo_contents = r""" void bar(); void baz(); @@ -67,7 +78,12 @@ int main(void) baz(); return 0; } -""") +""" + +test.write('foo1.c', foo_contents) +test.write('foo2.c', foo_contents) +test.write('foo3.c', foo_contents) +test.write('foo4.c', foo_contents) test.write(['sub1', 'bar.c'], r""" #include @@ -98,24 +114,27 @@ void baz() test.run(arguments = '.') -test.run(program=foo_exe, stdout='sub1/bar.c\nsub1/baz.c\n') +test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c\n') +test.run(program=foo2_exe, stdout='sub1/bar.c\nsub1/baz.c\n') +test.run(program=foo3_exe, stdout='sub1/bar.c\nsub1/baz.c\n') +test.run(program=foo4_exe, stdout='sub1/bar.c\nsub1/baz.c\n') # test.write('SConstruct', """ env = Environment() -env.Program(target='foo', source='foo.c', LIBS=['baz', 'bar'], LIBPATH = '.') +env.Program(target='foo1', source='foo1.c', LIBS=['baz', 'bar'], LIBPATH = '.') SConscript('sub1/SConscript', 'env') SConscript('sub2/SConscript', 'env') """) test.run(arguments = '.') -test.run(program=foo_exe, stdout='sub1/bar.c\nsub2/baz.c\n') +test.run(program=foo1_exe, stdout='sub1/bar.c\nsub2/baz.c\n') # test.write('SConstruct', """ env = Environment(LIBS=['bar', 'baz'], LIBPATH = '.') -env.Program(target='foo', source='foo.c') +env.Program(target='foo1', source='foo1.c') SConscript('sub1/SConscript', 'env') SConscript('sub2/SConscript', 'env') """) @@ -126,19 +145,19 @@ test.run(arguments = '.', stderr=None) sw = 'ld32: WARNING 84 : ./libbaz.a is not used for resolving any symbol.\n' test.fail_test(not test.stderr() in ['', sw]) -test.run(program=foo_exe, stdout='sub1/bar.c\nsub1/baz.c\n') +test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c\n') # test.write('SConstruct', """ env = Environment() -env.Program(target='foo', source='foo.c', LIBS=['bar', 'baz'], LIBPATH = '.') +env.Program(target='foo1', source='foo1.c', LIBS=['bar', 'baz'], LIBPATH = '.') SConscript('sub1/SConscript', 'env') SConscript('sub2/SConscript', 'env') """) test.run(arguments = '.') -test.run(program=foo_exe, stdout='sub1/bar.c\nsub1/baz.c\n') +test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c\n') test.write(['sub1', 'baz.c'], r""" #include @@ -152,6 +171,6 @@ void baz() test.run(arguments = '.', stderr=None) test.fail_test(not test.stderr() in ['', sw]) -test.run(program=foo_exe, stdout='sub1/bar.c\nsub1/baz.c 2\n') +test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c 2\n') test.pass_test()