diff options
| author | William Deegan <bill@baddogconsulting.com> | 2015-09-21 17:03:12 (GMT) |
|---|---|---|
| committer | William Deegan <bill@baddogconsulting.com> | 2015-09-21 17:03:12 (GMT) |
| commit | 0941093e0e5a030faa49968457638a3a6aee7ad8 (patch) | |
| tree | 6d33513c14eb6eac0531dd050de0ecca4c39bd79 /test/SWIG | |
| download | SCons-2.4.0.zip SCons-2.4.0.tar.gz SCons-2.4.0.tar.bz2 | |
release 2.4.02.4.0
Diffstat (limited to 'test/SWIG')
| -rw-r--r-- | test/SWIG/SWIG.py | 112 | ||||
| -rw-r--r-- | test/SWIG/SWIGCOM.py | 72 | ||||
| -rw-r--r-- | test/SWIG/SWIGCOMSTR.py | 77 | ||||
| -rw-r--r-- | test/SWIG/SWIGFLAGS.py | 75 | ||||
| -rw-r--r-- | test/SWIG/SWIGOUTDIR-python.py | 94 | ||||
| -rw-r--r-- | test/SWIG/SWIGOUTDIR.py | 89 | ||||
| -rw-r--r-- | test/SWIG/SWIGPATH.py | 98 | ||||
| -rw-r--r-- | test/SWIG/build-dir.py | 174 | ||||
| -rw-r--r-- | test/SWIG/generated_swigfile.py | 98 | ||||
| -rw-r--r-- | test/SWIG/implicit-dependencies.py | 78 | ||||
| -rw-r--r-- | test/SWIG/live.py | 170 | ||||
| -rw-r--r-- | test/SWIG/module-deduced-name.py | 87 | ||||
| -rw-r--r-- | test/SWIG/module-parens.py | 132 | ||||
| -rw-r--r-- | test/SWIG/module-quoted.py | 107 | ||||
| -rw-r--r-- | test/SWIG/module-spaces.py | 107 | ||||
| -rw-r--r-- | test/SWIG/noproxy.py | 98 | ||||
| -rw-r--r-- | test/SWIG/remove-modules.py | 99 | ||||
| -rw-r--r-- | test/SWIG/subdir.py | 116 |
18 files changed, 1883 insertions, 0 deletions
diff --git a/test/SWIG/SWIG.py b/test/SWIG/SWIG.py new file mode 100644 index 0000000..96e00e7 --- /dev/null +++ b/test/SWIG/SWIG.py @@ -0,0 +1,112 @@ +#!/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 the swig tool generates file names that we expect. +""" + +import TestSCons + +_exe = TestSCons._exe +_obj = TestSCons._obj + +test = TestSCons.TestSCons() + +python = test.where_is('python') +if not python: + test,skip_test('Can not find installed "python", skipping test.\n') + + +test.write('myswig.py', r""" +import getopt +import sys +opts, args = getopt.getopt(sys.argv[1:], 'c:o:') +for opt, arg in opts: + if opt == '-c': pass + elif opt == '-o': out = arg +infile = open(args[0], 'rb') +outfile = open(out, 'wb') +for l in infile.readlines(): + if l[:4] != 'swig': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools=['default', 'swig'], + SWIG = [r'%(python)s', 'myswig.py']) +env.Program(target = 'test1', source = 'test1.i') +env.CFile(target = 'test2', source = 'test2.i') +env.Clone(SWIGFLAGS = '-c++').Program(target = 'test3', source = 'test3.i') +""" % locals()) + +test.write('test1.i', r""" +#include <stdio.h> +#include <stdlib.h> +int +main(int argc, char *argv[]) { + argv[argc++] = "--"; + printf("test1.i\n"); + exit (0); +} +swig +""") + +test.write('test2.i', r"""test2.i +swig +""") + +test.write('test3.i', r""" +#include <stdio.h> +#include <stdlib.h> +int +main(int argc, char *argv[]) { + argv[argc++] = "--"; + printf("test3.i\n"); + exit (0); +} +swig +""") + +test.run(arguments = '.', stderr = None) + +test.run(program = test.workpath('test1' + _exe), stdout = "test1.i\n") +test.must_exist(test.workpath('test1_wrap.c')) +test.must_exist(test.workpath('test1_wrap' + _obj)) + +test.must_match('test2_wrap.c', "test2.i\n") + +test.run(program = test.workpath('test3' + _exe), stdout = "test3.i\n") +test.must_exist(test.workpath('test3_wrap.cc')) +test.must_exist(test.workpath('test3_wrap' + _obj)) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/SWIG/SWIGCOM.py b/test/SWIG/SWIGCOM.py new file mode 100644 index 0000000..44602fd --- /dev/null +++ b/test/SWIG/SWIGCOM.py @@ -0,0 +1,72 @@ +#!/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 the ability to configure the $SWIGCOM construction variable. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myswig.py', """ +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*swig*/\\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools=['default', 'swig'], + SWIGCOM = r'%(_python_)s myswig.py $TARGET $SOURCES') +env.CFile(target = 'aaa', source = 'aaa.i') +env.CXXFile(target = 'bbb', source = 'bbb.i', SWIGFLAGS='-c++') +""" % locals()) + +test.write('aaa.i', "aaa.i\n/*swig*/\n") +test.write('bbb.i', "bbb.i\n/*swig*/\n") + +test.run(arguments = '.') + +test.must_match('aaa_wrap.c', "aaa.i\n") +test.must_match('bbb_wrap.cc', "bbb.i\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/SWIG/SWIGCOMSTR.py b/test/SWIG/SWIGCOMSTR.py new file mode 100644 index 0000000..1df3499 --- /dev/null +++ b/test/SWIG/SWIGCOMSTR.py @@ -0,0 +1,77 @@ +#!/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 the $SWIGCOMSTR construction variable allows you to customize +the displayed string when swig is called. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myswig.py', """ +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*swig*/\\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools=['default', 'swig'], + SWIGCOM = r'%(_python_)s myswig.py $TARGET $SOURCES', + SWIGCOMSTR = 'Swigging $TARGET from $SOURCE') +env.CFile(target = 'aaa', source = 'aaa.i') +env.CXXFile(target = 'bbb', source = 'bbb.i', SWIGFLAGS='-c++') +""" % locals()) + +test.write('aaa.i', "aaa.i\n/*swig*/\n") +test.write('bbb.i', "bbb.i\n/*swig*/\n") + +test.run(stdout = test.wrap_stdout("""\ +Swigging aaa_wrap.c from aaa.i +Swigging bbb_wrap.cc from bbb.i +""")) + +test.must_match('aaa_wrap.c', "aaa.i\n") +test.must_match('bbb_wrap.cc', "bbb.i\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/SWIG/SWIGFLAGS.py b/test/SWIG/SWIGFLAGS.py new file mode 100644 index 0000000..cb91699 --- /dev/null +++ b/test/SWIG/SWIGFLAGS.py @@ -0,0 +1,75 @@ +#!/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 can use ${SOURCE} expansions in $SWIGFLAGS. +""" + +import sys +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') + +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + + + +test.subdir('src') + +test.write(['src', 'foo.i'], """\ +%module foo + +%include bar.i +""") + +test.write(['src', 'bar.i'], """\ +%module bar +""") + +test.write('SConstruct', """ +# Note that setting the -I option in $SWIGFLAGS is not good and the +# documentation says to use $SWIGPATH. This is just for testing. +env = Environment(SWIGFLAGS='-python -I${SOURCE.dir}', + SWIG=r'%(swig)s') +env.CFile(target = 'foo', source = ['src/foo.i']) +""" % locals()) + +test.run() + +test.up_to_date(arguments = "foo_wrap.c") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/SWIG/SWIGOUTDIR-python.py b/test/SWIG/SWIGOUTDIR-python.py new file mode 100644 index 0000000..db0cc95 --- /dev/null +++ b/test/SWIG/SWIGOUTDIR-python.py @@ -0,0 +1,94 @@ +#!/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 use of the $SWIGOUTDIR variable causes SCons to recognize +that Python files are created in the specified output directory. +""" + +import TestSCons +import os +import sys + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# On Windows, build a 32-bit exe if on 32-bit python. +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write(['SConstruct'], """\ +env = Environment(SWIGFLAGS = '-python -c++', + %(swig_arch_var)s + CPPPATH=[r"%(python_include)s"], + SWIG=[r'%(swig)s'], + SWIGOUTDIR='python/build dir', + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s', + ) + +env.LoadableModule('python_foo_interface', 'python_foo_interface.i') +""" % locals()) + +test.write('python_foo_interface.i', """\ +%module foopack +""") + +# SCons should realize that it needs to create the "python/build dir" +# subdirectory to hold the generated .py files. +test.run(arguments = '.') + +test.must_exist('python/build dir/foopack.py') + +# SCons should remove the built .py files. +test.run(arguments = '-c') + +test.must_not_exist('python/build dir/foopack.py') + +# SCons should realize it needs to rebuild the removed .py files. +test.not_up_to_date(arguments = '.') + +test.must_exist('python/build dir/foopack.py') + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/SWIG/SWIGOUTDIR.py b/test/SWIG/SWIGOUTDIR.py new file mode 100644 index 0000000..10b1575 --- /dev/null +++ b/test/SWIG/SWIGOUTDIR.py @@ -0,0 +1,89 @@ +#!/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 use of the $SWIGOUTDIR variable causes SCons to recognize +that Java files are created in the specified output directory. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') + +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +where_java_include=test.java_where_includes() + +if not where_java_include: + test.skip_test('Can not find installed Java include files, skipping test.\n') + +test.write(['SConstruct'], """\ +env = Environment(tools = ['default', 'swig'], + CPPPATH=%(where_java_include)s, + ) + +Java_foo_interface = env.SharedLibrary( + 'Java_foo_interface', + 'Java_foo_interface.i', + SWIGOUTDIR = 'java/build dir', + SWIGFLAGS = '-c++ -java -Wall', + SWIGCXXFILESUFFIX = "_wrap.cpp") +""" % locals()) + +test.write('Java_foo_interface.i', """\ +%module foopack +""") + +# SCons should realize that it needs to create the "java/build dir" +# subdirectory to hold the generated .java files. +test.run(arguments = '.') + +test.must_exist('java/build dir/foopackJNI.java') +test.must_exist('java/build dir/foopack.java') + +# SCons should remove the built .java files. +test.run(arguments = '-c') + +test.must_not_exist('java/build dir/foopackJNI.java') +test.must_not_exist('java/build dir/foopack.java') + +# SCons should realize it needs to rebuild the removed .java files. +test.not_up_to_date(arguments = '.') + +test.must_exist('java/build dir/foopackJNI.java') +test.must_exist('java/build dir/foopack.java') + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/SWIG/SWIGPATH.py b/test/SWIG/SWIGPATH.py new file mode 100644 index 0000000..55e8d7e --- /dev/null +++ b/test/SWIG/SWIGPATH.py @@ -0,0 +1,98 @@ +#!/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 use of SWIGPATH finds dependency files in subdirectories. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python = test.where_is('python') +if not python: + test,skip_test('Can not find installed "python", skipping test.\n') + + +test.subdir('inc1', 'inc2') + +test.write(['inc2', 'dependency.i'], """\ +%module dependency +""") + +test.write("dependent.i", """\ +%module dependent + +%include dependency.i +""") + +test.write('SConstruct', """ +foo = Environment(SWIGFLAGS='-python', + SWIG='%(swig)s', + SWIGPATH=['inc1', 'inc2']) +swig = foo.Dictionary('SWIG') +bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig]) +foo.CFile(target = 'dependent', source = ['dependent.i']) +""" % locals()) + +test.run() + +test.up_to_date(arguments = "dependent_wrap.c") + +test.write(['inc1', 'dependency.i'], """\ +%module dependency + +extern char *dependency_1(); +""") + +test.not_up_to_date(arguments = "dependent_wrap.c") + +test.write(['inc2', 'dependency.i'], """\ +%module dependency +extern char *dependency_2(); +""") + +test.up_to_date(arguments = "dependent_wrap.c") + +test.unlink(['inc1', 'dependency.i']) + +test.not_up_to_date(arguments = "dependent_wrap.c") + +test.up_to_date(arguments = "dependent_wrap.c") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/SWIG/build-dir.py b/test/SWIG/build-dir.py new file mode 100644 index 0000000..304932f --- /dev/null +++ b/test/SWIG/build-dir.py @@ -0,0 +1,174 @@ +#!/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__" + +""" +Make sure SWIG works when a VariantDir (or variant_dir) is used. + +Test case courtesy Joe Maruszewski. +""" + +import os.path +import sys + +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.dll' +else: + _dll = '.so' + +test.subdir(['source']) + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write(['SConstruct'], """\ +# +# Create the build environment. +# +env = Environment(CPPPATH = [".", r'%(python_include)s'], + %(swig_arch_var)s + CPPDEFINES = "NDEBUG", + SWIG = [r'%(swig)s'], + SWIGFLAGS = ["-python", "-c++"], + SWIGCXXFILESUFFIX = "_wrap.cpp", + LDMODULEPREFIX='_', + LDMODULESUFFIX='%(_dll)s', + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s', + ) + +Export("env") + +# +# Build the libraries. +# +SConscript("source/SConscript", variant_dir = "build") +""" % locals()) + +test.write(['source', 'SConscript'], """\ +Import("env") +lib = env.SharedLibrary("_linalg", + "linalg.i", + SHLIBPREFIX = "", + SHLIBSUFFIX = ".pyd") +""") + +test.write(['source', 'Vector.hpp'], """\ +class Vector +{ + public: + Vector(int size = 0) : _size(size) + { + _v = new double[_size]; + for (int i = 0; i < _size; ++i) + _v[i] = 0.0; + } + + ~Vector() { delete [] _v; } + + int size() const { return _size; } + + double& operator[](int key) { return _v[key]; } + double const& operator[](int key) const { return _v[key]; } + + private: + int _size; + double* _v; +}; +""") + +test.write(['source', 'linalg.i'], """\ +%module linalg +%{ +#include <sstream> +#include "Vector.hpp" +%} + + +class Vector +{ +public: + Vector(int n = 0); + ~Vector(); + + %extend + { + const char* __str__() { return "linalg.Vector()"; } + + %pythoncode %{ + def __iter__(self): + for i in range(len(self)): + yield self[i] + %} + } +}; +""") + +test.write(['source', 'test.py'], """\ +#!/usr/bin/env python +import linalg + + +x = linalg.Vector(5) +print x + +x[1] = 99.5 +x[3] = 8.3 +x[4] = 11.1 + + +for i, v in enumerate(x): + print "\tx[%d] = %g" % (i, v) + +""") + +test.run(arguments = '.') + +test.up_to_date(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/SWIG/generated_swigfile.py b/test/SWIG/generated_swigfile.py new file mode 100644 index 0000000..d09b473 --- /dev/null +++ b/test/SWIG/generated_swigfile.py @@ -0,0 +1,98 @@ +#!/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 SCons realizes the -noproxy option means no .py file will +be created. +""" + +import os +import sys + +import TestSCons + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.dll' +else: + _dll = '.so' + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.dll' +else: + _dll = '.so' + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# handle testing on other platforms: +ldmodule_prefix = '_' + + +test.write('SConstruct', """ +foo = Environment(CPPPATH=[r'%(python_include)s'], + SWIG=[r'%(swig)s'], + LIBPATH=[r'%(python_libpath)s'], + ) +python_interface = foo.Command( 'test_py_swig.i', Value(1), 'echo %%module test_py_swig > test_py_swig.i' ) +python_c_file = foo.CFile( target='python_swig_test',source=python_interface, SWIGFLAGS = '-python -c++' ) +java_interface = foo.Command( 'test_java_swig.i', Value(1),'echo %%module test_java_swig > test_java_swig.i' ) +java_c_file = foo.CFile( target='java_swig_test' ,source=java_interface, SWIGFLAGS = '-java -c++' ) + +""" % locals()) + +expected_stdout = """\ +echo %%module test_java_swig > test_java_swig.i +%(swig)s -o java_swig_test_wrap.cc -java -c++ test_java_swig.i +echo %%module test_py_swig > test_py_swig.i +%(swig)s -o python_swig_test_wrap.cc -python -c++ test_py_swig.i +""" % locals() +test.run(arguments = '.',stdout=test.wrap_stdout(expected_stdout)) + + +# If we mistakenly depend on the .py file that SWIG didn't create +# (suppressed by the -noproxy option) then the build won't be up-to-date. +test.up_to_date(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/SWIG/implicit-dependencies.py b/test/SWIG/implicit-dependencies.py new file mode 100644 index 0000000..465a0d6 --- /dev/null +++ b/test/SWIG/implicit-dependencies.py @@ -0,0 +1,78 @@ +#!/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 SWIG implicit dependencies are caught. +""" + +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python = test.where_is('python') +if not python: + test.skip_test('Can not find installed "python", skipping test.\n') + + +test.write("dependency.i", """\ +%module dependency +""") + +test.write("dependent.i", """\ +%module dependent + +%include dependency.i +""") + +test.write('SConstruct', """ +foo = Environment(SWIGFLAGS='-python', SWIG='%(swig)s') +swig = foo.Dictionary('SWIG') +bar = foo.Clone(SWIG = [r'%(python)s', r'wrapper.py', swig]) +foo.CFile(target = 'dependent', source = ['dependent.i']) +""" % locals()) + +test.run() + +test.write("dependency.i", """%module dependency + +extern char *dependency_string(); +""") + +test.not_up_to_date(arguments = "dependent_wrap.c") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/SWIG/live.py b/test/SWIG/live.py new file mode 100644 index 0000000..7d79bae --- /dev/null +++ b/test/SWIG/live.py @@ -0,0 +1,170 @@ +#!/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 SWIG behavior with a live, installed SWIG. +""" + +import os.path +import sys + +import TestSCons + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.pyd' +else: + _dll = '.so' + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# handle testing on other platforms: +ldmodule_prefix = '_' + +# On Windows, build a 32-bit exe if on 32-bit python. +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write("wrapper.py", +"""import os +import sys +open('%s', 'wb').write("wrapper.py\\n") +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + +test.write('SConstruct', """\ +foo = Environment(SWIGFLAGS='-python', + LIBPATH=[r'%(python_libpath)s'], + CPPPATH=[r'%(python_include)s'], + LDMODULEPREFIX='%(ldmodule_prefix)s', + LDMODULESUFFIX='%(_dll)s', + SWIG=[r'%(swig)s'], + %(swig_arch_var)s + LIBS='%(python_lib)s', + ) + +swig = foo.Dictionary('SWIG') +bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig]) +foo.LoadableModule(target = 'foo', source = ['foo.c', 'foo.i']) +bar.LoadableModule(target = 'bar', source = ['bar.c', 'bar.i']) +""" % locals()) + +test.write("foo.c", """\ +char * +foo_string() +{ + return "This is foo.c!"; +} +""") + +test.write("foo.i", """\ +%module foo +%{ +/* Put header files here (optional) */ +/* + * This duplication shouldn't be necessary, I guess, but it seems + * to suppress "cast to pointer from integer of different size" + * warning messages on some systems. + */ +extern char *foo_string(); +%} + +extern char *foo_string(); +""") + +test.write("bar.c", """\ +char * +bar_string() +{ + return "This is bar.c!"; +} +""") + +test.write("bar.i", """\ +%module \t bar +%{ +/* Put header files here (optional) */ +/* + * This duplication shouldn't be necessary, I guess, but it seems + * to suppress "cast to pointer from integer of different size" + * warning messages on some systems. + */ +extern char *bar_string(); +%} + +extern char *bar_string(); +""") + +test.run(arguments = ldmodule_prefix+'foo' + _dll) + +test.must_not_exist(test.workpath('wrapper.out')) + +test.run(program = python, stdin = """\ +import foo +print foo.foo_string() +""", stdout="""\ +This is foo.c! +""") + +test.up_to_date(arguments = ldmodule_prefix+'foo' + _dll) + +test.run(arguments = ldmodule_prefix+'bar' + _dll) + +test.must_match('wrapper.out', "wrapper.py\n") + +test.run(program = python, stdin = """\ +import foo +import bar +print foo.foo_string() +print bar.bar_string() +""", stdout="""\ +This is foo.c! +This is bar.c! +""") + +test.up_to_date(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/SWIG/module-deduced-name.py b/test/SWIG/module-deduced-name.py new file mode 100644 index 0000000..bdaef4f --- /dev/null +++ b/test/SWIG/module-deduced-name.py @@ -0,0 +1,87 @@ +#!/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 under the use of the $SWIGOUTDIR variable, SCons correctly deduces +module names from *.i files. As reported by Antoine Dechaume in #2707, the SWIG +emitter should return the basename of the module only. +""" + +import TestSCons +import os +import sys + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Cannot find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Cannot find %s, skipping test.\n' % Python_h) + +# On Windows, build a 32-bit exe if on 32-bit python. +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write(['SConstruct'], """\ +env = Environment(SWIGFLAGS = '-python -c++', + %(swig_arch_var)s + CPPPATH=[r"%(python_include)s"], + SWIG=[r'%(swig)s'], + SWIGOUTDIR='python/build dir', + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s', + ) + +env.LoadableModule('python_foo_interface', 'interfaces/python_foo_interface.i') + +Command("interfaces/python_foo_interface.i", "interfaces/python_foo_interface.ix", Copy("$TARGET", "$SOURCE")) +""" % locals()) + +test.subdir('interfaces') +test.write(['interfaces/python_foo_interface.ix'], """\ +%module python_foo_interface +""") + +test.run(arguments = '.') + +test.must_not_exist(['python','build dir','interfaces']) +test.must_not_exist(['python','build dir','interfaces','python_foo_interface.py']) +test.must_exist(['python','build dir','python_foo_interface.py']) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/SWIG/module-parens.py b/test/SWIG/module-parens.py new file mode 100644 index 0000000..d8c1744 --- /dev/null +++ b/test/SWIG/module-parens.py @@ -0,0 +1,132 @@ +#!/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 handle %module(directors="1") statements, both with and +without white space before the opening parenthesis. +""" + +import os.path +import sys +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.pyd' +else: + _dll = '.so' + +# On Windows, build a 32-bit exe if on 32-bit python. +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write(['SConstruct'], """\ +env = Environment(SWIGFLAGS = '-python -c++', + %(swig_arch_var)s + CPPPATH=[r'%(python_include)s'], + SWIG=[r'%(swig)s'], + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s', + LDMODULESUFFIX='%(_dll)s', + ) + +env.LoadableModule('test1', ['test1.i', 'test1.cc']) +env.LoadableModule('test2', ['test2.i', 'test2.cc']) +""" % locals()) + +test.write(['test1.cc'], """\ +int test1func() +{ + return 0; +} +""") + +test.write(['test1.h'], """\ +int test1func(); +""") + +test.write(['test1.i'], """\ +%module(directors="1") test1 + +%{ +#include "test1.h" +%} + +%include "test1.h" +""") + +test.write(['test2.cc'], """\ +int test2func() +{ + return 0; +} +""") + +test.write(['test2.h'], """\ +int test2func(); +""") + +test.write(['test2.i'], """\ +%module (directors="1") test2 + +%{ +#include "test2.h" +%} + +%include "test2.h" +""") + +test.run(arguments = '.') + +# Note that both tests use directors, so a file *_wrap.h should be generated +# in each case. If the emitter does not correctly allow for this, the test will +# not be up to date. +test.must_exist('test1_wrap.h') +test.must_exist('test2_wrap.h') +test.up_to_date(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/SWIG/module-quoted.py b/test/SWIG/module-quoted.py new file mode 100644 index 0000000..6f4b891 --- /dev/null +++ b/test/SWIG/module-quoted.py @@ -0,0 +1,107 @@ +#!/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 correctly parse quoted module names; e.g. %module "test" +(SWIG permits double-quoted names but not single-quoted ones.) +""" + +import os.path +import sys +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.pyd' +else: + _dll = '.so' + +# On Windows, build a 32-bit exe if on 32-bit python. +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write(['SConstruct'], """\ +env = Environment(SWIGFLAGS = '-python -c++', + %(swig_arch_var)s + CPPPATH=[r'%(python_include)s'], + SWIG=[r'%(swig)s'], + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s', + LDMODULESUFFIX='%(_dll)s', + ) + +env.LoadableModule('test1', ['test1.i', 'test1.cc']) +""" % locals()) + +test.write(['test1.cc'], """\ +int test1func() +{ + return 0; +} +""") + +test.write(['test1.h'], """\ +int test1func(); +""") + +test.write(['test1.i'], """\ +%module "test1" + +%{ +#include "test1.h" +%} + +%include "test1.h" +""") + +test.run(arguments = '.') + +# If we erroneously think the generated Python module is called "test1".py +# rather than test1.py, the test will not be up to date +test.up_to_date(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/SWIG/module-spaces.py b/test/SWIG/module-spaces.py new file mode 100644 index 0000000..2833dff --- /dev/null +++ b/test/SWIG/module-spaces.py @@ -0,0 +1,107 @@ +#!/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 correctly parse module names with spaces on the line after +the module name ; e.g. "%module test " +""" + +import os.path +import sys +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.pyd' +else: + _dll = '.so' + +# On Windows, build a 32-bit exe if on 32-bit python. +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write(['SConstruct'], """\ +env = Environment(SWIGFLAGS = '-python -c++', + %(swig_arch_var)s + CPPPATH=[r'%(python_include)s'], + SWIG=[r'%(swig)s'], + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s', + LDMODULESUFFIX='%(_dll)s', + ) + +env.LoadableModule('test1', ['test1.i', 'test1.cc']) +""" % locals()) + +test.write(['test1.cc'], """\ +int test1func() +{ + return 0; +} +""") + +test.write(['test1.h'], """\ +int test1func(); +""") + +test.write(['test1.i'], """\ +%module test1 + +%{ +#include "test1.h" +%} + +%include "test1.h" +""") + +test.run(arguments = '.') + +# If we erroneously think the generated Python module is called "test1".py +# rather than test1.py, the test will not be up to date +test.up_to_date(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/SWIG/noproxy.py b/test/SWIG/noproxy.py new file mode 100644 index 0000000..1aaeb08 --- /dev/null +++ b/test/SWIG/noproxy.py @@ -0,0 +1,98 @@ +#!/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 SCons realizes the -noproxy option means no .py file will +be created. +""" + +import os +import sys + +import TestSCons + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.dll' +else: + _dll = '.so' + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# handle testing on other platforms: +ldmodule_prefix = '_' + +test.write("dependency.i", """\ +%module dependency +""") + +test.write("dependent.i", """\ +%module dependent + +%include dependency.i +""") + +test.write('SConstruct', """ +foo = Environment(SWIGFLAGS=['-python', '-noproxy'], + CPPPATH=[r'%(python_include)s'], + LDMODULEPREFIX='%(ldmodule_prefix)s', + LDMODULESUFFIX='%(_dll)s', + SWIG=[r'%(swig)s'], + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s', + ) + +swig = foo.Dictionary('SWIG') +bar = foo.Clone(SWIG = [r'%(python)s', 'wrapper.py', swig]) +foo.CFile(target = 'dependent', source = ['dependent.i']) +""" % locals()) + +test.run(arguments = '.') + +# If we mistakenly depend on the .py file that SWIG didn't create +# (suppressed by the -noproxy option) then the build won't be up-to-date. +test.up_to_date(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/SWIG/remove-modules.py b/test/SWIG/remove-modules.py new file mode 100644 index 0000000..f5ce60d --- /dev/null +++ b/test/SWIG/remove-modules.py @@ -0,0 +1,99 @@ +#!/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 swig-generated modules are removed. +The %module directive specifies the module name. +""" + +import os.path +import sys + +import TestSCons + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.dll' +else: + _dll = '.so' + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# handle testing on other platforms: +ldmodule_prefix = '_' + +# On Windows, build a 32-bit exe if on 32-bit python. +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write("module.i", """\ +%module modulename +""") + +test.write('SConstruct', """ +foo = Environment(SWIGFLAGS='-python', + %(swig_arch_var)s + CPPPATH=['%(python_include)s'], + LDMODULEPREFIX='%(ldmodule_prefix)s', + LDMODULESUFFIX='%(_dll)s', + SWIG=[r'%(swig)s'], + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s', + ) + +foo.LoadableModule(target = 'modulename', source = ['module.i']) +""" % locals()) + +test.run() + +test.must_exist(test.workpath("modulename.py")) + +test.run(arguments = "-c") + +test.must_not_exist(test.workpath("modulename.py")) + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/SWIG/subdir.py b/test/SWIG/subdir.py new file mode 100644 index 0000000..e23b858 --- /dev/null +++ b/test/SWIG/subdir.py @@ -0,0 +1,116 @@ +#!/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 expect the .py file created by the -python flag to be in +the same subdirectory as the taget. +""" + +import os +import sys + +import TestSCons + +# swig-python expects specific filenames. +# the platform specific suffix won't necessarily work. +if sys.platform == 'win32': + _dll = '.dll' +else: + _dll = '.so' + +test = TestSCons.TestSCons() + +test.subdir('sub') + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +python, python_include, python_libpath, python_lib = \ + test.get_platform_python_info() +Python_h = os.path.join(python_include, 'Python.h') +if not os.path.exists(Python_h): + test.skip_test('Can not find %s, skipping test.\n' % Python_h) + +# handle testing on other platforms: +ldmodule_prefix = '_' + +# On Windows, build a 32-bit exe if on 32-bit python. +if sys.platform == 'win32' and sys.maxsize <= 2**32: + swig_arch_var="TARGET_ARCH='x86'," +else: + swig_arch_var="" + +test.write('SConstruct', """ +env = Environment(SWIGFLAGS='-python', + %(swig_arch_var)s + CPPPATH=['%(python_include)s/'], + LDMODULEPREFIX='%(ldmodule_prefix)s', + LDMODULESUFFIX='%(_dll)s', + SWIG=r'%(swig)s', + LIBPATH=[r'%(python_libpath)s'], + LIBS='%(python_lib)s' + ) + +env.LoadableModule('sub/_foo', + ['sub/foo.i', 'sub/foo.c'], + LDMODULEPREFIX='') +""" % locals()) + +test.write(['sub', 'foo.i'], """\ +%module foo +%{ +/* Put header files here (optional) */ +/* + * This duplication shouldn't be necessary, I guess, but it seems + * to suppress "cast to pointer from integer of different size" + * warning messages on some systems. + */ +extern char *foo_string(); +%} + +extern char *foo_string(); +""") + +test.write(['sub', 'foo.c'], """\ +char * +foo_string() +{ + return "This is foo.c!"; +} +""") + +test.run(arguments = '.') + +test.up_to_date(options = '--debug=explain', arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: |
