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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
35 subdir_prog = os.path.join('subdir', 'prog' + _exe)
36 variant_prog = os.path.join('variant', 'prog' + _exe)
38 args = prog + ' ' + subdir_prog + ' ' + variant_prog
40 test = TestSCons.TestSCons()
42 test.subdir('include', 'subdir', ['subdir', 'include'], 'inc2')
44 test.write('SConstruct', """
45 env = Environment(CPPPATH = Split('inc2 include'))
46 obj = env.Object(target='prog', source='subdir/prog.c')
47 env.Program(target='prog', source=obj)
48 SConscript('subdir/SConscript', "env")
50 BuildDir('variant', 'subdir', 0)
51 include = Dir('include')
52 env = Environment(CPPPATH=['inc2', include])
53 SConscript('variant/SConscript', "env")
55 def copy(target, source, env):
56 open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
57 nodep = env.Command('nodeps.c', 'nodeps.in', action=copy)
58 env.Program('nodeps', 'nodeps.c')
60 env.Object(['one', 'two'], ['one.c'])
63 test.write(['subdir', 'SConscript'],
66 env.Program(target='prog', source='prog.c')
69 test.write('nodeps.in', r"""
71 main(int argc, char *argv[])
79 test.write(['include', 'foo.h'], r"""
80 #define FOO_STRING "include/foo.h 1\n"
84 test.write(['include', 'bar.h'], r"""
85 #define BAR_STRING "include/bar.h 1\n"
88 test.write(['include', 'baz.h'], r"""
89 #define BAZ_STRING "include/baz.h 1\n"
92 test.write(['subdir', 'prog.c'], r"""
97 main(int argc, char *argv[])
100 printf("subdir/prog.c\n");
107 test.write(['subdir', 'include', 'foo.h'], r"""
108 #define FOO_STRING "subdir/include/foo.h 1\n"
112 test.write(['subdir', 'include', 'bar.h'], r"""
113 #define BAR_STRING "subdir/include/bar.h 1\n"
116 test.write('one.c' , r"""
122 test.run(arguments = "--implicit-cache " + args)
124 test.run(program = test.workpath(prog),
125 stdout = "subdir/prog.c\ninclude/foo.h 1\ninclude/bar.h 1\n")
127 test.run(program = test.workpath(subdir_prog),
128 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
130 test.run(program = test.workpath(variant_prog),
131 stdout = "subdir/prog.c\ninclude/foo.h 1\ninclude/bar.h 1\n")
133 test.up_to_date(arguments = args)
137 # Make sure implicit dependencies work right when one is modifed:
138 test.write(['include', 'foo.h'], r"""
139 #define FOO_STRING "include/foo.h 2\n"
143 test.run(arguments = "--implicit-cache " + args)
145 test.run(program = test.workpath(prog),
146 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
148 test.run(program = test.workpath(subdir_prog),
149 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
151 test.run(program = test.workpath(variant_prog),
152 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
154 test.up_to_date(arguments = args)
158 # Make sure that changing the order of includes causes rebuilds and
159 # doesn't produce redundant rebuilds:
160 test.write(['include', 'foo.h'], r"""
161 #define FOO_STRING "include/foo.h 2\n"
166 test.run(arguments = "--implicit-cache " + args)
168 test.run(program = test.workpath(prog),
169 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
171 test.run(program = test.workpath(subdir_prog),
172 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
174 test.run(program = test.workpath(variant_prog),
175 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
177 test.up_to_date(arguments = args)
181 test.write(['include', 'foo.h'], r"""
182 #define FOO_STRING "include/foo.h 2\n"
187 test.run(arguments = "--implicit-cache " + args)
189 test.run(program = test.workpath(prog),
190 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
192 test.run(program = test.workpath(subdir_prog),
193 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
195 test.run(program = test.workpath(variant_prog),
196 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
198 test.up_to_date(arguments = args)
202 # Add inc2/foo.h that should shadow include/foo.h, but
203 # because of implicit dependency caching, scons doesn't
205 test.write(['inc2', 'foo.h'], r"""
206 #define FOO_STRING "inc2/foo.h 1\n"
210 test.run(arguments = "--implicit-cache " + args)
212 test.run(program = test.workpath(prog),
213 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
215 test.run(program = test.workpath(subdir_prog),
216 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
218 test.run(program = test.workpath(variant_prog),
219 stdout = "subdir/prog.c\ninclude/foo.h 2\ninclude/bar.h 1\n")
223 # Now modifying include/foo.h should make scons aware of inc2/foo.h
224 test.write(['include', 'foo.h'], r"""
225 #define FOO_STRING "include/foo.h 3\n"
229 test.run(arguments = "--implicit-cache " + args)
231 test.run(program = test.workpath(prog),
232 stdout = "subdir/prog.c\ninc2/foo.h 1\ninclude/bar.h 1\n")
234 test.run(program = test.workpath(subdir_prog),
235 stdout = "subdir/prog.c\nsubdir/include/foo.h 1\nsubdir/include/bar.h 1\n")
237 test.run(program = test.workpath(variant_prog),
238 stdout = "subdir/prog.c\ninclude/foo.h 3\ninclude/bar.h 1\n")
242 # test a file with no dependencies where the source file is generated:
243 test.run(arguments = "--implicit-cache nodeps%s"%_exe)
245 test.write('nodeps.in', r"""
249 main(int argc, char *argv[])
256 test.run(arguments = "--implicit-cache one%s"%_obj)
260 # Test forcing of implicit caching:
261 test.write(['include', 'foo.h'], r"""
262 #define FOO_STRING "include/foo.h 3\n"
266 test.run(arguments = "--implicit-cache " + args)
268 test.write(['include', 'foo.h'], r"""
269 #define FOO_STRING "include/foo.h 3\n"
274 test.not_up_to_date(options = "--implicit-deps-unchanged",
275 arguments = variant_prog)
277 test.write(['include', 'baz.h'], r"""
278 #define BAZ_STRING "include/baz.h 2\n"
281 test.up_to_date(options = "--implicit-deps-unchanged",
282 arguments = variant_prog)
284 test.not_up_to_date(arguments = variant_prog)
288 # Test forcing rescanning:
289 test.write(['include', 'foo.h'], r"""
290 #define FOO_STRING "include/foo.h 3\n"
294 test.run(arguments = "--implicit-cache " + args)
296 test.write(['include', 'foo.h'], r"""
297 #define FOO_STRING "include/foo.h 3\n"
302 test.not_up_to_date(options = "--implicit-deps-unchanged",
303 arguments = variant_prog)
305 test.write(['include', 'baz.h'], r"""
306 #define BAZ_STRING "include/baz.h 2\n"
309 test.up_to_date(options = "--implicit-deps-unchanged",
310 arguments = variant_prog)
312 test.not_up_to_date(options = "--implicit-deps-changed",
313 arguments = variant_prog)