Merged revisions 2454-2525 via svnmerge from
[scons.git] / test / sconsign / script / no-SConsignFile.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 sconsign script works when using an individual
29 .sconsign file in each directory (SConsignFile(None)).
30 """
31
32 import TestSCons
33 import TestSConsign
34
35 _python_ = TestSCons._python_
36
37 test = TestSConsign.TestSConsign(match = TestSConsign.match_re)
38
39 test.subdir('sub1', 'sub2')
40
41 test.write('fake_cc.py', r"""
42 import os.path
43 import re
44 import string
45 import sys
46
47 path = string.split(sys.argv[1])
48 output = open(sys.argv[2], 'wb')
49 input = open(sys.argv[3], 'rb')
50
51 output.write('fake_cc.py:  %s\n' % sys.argv)
52
53 def find_file(f):
54     for dir in path:
55         p = dir + os.sep + f
56         if os.path.exists(p):
57             return open(p, 'rb')
58     return None
59
60 def process(infp, outfp):
61     for line in infp.readlines():
62         m = re.match('#include <(.*)>', line)
63         if m:
64             file = m.group(1)
65             process(find_file(file), outfp)
66         else:
67             outfp.write(line)
68
69 process(input, output)
70
71 sys.exit(0)
72 """)
73
74 test.write('fake_link.py', r"""
75 import sys
76
77 output = open(sys.argv[1], 'wb')
78 input = open(sys.argv[2], 'rb')
79
80 output.write('fake_link.py:  %s\n' % sys.argv)
81
82 output.write(input.read())
83
84 sys.exit(0)
85 """)
86
87 # Note:  We don't use os.path.join() representations of the file names
88 # in the expected output because paths in the .sconsign files are
89 # canonicalized to use / as the separator.
90
91 sub1_hello_c    = 'sub1/hello.c'
92 sub1_hello_obj  = 'sub1/hello.obj'
93 sub2_hello_c    = 'sub2/hello.c'
94 sub2_hello_obj  = 'sub2/hello.obj'
95 sub2_inc1_h     = 'sub2/inc1.h'
96 sub2_inc2_h     = 'sub2/inc2.h'
97
98 test.write(['SConstruct'], """
99 SConsignFile(None)
100 env1 = Environment(PROGSUFFIX = '.exe',
101                    OBJSUFFIX = '.obj',
102                    CCCOM = r'%(_python_)s fake_cc.py sub2 $TARGET $SOURCE',
103                    LINKCOM = r'%(_python_)s fake_link.py $TARGET $SOURCE')
104 env1.Program('sub1/hello.c')
105 env2 = env1.Clone(CPPPATH = ['sub2'])
106 env2.Program('sub2/hello.c')
107 """ % locals())
108
109 test.write(['sub1', 'hello.c'], r"""\
110 sub1/hello.c
111 """)
112
113 test.write(['sub2', 'hello.c'], r"""\
114 #include <inc1.h>
115 #include <inc2.h>
116 sub2/hello.c
117 """)
118
119 test.write(['sub2', 'inc1.h'], r"""\
120 #define STRING1 "inc1.h"
121 """)
122
123 test.write(['sub2', 'inc2.h'], r"""\
124 #define STRING2 "inc2.h"
125 """)
126
127 test.run(arguments = '--implicit-cache --tree=prune .')
128
129 sig_re = r'[0-9a-fA-F]{32}'
130
131 expect = r"""hello.c: %(sig_re)s \d+ \d+
132 hello.exe: %(sig_re)s \d+ \d+
133         %(sub1_hello_obj)s: %(sig_re)s \d+ \d+
134         %(sig_re)s \[.*\]
135 hello.obj: %(sig_re)s \d+ \d+
136         %(sub1_hello_c)s: %(sig_re)s \d+ \d+
137         %(sig_re)s \[.*\]
138 """ % locals()
139
140 test.run_sconsign(arguments = "sub1/.sconsign", stdout=expect)
141 #test.run_sconsign(arguments = "sub1/.sconsign")
142 #print test.stdout()
143
144 test.run_sconsign(arguments = "--raw sub1/.sconsign",
145          stdout = r"""hello.c: {'csig': '%(sig_re)s', 'timestamp': \d+, 'size': \d+L?, '_version_id': 1}
146 hello.exe: {'csig': '%(sig_re)s', 'timestamp': \d+, 'size': \d+L?, '_version_id': 1}
147         %(sub1_hello_obj)s: {'csig': '%(sig_re)s', 'timestamp': \d+, 'size': \d+L?, '_version_id': 1}
148         %(sig_re)s \[.*\]
149 hello.obj: {'csig': '%(sig_re)s', 'timestamp': \d+, 'size': \d+L?, '_version_id': 1}
150         %(sub1_hello_c)s: {'csig': '%(sig_re)s', 'timestamp': \d+, 'size': \d+L?, '_version_id': 1}
151         %(sig_re)s \[.*\]
152 """ % locals())
153
154 test.run_sconsign(arguments = "-v sub1/.sconsign",
155          stdout = r"""hello.c:
156     csig: %(sig_re)s
157     timestamp: \d+
158     size: \d+
159 hello.exe:
160     csig: %(sig_re)s
161     timestamp: \d+
162     size: \d+
163     implicit:
164         %(sub1_hello_obj)s:
165             csig: %(sig_re)s
166             timestamp: \d+
167             size: \d+
168     action: %(sig_re)s \[.*\]
169 hello.obj:
170     csig: %(sig_re)s
171     timestamp: \d+
172     size: \d+
173     implicit:
174         %(sub1_hello_c)s:
175             csig: %(sig_re)s
176             timestamp: \d+
177             size: \d+
178     action: %(sig_re)s \[.*\]
179 """ % locals())
180
181 test.run_sconsign(arguments = "-c -v sub1/.sconsign",
182          stdout = r"""hello.c:
183     csig: %(sig_re)s
184 hello.exe:
185     csig: %(sig_re)s
186 hello.obj:
187     csig: %(sig_re)s
188 """ % locals())
189
190 test.run_sconsign(arguments = "-s -v sub1/.sconsign",
191          stdout = r"""hello.c:
192     size: \d+
193 hello.exe:
194     size: \d+
195 hello.obj:
196     size: \d+
197 """ % locals())
198
199 test.run_sconsign(arguments = "-t -v sub1/.sconsign",
200          stdout = r"""hello.c:
201     timestamp: \d+
202 hello.exe:
203     timestamp: \d+
204 hello.obj:
205     timestamp: \d+
206 """ % locals())
207
208 test.run_sconsign(arguments = "-e hello.obj sub1/.sconsign",
209          stdout = r"""hello.obj: %(sig_re)s \d+ \d+
210         %(sub1_hello_c)s: %(sig_re)s \d+ \d+
211         %(sig_re)s \[.*\]
212 """ % locals())
213
214 test.run_sconsign(arguments = "-e hello.obj -e hello.exe -e hello.obj sub1/.sconsign",
215          stdout = r"""hello.obj: %(sig_re)s \d+ \d+
216         %(sub1_hello_c)s: %(sig_re)s \d+ \d+
217         %(sig_re)s \[.*\]
218 hello.exe: %(sig_re)s \d+ \d+
219         %(sub1_hello_obj)s: %(sig_re)s \d+ \d+
220         %(sig_re)s \[.*\]
221 hello.obj: %(sig_re)s \d+ \d+
222         %(sub1_hello_c)s: %(sig_re)s \d+ \d+
223         %(sig_re)s \[.*\]
224 """ % locals())
225
226 test.run_sconsign(arguments = "sub2/.sconsign",
227          stdout = r"""hello.c: %(sig_re)s \d+ \d+
228 hello.exe: %(sig_re)s \d+ \d+
229         %(sub2_hello_obj)s: %(sig_re)s \d+ \d+
230         %(sig_re)s \[.*\]
231 hello.obj: %(sig_re)s \d+ \d+
232         %(sub2_hello_c)s: %(sig_re)s \d+ \d+
233         %(sub2_inc1_h)s: %(sig_re)s \d+ \d+
234         %(sub2_inc2_h)s: %(sig_re)s \d+ \d+
235         %(sig_re)s \[.*\]
236 inc1.h: %(sig_re)s \d+ \d+
237 inc2.h: %(sig_re)s \d+ \d+
238 """ % locals())
239
240 #test.run_sconsign(arguments = "-i -v sub2/.sconsign",
241 #         stdout = r"""hello.c: %(sig_re)s \d+ \d+
242 #hello.exe: %(sig_re)s \d+ \d+
243 #    implicit:
244 #        hello.obj: %(sig_re)s \d+ \d+
245 #hello.obj: %(sig_re)s \d+ \d+
246 #    implicit:
247 #        hello.c: %(sig_re)s \d+ \d+
248 #        inc1.h: %(sig_re)s \d+ \d+
249 #        inc2.h: %(sig_re)s \d+ \d+
250 #""" % locals())
251
252 test.run_sconsign(arguments = "-e hello.obj sub2/.sconsign sub1/.sconsign",
253          stdout = r"""hello.obj: %(sig_re)s \d+ \d+
254         %(sub2_hello_c)s: %(sig_re)s \d+ \d+
255         %(sub2_inc1_h)s: %(sig_re)s \d+ \d+
256         %(sub2_inc2_h)s: %(sig_re)s \d+ \d+
257         %(sig_re)s \[.*\]
258 hello.obj: %(sig_re)s \d+ \d+
259         %(sub1_hello_c)s: %(sig_re)s \d+ \d+
260         %(sig_re)s \[.*\]
261 """ % locals())
262
263 test.pass_test()