Updates to PR 4374 from mwichmann to correct config file hash changes
[scons.git] / test / sconsign / ghost-entries.py
blob59a1ec20544fbde839ecda25c2c9322de2fc9e66
1 #!/usr/bin/env python
3 # __COPYRIGHT__
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__"
27 """
28 Verify that "ghost" entries in the .sconsign file don't have Nodes
29 created for them on subsequent runs (which would cause errors
30 when scanning directories).
31 """
33 import os.path
35 d_current_txt = os.path.join('d', 'current.txt')
37 import TestSCons
39 test = TestSCons.TestSCons()
41 # This test case is from Morten Elo Petersen. It's harder because
42 # blib-case1only actually exists in the build dir after the -c, so the
43 # Dir scanner finds it and adds it to the dir's entries.
44 # Unfortunately FS.py's File.exists() method checks it later and finds
45 # it looks like a stale build copy of a missing source, so it deletes
46 # it. And then it's later discovered to be missing since it's still
47 # in the dir's entries list. The fix for this is to test for missing
48 # source files in the dir scanner (Scanner/Dir.py), and delete them
49 # (just like File.exists() does if they're found in the build dir
50 # rather than making entries for them.
52 test.write('SConstruct', """\
53 def cat(target, source, env):
54 with open(str(target[0]), 'wb') as fp:
55 for s in source:
56 with open(str(s), 'rb') as infp:
57 fp.write(infp.read())
58 env=Environment()
59 Export('env')
60 env['BUILDERS']['Cat']=Builder(action=cat, multi=1)
61 SConscript('src/SConscript',variant_dir='build')
62 """)
64 test.subdir('src')
65 test.write(['src', 'SConscript'], """\
66 Import('env')
67 if ARGUMENTS['case']=='1':
68 A=env.Cat('#build/lib/blib-case1only','src.txt')
69 B=env.Cat('#build/lib/blibB','#build/lib/blib-case1only')
70 if ARGUMENTS['case']=='2':
71 A=env.Cat('case2only','src.txt')
72 B=env.Cat('#build/lib/blibB.txt','case2only')
73 env.Alias('go','#build/lib')
74 """)
76 test.write(['src', 'src.txt'], "anything")
78 test.run(arguments="-Q go case=1")
79 test.must_exist('build/lib/blib-case1only')
80 test.run(arguments="-Q go case=2")
81 test.run(arguments="-Q go case=2 -c")
82 test.run(arguments="-Q go case=2")
85 #############################################################################
86 # This test case is from Jason Orendorff.
87 # Checking for existence before making nodes for things found in the
88 # .sconsign fixes this one.
90 test.write('SConstruct', """\
91 Command("d/current.txt", [], [Touch("$TARGET")])
92 if 'pass' in ARGUMENTS and ARGUMENTS['pass'] == '1':
93 Command("d/obsolete.txt", [], [Touch("$TARGET")])
94 Command("installer.exe", ['d'], [Touch("$TARGET")])
95 """)
97 test.run(arguments='-Q pass=1')
99 # Now delete the created files
100 test.unlink(['d', 'obsolete.txt'])
101 test.unlink(['d', 'current.txt'])
102 test.rmdir(['d'])
104 # Run again, as pass 2
105 expect = """Touch("%(d_current_txt)s")
106 Touch("installer.exe")
107 """ % locals()
109 test.run(arguments='-Q pass=2', stdout=expect)
111 test.pass_test()
113 # Local Variables:
114 # tab-width:4
115 # indent-tabs-mode:nil
116 # End:
117 # vim: set expandtab tabstop=4 shiftwidth=4: