From: stevenknight Date: Fri, 12 Dec 2003 16:36:41 +0000 (+0000) Subject: Fix stripping the library prefix. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=10ef1782b2ac9aa4dd6726b8d8eef8d4dcac77b8;p=scons.git Fix stripping the library prefix. git-svn-id: http://scons.tigris.org/svn/scons/trunk@861 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 52dbafc2..bbeac15e 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -89,6 +89,9 @@ RELEASE 0.95 - XXX - Correct error message spellings of "non-existant" to "non-existent." + - When scanning for libraries to link with, don't append $LIBPREFIXES + or $LIBSUFFIXES values to the $LIBS values if they're already present. + From Vincent Risi: - Add support for the bcc32, ilink32 and tlib Borland tools. diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py index 83722922..339a3768 100644 --- a/src/engine/SCons/Builder.py +++ b/src/engine/SCons/Builder.py @@ -313,31 +313,24 @@ class BuilderBase: def _create_nodes(self, env, overrides, target = None, source = None): """Create and return lists of target and source nodes. """ - def adjustixes(files, pre, suf, self=self): + def _adjustixes(files, pre, suf): if not files: return [] - ret = [] + result = [] if not SCons.Util.is_List(files): files = [files] for f in files: if SCons.Util.is_String(f): - if pre: - path, fn = os.path.split(os.path.normpath(f)) - if fn[:len(pre)] != pre: - f = os.path.join(path, pre + fn) - # Only append a suffix if the file does not have one. - if suf and not self.splitext(f)[1]: - if f[-len(suf):] != suf: - f = f + suf - ret.append(f) - return ret + f = SCons.Util.adjustixes(f, pre, suf) + result.append(f) + return result env = env.Override(overrides) src_suf = self.get_src_suffix(env) - source = adjustixes(source, None, src_suf) + source = _adjustixes(source, None, src_suf) slist = env.arg2nodes(source, self.source_factory) pre = self.get_prefix(env, slist) @@ -350,7 +343,7 @@ class BuilderBase: raise UserError("Do not know how to create a target from source `%s'" % slist[0]) tlist = [ t_from_s(pre, suf, self.splitext) ] else: - target = adjustixes(target, pre, suf) + target = _adjustixes(target, pre, suf) tlist = env.arg2nodes(target, self.target_factory) if self.emitter: diff --git a/src/engine/SCons/Scanner/Prog.py b/src/engine/SCons/Scanner/Prog.py index 650d26a1..5b3c9355 100644 --- a/src/engine/SCons/Scanner/Prog.py +++ b/src/engine/SCons/Scanner/Prog.py @@ -78,14 +78,16 @@ def scan(node, env, libpath = (), fs = SCons.Node.FS.default_fs): suffix = [ '' ] find_file = SCons.Node.FS.find_file - ret = [] + adjustixes = SCons.Util.adjustixes + result = [] for suf in map(env.subst, suffix): for pref in map(env.subst, prefix): for lib in libs: if SCons.Util.is_String(lib): - f = find_file(pref + lib + suf, libpath, fs.File) - if f: - ret.append(f) + lib = adjustixes(lib, pref, suf) + lib = find_file(lib, libpath, fs.File) + if lib: + result.append(lib) else: - ret.append(lib) - return ret + result.append(lib) + return result diff --git a/src/engine/SCons/Scanner/ProgTests.py b/src/engine/SCons/Scanner/ProgTests.py index 9162b8e6..9f178f88 100644 --- a/src/engine/SCons/Scanner/ProgTests.py +++ b/src/engine/SCons/Scanner/ProgTests.py @@ -35,20 +35,21 @@ import SCons.Scanner.Prog test = TestCmd.TestCmd(workdir = '') -test.subdir('d1', ['d1', 'd2']) +test.subdir('d1', ['d1', 'd2'], 'dir', ['dir', 'sub']) -libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ] +libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib', + 'dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other'] for h in libs: - test.write(h, " ") + test.write(h, "\n") # define some helpers: class DummyEnvironment: def __init__(self, **kw): - self._dict = kw - self._dict['LIBSUFFIXES'] = '.lib' - + self._dict = {'LIBSUFFIXES' : '.lib'} + self._dict.update(kw) + def Dictionary(self, *args): if not args: return self._dict @@ -150,12 +151,24 @@ class ProgScanTestCase5(unittest.TestCase): deps = s('dummy', env, path) assert deps_match(deps, [ 'd1/l2.lib' ]), map(str, deps) +class ProgScanTestCase6(unittest.TestCase): + def runTest(self): + env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ], + LIBS=['foo', 'sub/libbar', 'xyz.other'], + LIBPREFIXES=['lib'], + LIBSUFFIXES=['.a']) + 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()) suite.addTest(ProgScanTestCase2()) suite.addTest(ProgScanTestCase3()) suite.addTest(ProgScanTestCase5()) + suite.addTest(ProgScanTestCase6()) if hasattr(types, 'UnicodeType'): code = """if 1: class ProgScanTestCase4(unittest.TestCase): diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index a558c2a3..34822a61 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -982,3 +982,13 @@ if sys.platform == 'cygwin': else: def case_sensitive_suffixes(s1, s2): return (os.path.normcase(s1) != os.path.normcase(s2)) + +def adjustixes(file, pre, suf): + if pre: + path, fn = os.path.split(os.path.normpath(file)) + if fn[:len(pre)] != pre: + file = os.path.join(path, pre + fn) + # Only append a suffix if the file does not have one. + if suf and not splitext(file)[1] and file[-len(suf):] != suf: + file = file + suf + return file diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index 2732f93b..d6777086 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -1044,6 +1044,21 @@ class UtilTestCase(unittest.TestCase): ret = s(env, ['bar.g']) assert ret == 'GGG', ret + def test_adjustixes(self): + """Test the adjustixes() function""" + r = adjustixes('file', 'pre-', '-suf') + assert r == 'pre-file-suf', r + r = adjustixes('pre-file', 'pre-', '-suf') + assert r == 'pre-file-suf', r + r = adjustixes('file-suf', 'pre-', '-suf') + assert r == 'pre-file-suf', r + r = adjustixes('pre-file-suf', 'pre-', '-suf') + assert r == 'pre-file-suf', r + r = adjustixes('pre-file.xxx', 'pre-', '-suf') + assert r == 'pre-file.xxx', r + r = adjustixes('dir/file', 'pre-', '-suf') + assert r == 'dir/pre-file-suf', r + if __name__ == "__main__": suite = unittest.makeSuite(UtilTestCase, 'test_') if not unittest.TextTestRunner().run(suite).wasSuccessful(): diff --git a/test/LIBS.py b/test/LIBS.py index c3125c7e..e66899e7 100644 --- a/test/LIBS.py +++ b/test/LIBS.py @@ -173,4 +173,67 @@ test.fail_test(not test.stderr() in ['', sw]) test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c 2\n') +# Make sure we don't add $LIBPREFIX to library names that +# already have the prefix on them. +blender_exe = test.workpath('blender' + _exe) + +test.subdir('src', ['src', 'component1'], ['src', 'component2']) + +test.write('SConstruct', """\ +SConscript(['src/SConscript']) + +libpath = (['lib']) +libraries = (['libtest_component2', + 'libtest_component1']) + +# To remove the dependency problem, you should rename blender to mlender. +Program (source='', target='blender', LIBS=libraries, LIBPREFIX='lib', LIBPATH=libpath) +""") + +test.write(['src', 'SConscript'], """\ +SConscript(['component1/SConscript', + 'component2/SConscript']) +""") + +test.write(['src', 'component1', 'SConscript'], """\ +source_files = ['message.c'] +Library (target='../../lib/libtest_component1', source=source_files) +""") + +test.write(['src', 'component1', 'message.c'], """\ +#include + +void DisplayMessage (void) +{ + printf ("src/component1/message.c\\n"); +} +""") + +test.write(['src', 'component1', 'message.h'], """\ +void DisplayMessage (void); +""") + +test.write(['src', 'component2', 'SConscript'], """\ +source_files = ['hello.c'] +include_paths = ['../component1'] +Library (target='../../lib/libtest_component2', source=source_files, CPPPATH=include_paths) +""") + +test.write(['src', 'component2', 'hello.c'], """\ +#include +#include "message.h" + +int main (void) +{ + DisplayMessage(); + printf ("src/component2/hello.c\\n"); + exit (0); +} +""") + +test.run(arguments = '.') + +test.run(program=blender_exe, + stdout='src/component1/message.c\nsrc/component2/hello.c\n') + test.pass_test()