Steven checked in some changes yesterday which fixed a great number of
[scons.git] / test / CPPPATH / CPPPATH.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import os.path
28
29 import TestSCons
30
31 _exe = TestSCons._exe
32
33 prog = 'prog' + _exe
34 subdir_prog = os.path.join('subdir', 'prog' + _exe)
35 variant_prog = os.path.join('variant', 'prog' + _exe)
36
37 args = prog + ' ' + subdir_prog + ' ' + variant_prog
38
39 test = TestSCons.TestSCons()
40
41 test.subdir('foobar',
42             'include',
43             'subdir',
44             ['subdir', 'include'],
45             'inc2')
46
47 test.write('SConstruct', """
48 env = Environment(CPPPATH = ['$FOO', '${TARGET.dir}', '${SOURCE.dir}'],
49                   FOO='include')
50 obj = env.Object(target='foobar/prog', source='subdir/prog.c')
51 env.Program(target='prog', source=obj)
52 SConscript('subdir/SConscript', "env")
53
54 VariantDir('variant', 'subdir', 0)
55 include = Dir('include')
56 env = Environment(CPPPATH=[include, '#foobar', '#subdir'])
57 SConscript('variant/SConscript', "env")
58 """)
59
60 test.write(['subdir', 'SConscript'],
61 """
62 Import("env")
63 env.Program(target='prog', source='prog.c')
64 """)
65
66 test.write(['include', 'foo.h'],
67 r"""
68 #define FOO_STRING "include/foo.h 1\n"
69 #include <bar.h>
70 """)
71
72 test.write(['include', 'bar.h'],
73 r"""
74 #define BAR_STRING "include/bar.h 1\n"
75 """)
76
77 test.write(['subdir', 'sss.h'],
78 r"""
79 #define SSS_STRING      "subdir/sss.h\n"
80 """)
81
82 test.write(['foobar', 'ttt.h'],
83 r"""
84 #define TTT_STRING      "foobar/ttt.h\n"
85 """)
86
87 test.write(['subdir', 'ttt.h'],
88 r"""
89 #define TTT_STRING      "subdir/ttt.h\n"
90 """)
91
92 test.write(['subdir', 'prog.c'],
93 r"""
94 #include <foo.h>
95 #include <sss.h>
96 #include <ttt.h>
97 #include <stdio.h>
98
99 int
100 main(int argc, char *argv[])
101 {
102     argv[argc++] = "--";
103     printf("subdir/prog.c\n");
104     printf(FOO_STRING);
105     printf(BAR_STRING);
106     printf(SSS_STRING);
107     printf(TTT_STRING);
108     return 0;
109 }
110 """)
111
112 test.write(['subdir', 'include', 'foo.h'],
113 r"""
114 #define FOO_STRING "subdir/include/foo.h 1\n"
115 #include "bar.h"
116 """)
117
118 test.write(['subdir', 'include', 'bar.h'],
119 r"""
120 #define BAR_STRING "subdir/include/bar.h 1\n"
121 """)
122
123
124
125 test.run(arguments = args)
126
127 test.run(program = test.workpath(prog),
128          stdout = """\
129 subdir/prog.c
130 include/foo.h 1
131 include/bar.h 1
132 subdir/sss.h
133 foobar/ttt.h
134 """)
135
136 test.run(program = test.workpath(subdir_prog),
137          stdout = """\
138 subdir/prog.c
139 subdir/include/foo.h 1
140 subdir/include/bar.h 1
141 subdir/sss.h
142 subdir/ttt.h
143 """)
144
145 test.run(program = test.workpath(variant_prog),
146          stdout = """\
147 subdir/prog.c
148 include/foo.h 1
149 include/bar.h 1
150 subdir/sss.h
151 foobar/ttt.h
152 """)
153
154
155
156 # Make sure we didn't duplicate the source file in the variant subdirectory.
157 test.must_not_exist(test.workpath('variant', 'prog.c'))
158
159 test.up_to_date(arguments = args)
160
161 test.write(['include', 'foo.h'],
162 r"""
163 #define FOO_STRING "include/foo.h 2\n"
164 #include "bar.h"
165 """)
166
167 test.run(arguments = args)
168
169 test.run(program = test.workpath(prog),
170          stdout = """\
171 subdir/prog.c
172 include/foo.h 2
173 include/bar.h 1
174 subdir/sss.h
175 foobar/ttt.h
176 """)
177
178 test.run(program = test.workpath(subdir_prog),
179          stdout = """\
180 subdir/prog.c
181 subdir/include/foo.h 1
182 subdir/include/bar.h 1
183 subdir/sss.h
184 subdir/ttt.h
185 """)
186
187 test.run(program = test.workpath(variant_prog),
188          stdout = """\
189 subdir/prog.c
190 include/foo.h 2
191 include/bar.h 1
192 subdir/sss.h
193 foobar/ttt.h
194 """)
195
196
197
198 # Make sure we didn't duplicate the source file in the variant subdirectory.
199 test.must_not_exist(test.workpath('variant', 'prog.c'))
200
201 test.up_to_date(arguments = args)
202
203
204
205 #
206 test.write(['include', 'bar.h'],
207 r"""
208 #define BAR_STRING "include/bar.h 2\n"
209 """)
210
211 test.run(arguments = args)
212
213 test.run(program = test.workpath(prog),
214          stdout = """\
215 subdir/prog.c
216 include/foo.h 2
217 include/bar.h 2
218 subdir/sss.h
219 foobar/ttt.h
220 """)
221
222 test.run(program = test.workpath(subdir_prog),
223          stdout = """\
224 subdir/prog.c
225 subdir/include/foo.h 1
226 subdir/include/bar.h 1
227 subdir/sss.h
228 subdir/ttt.h
229 """)
230
231 test.run(program = test.workpath(variant_prog),
232          stdout = """\
233 subdir/prog.c
234 include/foo.h 2
235 include/bar.h 2
236 subdir/sss.h
237 foobar/ttt.h
238 """)
239
240 # Make sure we didn't duplicate the source file in the variant subdirectory.
241 test.must_not_exist(test.workpath('variant', 'prog.c'))
242
243 test.up_to_date(arguments = args)
244
245
246
247 # Change CPPPATH and make sure we don't rebuild because of it.
248 test.write('SConstruct', """
249 env = Environment(CPPPATH = Split('inc2 include ${TARGET.dir} ${SOURCE.dir}'))
250 obj = env.Object(target='foobar/prog', source='subdir/prog.c')
251 env.Program(target='prog', source=obj)
252 SConscript('subdir/SConscript', "env")
253
254 VariantDir('variant', 'subdir', 0)
255 include = Dir('include')
256 env = Environment(CPPPATH=['inc2', include, '#foobar', '#subdir'])
257 SConscript('variant/SConscript', "env")
258 """)
259
260 test.up_to_date(arguments = args)
261
262
263
264 #
265 test.write(['inc2', 'foo.h'],
266 r"""
267 #define FOO_STRING "inc2/foo.h 1\n"
268 #include <bar.h>
269 """)
270
271 test.run(arguments = args)
272
273 test.run(program = test.workpath(prog),
274          stdout = """\
275 subdir/prog.c
276 inc2/foo.h 1
277 include/bar.h 2
278 subdir/sss.h
279 foobar/ttt.h
280 """)
281
282 test.run(program = test.workpath(subdir_prog),
283          stdout = """\
284 subdir/prog.c
285 subdir/include/foo.h 1
286 subdir/include/bar.h 1
287 subdir/sss.h
288 subdir/ttt.h
289 """)
290
291 test.run(program = test.workpath(variant_prog),
292          stdout = """\
293 subdir/prog.c
294 include/foo.h 2
295 include/bar.h 2
296 subdir/sss.h
297 foobar/ttt.h
298 """)
299
300 test.up_to_date(arguments = args)
301
302
303
304 test.pass_test()
305
306 # Local Variables:
307 # tab-width:4
308 # indent-tabs-mode:nil
309 # End:
310 # vim: set expandtab tabstop=4 shiftwidth=4: