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__"
28 Test retrieving derived files from a CacheDir when a BuildDir is used.
35 test = TestSCons.TestSCons()
37 test.subdir('cache', 'src')
39 cache = test.workpath('cache')
40 cat_out = test.workpath('cat.out')
42 test.write(['src', 'SConstruct'], """\
43 CacheDir(r'%(cache)s')
44 SConscript('SConscript')
47 test.write(['src', 'SConscript'], """\
48 def cat(env, source, target):
49 target = str(target[0])
50 open('cat.out', 'ab').write(target + "\\n")
51 source = map(str, source)
52 f = open(target, "wb")
54 f.write(open(src, "rb").read())
56 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
57 env.Cat('aaa.out', 'aaa.in')
58 env.Cat('bbb.out', 'bbb.in')
59 env.Cat('ccc.out', 'ccc.in')
60 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
63 build_aaa_out = os.path.join('build', 'aaa.out')
64 build_bbb_out = os.path.join('build', 'bbb.out')
65 build_ccc_out = os.path.join('build', 'ccc.out')
66 build_all = os.path.join('build', 'all')
68 test.write(['src', 'aaa.in'], "aaa.in\n")
69 test.write(['src', 'bbb.in'], "bbb.in\n")
70 test.write(['src', 'ccc.in'], "ccc.in\n")
73 test.write('SConstruct', """\
74 env = Environment(TWO = '2')
76 BuildDir('build', 'src', duplicate=0)
77 SConscript('build/SConscript')
78 """ % test.workpath('cache${TWO}'))
80 # Verify that a normal build works correctly, and clean up.
81 # This should populate the cache with our derived files.
84 test.must_match(['build', 'all'], "aaa.in\nbbb.in\nccc.in\n")
85 test.must_match('cat.out', "%s\n%s\n%s\n%s\n" % (build_aaa_out, build_bbb_out, build_ccc_out, build_all))
87 test.up_to_date(arguments = '.')
89 test.run(arguments = '-c .')
90 test.unlink('cat.out')
92 # Verify that we now retrieve the derived files from cache,
93 # not rebuild them. Then clean up.
94 test.run(stdout = test.wrap_stdout("""\
95 Retrieved `%s' from cache
96 Retrieved `%s' from cache
97 Retrieved `%s' from cache
98 Retrieved `%s' from cache
99 """ % (build_aaa_out, build_bbb_out, build_ccc_out, build_all)))
101 test.must_not_exist(cat_out)
103 test.up_to_date(arguments = '.')
105 test.run(arguments = '-c .')
107 # Verify that rebuilding with -n reports that everything was retrieved
108 # from the cache, but that nothing really was.
109 test.run(arguments = '-n .', stdout = test.wrap_stdout("""\
110 Retrieved `%s' from cache
111 Retrieved `%s' from cache
112 Retrieved `%s' from cache
113 Retrieved `%s' from cache
114 """ % (build_aaa_out, build_bbb_out, build_ccc_out, build_all)))
116 test.must_not_exist(test.workpath('build', 'aaa.out'))
117 test.must_not_exist(test.workpath('build', 'bbb.out'))
118 test.must_not_exist(test.workpath('build', 'ccc.out'))
119 test.must_not_exist(test.workpath('build', 'all'))
121 # Verify that rebuilding with -s retrieves everything from the cache
122 # even though it doesn't report anything.
123 test.run(arguments = '-s .', stdout = "")
125 test.must_match(['build', 'all'], "aaa.in\nbbb.in\nccc.in\n")
126 test.must_not_exist(cat_out)
128 test.up_to_date(arguments = '.')
130 test.run(arguments = '-c .')
132 # Verify that updating one input file builds its derived file and
133 # dependency but that the other files are retrieved from cache.
134 test.write(['src', 'bbb.in'], "bbb.in 2\n")
136 test.run(stdout = test.wrap_stdout("""\
137 Retrieved `%s' from cache
139 Retrieved `%s' from cache
140 cat(["%s"], ["%s", "%s", "%s"])
141 """ % (build_aaa_out,
142 build_bbb_out, os.path.join('src', 'bbb.in'),
144 build_all, build_aaa_out, build_bbb_out, build_ccc_out)))
146 test.must_match(['build', 'all'], "aaa.in\nbbb.in 2\nccc.in\n")
147 test.must_match('cat.out', "%s\n%s\n" % (build_bbb_out, build_all))
149 test.up_to_date(arguments = '.')