added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / Java / swig-dependencies.py
blob3fa563dd442938d3201a0bfee74fb8d881c484bd
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Verify that dependencies on SWIG-generated .java files work correctly.
29 Test case courtesy Jonathan (toolshed@tigris.org).
30 """
32 import TestSCons
34 test = TestSCons.TestSCons()
36 swig = test.where_is('swig')
37 if not swig:
38 test.skip_test('Can not find installed "swig", skipping test.\n')
40 where_javac, java_version = test.java_where_javac()
41 where_java_include=test.java_where_includes()
43 test.subdir(['foo'],
44 ['java'],
45 ['java', 'build'])
47 test.write(['SConstruct'], """\
48 import os
50 _ = DefaultEnvironment(tools=[])
51 env = Environment(ENV=os.environ)
52 if env['PLATFORM'] != 'win32':
53 env.Append(CPPFLAGS=' -g -Wall')
54 env['CPPPATH'] = '$JAVAINCLUDES'
56 Export('env')
58 SConscript('#foo/SConscript')
59 SConscript('#java/SConscript')
60 """)
62 test.write(['foo', 'SConscript'], """\
63 Import('env')
65 env.SharedLibrary('foo', 'foo.cpp')
66 """)
68 test.write(['foo', 'foo.cpp'], """\
69 #include "foo.h"
71 int fooAdd(int a, int b) {
72 return a + b;
74 """)
76 test.write(['foo', 'foo.h'], """\
77 #ifdef _MSC_VER
78 __declspec(dllexport)
79 #endif
80 int fooAdd(int, int);
81 """)
83 test.write(['java', 'Java_foo_interface.i'], """\
84 #include "foo.h"
86 #include <windows.i>
88 %module foopack
92 #ifdef _MSC_VER
93 __declspec(dllexport)
94 #endif
95 int hello(){
96 return 1;
99 """)
101 test.write(['java', 'SConscript'], """\
102 import os
104 Import('env')
106 # unnecessary?
107 env = env.Clone()
109 env.Prepend(CPPPATH = ['#foo',])
111 libadd = ['foo',]
113 libpath = ['#foo',]
115 #swigflags = '-c++ -java -Wall -package foopack -Ifoo'
116 swigflags = '-c++ -java -Wall -Ifoo -DTEST_$PLATFORM'
118 Java_foo_interface = env.SharedLibrary(
119 'Java_foo_interface',
120 'Java_foo_interface.i',
121 LIBS = libadd,
122 LIBPATH = libpath,
123 SWIGFLAGS = swigflags,
124 SWIGOUTDIR = Dir('build'),
125 SWIGCXXFILESUFFIX = "_wrap.cpp")
127 foopack_jar_javac = env.Java('classes', 'build')
129 env['JARCHDIR'] = 'java/classes'
130 foopack_jar = env.Jar(target = 'foopack.jar', source = 'classes')
131 """)
133 # Disable looking at stderr because some combinations of SWIG/gcc
134 # generate a warning about the sWIG_JavaThrowException() function
135 # being defined but not used.
136 try:
137 test.run(arguments = '.', stderr=None)
138 except:
139 # catch exception which is causing failure for issue not related to java.
140 # Bug ticket reported also this seems work fine when running outsite
141 # the test framework
142 test.skip_test('Throwing no result for this test because of bug ' +
143 'related here: https://github.com/SCons/scons/issues/2907\n')
144 #test.must_exist(['java', 'classes', 'foopack', 'foopack.class'])
145 #test.must_exist(['java', 'classes', 'foopack', 'foopackJNI.class'])
146 test.must_exist(['java', 'classes', 'foopack.class'])
147 test.must_exist(['java', 'classes', 'foopackJNI.class'])
149 test.up_to_date(arguments = '.')
151 test.pass_test()
153 # Local Variables:
154 # tab-width:4
155 # indent-tabs-mode:nil
156 # End:
157 # vim: set expandtab tabstop=4 shiftwidth=4: