Merged revisions 2302-2362,2364-2452 via svnmerge from
[scons.git] / test / SourceSignatures / basic.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 import os
28 import os.path
29
30 import TestSCons
31
32 test = TestSCons.TestSCons()
33
34
35
36 base_sconstruct_contents = """\
37 def build(env, target, source):
38     open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read())
39 B = Builder(action = build)
40 env = Environment(BUILDERS = { 'B' : B })
41 env.B(target = 'f1.out', source = 'f1.in')
42 env.B(target = 'f2.out', source = 'f2.in')
43 env.B(target = 'f3.out', source = 'f3.in')
44 env.B(target = 'f4.out', source = 'f4.in')
45 """
46
47 def write_SConstruct(test, sigtype):
48     contents = base_sconstruct_contents
49     if sigtype:
50          contents = contents + ("\nSourceSignatures('%s')\n" % sigtype)
51     test.write('SConstruct', contents)
52
53
54
55 write_SConstruct(test, 'timestamp')
56
57 test.write('f1.in', "f1.in\n")
58 test.write('f2.in', "f2.in\n")
59 test.write('f3.in', "f3.in\n")
60 test.write('f4.in', "f4.in\n")
61
62 test.run(arguments = 'f1.out f3.out')
63
64 test.run(arguments = 'f1.out f2.out f3.out f4.out',
65          stdout = test.wrap_stdout("""\
66 scons: `f1.out' is up to date.
67 build(["f2.out"], ["f2.in"])
68 scons: `f3.out' is up to date.
69 build(["f4.out"], ["f4.in"])
70 """))
71
72
73
74 os.utime(test.workpath('f1.in'), 
75          (os.path.getatime(test.workpath('f1.in')),
76           os.path.getmtime(test.workpath('f1.in'))+10))
77 os.utime(test.workpath('f3.in'), 
78          (os.path.getatime(test.workpath('f3.in')),
79           os.path.getmtime(test.workpath('f3.in'))+10))
80
81 test.run(arguments = 'f1.out f2.out f3.out f4.out',
82          stdout = test.wrap_stdout("""\
83 build(["f1.out"], ["f1.in"])
84 scons: `f2.out' is up to date.
85 build(["f3.out"], ["f3.in"])
86 scons: `f4.out' is up to date.
87 """))
88
89
90
91 # Switching to content signatures from timestamps should rebuild,
92 # because we didn't record the content signatures last time.
93
94 write_SConstruct(test, 'MD5')
95
96 test.not_up_to_date(arguments = 'f1.out f2.out f3.out f4.out')
97
98
99
100 test.sleep()
101
102 test.write('f1.in', "f1.in\n")
103 test.write('f2.in', "f2.in\n")
104 test.write('f3.in', "f3.in\n")
105 test.write('f4.in', "f4.in\n")
106
107 test.up_to_date(arguments = 'f1.out f2.out f3.out f4.out')
108
109
110
111 test.touch('f1.in', os.path.getmtime(test.workpath('f1.in'))+10)
112 test.touch('f3.in', os.path.getmtime(test.workpath('f3.in'))+10)
113
114 test.up_to_date(arguments = 'f1.out f2.out f3.out f4.out')
115
116
117
118 write_SConstruct(test, None)
119
120 test.up_to_date(arguments = 'f1.out f2.out f3.out f4.out')
121
122
123
124 test.pass_test()