Added fix for TeX includes with same name as subdirs.
[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     f = open(target, "wb")
45     for src in source:
46         f.write(open(str(src), "rb").read())
47     f.close()
48 env = Environment(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'))
55
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")
59
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 = '.')
63
64 test.fail_test(test.read(['src', 'all']) != "aaa.in\nbbb.in\nccc.in\n")
65 test.fail_test(test.read(['src', 'cat.out']) != "aaa.out\nbbb.out\nccc.out\nall\n")
66
67 test.up_to_date(chdir = 'src', arguments = '.')
68
69 test.run(chdir = 'src', arguments = '-c .')
70 test.unlink(['src', 'cat.out'])
71
72 # Verify that we now retrieve the derived files from cache,
73 # not rebuild them.  DO NOT CLEAN UP.
74 test.run(chdir = 'src', arguments = '.', stdout = test.wrap_stdout("""\
75 Retrieved `aaa.out' from cache
76 Retrieved `bbb.out' from cache
77 Retrieved `ccc.out' from cache
78 Retrieved `all' from cache
79 """))
80
81 test.fail_test(os.path.exists(test.workpath('src', 'cat.out')))
82
83 test.up_to_date(chdir = 'src', arguments = '.')
84
85 # Blow away and recreate the CacheDir, then verify that --cache-force
86 # repopulates the cache with the local built targets.  DO NOT CLEAN UP.
87 shutil.rmtree(test.workpath('cache'))
88 test.subdir('cache')
89
90 test.run(chdir = 'src', arguments = '--cache-force .')
91
92 test.run(chdir = 'src', arguments = '-c .')
93
94 test.run(chdir = 'src', arguments = '.', stdout = test.wrap_stdout("""\
95 Retrieved `aaa.out' from cache
96 Retrieved `bbb.out' from cache
97 Retrieved `ccc.out' from cache
98 Retrieved `all' from cache
99 """))
100
101 test.fail_test(os.path.exists(test.workpath('src', 'cat.out')))
102
103 # Blow away and recreate the CacheDir, then verify that --cache-populate
104 # repopulates the cache with the local built targets.  DO NOT CLEAN UP.
105 shutil.rmtree(test.workpath('cache'))
106 test.subdir('cache')
107
108 test.run(chdir = 'src', arguments = '--cache-populate .')
109
110 test.run(chdir = 'src', arguments = '-c .')
111
112 test.run(chdir = 'src', arguments = '.', stdout = test.wrap_stdout("""\
113 Retrieved `aaa.out' from cache
114 Retrieved `bbb.out' from cache
115 Retrieved `ccc.out' from cache
116 Retrieved `all' from cache
117 """))
118
119 test.fail_test(os.path.exists(test.workpath('src', 'cat.out')))
120
121 # All done.
122 test.pass_test()
123
124 # Local Variables:
125 # tab-width:4
126 # indent-tabs-mode:nil
127 # End:
128 # vim: set expandtab tabstop=4 shiftwidth=4: