f6ff39a2977d5ac54d4418d77e5ba87ee04cf875
[scons.git] / test / explain / save-info.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 the --debug=explain information gets saved by default.
29 """
30
31 import TestSCons
32
33 _python_ = TestSCons._python_
34
35 test = TestSCons.TestSCons()
36
37 test.subdir( 'src', ['src', 'subdir'])
38
39 cat_py = test.workpath('cat.py')
40 inc_bbb_k = test.workpath('inc', 'bbb.k')
41 inc_ddd = test.workpath('inc', 'ddd')
42 inc_eee = test.workpath('inc', 'eee')
43
44 test.write(cat_py, r"""
45 import sys
46
47 def process(outfp, infp):
48     for line in infp.readlines():
49         if line[:8] == 'include ':
50             file = line[8:-1]
51             try:
52                 fp = open(file, 'rb')
53             except IOError:
54                 import os
55                 print "os.getcwd() =", os.getcwd()
56                 raise
57             process(outfp, fp)
58         else:
59             outfp.write(line)
60
61 outfp = open(sys.argv[1], 'wb')
62 for f in sys.argv[2:]:
63     if f != '-':
64         process(outfp, open(f, 'rb'))
65
66 sys.exit(0)
67 """)
68
69 test.write(['src', 'SConstruct'], """\
70 import re
71
72 include_re = re.compile(r'^include\s+(\S+)$', re.M)
73
74 def kfile_scan(node, env, target, arg):
75     contents = node.get_text_contents()
76     includes = include_re.findall(contents)
77     return includes
78
79 kscan = Scanner(name = 'kfile',
80                 function = kfile_scan,
81                 argument = None,
82                 skeys = ['.k'])
83
84 cat = Builder(action = r'%(_python_)s %(cat_py)s $TARGET $SOURCES')
85
86 env = Environment()
87 env.Append(BUILDERS = {'Cat':cat},
88            SCANNERS = kscan)
89
90 Export("env")
91 SConscript('SConscript')
92 env.Install('../inc', 'aaa')
93 env.InstallAs('../inc/bbb.k', 'bbb.k')
94 env.Install('../inc', 'ddd')
95 env.InstallAs('../inc/eee', 'eee.in')
96 """ % locals())
97
98 test.write(['src', 'SConscript'], """\
99 Import("env")
100 env.Cat('file1', 'file1.in')
101 env.Cat('file2', 'file2.k')
102 env.Cat('file3', ['xxx', 'yyy', 'zzz'])
103 env.Command('file4', 'file4.in', r'%(_python_)s %(cat_py)s $TARGET - $SOURCES')
104 env.Cat('file5', 'file5.k')
105 env.Cat('subdir/file6', 'subdir/file6.in')
106 """ % locals())
107
108 test.write(['src', 'aaa'], "aaa 1\n")
109 test.write(['src', 'bbb.k'], """\
110 bbb.k 1
111 include ccc
112 include ../inc/ddd
113 include ../inc/eee
114 """)
115 test.write(['src', 'ccc'], "ccc 1\n")
116 test.write(['src', 'ddd'], "ddd 1\n")
117 test.write(['src', 'eee.in'], "eee.in 1\n")
118
119 test.write(['src', 'file1.in'], "file1.in 1\n")
120
121 test.write(['src', 'file2.k'], """\
122 file2.k 1 line 1
123 include xxx
124 include yyy
125 file2.k 1 line 4
126 """)
127
128 test.write(['src', 'file4.in'], "file4.in 1\n")
129
130 test.write(['src', 'xxx'], "xxx 1\n")
131 test.write(['src', 'yyy'], "yyy 1\n")
132 test.write(['src', 'zzz'], "zzz 1\n")
133
134 test.write(['src', 'file5.k'], """\
135 file5.k 1 line 1
136 include ../inc/aaa
137 include ../inc/bbb.k
138 file5.k 1 line 4
139 """)
140
141 test.write(['src', 'subdir', 'file6.in'], "subdir/file6.in 1\n")
142
143 #
144 test.run(chdir='src', arguments='.')
145
146 test.must_match(['src', 'file1'], "file1.in 1\n")
147 test.must_match(['src', 'file2'], """\
148 file2.k 1 line 1
149 xxx 1
150 yyy 1
151 file2.k 1 line 4
152 """)
153 test.must_match(['src', 'file3'], "xxx 1\nyyy 1\nzzz 1\n")
154 test.must_match(['src', 'file4'], "file4.in 1\n")
155 test.must_match(['src', 'file5'], """\
156 file5.k 1 line 1
157 aaa 1
158 bbb.k 1
159 ccc 1
160 ddd 1
161 eee.in 1
162 file5.k 1 line 4
163 """)
164
165 test.write(['src', 'file1.in'], "file1.in 2\n")
166 test.write(['src', 'yyy'], "yyy 2\n")
167 test.write(['src', 'zzz'], "zzz 2\n")
168 test.write(['src', 'bbb.k'], "bbb.k 2\ninclude ccc\n")
169
170 expect = test.wrap_stdout("""\
171 scons: rebuilding `file1' because `file1.in' changed
172 %(_python_)s %(cat_py)s file1 file1.in
173 scons: rebuilding `file2' because `yyy' changed
174 %(_python_)s %(cat_py)s file2 file2.k
175 scons: rebuilding `file3' because:
176            `yyy' changed
177            `zzz' changed
178 %(_python_)s %(cat_py)s file3 xxx yyy zzz
179 scons: rebuilding `%(inc_bbb_k)s' because:
180            `%(inc_ddd)s' is no longer a dependency
181            `%(inc_eee)s' is no longer a dependency
182            `bbb.k' changed
183 Install file: "bbb.k" as "%(inc_bbb_k)s"
184 scons: rebuilding `file5' because `%(inc_bbb_k)s' changed
185 %(_python_)s %(cat_py)s file5 file5.k
186 """ % locals())
187
188 test.run(chdir='src', arguments='--debug=explain .', stdout=expect)
189
190 test.must_match(['src', 'file1'], "file1.in 2\n")
191 test.must_match(['src', 'file2'], """\
192 file2.k 1 line 1
193 xxx 1
194 yyy 2
195 file2.k 1 line 4
196 """)
197 test.must_match(['src', 'file3'], "xxx 1\nyyy 2\nzzz 2\n")
198 test.must_match(['src', 'file5'], """\
199 file5.k 1 line 1
200 aaa 1
201 bbb.k 2
202 ccc 1
203 file5.k 1 line 4
204 """)
205
206
207
208 test.pass_test()