Add announcements of checkpoint release 0.97.0d20070809.
[scons.git] / test / option--cs.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 """
28 Test printing build actions when using the --cache-show option and
29 retrieving derived files from a CacheDir.
30 """
31
32 import os.path
33 import shutil
34
35 import TestSCons
36
37 _python_ = TestSCons._python_
38 _exe = TestSCons._exe
39 _obj = TestSCons._obj
40
41 test = TestSCons.TestSCons()
42
43 test.subdir('cache', 'src1', 'src2')
44
45 test.write(['src1', 'build.py'], r"""
46 import sys
47 open('cat.out', 'ab').write(sys.argv[1] + "\n")
48 file = open(sys.argv[1], 'wb')
49 for src in sys.argv[2:]:
50     file.write(open(src, 'rb').read())
51 file.close()
52 """)
53
54 cache = test.workpath('cache')
55
56 test.write(['src1', 'SConstruct'], """
57 def cat(env, source, target):
58     target = str(target[0])
59     open('cat.out', 'ab').write(target + "\\n")
60     source = map(str, source)
61     f = open(target, "wb")
62     for src in source:
63         f.write(open(src, "rb").read())
64     f.close()
65 env = Environment(BUILDERS={'Internal':Builder(action=cat),
66                             'External':Builder(action='%(_python_)s build.py $TARGET $SOURCES')})
67 env.External('aaa.out', 'aaa.in')
68 env.External('bbb.out', 'bbb.in')
69 env.Internal('ccc.out', 'ccc.in')
70 env.Internal('all', ['aaa.out', 'bbb.out', 'ccc.out'])
71 CacheDir(r'%(cache)s')
72 """ % locals())
73
74 test.write(['src1', 'aaa.in'], "aaa.in\n")
75 test.write(['src1', 'bbb.in'], "bbb.in\n")
76 test.write(['src1', 'ccc.in'], "ccc.in\n")
77
78 # Verify that a normal build works correctly, and clean up.
79 # This should populate the cache with our derived files.
80 test.run(chdir = 'src1', arguments = '.')
81
82 test.must_match(['src1', 'all'], "aaa.in\nbbb.in\nccc.in\n")
83
84 test.must_match(['src1', 'cat.out'], "aaa.out\nbbb.out\nccc.out\nall\n")
85
86 test.up_to_date(chdir = 'src1', arguments = '.')
87
88 test.run(chdir = 'src1', arguments = '-c .')
89 test.unlink(['src1', 'cat.out'])
90
91 # Verify that we now retrieve the derived files from cache,
92 # not rebuild them.  Then clean up.
93 test.run(chdir = 'src1', arguments = '.', stdout = test.wrap_stdout("""\
94 Retrieved `aaa.out' from cache
95 Retrieved `bbb.out' from cache
96 Retrieved `ccc.out' from cache
97 Retrieved `all' from cache
98 """))
99
100 test.must_not_exist(test.workpath('src1', 'cat.out'))
101
102 test.up_to_date(chdir = 'src1', arguments = '.')
103
104 test.run(chdir = 'src1', arguments = '-c .')
105
106 # Verify that using --cache-show reports the files as being rebuilt,
107 # even though we actually fetch them from the cache.  Then clean up.
108 expect = test.wrap_stdout("""\
109 %(_python_)s build.py aaa.out aaa.in
110 %(_python_)s build.py bbb.out bbb.in
111 cat(["ccc.out"], ["ccc.in"])
112 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
113 """ % locals())
114
115 test.run(chdir = 'src1', arguments = '--cache-show .', stdout = expect)
116
117 test.must_not_exist(test.workpath('src1', 'cat.out'))
118
119 test.up_to_date(chdir = 'src1', arguments = '.')
120
121 test.run(chdir = 'src1', arguments = '-c .')
122
123 # Verify that using --cache-show -n reports the files as being rebuilt,
124 # even though we don't actually fetch them from the cache.  No need to
125 # clean up.
126 expect = test.wrap_stdout("""\
127 %(_python_)s build.py aaa.out aaa.in
128 %(_python_)s build.py bbb.out bbb.in
129 cat(["ccc.out"], ["ccc.in"])
130 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
131 """ % locals())
132
133 test.run(chdir = 'src1', arguments = '--cache-show -n .', stdout = expect)
134
135 test.must_not_exist(test.workpath('src1', 'cat.out'))
136
137 test.must_not_exist(test.workpath('src1', 'aaa.out'))
138 test.must_not_exist(test.workpath('src1', 'bbb.out'))
139 test.must_not_exist(test.workpath('src1', 'ccc.out'))
140 test.must_not_exist(test.workpath('src1', 'all'))
141
142 # Verify that using --cache-show -s doesn't report anything, even though
143 # we do fetch the files from the cache.  No need to clean up.
144 test.run(chdir = 'src1',
145          arguments = '--cache-show -s .',
146          stdout = "")
147
148 test.must_match(['src1', 'all'], "aaa.in\nbbb.in\nccc.in\n")
149 test.must_not_exist(test.workpath('src1', 'cat.out'))
150
151 #
152 hello_exe = 'hello' + _exe
153 hello_obj = 'hello' + _obj
154 src2_hello = test.workpath('src2', hello_exe)
155
156 test.write(['src2', 'SConstruct'], """
157 env = Environment()
158 env.Program('hello.c')
159 CacheDir(r'%s')
160 """ % (test.workpath('cache')))
161
162 test.write(['src2', 'hello.c'], r"""\
163 #include <stdio.h>
164 #include <stdlib.h>
165 int
166 main(int argc, char *argv[])
167 {
168         argv[argc++] = "--";
169         printf("src2/hello.c\n");
170         exit (0);
171 }
172 """)
173
174 # Normal build.
175 test.run(chdir = 'src2', arguments = '.')
176
177 test.run(program = src2_hello, stdout = "src2/hello.c\n")
178
179 test.up_to_date(chdir = 'src2', arguments = '.')
180
181 test.run(chdir = 'src2', arguments = '-c .')
182
183 # Verify that using --cache-show doesn't blow up.
184 # Don't bother checking the output, since we verified the correct
185 # behavior above.  We just want to make sure the canonical Program()
186 # invocation works with --cache-show.
187 test.run(chdir = 'src2', arguments = '--cache-show .')
188
189 test.run(program = src2_hello, stdout = "src2/hello.c\n")
190
191 test.up_to_date(chdir = 'src2', arguments = '.')
192
193 # All done.
194 test.pass_test()