[ci skip] Add note that this change may break SetOption() + ninja usage with fix
[scons.git] / test / SWIG / SWIG.py
blob585895224159e3715791c61fc82501c7adfce40c
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 the swig tool generates file names that we expect.
28 """
30 import TestSCons
32 _exe = TestSCons._exe
33 _obj = TestSCons._obj
35 test = TestSCons.TestSCons()
37 _python_ = TestSCons._python_
39 test.write('myswig.py', """\
40 import getopt
41 import sys
43 opts, args = getopt.getopt(sys.argv[1:], "c:o:v:")
44 for opt, arg in opts:
45 if opt == "-c":
46 pass
47 elif opt == "-o":
48 out = arg
49 elif opt == "-v" and arg == "ersion":
50 print("")
51 print("SWIG Version 0.1.2")
52 print("")
53 print("Compiled with g++ [x86_64-pc-linux-gnu]")
54 print("")
55 print("Configured options: +pcre")
56 print("")
57 print("Please see https://www.swig.org for reporting bugs "
58 "and further information")
59 sys.exit(0)
61 with open(args[0], "r") as ifp, open(out, "w") as ofp:
62 for line in ifp:
63 if not line.startswith("swig"):
64 ofp.write(line)
65 sys.exit(0)
66 """)
68 test.write('SConstruct', """\
69 env = Environment(tools=["default", "swig"], SWIG=[r"%(_python_)s", "myswig.py"])
70 print(env.subst("Using SWIG $SWIGVERSION"))
71 env.Program(target="test1", source="test1.i")
72 env.CFile(target="test2", source="test2.i")
73 env.Clone(SWIGFLAGS="-c++").Program(target="test3", source="test3.i")
74 """ % locals())
76 test.write('test1.i', r"""
77 #include <stdio.h>
78 #include <stdlib.h>
79 int
80 main(int argc, char *argv[]) {
81 argv[argc++] = "--";
82 printf("test1.i\n");
83 exit (0);
85 swig
86 """)
88 test.write('test2.i', r"""test2.i
89 swig
90 """)
92 test.write('test3.i', r"""
93 #include <stdio.h>
94 #include <stdlib.h>
95 int
96 main(int argc, char *argv[]) {
97 argv[argc++] = "--";
98 printf("test3.i\n");
99 exit (0);
101 swig
102 """)
104 test.run(arguments='.', stderr=None, stdout=r'.*Using SWIG 0.1.2.*',
105 match=TestSCons.match_re_dotall)
107 test.run(program=test.workpath('test1' + _exe), stdout="test1.i\n")
108 test.must_exist(test.workpath('test1_wrap.c'))
109 test.must_exist(test.workpath('test1_wrap' + _obj))
111 test.must_match('test2_wrap.c', "test2.i\n", mode='r')
113 test.run(program=test.workpath('test3' + _exe), stdout="test3.i\n")
114 test.must_exist(test.workpath('test3_wrap.cc'))
115 test.must_exist(test.workpath('test3_wrap' + _obj))
117 test.pass_test()
119 # Local Variables:
120 # tab-width:4
121 # indent-tabs-mode:nil
122 # End:
123 # vim: set expandtab tabstop=4 shiftwidth=4: