[ci skip] update generated files
[scons.git] / test / Java / JAVAH.py
blob1ad3933c05915ce428b9e39d553133ff5708874b
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 import os
27 import pathlib
29 import TestSCons
31 _python_ = TestSCons._python_
33 test = TestSCons.TestSCons()
35 where_javac, java_version = test.java_where_javac()
36 where_javah = test.java_where_javah()
37 if java_version:
38 java_version = repr(java_version)
40 # Skip this test as SCons doesn't (currently) predict the generated
41 # inner/anonymous class generated .class files generated by gcj
42 # and so will always fail
43 if test.javac_is_gcj:
44 test.skip_test('Test not valid for gcj (gnu java); skipping test(s).\n')
46 # TODO rework for 'javac -h', for now skip
47 # The logical test would be: if java_version > 9:
48 # but java_where_javah() roots around and will find from an older version
49 if not test.Environment().WhereIs('javah'):
50 test.skip_test("No Java javah for version > 9, skipping test.\n")
52 # On some systems, the alternatives system does not remove javah even if the
53 # preferred Java doesn't have it, so try another check
54 javacdir = pathlib.Path(where_javac).parent
55 javahdir = pathlib.Path(where_javah).parent
56 if javacdir != javahdir:
57 test.skip_test("Cannot find Java javah matching javac, skipping test.\n")
59 test.file_fixture('wrapper_with_args.py')
61 test.write('SConstruct', """
62 DefaultEnvironment(tools=[])
63 foo = Environment(tools=['javac', 'javah', 'install'])
64 jv = %(java_version)s
65 if jv:
66 foo['JAVAVERSION'] = jv
67 javah = foo.Dictionary('JAVAH')
68 bar = foo.Clone(JAVAH=r'%(_python_)s wrapper_with_args.py ' + javah)
69 foo.Java(target='class1', source='com/sub/foo')
70 bar_classes = bar.Java(target='class2', source='com/sub/bar')
71 foo_classes = foo.Java(target='class3', source='src')
72 foo.JavaH(
73 target='outdir1',
74 source=[
75 'class1/com/sub/foo/Example1.class',
76 'class1/com/other/Example2',
77 'class1/com/sub/foo/Example3',
79 JAVACLASSDIR='class1',
81 bar.JavaH(target='outdir2', source=bar_classes)
82 foo.JavaH(target=File('output.h'), source=foo_classes)
83 foo.Install('class4/com/sub/foo', 'class1/com/sub/foo/Example1.class')
84 foo.JavaH(
85 target='outdir4',
86 source=['class4/com/sub/foo/Example1.class'],
87 JAVACLASSDIR='class4',
89 """ % locals())
91 test.subdir(
92 'com',
93 ['com', 'sub'],
94 ['com', 'sub', 'foo'],
95 ['com', 'sub', 'bar'],
96 'src',
99 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
100 package com.sub.foo;
102 public class Example1
105 public static void main(String[] args)
111 """)
113 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
114 package com.other;
116 public class Example2
119 public static void main(String[] args)
125 """)
127 test.write(['com', 'sub', 'foo', 'Example3.java'], """\
128 package com.sub.foo;
130 public class Example3
133 public static void main(String[] args)
139 """)
141 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
142 package com.sub.bar;
144 public class Example4
147 public static void main(String[] args)
153 """)
155 test.write(['com', 'sub', 'bar', 'Example5.java'], """\
156 package com.other;
158 public class Example5
161 public static void main(String[] args)
167 """)
169 test.write(['com', 'sub', 'bar', 'Example6.java'], """\
170 package com.sub.bar;
172 public class Example6
175 public static void main(String[] args)
181 """)
183 test.write(['src', 'Test.java'], """\
184 class Empty {
187 interface Listener {
188 public void execute();
191 public
192 class
193 Test {
194 class Inner {
195 void go() {
196 use(new Listener() {
197 public void execute() {
198 System.out.println("In Inner");
202 String s1 = "class A";
203 String s2 = "new Listener() { }";
204 /* class B */
205 /* new Listener() { } */
208 public static void main(String[] args) {
209 new Test().run();
212 void run() {
213 use(new Listener() {
214 public void execute() {
215 use(new Listener( ) {
216 public void execute() {
217 System.out.println("Inside execute()");
223 new Inner().go();
226 void use(Listener l) {
227 l.execute();
231 class Private {
232 void run() {
233 new Listener() {
234 public void execute() {
239 """)
241 test.run(arguments = '.')
243 test.must_match(
244 'wrapper.out',
245 "wrapper_with_args.py javah -d outdir2 -classpath class2 com.sub.bar.Example4 com.other.Example5 com.sub.bar.Example6\n",
246 mode='r',
249 test.must_exist(['outdir1', 'com_sub_foo_Example1.h'])
250 test.must_exist(['outdir1', 'com_other_Example2.h'])
251 test.must_exist(['outdir1', 'com_sub_foo_Example3.h'])
253 test.must_exist(['outdir2', 'com_sub_bar_Example4.h'])
254 test.must_exist(['outdir2', 'com_other_Example5.h'])
255 test.must_exist(['outdir2', 'com_sub_bar_Example6.h'])
257 test.up_to_date(arguments = '.')
259 test.pass_test()
261 # Local Variables:
262 # tab-width:4
263 # indent-tabs-mode:nil
264 # End:
265 # vim: set expandtab tabstop=4 shiftwidth=4: