Fix stripping the library prefix.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 12 Dec 2003 16:36:41 +0000 (16:36 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 12 Dec 2003 16:36:41 +0000 (16:36 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@861 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Builder.py
src/engine/SCons/Scanner/Prog.py
src/engine/SCons/Scanner/ProgTests.py
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py
test/LIBS.py

index 52dbafc265e8e60c984d04080646a110640560c8..bbeac15ebf43932cfdf28bc40c3999f71122b6c0 100644 (file)
@@ -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.
index 837229223493c0cf0bbc51699be8d4edec45993b..339a37689e60d5efcf35d232d754d8e6e7fa25bc 100644 (file)
@@ -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:
index 650d26a1627c8656affb2e453cf876188e7bf30d..5b3c93553debcccedd6767a1f7b362f551ed5899 100644 (file)
@@ -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
index 9162b8e6847a43c1cb1c78274d61b18e154d95f8..9f178f88774d9931c88d8a782916a3b74b43708e 100644 (file)
@@ -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):
index a558c2a36ba8888a08507b889261a6590a6d4b59..34822a610ec46f4ab831df54fac096b5b4d37a57 100644 (file)
@@ -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
index 2732f93b8bf976c6cdf97231a362ed0d7198a410..d6777086ab5ea3cf0f8932d1a7c9ff27c63c3a93 100644 (file)
@@ -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():
index c3125c7e17e0f6c9f35f61ea393c7f9c45d36ae7..e66899e71d86a286cb01496f4dd1b41d805f2b04 100644 (file)
@@ -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 <stdio.h>
+
+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 <stdio.h>
+#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()