Merged revisions 1826-1882 via svnmerge from
[scons.git] / test / CacheDir / up-to-date-q.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 Verify that targets retrieved from CacheDir() are reported as
29 up-to-date by the -q option.
30
31 Thanks to dvitek for the test case.
32 """
33
34 # Demonstrate a regression between 0.96.1 and 0.96.93.
35 #
36 # SCons would incorrectly believe files are stale if they were retrieved
37 # from the cache in a previous invocation.
38 #
39 # What this script does:
40 # 1. Set up two identical C project directories called 'alpha' and
41 #    'beta', which use the same cache
42 # 2. Invoke scons on 'alpha'
43 # 3. Invoke scons on 'beta', which successfully draws output 
44 #    files from the cache
45 # 4. Invoke scons again, asserting (with -q) that 'beta' is up to date
46 #
47 # Step 4 failed in 0.96.93.  In practice, this problem would lead to
48 # lots of unecessary fetches from the cache during incremental 
49 # builds (because they behaved like non-incremental builds).
50
51 import TestSCons
52
53 test = TestSCons.TestSCons()
54
55 test.subdir('cache', 'alpha', 'beta')
56
57 foo_c = """
58 int main(){ return 0; }
59 """
60
61 sconstruct = """
62 import os
63 CacheDir(r'%s')
64 Program('foo', 'foo.c')
65 """ % test.workpath('cache')
66
67 test.write('alpha/foo.c', foo_c)
68 test.write('alpha/SConstruct', sconstruct)
69
70 test.write('beta/foo.c', foo_c)
71 test.write('beta/SConstruct', sconstruct)
72
73 # First build, populates the cache
74 test.run(chdir = 'alpha', arguments = '.')
75
76 # Second build, everything is a cache hit
77 test.run(chdir = 'beta', arguments = '.')
78
79 # Since we just built 'beta', it ought to be up to date.
80 test.run(chdir = 'beta', arguments = '. -q')
81
82 test.pass_test()