[ci skip] update generated files
[scons.git] / test / Decider / timestamp.py
blobd713a621ddb23ae82981a2f31f8ec1961f8817ab
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Verify various interactions of the timestamp-match and timestamp-newer
28 Decider() settings:.
29 """
31 import os
32 import stat
34 import TestSCons
36 test = TestSCons.TestSCons()
38 test.write('SConstruct', """\
39 DefaultEnvironment(tools=[])
40 m = Environment(tools=[])
41 m.Decider('timestamp-match')
42 m.Command('match1.out', 'match1.in', Copy('$TARGET', '$SOURCE'))
43 m.Command('match2.out', 'match2.in', Copy('$TARGET', '$SOURCE'))
44 n = Environment(tools=[])
45 n.Decider('timestamp-newer')
46 n.Command('newer1.out', 'newer1.in', Copy('$TARGET', '$SOURCE'))
47 n.Command('newer2.out', 'newer2.in', Copy('$TARGET', '$SOURCE'))
48 """)
50 test.write('match1.in', "match1.in\n")
51 test.write('match2.in', "match2.in\n")
52 test.write('newer1.in', "newer1.in\n")
53 test.write('newer2.in', "newer2.in\n")
55 test.run(arguments = '.')
56 test.up_to_date(arguments = '.')
58 time_match = os.stat('match2.out')[stat.ST_MTIME]
59 time_newer = os.stat('newer2.out')[stat.ST_MTIME]
61 # Now make all the source files newer than (different timestamps from)
62 # the last time the targets were built, and touch the target files
63 # of match1.out and newer1.out to see the different effects.
64 test.sleep() # delay for timestamps
65 test.touch('match1.in')
66 test.touch('newer1.in')
67 test.touch('match2.in')
68 test.touch('newer2.in')
70 test.sleep() # delay for timestamps
71 test.touch('match1.out')
72 test.touch('newer1.out')
74 # We should see both match1.out and match2.out rebuilt, because the
75 # source file timestamps do not match the last time they were built,
76 # but only newer2.out rebuilt. newer1.out is *not* rebuilt because
77 # the actual target file timestamp is, in fact, newer than the
78 # source file (newer1.in) timestamp.
80 expect = test.wrap_stdout("""\
81 Copy("match1.out", "match1.in")
82 Copy("match2.out", "match2.in")
83 Copy("newer2.out", "newer2.in")
84 """)
86 test.run(arguments='.', stdout=expect)
88 # Now, for the somewhat pathological case, reset the match2.out and
89 # newer2.out timestamps to the older timestamp when the targets were
90 # first built. This will cause newer2.out to be rebuilt, because
91 # the newer1.in timestamp is now newer than the older, reset target
92 # file timestamp, but match2.out is *not* rebuilt because its source
93 # file (match2.in) timestamp still exactly matches the timestamp
94 # recorded when the target file was last built.
96 test.touch('match2.out', time_match)
97 test.touch('newer2.out', time_newer)
99 expect = test.wrap_stdout("""\
100 Copy("newer2.out", "newer2.in")
101 """)
103 test.run(arguments='.', stdout=expect)
105 test.pass_test()
107 # Local Variables:
108 # tab-width:4
109 # indent-tabs-mode:nil
110 # End:
111 # vim: set expandtab tabstop=4 shiftwidth=4: