[ci skip] update generated files
[scons.git] / test / Decider / switch-rebuild.py
blob29264553cba2e739330df085d31843a313a4ecc6
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 Test that switching Decider() types between MD5 and timestamp-match
29 does not cause unnecessary rebuilds.
30 """
32 import TestSCons
34 test = TestSCons.TestSCons(match=TestSCons.match_re_dotall)
36 base_sconstruct_contents = """\
37 DefaultEnvironment(tools=[])
38 Decider('%s')
40 def build(env, target, source):
41 with open(str(target[0]), 'wt') as f, open(str(source[0]), 'rt') as ifp:
42 f.write(ifp.read())
43 B = Builder(action=build)
44 env = Environment(tools=[], BUILDERS = { 'B' : B })
45 env.B(target='switch.out', source='switch.in')
46 """
48 def write_SConstruct(test, sig_type):
49 contents = base_sconstruct_contents % sig_type
50 test.write('SConstruct', contents)
53 # Build first MD5 checksums.
54 write_SConstruct(test, 'MD5')
56 test.write('switch.in', "switch.in\n")
58 switch_out_switch_in = test.wrap_stdout(r'build\(\["switch.out"\], \["switch.in"\]\)\n')
60 test.run(arguments='switch.out', stdout=switch_out_switch_in)
62 test.up_to_date(arguments='switch.out')
65 # Now rebuild with timestamp-match. Because we always store timestamps,
66 # even when making the decision based on MD5 checksums, the build is
67 # still up to date.
68 write_SConstruct(test, 'timestamp-match')
70 test.up_to_date(arguments='switch.out')
73 # Now switch back to MD5 checksums. When we rebuilt with the timestamp,
74 # it wiped out the MD5 value (because the point of timestamps is to not
75 # open up and checksum the contents), so the file is considered *not*
76 # up to date and must be rebuilt to generate a checksum.
77 write_SConstruct(test, 'MD5')
79 test.not_up_to_date(arguments='switch.out')
82 # And just for good measure, make sure that we now rebuild in response
83 # to a content change.
84 test.write('switch.in', "switch.in 2\n")
86 test.run(arguments='switch.out', stdout=switch_out_switch_in)
89 test.pass_test()
91 # Local Variables:
92 # tab-width:4
93 # indent-tabs-mode:nil
94 # End:
95 # vim: set expandtab tabstop=4 shiftwidth=4: