- 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.
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)
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:
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
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
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):
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
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():
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()