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__"
28 Test the --debug=explain option.
36 _python_ = TestSCons._python_
38 test = TestSCons.TestSCons()
40 test.subdir('work1', ['work1', 'src'], ['work1', 'src', 'subdir'],
41 'work4', ['work4', 'src'], ['work4', 'src', 'subdir'],
44 subdir_file6 = os.path.join('subdir', 'file6')
45 subdir_file6_in = os.path.join('subdir', 'file6.in')
46 cat_py = test.workpath('cat.py')
48 test.write(cat_py, r"""
51 def process(outfp, infp):
52 for line in infp.readlines():
53 if line[:8] == 'include ':
59 print "os.getcwd() =", os.getcwd()
65 outfp = open(sys.argv[1], 'wb')
66 for f in sys.argv[2:]:
68 process(outfp, open(f, 'rb'))
73 SConstruct_contents = """\
76 include_re = re.compile(r'^include\s+(\S+)$', re.M)
78 def kfile_scan(node, env, target, arg):
79 contents = node.get_contents()
80 includes = include_re.findall(contents)
83 kscan = Scanner(name = 'kfile',
84 function = kfile_scan,
88 cat = Builder(action = r'%(_python_)s %(cat_py)s $TARGET $SOURCES')
91 env.Append(BUILDERS = {'Cat':cat},
95 SConscript('SConscript')
96 env.Install('../inc', 'aaa')
97 env.InstallAs('../inc/bbb.k', 'bbb.k')
98 env.Install('../inc', 'ddd')
99 env.InstallAs('../inc/eee', 'eee.in')
102 args = '--debug=explain .'
104 #############################################################################
105 test.write(['work1', 'src', 'SConstruct'], SConstruct_contents)
107 test.write(['work1', 'src', 'SConscript'], """\
109 env.Cat('file1', 'file1.in')
110 env.Cat('file2', 'file2.k')
111 env.Cat('file3', ['xxx', 'yyy', 'zzz'])
112 env.Command('file4', 'file4.in',
113 r'%(_python_)s %(cat_py)s $TARGET $FILE4FLAG $SOURCES',
115 env.Cat('file5', 'file5.k')
116 env.Cat('subdir/file6', 'subdir/file6.in')
119 test.write(['work1', 'src', 'aaa'], "aaa 1\n")
120 test.write(['work1', 'src', 'bbb.k'], """\
126 test.write(['work1', 'src', 'ccc'], "ccc 1\n")
127 test.write(['work1', 'src', 'ddd'], "ddd 1\n")
128 test.write(['work1', 'src', 'eee.in'], "eee.in 1\n")
130 test.write(['work1', 'src', 'file1.in'], "file1.in 1\n")
132 test.write(['work1', 'src', 'file2.k'], """\
139 test.write(['work1', 'src', 'file4.in'], "file4.in 1\n")
141 test.write(['work1', 'src', 'xxx'], "xxx 1\n")
142 test.write(['work1', 'src', 'yyy'], "yyy 1\n")
143 test.write(['work1', 'src', 'zzz'], "zzz 1\n")
145 test.write(['work1', 'src', 'file5.k'], """\
152 test.write(['work1', 'src', 'subdir', 'file6.in'], "subdir/file6.in 1\n")
154 work1_inc_aaa = test.workpath('work1', 'inc', 'aaa')
155 work1_inc_ddd = test.workpath('work1', 'inc', 'ddd')
156 work1_inc_eee = test.workpath('work1', 'inc', 'eee')
157 work1_inc_bbb_k = test.workpath('work1', 'inc', 'bbb.k')
160 expect = test.wrap_stdout("""\
161 scons: building `file1' because it doesn't exist
162 %(_python_)s %(cat_py)s file1 file1.in
163 scons: building `file2' because it doesn't exist
164 %(_python_)s %(cat_py)s file2 file2.k
165 scons: building `file3' because it doesn't exist
166 %(_python_)s %(cat_py)s file3 xxx yyy zzz
167 scons: building `file4' because it doesn't exist
168 %(_python_)s %(cat_py)s file4 - file4.in
169 scons: building `%(work1_inc_aaa)s' because it doesn't exist
170 Install file: "aaa" as "%(work1_inc_aaa)s"
171 scons: building `%(work1_inc_ddd)s' because it doesn't exist
172 Install file: "ddd" as "%(work1_inc_ddd)s"
173 scons: building `%(work1_inc_eee)s' because it doesn't exist
174 Install file: "eee.in" as "%(work1_inc_eee)s"
175 scons: building `%(work1_inc_bbb_k)s' because it doesn't exist
176 Install file: "bbb.k" as "%(work1_inc_bbb_k)s"
177 scons: building `file5' because it doesn't exist
178 %(_python_)s %(cat_py)s file5 file5.k
179 scons: building `%(subdir_file6)s' because it doesn't exist
180 %(_python_)s %(cat_py)s %(subdir_file6)s %(subdir_file6_in)s
183 test.run(chdir='work1/src', arguments=args, stdout=expect)
185 test.must_match(['work1', 'src', 'file1'], "file1.in 1\n")
186 test.must_match(['work1', 'src', 'file2'], """\
192 test.must_match(['work1', 'src', 'file3'], "xxx 1\nyyy 1\nzzz 1\n")
193 test.must_match(['work1', 'src', 'file4'], "file4.in 1\n")
194 test.must_match(['work1', 'src', 'file5'], """\
205 test.write(['work1', 'src', 'file1.in'], "file1.in 2\n")
206 test.write(['work1', 'src', 'yyy'], "yyy 2\n")
207 test.write(['work1', 'src', 'zzz'], "zzz 2\n")
208 test.write(['work1', 'src', 'bbb.k'], "bbb.k 2\ninclude ccc\n")
210 expect = test.wrap_stdout("""\
211 scons: rebuilding `file1' because `file1.in' changed
212 %(_python_)s %(cat_py)s file1 file1.in
213 scons: rebuilding `file2' because `yyy' changed
214 %(_python_)s %(cat_py)s file2 file2.k
215 scons: rebuilding `file3' because:
218 %(_python_)s %(cat_py)s file3 xxx yyy zzz
219 scons: rebuilding `%(work1_inc_bbb_k)s' because:
220 `%(work1_inc_ddd)s' is no longer a dependency
221 `%(work1_inc_eee)s' is no longer a dependency
223 Install file: "bbb.k" as "%(work1_inc_bbb_k)s"
224 scons: rebuilding `file5' because `%(work1_inc_bbb_k)s' changed
225 %(_python_)s %(cat_py)s file5 file5.k
228 test.run(chdir='work1/src', arguments=args, stdout=expect)
230 test.must_match(['work1', 'src', 'file1'], "file1.in 2\n")
231 test.must_match(['work1', 'src', 'file2'], """\
237 test.must_match(['work1', 'src', 'file3'], "xxx 1\nyyy 2\nzzz 2\n")
238 test.must_match(['work1', 'src', 'file5'], """\
247 test.write(['work1', 'src', 'SConscript'], """\
249 env.Cat('file3', ['xxx', 'yyy'])
252 expect = test.wrap_stdout("""\
253 scons: rebuilding `file3' because `zzz' is no longer a dependency
254 %(_python_)s %(cat_py)s file3 xxx yyy
257 test.run(chdir='work1/src', arguments=args, stdout=expect)
259 test.must_match(['work1', 'src', 'file3'], "xxx 1\nyyy 2\n")
262 test.write(['work1', 'src', 'SConscript'], """\
264 env.Cat('file3', ['xxx', 'yyy', 'zzz'])
267 expect = test.wrap_stdout("""\
268 scons: rebuilding `file3' because `zzz' is a new dependency
269 %(_python_)s %(cat_py)s file3 xxx yyy zzz
272 test.run(chdir='work1/src', arguments=args, stdout=expect)
274 test.must_match(['work1', 'src', 'file3'], "xxx 1\nyyy 2\nzzz 2\n")
277 test.write(['work1', 'src', 'SConscript'], """\
279 env.Cat('file3', ['zzz', 'yyy', 'xxx'])
282 expect = test.wrap_stdout("""\
283 scons: rebuilding `file3' because the dependency order changed:
284 old: ['xxx', 'yyy', 'zzz']
285 new: ['zzz', 'yyy', 'xxx']
286 %(_python_)s %(cat_py)s file3 zzz yyy xxx
289 test.run(chdir='work1/src', arguments=args, stdout=expect)
291 test.must_match(['work1', 'src', 'file3'], "zzz 2\nyyy 2\nxxx 1\n")
294 test.write(['work1', 'src', 'SConscript'], """\
297 env.Cat(f3, ['zzz', 'yyy', 'xxx'])
298 env.AddPostAction(f3, r'%(_python_)s %(cat_py)s ${TARGET}.yyy $SOURCES yyy')
299 env.AddPreAction(f3, r'%(_python_)s %(cat_py)s ${TARGET}.alt $SOURCES')
302 expect = test.wrap_stdout("""\
303 scons: rebuilding `file3' because the build action changed:
304 old: %(_python_)s %(cat_py)s $TARGET $SOURCES
305 new: %(_python_)s %(cat_py)s ${TARGET}.alt $SOURCES
306 %(_python_)s %(cat_py)s $TARGET $SOURCES
307 %(_python_)s %(cat_py)s ${TARGET}.yyy $SOURCES yyy
308 %(_python_)s %(cat_py)s file3.alt zzz yyy xxx
309 %(_python_)s %(cat_py)s file3 zzz yyy xxx
310 %(_python_)s %(cat_py)s file3.yyy zzz yyy xxx yyy
313 test.run(chdir='work1/src', arguments=args, stdout=expect)
315 test.must_match(['work1', 'src', 'file3'], "zzz 2\nyyy 2\nxxx 1\n")
316 test.must_match(['work1', 'src', 'file3.alt'], "zzz 2\nyyy 2\nxxx 1\n")
317 test.must_match(['work1', 'src', 'file3.yyy'], "zzz 2\nyyy 2\nxxx 1\nyyy 2\n")
320 test.write(['work1', 'src', 'SConscript'], """\
323 env.Cat(f3, ['zzz', 'yyy', 'xxx'])
324 env.AddPostAction(f3, r'%(_python_)s %(cat_py)s ${TARGET}.yyy $SOURCES xxx')
325 env.AddPreAction(f3, r'%(_python_)s %(cat_py)s ${TARGET}.alt $SOURCES')
328 expect = test.wrap_stdout("""\
329 scons: rebuilding `file3' because the build action changed:
330 old: %(_python_)s %(cat_py)s ${TARGET}.alt $SOURCES
331 %(_python_)s %(cat_py)s $TARGET $SOURCES
332 %(_python_)s %(cat_py)s ${TARGET}.yyy $SOURCES yyy
333 new: %(_python_)s %(cat_py)s ${TARGET}.alt $SOURCES
334 %(_python_)s %(cat_py)s $TARGET $SOURCES
335 %(_python_)s %(cat_py)s ${TARGET}.yyy $SOURCES xxx
336 %(_python_)s %(cat_py)s file3.alt zzz yyy xxx
337 %(_python_)s %(cat_py)s file3 zzz yyy xxx
338 %(_python_)s %(cat_py)s file3.yyy zzz yyy xxx xxx
341 test.run(chdir='work1/src', arguments=args, stdout=expect)
343 test.must_match(['work1', 'src', 'file3'], "zzz 2\nyyy 2\nxxx 1\n")
344 test.must_match(['work1', 'src', 'file3.alt'], "zzz 2\nyyy 2\nxxx 1\n")
345 test.must_match(['work1', 'src', 'file3.yyy'], "zzz 2\nyyy 2\nxxx 1\nxxx 1\n")
348 test.write(['work1', 'src', 'SConscript'], """\
350 env.Command('file4', 'file4.in',
351 r'%(_python_)s %(cat_py)s $TARGET $FILE4FLAG $SOURCES',
355 expect = test.wrap_stdout("""\
356 scons: rebuilding `file4' because the contents of the build action changed
357 action: %(_python_)s %(cat_py)s $TARGET $FILE4FLAG $SOURCES
358 %(_python_)s %(cat_py)s file4 file4.in
361 test.run(chdir='work1/src',arguments=args, stdout=expect)
363 test.must_match(['work1', 'src', 'file4'], "file4.in 1\n")
365 test.up_to_date(chdir='work1/src',arguments='.')
367 # Test the transition when you turn ON SConsignFile().
368 # This will (or might) rebuild things, but we don't care what,
369 # we just want to make sure we don't blow up.
370 test.write(['work1', 'src', 'SConstruct'],
371 "SConsignFile()\n" + SConstruct_contents)
373 test.run(chdir='work1/src', arguments=args)
375 test.up_to_date(chdir='work1/src',arguments='.')
377 #############################################################################
378 # Test that the --debug=explain information gets saved by default.
379 test.write(['work4', 'src', 'SConstruct'], SConstruct_contents)
381 test.write(['work4', 'src', 'SConscript'], """\
383 env.Cat('file1', 'file1.in')
384 env.Cat('file2', 'file2.k')
385 env.Cat('file3', ['xxx', 'yyy', 'zzz'])
386 env.Command('file4', 'file4.in', r'%(_python_)s %(cat_py)s $TARGET - $SOURCES')
387 env.Cat('file5', 'file5.k')
388 env.Cat('subdir/file6', 'subdir/file6.in')
391 test.write(['work4', 'src', 'aaa'], "aaa 1\n")
392 test.write(['work4', 'src', 'bbb.k'], """\
398 test.write(['work4', 'src', 'ccc'], "ccc 1\n")
399 test.write(['work4', 'src', 'ddd'], "ddd 1\n")
400 test.write(['work4', 'src', 'eee.in'], "eee.in 1\n")
402 test.write(['work4', 'src', 'file1.in'], "file1.in 1\n")
404 test.write(['work4', 'src', 'file2.k'], """\
411 test.write(['work4', 'src', 'file4.in'], "file4.in 1\n")
413 test.write(['work4', 'src', 'xxx'], "xxx 1\n")
414 test.write(['work4', 'src', 'yyy'], "yyy 1\n")
415 test.write(['work4', 'src', 'zzz'], "zzz 1\n")
417 test.write(['work4', 'src', 'file5.k'], """\
424 test.write(['work4', 'src', 'subdir', 'file6.in'], "subdir/file6.in 1\n")
427 test.run(chdir='work4/src', arguments='.')
429 test.must_match(['work4', 'src', 'file1'], "file1.in 1\n")
430 test.must_match(['work4', 'src', 'file2'], """\
436 test.must_match(['work4', 'src', 'file3'], "xxx 1\nyyy 1\nzzz 1\n")
437 test.must_match(['work4', 'src', 'file4'], "file4.in 1\n")
438 test.must_match(['work4', 'src', 'file5'], """\
449 test.write(['work4', 'src', 'file1.in'], "file1.in 2\n")
450 test.write(['work4', 'src', 'yyy'], "yyy 2\n")
451 test.write(['work4', 'src', 'zzz'], "zzz 2\n")
452 test.write(['work4', 'src', 'bbb.k'], "bbb.k 2\ninclude ccc\n")
454 work4_inc_bbb_k = test.workpath('work4', 'inc', 'bbb.k')
455 work4_inc_ddd = test.workpath('work4', 'inc', 'ddd')
456 work4_inc_eee = test.workpath('work4', 'inc', 'eee')
458 test.run(chdir='work4/src', arguments=args, stdout=test.wrap_stdout("""\
459 scons: rebuilding `file1' because `file1.in' changed
460 %(_python_)s %(cat_py)s file1 file1.in
461 scons: rebuilding `file2' because `yyy' changed
462 %(_python_)s %(cat_py)s file2 file2.k
463 scons: rebuilding `file3' because:
466 %(_python_)s %(cat_py)s file3 xxx yyy zzz
467 scons: rebuilding `%(work4_inc_bbb_k)s' because:
468 `%(work4_inc_ddd)s' is no longer a dependency
469 `%(work4_inc_eee)s' is no longer a dependency
471 Install file: "bbb.k" as "%(work4_inc_bbb_k)s"
472 scons: rebuilding `file5' because `%(work4_inc_bbb_k)s' changed
473 %(_python_)s %(cat_py)s file5 file5.k
476 test.must_match(['work4', 'src', 'file1'], "file1.in 2\n")
477 test.must_match(['work4', 'src', 'file2'], """\
483 test.must_match(['work4', 'src', 'file3'], "xxx 1\nyyy 2\nzzz 2\n")
484 test.must_match(['work4', 'src', 'file5'], """\
494 test.write(['work5', 'SConstruct'], """\
498 mode = int(ARGUMENTS.get('mode'))
500 def DifferentCopy(target, source, env):
503 shutil.copy(src, tgt)
504 def AltCopyStage2(target, source, env):
506 MyCopy = Builder(action = [DifferentCopy, AltCopyStage2])
508 def ChangingCopy(target, source, env):
511 shutil.copy(src, tgt)
512 ChangingCopy = Builder(action = ChangingCopy)
514 MyCopy = Builder(action = Copy('$TARGET', '$SOURCE'))
515 def ChangingCopy(target, source, env):
516 tgt = str(target[0].abspath)
517 src = str(source[0].abspath)
518 shutil.copy(src, tgt)
519 ChangingCopy = Builder(action = ChangingCopy)
521 env['BUILDERS']['MyCopy'] = MyCopy
522 env['BUILDERS']['ChangingCopy'] = ChangingCopy
524 env.MyCopy('f1.out', 'f1.in')
525 env.ChangingCopy('f2.out', 'f2.in')
528 test.write(['work5', 'f1.in'], "work5/f1.in\n")
529 test.write(['work5', 'f2.in'], "work5/f2.in\n")
531 test.run(chdir = 'work5', arguments = "mode=0 .")
533 test.must_match(['work5', 'f1.out'], "work5/f1.in\n")
534 test.must_match(['work5', 'f2.out'], "work5/f2.in\n")
536 test.run(chdir = 'work5',
537 arguments = "--debug=explain mode=1 .",
538 stdout = test.wrap_stdout("""\
539 scons: rebuilding `f1.out' because the build action changed:
540 old: Copy("$TARGET", "$SOURCE")
541 new: DifferentCopy(target, source, env)
542 AltCopyStage2(target, source, env)
543 DifferentCopy(["f1.out"], ["f1.in"])
544 AltCopyStage2(["f1.out"], ["f1.in"])
545 scons: rebuilding `f2.out' because the contents of the build action changed
546 action: ChangingCopy(target, source, env)
547 ChangingCopy(["f2.out"], ["f2.in"])