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.
27 Test CompilationDatabase and several variations of ways to call it
28 and values of COMPILATIONDB_USE_ABSPATH
36 test
= TestSCons
.TestSCons()
38 test
.file_fixture('mylink.py')
39 test
.file_fixture('mygcc.py')
42 test
.file_fixture('fixture/SConstruct_variant', 'SConstruct')
43 test
.file_fixture('test_main.c', 'src/test_main.c')
47 'compile_commands_only_arg.json',
48 'compile_commands_target.json',
49 'compile_commands.json',
50 'compile_commands_over_rel.json',
51 'compile_commands_over_abs_0.json'
55 'compile_commands_clone_abs.json',
56 'compile_commands_over_abs.json',
57 'compile_commands_target_over_abs.json',
58 'compile_commands_over_abs_1.json',
61 filter_build_files
= [
62 'compile_commands_filter_build.json',
65 filter_build2_files
= [
66 'compile_commands_filter_build2.json',
69 example_rel_file
= """[
71 "command": "%(exe)s mygcc.py cc -o %(output_file)s -c %(variant_src_file)s",
72 "directory": "%(workdir)s",
73 "file": "%(src_file)s",
74 "output": "%(output_file)s"
77 "command": "%(exe)s mygcc.py cc -o %(output2_file)s -c %(src_file)s",
78 "directory": "%(workdir)s",
79 "file": "%(src_file)s",
80 "output": "%(output2_file)s"
83 """ % {'exe': sys
.executable
,
84 'workdir': test
.workdir
,
85 'src_file': os
.path
.join('src', 'test_main.c'),
86 'output_file': os
.path
.join('build', 'test_main.o'),
87 'output2_file': os
.path
.join('build2', 'test_main.o'),
88 'variant_src_file': os
.path
.join('build', 'test_main.c')
91 if sys
.platform
== 'win32':
92 example_rel_file
= example_rel_file
.replace('\\', '\\\\')
95 # print("Checking:%s" % f)
97 test
.must_match(f
, example_rel_file
, mode
='r')
99 example_abs_file
= """[
101 "command": "%(exe)s mygcc.py cc -o %(output_file)s -c %(variant_src_file)s",
102 "directory": "%(workdir)s",
103 "file": "%(abs_src_file)s",
104 "output": "%(abs_output_file)s"
107 "command": "%(exe)s mygcc.py cc -o %(output2_file)s -c %(src_file)s",
108 "directory": "%(workdir)s",
109 "file": "%(abs_src_file)s",
110 "output": "%(abs_output2_file)s"
113 """ % {'exe': sys
.executable
,
114 'workdir': test
.workdir
,
115 'src_file': os
.path
.join('src', 'test_main.c'),
116 'abs_src_file': os
.path
.join(test
.workdir
, 'src', 'test_main.c'),
117 'abs_output_file': os
.path
.join(test
.workdir
, 'build', 'test_main.o'),
118 'abs_output2_file': os
.path
.join(test
.workdir
, 'build2', 'test_main.o'),
119 'output_file': os
.path
.join('build', 'test_main.o'),
120 'output2_file': os
.path
.join('build2', 'test_main.o'),
121 'variant_src_file': os
.path
.join('build', 'test_main.c')}
123 if sys
.platform
== 'win32':
124 example_abs_file
= example_abs_file
.replace('\\', '\\\\')
128 test
.must_match(f
, example_abs_file
, mode
='r')
130 example_filter_build_file
= """[
132 "command": "%(exe)s mygcc.py cc -o %(output_file)s -c %(variant_src_file)s",
133 "directory": "%(workdir)s",
134 "file": "%(src_file)s",
135 "output": "%(output_file)s"
138 """ % {'exe': sys
.executable
,
139 'workdir': test
.workdir
,
140 'src_file': os
.path
.join('src', 'test_main.c'),
141 'output_file': os
.path
.join('build', 'test_main.o'),
142 'variant_src_file': os
.path
.join('build', 'test_main.c')
145 if sys
.platform
== 'win32':
146 example_filter_build_file
= example_filter_build_file
.replace('\\', '\\\\')
148 for f
in filter_build_files
:
150 test
.must_match(f
, example_filter_build_file
, mode
='r')
152 example_filter_build2_file
= """[
154 "command": "%(exe)s mygcc.py cc -o %(output2_file)s -c %(src_file)s",
155 "directory": "%(workdir)s",
156 "file": "%(src_file)s",
157 "output": "%(output2_file)s"
160 """ % {'exe': sys
.executable
,
161 'workdir': test
.workdir
,
162 'src_file': os
.path
.join('src', 'test_main.c'),
163 'output2_file': os
.path
.join('build2', 'test_main.o'),
166 if sys
.platform
== 'win32':
167 example_filter_build2_file
= example_filter_build2_file
.replace('\\', '\\\\')
169 for f
in filter_build2_files
:
171 test
.must_match(f
, example_filter_build2_file
, mode
='r')