cleaning up tool initialization to speed up tests
[scons.git] / test / CacheDir / option--cr.py
blob6ff6974b92ce0cd85e1c7ea4f5687036201c5bcd
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 Test the --cache-readonly option when retrieving derived files from a
28 CacheDir. It should retrieve as normal but not update files.
29 """
32 import TestSCons
34 test = TestSCons.TestSCons()
36 test.subdir('cache', 'src')
38 test.write(['src', 'SConstruct'], """
39 DefaultEnvironment(tools=[])
40 def cat(env, source, target):
41 target = str(target[0])
42 with open('cat.out', 'a') as f:
43 f.write(target + "\\n")
44 with open(target, "w") as f:
45 for src in source:
46 with open(str(src), "r") as f2:
47 f.write(f2.read())
48 env = Environment(tools=[], BUILDERS={'Cat':Builder(action=cat)})
49 env.Cat('aaa.out', 'aaa.in')
50 env.Cat('bbb.out', 'bbb.in')
51 env.Cat('ccc.out', 'ccc.in')
52 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
53 CacheDir(r'%s')
54 """ % test.workpath('cache'))
56 test.write(['src', 'aaa.in'], "aaa.in\n")
57 test.write(['src', 'bbb.in'], "bbb.in\n")
58 test.write(['src', 'ccc.in'], "ccc.in\n")
60 # Verify that a normal build works correctly, and clean up.
61 # This should populate the cache with our derived files.
62 test.run(chdir = 'src', arguments = '.')
64 test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n", mode='r')
65 test.must_match(['src', 'cat.out'], "aaa.out\nbbb.out\nccc.out\nall\n", mode='r')
67 test.up_to_date(chdir = 'src', arguments = '.')
69 test.run(chdir = 'src', arguments = '-c .')
70 test.unlink(['src', 'cat.out'])
72 # Verify that we now retrieve the derived files from cache,
73 # not rebuild them. Then clean up.
74 test.run(chdir = 'src', arguments = '--cache-readonly .',
75 stdout = test.wrap_stdout("""\
76 Retrieved `aaa.out' from cache
77 Retrieved `bbb.out' from cache
78 Retrieved `ccc.out' from cache
79 Retrieved `all' from cache
80 """))
82 test.must_match(['src', 'all'], "aaa.in\nbbb.in\nccc.in\n", mode='r')
83 test.must_not_exist(test.workpath('src', 'cat.out'))
85 test.up_to_date(chdir = 'src', arguments = '.')
87 test.run(chdir = 'src', arguments = '-c .')
89 # What we do now is to change one of the files and rebuild
90 test.write(['src', 'aaa.in'], "aaa.rebuild\n")
92 # This should just rebuild aaa.out (and all)
93 test.run(chdir = 'src',
94 arguments = '--cache-readonly .',
95 stdout = test.wrap_stdout("""\
96 cat(["aaa.out"], ["aaa.in"])
97 Retrieved `bbb.out' from cache
98 Retrieved `ccc.out' from cache
99 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
100 """))
102 test.must_match(['src', 'all'], "aaa.rebuild\nbbb.in\nccc.in\n", mode='r')
103 # cat.out contains only the things we built (not got from cache)
104 test.must_match(['src', 'cat.out'], "aaa.out\nall\n", mode='r')
106 test.up_to_date(chdir = 'src', arguments = '.')
108 test.run(chdir = 'src', arguments = '-c .')
109 test.unlink(['src', 'cat.out'])
111 # Verify that aaa.out contents weren't updated with the last build
112 # Then clean up.
113 test.run(chdir = 'src',
114 arguments = '--cache-readonly .',
115 stdout = test.wrap_stdout("""\
116 cat(["aaa.out"], ["aaa.in"])
117 Retrieved `bbb.out' from cache
118 Retrieved `ccc.out' from cache
119 cat(["all"], ["aaa.out", "bbb.out", "ccc.out"])
120 """))
122 test.must_match(['src', 'all'], "aaa.rebuild\nbbb.in\nccc.in\n", mode='r')
123 test.must_match(['src', 'cat.out'], "aaa.out\nall\n", mode='r')
125 test.up_to_date(chdir = 'src', arguments = '.')
127 test.run(chdir = 'src', arguments = '-c .')
128 test.unlink(['src', 'cat.out'])
130 # All done.
131 test.pass_test()
133 # Local Variables:
134 # tab-width:4
135 # indent-tabs-mode:nil
136 # End:
137 # vim: set expandtab tabstop=4 shiftwidth=4: