diff options
Diffstat (limited to 'test/Libs')
| -rw-r--r-- | test/Libs/LIBPATH.py | 181 | ||||
| -rw-r--r-- | test/Libs/LIBPREFIX.py | 44 | ||||
| -rw-r--r-- | test/Libs/LIBPREFIXES.py | 86 | ||||
| -rw-r--r-- | test/Libs/LIBS-LIBPREFIX-exists.py | 130 | ||||
| -rw-r--r-- | test/Libs/LIBS.py | 219 | ||||
| -rw-r--r-- | test/Libs/LIBSUFFIX.py | 44 | ||||
| -rw-r--r-- | test/Libs/LIBSUFFIXES.py | 86 | ||||
| -rw-r--r-- | test/Libs/Library.py | 173 | ||||
| -rw-r--r-- | test/Libs/SHLIBPREFIX.py | 59 | ||||
| -rw-r--r-- | test/Libs/SHLIBSUFFIX.py | 59 | ||||
| -rw-r--r-- | test/Libs/SharedLibrary-update-deps.py | 70 | ||||
| -rw-r--r-- | test/Libs/SharedLibrary.py | 309 | ||||
| -rw-r--r-- | test/Libs/SharedLibraryIxes.py | 298 | ||||
| -rw-r--r-- | test/Libs/bug2903/SConstruct | 13 | ||||
| -rw-r--r-- | test/Libs/bug2903/SConstruct-libs | 5 | ||||
| -rw-r--r-- | test/Libs/bug2903/lib.c | 4 | ||||
| -rw-r--r-- | test/Libs/bug2903/main.c | 6 |
17 files changed, 1786 insertions, 0 deletions
diff --git a/test/Libs/LIBPATH.py b/test/Libs/LIBPATH.py new file mode 100644 index 0000000..b5a1b54 --- /dev/null +++ b/test/Libs/LIBPATH.py @@ -0,0 +1,181 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os.path +import time + +import TestSCons + +_exe = TestSCons._exe +_dll = TestSCons._dll +dll_ = TestSCons.dll_ + +test = TestSCons.TestSCons() + +test.subdir('lib1', 'lib2') + +prog1 = test.workpath('prog') + _exe +prog2 = test.workpath(dll_ + 'shlib') + _dll + +test.write('SConstruct', """ +env1 = Environment(LIBS = [ 'foo1' ], + LIBPATH = [ '$FOO' ], + FOO='./lib1') + +f1 = env1.SharedObject('f1', 'f1.c') + +env1.Program(target = 'prog', source = 'prog.c') +env1.Library(target = './lib1/foo1', source = f1) + +env2 = Environment(LIBS = 'foo2', + LIBPATH = '.') +env2.SharedLibrary(target = 'shlib', source = 'shlib.c', no_import_lib = 1) +env2.Library(target = 'foo2', source = f1) +""") + +test.write('f1.c', r""" +#include <stdio.h> + +void +f1(void) +{ + printf("f1.c\n"); +} +""") + +test.write('shlib.c', r""" +void f1(void); +int +test() +{ + f1(); + return 0; +} +""") + +test.write('prog.c', r""" +#include <stdio.h> + +void f1(void); +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + f1(); + printf("prog.c\n"); + return 0; +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +test.run(program = prog1, + stdout = "f1.c\nprog.c\n") + +oldtime1 = os.path.getmtime(prog1) +oldtime2 = os.path.getmtime(prog2) +time.sleep(2) +test.run(arguments = '.') + +test.fail_test(oldtime1 != os.path.getmtime(prog1)) +test.fail_test(oldtime2 != os.path.getmtime(prog2)) + +test.write('f1.c', r""" +#include <stdio.h> + +void +f1(void) +{ + printf("f1.c 1\n"); +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) +test.run(program = prog1, + stdout = "f1.c 1\nprog.c\n") +test.fail_test(oldtime2 == os.path.getmtime(prog2)) +#test.up_to_date(arguments = '.') +# Change LIBPATH and make sure we don't rebuild because of it. +test.write('SConstruct', """ +env1 = Environment(LIBS = [ 'foo1' ], + LIBPATH = [ './lib1', './lib2' ]) + +f1 = env1.SharedObject('f1', 'f1.c') + +env1.Program(target = 'prog', source = 'prog.c') +env1.Library(target = './lib1/foo1', source = f1) + +env2 = Environment(LIBS = 'foo2', + LIBPATH = Split('. ./lib2')) +env2.SharedLibrary(target = 'shlib', source = 'shlib.c', no_import_lib = 1) +env2.Library(target = 'foo2', source = f1) +""") + +test.up_to_date(arguments = '.', stderr=None) + +test.write('f1.c', r""" +#include <stdio.h> + +void +f1(void) +{ + printf("f1.c 2\n"); +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) +test.run(program = prog1, + stdout = "f1.c 2\nprog.c\n") + +test.up_to_date(arguments = '.') + +# We need at least one file for some implementations of the Library +# builder, notably the SGI one. +test.write('empty.c', 'int a=0;\n') + +# Check that a null-string LIBPATH doesn't blow up. +test.write('SConstruct', """ +env = Environment(LIBPATH = '') +env.Library('foo', source = 'empty.c') +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/LIBPREFIX.py b/test/Libs/LIBPREFIX.py new file mode 100644 index 0000000..764fb4e --- /dev/null +++ b/test/Libs/LIBPREFIX.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons + +test = TestSCons.TestSCons() + +test.pass_test() #XXX Short-circuit until this is implemented. + +test.write('SConstruct', """ +""") + +test.run(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/LIBPREFIXES.py b/test/Libs/LIBPREFIXES.py new file mode 100644 index 0000000..aed451e --- /dev/null +++ b/test/Libs/LIBPREFIXES.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import sys +import TestSCons + +if sys.platform == 'win32': + _lib = '.lib' + import SCons.Tool.MSCommon as msc + if not msc.msvc_exists(): + _lib = '.a' +else: + _lib = '.a' + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +env = Environment(LIBPREFIX = 'xxx-', + LIBPREFIXES = ['xxx-']) +lib = env.Library(target = 'foo', source = 'foo.c') +env.Program(target = 'prog', source = ['prog.c', lib]) +""") + +test.write('foo.c', r""" +#include <stdio.h> + +void +foo(void) +{ + printf("foo.c\n"); +} +""") + +test.write('prog.c', r""" +#include <stdio.h> + +void foo(void); +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + foo(); + printf("prog.c\n"); + return 0; +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +test.fail_test(not os.path.exists(test.workpath('xxx-foo' + _lib))) + +test.run(program = test.workpath('prog'), stdout = "foo.c\nprog.c\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/LIBS-LIBPREFIX-exists.py b/test/Libs/LIBS-LIBPREFIX-exists.py new file mode 100644 index 0000000..814eda9 --- /dev/null +++ b/test/Libs/LIBS-LIBPREFIX-exists.py @@ -0,0 +1,130 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that we don't add $LIBPREFIX to library names in $LIBS that +already have the prefix on them. +""" + +import TestSCons + +_exe = TestSCons._exe + +test = TestSCons.TestSCons() + +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='main.c', + target='blender', + LIBS=libraries, + LIBPREFIX='lib', + LIBPATH=libpath, + CPPPATH=['src/component2']) +""") + +test.write('main.c', """\ +#include <stdlib.h> +#include "message2.h" + +int main (void) +{ + DisplayMessage2(); + exit (0); +} +""") + +test.write(['src', 'SConscript'], """\ +SConscript(['component1/SConscript', + 'component2/SConscript']) +""") + +test.write(['src', 'component1', 'SConscript'], """\ +source_files = ['message1.c'] +Library(target='../../lib/libtest_component1', + source=source_files, + LINKFLAGS='') +""") + +test.write(['src', 'component1', 'message1.c'], """\ +#include <stdio.h> + +void DisplayMessage1 (void) +{ + printf ("src/component1/message.c\\n"); +} +""") + +test.write(['src', 'component1', 'message1.h'], """\ +void DisplayMessage1 (void); +""") + +test.write(['src', 'component2', 'SConscript'], """\ +source_files = ['message2.c'] +include_paths = ['../component1'] +Library(target='../../lib/libtest_component2', + source=source_files, + CPPPATH=include_paths) +""") + +test.write(['src', 'component2', 'message2.h'], """\ +void DisplayMessage2 (void); +""") + +test.write(['src', 'component2', 'message2.c'], """\ +#include <stdio.h> +#include "message1.h" + +void DisplayMessage2 (void) +{ + DisplayMessage1(); + printf ("src/component2/hello.c\\n"); +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +test.run(program=blender_exe, + stdout='src/component1/message.c\nsrc/component2/hello.c\n') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/LIBS.py b/test/Libs/LIBS.py new file mode 100644 index 0000000..5639228 --- /dev/null +++ b/test/Libs/LIBS.py @@ -0,0 +1,219 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons +import sys + +if sys.platform == 'win32': + _exe = '.exe' + bar_lib = 'bar.lib' + import SCons.Tool.MSCommon as msc + if not msc.msvc_exists(): + bar_lib = 'libbar.a' +else: + _exe = '' + bar_lib = 'libbar.a' + +test = TestSCons.TestSCons() + +test.subdir('sub1', 'sub2') + +foo1_exe = test.workpath('foo1' + _exe) +foo2_exe = test.workpath('foo2' + _exe) +foo3_exe = test.workpath('foo3' + _exe) +foo4_exe = test.workpath('foo4' + _exe) +foo5_exe = test.workpath('foo5' + _exe) +slprog_exe = test.workpath('slprog' + _exe) + +test.write('SConstruct', """ +env = Environment(LIBS=['bar'], LIBPATH = '.') +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') +env5 = Environment(LIBS=['bar', '$UNSPECIFIED'], LIBPATH = '.') +env5.Program(target='foo5', source='foo5.c') +sl = env.StaticLibrary('sl.c') +env.Program(target='slprog.c', LIBS=[sl]) +SConscript('sub1/SConscript', 'env') +SConscript('sub2/SConscript', 'env') +""" % (bar_lib, bar_lib)) + +test.write(['sub1', 'SConscript'], r""" +Import('env') +lib = env.Library(target='bar', source=Split('bar.c baz.c')) +env.Install('..', lib) +""") + +test.write(['sub2', 'SConscript'], r""" +Import('env') +lib = env.Library(target='baz', source='baz.c') +env.Install('..', lib) +""") + +foo_contents = r""" +void bar(); +void baz(); + +int main(void) +{ + bar(); + 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('foo5.c', foo_contents) + +test.write('sl.c', """\ +#include <stdio.h> +void +sl(void) +{ + printf("sl.c\\n"); +} +""") + +test.write('slprog.c', """\ +#include <stdio.h> +int +main(int argc, char *argv[]) +{ + sl(); + printf("slprog.c\\n"); + exit (0); +} +""") + +test.write(['sub1', 'bar.c'], r""" +#include <stdio.h> + +void bar() +{ + printf("sub1/bar.c\n"); +} +""") + +test.write(['sub1', 'baz.c'], r""" +#include <stdio.h> + +void baz() +{ + printf("sub1/baz.c\n"); +} +""") + +test.write(['sub2', 'baz.c'], r""" +#include <stdio.h> + +void baz() +{ + printf("sub2/baz.c\n"); +} +""") + +# ar sometimes produces a "warning" on stderr -- ar: creating sub1/libbar.a +test.run(arguments = '.', stderr=None) + +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.run(program=foo5_exe, stdout='sub1/bar.c\nsub1/baz.c\n') +test.run(program=slprog_exe, stdout='sl.c\nslprog.c\n') + +# +test.write('SConstruct', """ +env = Environment(LIBS=['baz']) +env.Program(target='foo1', source='foo1.c', LIBS=['$LIBS', 'bar'], LIBPATH = '.') +SConscript('sub1/SConscript', 'env') +SConscript('sub2/SConscript', 'env') +""") + +test.run(arguments = '.') + +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='foo1', source='foo1.c') +SConscript('sub1/SConscript', 'env') +SConscript('sub2/SConscript', 'env') +""") + + +# on IRIX, ld32 prints out a warning saying that libbaz.a isn't used +sw = 'ld32: WARNING 84 : ./libbaz.a is not used for resolving any symbol.\n' +test.run(arguments = '.', + stderr='(%s|%s'%(sw, TestSCons.noisy_ar[1:]), + match=TestSCons.match_re_dotall) +#test.fail_test(not test.stderr() in ['', sw]) + +test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c\n') + +# +test.write('SConstruct', """ +env = Environment() +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=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c\n') + +test.write(['sub1', 'baz.c'], r""" +#include <stdio.h> + +void baz() +{ + printf("sub1/baz.c 2\n"); +} +""") + +test.run(arguments = '.', + stderr='(%s|%s'%(sw, TestSCons.noisy_ar[1:]), + match=TestSCons.match_re_dotall) +#test.fail_test(not test.stderr() in ['', sw, TestSCons.noisy_ar]) + +test.run(program=foo1_exe, stdout='sub1/bar.c\nsub1/baz.c 2\n') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/LIBSUFFIX.py b/test/Libs/LIBSUFFIX.py new file mode 100644 index 0000000..764fb4e --- /dev/null +++ b/test/Libs/LIBSUFFIX.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons + +test = TestSCons.TestSCons() + +test.pass_test() #XXX Short-circuit until this is implemented. + +test.write('SConstruct', """ +""") + +test.run(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/LIBSUFFIXES.py b/test/Libs/LIBSUFFIXES.py new file mode 100644 index 0000000..13baeab --- /dev/null +++ b/test/Libs/LIBSUFFIXES.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import sys +import TestSCons + +if sys.platform == 'win32': + lib_ = '' + import SCons.Tool.MSCommon as msc + if not msc.msvc_exists(): + lib_ = 'lib' +else: + lib_ = 'lib' + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +env = Environment(LIBSUFFIX = '.xxx', + LIBSUFFIXES = ['.xxx']) +lib = env.Library(target = 'foo', source = 'foo.c') +env.Program(target = 'prog', source = ['prog.c', lib]) +""") + +test.write('foo.c', r""" +#include <stdio.h> + +void +foo(void) +{ + printf("foo.c\n"); +} +""") + +test.write('prog.c', r""" +#include <stdio.h> + +void foo(void); +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + foo(); + printf("prog.c\n"); + return 0; +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +test.fail_test(not os.path.exists(test.workpath(lib_ + 'foo.xxx'))) + +test.run(program = test.workpath('prog'), stdout = "foo.c\nprog.c\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/Library.py b/test/Libs/Library.py new file mode 100644 index 0000000..b603926 --- /dev/null +++ b/test/Libs/Library.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +env = Environment(LIBS = [ 'foo1', 'libfoo2' ], + LIBPATH = [ '.' ]) +env.Library(target = 'foo1', source = 'f1.c') +Library(target = 'libfoo2', source = Split('f2a.c f2b.c f2c.c')) +libtgt=env.Library(target = 'foo3', source = ['f3a.c', 'f3b.c', 'f3c.cpp']) +env.Program(target = 'prog', source = [ 'prog.cpp', libtgt ]) +""") + +test.write('f1.c', r""" +#include <stdio.h> +void +f1(void) +{ + printf("f1.c\n"); +} +""") + +test.write('f2a.c', r""" +#include <stdio.h> +void +f2a(void) +{ + printf("f2a.c\n"); +} +""") + +test.write('f2b.c', r""" +#include <stdio.h> +void +f2b(void) +{ + printf("f2b.c\n"); +} +""") + +test.write('f2c.c', r""" +#include <stdio.h> +void +f2c(void) +{ + printf("f2c.c\n"); +} +""") + +test.write('f3a.c', r""" +#include <stdio.h> +void +f3a(void) +{ + printf("f3a.c\n"); +} +""") + +test.write('f3b.c', r""" +#include <stdio.h> +void +f3b(void) +{ + printf("f3b.c\n"); +} +""") + +test.write('f3c.cpp', r""" +#include <stdio.h> +extern "C" void +f3c(void) +{ + printf("f3c.cpp\n"); +} +""") + +test.write('prog.cpp', r""" +#include <stdio.h> +extern "C" { +void f1(void); +void f2a(void); +void f2b(void); +void f2c(void); +void f3a(void); +void f3b(void); +void f3c(void); +} +int +main(int argc, char *argv[]) +{ + argv[argc++] = (char *)"--"; + f1(); + f2a(); + f2b(); + f2c(); + f3a(); + f3b(); + f3c(); + printf("prog.c\n"); + return 0; +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +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 <stdio.h> +void nrd() { + puts("nrd"); +} +""") + +test.write('uses-nrd.c', r""" +void nrd(); +int main() { + nrd(); + return 0; +} +""") + +test.run(stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +test.run(program = test.workpath('uses-nrd'), + stdout = "nrd\n") + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/SHLIBPREFIX.py b/test/Libs/SHLIBPREFIX.py new file mode 100644 index 0000000..c46b5aa --- /dev/null +++ b/test/Libs/SHLIBPREFIX.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os + +import TestSCons + +_lib = TestSCons._dll + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +env = Environment(SHLIBPREFIX = 'shlib-') +env.SharedLibrary(target = 'foo', source = 'foo.c') +""") + +test.write('foo.c', r""" +#include <stdio.h> +void +foo(void) +{ + printf("foo.c\n"); +} +""") + +test.run(arguments = '.') + +test.fail_test(not os.path.exists(test.workpath('shlib-foo' + _lib))) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/SHLIBSUFFIX.py b/test/Libs/SHLIBSUFFIX.py new file mode 100644 index 0000000..31fe8ba --- /dev/null +++ b/test/Libs/SHLIBSUFFIX.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os + +import TestSCons + +dll_ = TestSCons.dll_ + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +env = Environment(SHLIBSUFFIX = '.shlib') +env.SharedLibrary(target = 'foo', source = 'foo.c') +""") + +test.write('foo.c', r""" +#include <stdio.h> +void +foo(void) +{ + printf("foo.c\n"); +} +""") + +test.run(arguments = '.') + +test.fail_test(not os.path.exists(test.workpath(dll_ + 'foo.shlib'))) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/SharedLibrary-update-deps.py b/test/Libs/SharedLibrary-update-deps.py new file mode 100644 index 0000000..076e3ad --- /dev/null +++ b/test/Libs/SharedLibrary-update-deps.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that SharedLibrary() updates when a different lib is linked, even if it has the same md5. +This is http://scons.tigris.org/issues/show_bug.cgi?id=2903 +""" + +import sys +import os.path +import TestSCons + +test = TestSCons.TestSCons() + +test.dir_fixture( "bug2903" ) + +# Build the sub-libs (don't care about details of this) +test.run(arguments='-f SConstruct-libs') + +# This should build the main lib, using libfoo.so +test.run(arguments='libname=foo') +# This should rebuild the main lib, using libbar.so; +# it should NOT say it's already up to date. +test.run(arguments='libname=bar') +test.must_not_contain_any_line(test.stdout(), ["is up to date"]) +# Try it again, in reverse, to make sure: +test.run(arguments='libname=foo') +test.must_not_contain_any_line(test.stdout(), ["is up to date"]) + +# Now try changing the link command line (in an innocuous way); should rebuild. +if sys.platform == 'win32': + extraflags='shlinkflags=/DEBUG' +else: + extraflags='shlinkflags=-g' + +test.run(arguments=['libname=foo', extraflags]) +test.must_not_contain_any_line(test.stdout(), ["is up to date"]) +test.run(arguments=['libname=foo', extraflags, '--debug=explain']) +test.must_contain_all_lines(test.stdout(), ["is up to date"]) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/SharedLibrary.py b/test/Libs/SharedLibrary.py new file mode 100644 index 0000000..eac575c --- /dev/null +++ b/test/Libs/SharedLibrary.py @@ -0,0 +1,309 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import sys + +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +import sys +env=Environment(WINDOWS_INSERT_DEF=1) +env2 = Environment(LIBS = [ 'foo1', 'foo2', 'foo3' ], + LIBPATH = [ '.' ]) +env.SharedLibrary(target = 'foo1', source = 'f1.c') +if sys.platform == 'win32': + env.StaticLibrary(target = 'foo1-static', source = 'f1.c') +else: + env.StaticLibrary(target = 'foo1', source = 'f1.c') +SharedLibrary(target = 'foo2', + source = Split('f2a.c f2b.c f2c.c'), + WINDOWS_INSERT_DEF = 1) +env.SharedLibrary(target = 'foo3', source = ['f3a.c', 'f3b.c', 'f3c.c'], no_import_lib = 1) +env2.Program(target = 'prog', source = 'prog.c') +""") + +test.write('SConstructFoo', """ +env=Environment() +obj = env.Object('foo', 'foo.c') +Default(env.SharedLibrary(target = 'foo', source = obj)) +""") + +test.write('SConstructFoo2', """ +env=Environment() +obj = env.SharedObject('bar', 'foo.c') +Default(env.Library(target = 'foo', source = obj)) +""") + +test.write('SConstructBaz', """ +env=Environment() +env['SHLIBVERSION'] = '1.0.0' +obj = env.SharedObject('baz', 'foo.c') +Default(env.SharedLibrary(target = 'baz', source = obj)) +""") + +test.write('foo.c', r""" +#include <stdio.h> + +void +f1(void) +{ + printf("foo.c\n"); + fflush(stdout); +} +""") + + +test.write('f1.c', r""" +#include <stdio.h> + +void +f1(void) +{ + printf("f1.c\n"); + fflush(stdout); +} +""") + +test.write("foo1.def", r""" +LIBRARY "foo1" +DESCRIPTION "Foo1 Shared Library" + +EXPORTS + f1 +""") + +test.write('f2a.c', r""" +#include <stdio.h> + +void +f2a(void) +{ + printf("f2a.c\n"); +} +""") + +test.write('f2b.c', r""" +#include <stdio.h> +void +f2b(void) +{ + printf("f2b.c\n"); +} +""") + +test.write('f2c.c', r""" +#include <stdio.h> + +void +f2c(void) +{ + printf("f2c.c\n"); + fflush(stdout); +} +""") + +test.write("foo2.def", r""" +LIBRARY "foo2" +DESCRIPTION "Foo2 Shared Library" + +EXPORTS + f2a + f2b + f2c +""") + +test.write('f3a.c', r""" +#include <stdio.h> +void +f3a(void) +{ + printf("f3a.c\n"); +} +""") + +test.write('f3b.c', r""" +#include <stdio.h> +void +f3b(void) +{ + printf("f3b.c\n"); +} +""") + +test.write('f3c.c', r""" +#include <stdio.h> + +void +f3c(void) +{ + printf("f3c.c\n"); + fflush(stdout); +} +""") + +test.write("foo3.def", r""" +LIBRARY "foo3" +DESCRIPTION "Foo3 Shared Library" + +EXPORTS + f3a + f3b + f3c +""") + +test.write('prog.c', r""" +#include <stdio.h> +void f1(void); +void f2a(void); +void f2b(void); +void f2c(void); +void f3a(void); +void f3b(void); +void f3c(void); +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + f1(); + f2a(); + f2b(); + f2c(); + f3a(); + f3b(); + f3c(); + printf("prog.c\n"); + return 0; +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +if os.name == 'posix': + os.environ['LD_LIBRARY_PATH'] = '.' +if sys.platform.find('irix') != -1: + os.environ['LD_LIBRARYN32_PATH'] = '.' + +test.run(program = test.workpath('prog'), + stdout = "f1.c\nf2a.c\nf2b.c\nf2c.c\nf3a.c\nf3b.c\nf3c.c\nprog.c\n") + +if sys.platform == 'cygwin': + # Cygwin: Make sure the DLLs are prefixed correctly. + test.must_exist('cygfoo1.dll', 'cygfoo2.dll', 'cygfoo3.dll') + test.must_exist('libfoo1.dll.a', 'libfoo2.dll.a') + test.must_not_exist('foo3.dll.a') + + +if sys.platform == 'win32' or sys.platform.find('irix') != -1: + test.run(arguments = '-f SConstructFoo') +else: + test.run(arguments = '-f SConstructFoo', status=2, stderr='''\ +scons: \*\*\* \[.*\] Source file: foo\..* is static and is not compatible with shared target: .* +''', + match=TestSCons.match_re_dotall) + # Run it again to make sure that we still get the error + # even though the static objects already exist. + test.run(arguments = '-f SConstructFoo', status=2, stderr='''\ +scons: \*\*\* \[.*\] Source file: foo\..* is static and is not compatible with shared target: .* +''', + match=TestSCons.match_re_dotall) + +test.run(arguments = '-f SConstructFoo2', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +if sys.platform == 'win32': + # Make sure we don't insert a .def source file (when + # WINDOWS_INSERT_DEF is set) and a .lib target file if + # they're specified explicitly. + + test.write('SConstructBar', ''' +env = Environment(WINDOWS_INSERT_DEF=1) +env2 = Environment(LIBS = [ 'foo4' ], + LIBPATH = [ '.' ]) +env.SharedLibrary(target = ['foo4', 'foo4.lib'], source = ['f4.c', 'foo4.def']) +env2.Program(target = 'progbar', source = 'progbar.c') +''') + + test.write('f4.c', r""" +#include <stdio.h> + +f4(void) +{ + printf("f4.c\n"); + fflush(stdout); +} +""") + + test.write("foo4.def", r""" +LIBRARY "foo4" +DESCRIPTION "Foo4 Shared Library" + +EXPORTS + f4 +""") + + test.write('progbar.c', r""" +#include <stdio.h> +void f4(void); +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + f4(); + printf("progbar.c\n"); + return 0; +} +""") + + test.run(arguments = '-f SConstructBar .') + + # Make sure there is (at most) one mention each of the + # appropriate .def and .lib files per line. + for line in test.stdout().split('\n'): + test.fail_test(line.count('foo4.def') > 1) + test.fail_test(line.count('foo4.lib') > 1) + + test.run(program = test.workpath('progbar'), + stdout = "f4.c\nprogbar.c\n") + +if sys.platform.startswith('openbsd'): + # Make sure we don't link libraries with -Wl,-soname on OpenBSD. + test.run(arguments = '-f SConstructBaz') + for line in test.stdout().split('\n'): + test.fail_test(line.find('-Wl,-soname=libbaz.so') != -1) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/SharedLibraryIxes.py b/test/Libs/SharedLibraryIxes.py new file mode 100644 index 0000000..6924769 --- /dev/null +++ b/test/Libs/SharedLibraryIxes.py @@ -0,0 +1,298 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that we can build shared libraries and link against shared +libraries that have non-standard library prefixes and suffixes. +""" + +import re +import sys +import TestSCons + +test = TestSCons.TestSCons() + +test.write('SConstruct', """ +import sys +isCygwin = sys.platform == 'cygwin' +isWindows = sys.platform == 'win32' +isMingw = False +if isWindows: + import SCons.Tool.MSCommon as msc + if not msc.msvc_exists(): + # We can't seem to find any MSVC version, so we assume + # that MinGW is installed instead. Accordingly, we use the + # standard gcc/g++ conventions for lib prefixes and suffixes + # in the following... + isWindows = False + isMingw = True + +env = Environment() + +# Make sure that the shared library can be located at runtime. +env.Append(RPATH=['.']) +env.Append(LIBPATH=['.']) + +# We first bake the LIBSUFFIXES, so that it will not change as a +# side-effect of changing SHLIBSUFFIX. +env['LIBSUFFIXES'] = list(map( env.subst, env.get('LIBSUFFIXES', []))) + +weird_prefixes = ['libXX', 'libYY'] + +if isWindows: + weird_suffixes = ['.xxx', '.yyy', '.xxx.dll', '.yyy.dll'] + env.Append(CCFLAGS = '/MD') +elif env['PLATFORM'] == 'darwin': + weird_suffixes = ['.xxx.dylib', '.yyy.dylib'] +else: + weird_suffixes = ['.xxx.so', '.yyy.so'] + +shlibprefix = env.subst('$SHLIBPREFIX') +shlibsuffix = env.subst('$SHLIBSUFFIX') + +progprefix = env.subst('$PROGPREFIX') +progsuffix = env.subst('$PROGSUFFIX') + +goo_obj = env.SharedObject(source='goo.c') +foo_obj = env.SharedObject(source='foo.c') +prog_obj = env.SharedObject(source='prog.c') + +# +# The following functions define all the different ways that one can +# use to link against a shared library. +# +def nodeInSrc(source, lib, libname): + return (source+lib, '') + +def pathInSrc(source, lib, libname): + return (source+list(map(str,lib)), '') + +def nodeInLib(source, lib, libname): + return (source, lib) + +def pathInLib(source, lib, libname): + return (source, list(map(str,lib))) + +def nameInLib(source, lib, libname): + # NOTE: libname must contain both the proper prefix and suffix. + # + # When using non-standard prefixes and suffixes, one has to + # provide the full name of the library since scons can not know + # which of the non-standard extension to use. + # + # Note that this is not necessarily SHLIBPREFIX and + # SHLIBSUFFIX. These are the ixes of the target library, not the + # ixes of the library that we are linking against. + return (source, libname) + +libmethods = [nodeInSrc, pathInSrc, nodeInLib, pathInLib] +# We skip the nameInLib test for MinGW and Cygwin...they would fail, due to +# the Tool's internal naming conventions +if not isMingw and not isCygwin: + libmethods.extend([nameInLib]) + +def buildAndlinkAgainst(builder, target, source, method, lib, libname, **kw): + '''Build a target using a given builder while linking against a given + library using a specified method for linking against the library.''' + + # On Windows, we have to link against the .lib file. + if isWindows: + for l in lib: + if str(l)[-4:] == '.lib': + lib = [l] + break + # If we use MinGW or Cygwin and create a SharedLibrary, we get two targets: a DLL, + # and the import lib created by the "--out-implib" parameter. We always + # want to link against the second one, in order to prevent naming issues + # for the linker command line... + if (isMingw or isCygwin) and len(lib) > 1: + lib = lib[1:] + + # Apply the naming method to be tested and call the specified Builder. + (source, LIBS) = method(source, lib, libname) + #build = builder(target=target, source=source, LIBS=LIBS, **kw) + kw = kw.copy() + kw['target'] = target + kw['source'] = source + kw['LIBS'] = LIBS + build = builder(**kw) + + # Check that the build target depends on at least one of the + # library target. + found_dep = False + children = build[0].children() + for l in lib: + if l in children: + found_dep = True + break; + assert found_dep, \ + "One of %s not found in %s, method=%s, libname=%s, shlibsuffix=%s" % \ + (list(map(str,lib)), list(map(str, build[0].children())), method.__name__, libname, shlibsuffix) + return build + +def prog(i, + goomethod, goolibprefix, goolibsuffix, + foomethod, foolibprefix, foolibsuffix): + '''Build a program + + The program links against a shared library foo which itself links + against a shared library goo. The libraries foo and goo can use + arbitrary library prefixes and suffixes.''' + + goo_name = goolibprefix+'goo'+str(i)+goolibsuffix + foo_name = foolibprefix+'foo'+str(i)+foolibsuffix + prog_name = progprefix+'prog'+str(i)+progsuffix + + print 'Prog: %d, %s, %s, %s' % (i, goo_name, foo_name, prog_name) + + # On Windows, we have to link against the .lib file. + if isWindows: + goo_libname = goolibprefix+'goo'+str(i)+'.lib' + foo_libname = foolibprefix+'foo'+str(i)+'.lib' + else: + goo_libname = goo_name + foo_libname = foo_name + + goo_lib = env.SharedLibrary( + goo_name, goo_obj, SHLIBSUFFIX=goolibsuffix) + foo_lib = buildAndlinkAgainst( + env.SharedLibrary, foo_name, foo_obj, + goomethod, goo_lib, goo_libname, SHLIBSUFFIX=foolibsuffix) + prog = buildAndlinkAgainst(env.Program, prog_name, prog_obj, + foomethod, foo_lib, foo_libname) + + +# +# Create the list of all possible permutations to test. +# +i = 0 +tests = [] +prefixes = [shlibprefix] + weird_prefixes +suffixes = [shlibsuffix] + weird_suffixes +for foolibprefix in prefixes: + for foolibsuffix in suffixes: + for foomethod in libmethods: + for goolibprefix in prefixes: + for goolibsuffix in suffixes: + for goomethod in libmethods: + tests.append( + (i, + goomethod, goolibprefix, goolibsuffix, + foomethod, foolibprefix, foolibsuffix)) + i = i + 1 + +# +# Pseudo-randomly choose 200 tests to run out of the possible +# tests. (Testing every possible permutation would take too long.) +# +import random +random.seed(123456) +try: + random.shuffle(tests) +except AttributeError: + pass + +for i in range(200): + prog(*tests[i]) + +""") + +test.write('goo.c', r""" +#include <stdio.h> + +#ifdef _WIN32 +#define EXPORT __declspec( dllexport ) +#else +#define EXPORT +#endif + +EXPORT void +goo(void) +{ + printf("goo.c\n"); +} +""") + +test.write('foo.c', r""" +#include <stdio.h> + +void goo(void); + +#ifdef _WIN32 +#define EXPORT __declspec( dllexport ) +#else +#define EXPORT +#endif + +EXPORT void +foo(void) +{ + goo(); + printf("foo.c\n"); +} +""") + +test.write('prog.c', r""" +#include <stdio.h> + +void foo(void); + +int +main(int argc, char *argv[]) +{ + argv[argc++] = "--"; + foo(); + printf("prog.c\n"); + return 0; +} +""") + +test.run(arguments = '.', + stderr=TestSCons.noisy_ar, + match=TestSCons.match_re_dotall) + +tests = re.findall(r'Prog: (\d+), (\S+), (\S+), (\S+)', test.stdout()) +expected = "goo.c\nfoo.c\nprog.c\n" + +for t in tests: + if sys.platform != 'cygwin': + test.must_exist(t[1]) + test.must_exist(t[2]) + else: + # Cygwin turns libFoo.xxx into cygFoo.xxx + for f in t[1:2]: + test.must_exist(re.sub('^lib', 'cyg', f)) + + test.must_exist(t[3]) + test.run(program = test.workpath(t[3]), stdout=expected) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Libs/bug2903/SConstruct b/test/Libs/bug2903/SConstruct new file mode 100644 index 0000000..12919ce --- /dev/null +++ b/test/Libs/bug2903/SConstruct @@ -0,0 +1,13 @@ +# SConstruct for testing but #2903. +# The test changes the lib name to make sure it rebuilds +# when the name changes, even if the content of the lib is the same. +# Also, the test passes in extra shlinkflags to ensure things rebuild +# when other linker options change, and not when they don't. +# (This doesn't specifically test LIBPATH, but there's a test for +# that already.) +env=Environment() +libname=ARGUMENTS.get('libname', 'foo') +env.Append(SHLINKFLAGS=' $EXTRA_SHLINKFLAGS') +shlinkflags=ARGUMENTS.get('shlinkflags', '') +env.SharedLibrary('myshared', ['main.c'], + LIBS=[libname], LIBPATH='.', EXTRA_SHLINKFLAGS=shlinkflags) diff --git a/test/Libs/bug2903/SConstruct-libs b/test/Libs/bug2903/SConstruct-libs new file mode 100644 index 0000000..1590062 --- /dev/null +++ b/test/Libs/bug2903/SConstruct-libs @@ -0,0 +1,5 @@ +env=Environment() +libfoo = env.SharedLibrary('foo', 'lib.c') +env.InstallAs('${SHLIBPREFIX}bar${SHLIBSUFFIX}', libfoo[0]) +if len(libfoo) > 1: # on Windows, there's an import lib (also a .exp, but we don't want that) + env.InstallAs('${LIBPREFIX}bar${LIBSUFFIX}', libfoo[1]) diff --git a/test/Libs/bug2903/lib.c b/test/Libs/bug2903/lib.c new file mode 100644 index 0000000..65f4cd2 --- /dev/null +++ b/test/Libs/bug2903/lib.c @@ -0,0 +1,4 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +int i; diff --git a/test/Libs/bug2903/main.c b/test/Libs/bug2903/main.c new file mode 100644 index 0000000..a4b1ecc --- /dev/null +++ b/test/Libs/bug2903/main.c @@ -0,0 +1,6 @@ +#ifdef _WIN32 +__declspec(dllexport) +#endif +void func() +{ +} |
