Variables testing: confirm space-containing values
[scons.git] / test / SWIG / recursive-includes-cpp.py
blob77ba2d4e8277ec8aad1c7bfa1154b394b3c14a61
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 SWIG include directives produce the correct dependencies
28 in cases of recursive inclusion.
29 """
31 import os
32 import sys
33 import TestSCons
34 import TestCmd
35 from SCons.Defaults import DefaultEnvironment
37 DefaultEnvironment( tools = [ 'swig' ] )
39 test = TestSCons.TestSCons()
41 # Check for prerequisites of this test.
42 if not test.where_is('swig'):
43 test.skip_test('Can not find installed "swig", skipping test.%s' % os.linesep)
45 python, python_include, python_libpath, python_lib = \
46 test.get_platform_python_info(python_h_required=True)
48 if TestCmd.IS_WINDOWS:
49 if not os.path.isfile(os.path.join(python_libpath, python_lib)):
50 test.skip_test(f"Can not find python lib {python_libh!r}, skipping test.\n")
52 test.write("recursive.h", """\
53 /* An empty header file. */
54 """)
56 test.write("main.h", """\
57 #include "recursive.h"
58 """)
60 test.write("main.c", """\
61 #include "main.h"
62 """)
64 test.write("mod.i", """\
65 %module mod
67 %include "main.h"
69 #include "main.h"
70 """)
73 if TestCmd.IS_WINDOWS:
74 if TestCmd.IS_64_BIT:
75 TARGET_ARCH = "TARGET_ARCH = 'x86_64',"
76 else:
77 TARGET_ARCH = "TARGET_ARCH = 'x86',"
78 else:
79 TARGET_ARCH = ""
80 test.write('SConstruct', f"""\
81 import os
82 import sys
83 import sysconfig
85 DefaultEnvironment()
86 env = Environment(
87 {TARGET_ARCH}
88 SWIGFLAGS=['-python'],
89 CPPPATH=[sysconfig.get_config_var("INCLUDEPY")],
90 SHLIBPREFIX="",
91 tools=['default', 'swig'],
94 if sys.platform == 'darwin':
95 env['LIBS'] = [f'python{sys.version_info.major}.{sys.version_info.minor}']
96 env.Append(LIBPATH=[sysconfig.get_config_var("LIBDIR")])
97 elif sys.platform == 'win32':
98 env.Append(LIBS=[f'python{sys.version_info.major}{sys.version_info.minor}.lib'])
99 env.Append(LIBPATH=[os.path.dirname(sys.executable) + "/libs"])
101 env.SharedLibrary('mod', ["mod.i", "main.c"])
102 """)
104 if sys.platform == 'win32':
105 object_suffix = ".obj"
106 elif sys.platform == 'sunos5':
107 object_suffix = ".pic.o"
108 else:
109 object_suffix = ".os"
111 expectMain = """\
112 +-main%s
113 +-main.c
114 +-main.h
115 +-recursive.h""" % object_suffix
117 expectMod = """\
118 +-mod_wrap%s
119 +-mod_wrap.c
120 | +-mod.i
121 | +-main.h
122 | +-recursive.h""" % object_suffix
124 # Validate that the recursive dependencies are found with SWIG scanning first.
125 test.run( arguments = '--tree=all mod_wrap'+object_suffix +' main'+object_suffix)
127 test.must_contain_all( test.stdout(), expectMain )
128 test.must_contain_all( test.stdout(), expectMod )
131 # Validate that the recursive dependencies are found consistently.
132 test.run( arguments = '--tree=all main'+object_suffix +' mod_wrap'+object_suffix)
134 test.must_contain_all( test.stdout(), expectMain )
135 test.must_contain_all( test.stdout(), expectMod )
137 test.run()
138 test.up_to_date()
140 test.pass_test()
142 # Local Variables:
143 # tab-width:4
144 # indent-tabs-mode:nil
145 # End:
146 # vim: set expandtab tabstop=4 shiftwidth=4: