b22375562761e113d921d3eb948273c7666d6a11
[scons.git] / test / CacheDir / option--cf.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 populating a CacheDir with the --cache-force option.
29 """
30
31 import os.path
32 import shutil
33
34 import TestSCons
35
36 test = TestSCons.TestSCons()
37
38 test.subdir('cache', 'src')
39
40 test.write(['src', 'SConstruct'], """
41 def cat(env, source, target):
42     target = str(target[0])
43     open('cat.out', 'ab').write(target + "\\n")
44     source = map(str, source)
45     f = open(target, "wb")
46     for src in source:
47         f.write(open(src, "rb").read())
48     f.close()
49 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
50 env.Cat('aaa.out', 'aaa.in')
51 env.Cat('bbb.out', 'bbb.in')
52 env.Cat('ccc.out', 'ccc.in')
53 env.Cat('all', ['aaa.out', 'bbb.out', 'ccc.out'])
54 CacheDir(r'%s')
55 """ % test.workpath('cache'))
56
57 test.write(['src', 'aaa.in'], "aaa.in\n")
58 test.write(['src', 'bbb.in'], "bbb.in\n")
59 test.write(['src', 'ccc.in'], "ccc.in\n")
60
61 # Verify that a normal build works correctly, and clean up.
62 # This should populate the cache with our derived files.
63 test.run(chdir = 'src', arguments = '.')
64
65 test.fail_test(test.read(['src', 'all']) != "aaa.in\nbbb.in\nccc.in\n")
66 test.fail_test(test.read(['src', 'cat.out']) != "aaa.out\nbbb.out\nccc.out\nall\n")
67
68 test.up_to_date(chdir = 'src', arguments = '.')
69
70 test.run(chdir = 'src', arguments = '-c .')
71 test.unlink(['src', 'cat.out'])
72
73 # Verify that we now retrieve the derived files from cache,
74 # not rebuild them.  DO NOT CLEAN UP.
75 test.run(chdir = 'src', arguments = '.', 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 """))
81
82 test.fail_test(os.path.exists(test.workpath('src', 'cat.out')))
83
84 test.up_to_date(chdir = 'src', arguments = '.')
85
86 # Blow away and recreate the CacheDir, then verify that --cache-force
87 # repopulates the cache with the local built targets.  DO NOT CLEAN UP.
88 shutil.rmtree(test.workpath('cache'))
89 test.subdir('cache')
90
91 test.run(chdir = 'src', arguments = '--cache-force .')
92
93 test.run(chdir = 'src', arguments = '-c .')
94
95 test.run(chdir = 'src', arguments = '.', stdout = test.wrap_stdout("""\
96 Retrieved `aaa.out' from cache
97 Retrieved `bbb.out' from cache
98 Retrieved `ccc.out' from cache
99 Retrieved `all' from cache
100 """))
101
102 test.fail_test(os.path.exists(test.workpath('src', 'cat.out')))
103
104 # Blow away and recreate the CacheDir, then verify that --cache-populate
105 # repopulates the cache with the local built targets.  DO NOT CLEAN UP.
106 shutil.rmtree(test.workpath('cache'))
107 test.subdir('cache')
108
109 test.run(chdir = 'src', arguments = '--cache-populate .')
110
111 test.run(chdir = 'src', arguments = '-c .')
112
113 test.run(chdir = 'src', arguments = '.', stdout = test.wrap_stdout("""\
114 Retrieved `aaa.out' from cache
115 Retrieved `bbb.out' from cache
116 Retrieved `ccc.out' from cache
117 Retrieved `all' from cache
118 """))
119
120 test.fail_test(os.path.exists(test.workpath('src', 'cat.out')))
121
122 # All done.
123 test.pass_test()
124
125 # Local Variables:
126 # tab-width:4
127 # indent-tabs-mode:nil
128 # End:
129 # vim: set expandtab tabstop=4 shiftwidth=4: