python = TestSCons.python
_exe = TestSCons._exe
_obj = TestSCons._obj
+_dll = TestSCons._dll
test = TestSCons.TestSCons()
""" % (python))
test.write('test1.i', r"""
-void
+int
main(int argc, char *argv[]) {
argv[argc++] = "--";
printf("test1.i\n");
test.write('test3.i', r"""
#include <stdio.h>
#include <stdlib.h>
-void
+int
main(int argc, char *argv[]) {
argv[argc++] = "--";
printf("test3.i\n");
if swig:
+ version = string.join(string.split(sys.version, '.')[:2], '.')
+
test.write("wrapper.py",
"""import os
import string
test.write('SConstruct', """
foo = Environment(SWIGFLAGS='-python',
- CPPPATH='/usr/include/python1.5/',
+ CPPPATH='/usr/include/python%s/',
SHCCFLAGS='',
SHOBJSUFFIX='.o',
SHLIBPREFIX='')
swig = foo.Dictionary('SWIG')
-#bar = Environment(SWIG = r'%s wrapper.py ' + swig)
-foo.SharedLibrary(target = 'example', source = ['example.c', 'example.i'])
-#foo.SharedLibrary(target = 'foo', source = ['example.c'])
-#foo.SharedLibrary(target = 'foo', source = ['example.i'])
-#bar.SharedLibrary(target = 'bar', source = 'example.i')
-""" % python)
-
- # Simple example.c and example.i stolen from the SWIG tutorial.
- test.write("example.c", """\
-#include <time.h>
-double My_variable = 3.0;
-
-int fact(int n) {
- if (n <= 1) return 1;
- else return n*fact(n-1);
+bar = foo.Copy(SWIG = r'%s wrapper.py ' + swig)
+foo.SharedLibrary(target = 'foo', source = ['foo.c', 'foo.i'])
+bar.SharedLibrary(target = 'bar', source = ['bar.c', 'bar.i'])
+""" % (version, python))
+
+ test.write("foo.c", """\
+char *
+foo_string()
+{
+ return "This is foo.c!";
}
+""")
-int my_mod(int x, int y) {
- return (x%y);
-}
-
-char *get_time()
+ test.write("foo.i", """\
+%module foo
+%{
+/* Put header files here (optional) */
+%}
+
+extern char *foo_string();
+""")
+
+ test.write("bar.c", """\
+char *
+bar_string()
{
- return "Tue Aug 12 23:32:15 2003";
+ return "This is bar.c!";
}
""")
- test.write("example.i", """\
-%module example
+ test.write("bar.i", """\
+%module bar
%{
/* Put header files here (optional) */
%}
-extern double My_variable;
-extern int fact(int n);
-extern int my_mod(int x, int y);
-extern char *get_time();
+extern char *bar_string();
""")
- test.run(arguments = '.')
+ test.run(arguments = 'foo' + _dll)
- test.up_to_date(arguments = '.')
+ test.fail_test(os.path.exists(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 = 'foo' + _dll)
+
+ test.run(arguments = 'bar' + _dll)
+
+ test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
test.run(program = python, stdin = """\
-import example
-print example.fact(5)
-print example.my_mod(7, 3)
-print example.get_time()
+import foo
+import bar
+print foo.foo_string()
+print bar.bar_string()
""", stdout="""\
-120
-1
-Tue Aug 12 23:32:15 2003
+This is foo.c!
+This is bar.c!
""")
+ test.up_to_date(arguments = '.')
+
test.pass_test()
for k in fromdict.keys():
if k != "ENV" and k != "SCANNERS" and k != "CFLAGS" and k != "CXXFLAGS" \
and not SCons.Util.is_Dict(fromdict[k]):
- # the next line fails in Cygwin because it tries to do env.subst on
- # $RMIC $RMICFLAGS -d ${TARGET.attributes.java_lookupdir} ...
- # when $TARGET is None, so $TARGET.attributes throws an exception
- todict[k] = env.subst(str(fromdict[k]))
+ # The next line can fail on some systems because it would try to
+ # do env.subst on:
+ # $RMIC $RMICFLAGS -d ${TARGET.attributes.java_lookupdir} ...
+ # When $TARGET is None, so $TARGET.attributes would throw an
+ # exception.
+ f = fromdict[k]
+ if SCons.Util.is_String(f) and string.find(f, "TARGET") == -1:
+ todict[k] = env.subst(f)
todict["CFLAGS"] = fromdict["CPPFLAGS"] + " " + \
string.join(map(lambda x: "-I" + x, env["CPPPATH"])) + " " + \
string.join(map(lambda x: "-L" + x, env["LIBPATH"]))