5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 Verify that the sconsign script works with files generated when
28 using the signatures in an SConsignFile().
34 from TestSCons
import _python_
35 from TestCmd
import NEED_HELPER
37 test
= TestSConsign
.TestSConsign(match
= TestSConsign
.match_re
)
40 test
.skip_test("Test host cannot directly execute scripts, skipping test\n")
42 test
.subdir('sub1', 'sub2')
44 fake_cc_py
= test
.workpath('fake_cc.py')
45 fake_link_py
= test
.workpath('fake_link.py')
54 path = sys.argv[1].split()
63 def process(infp, outfp):
64 for line in infp.readlines():
65 m = re.match(r'#include <(.*)>', line)
68 found = find_file(file)
75 with open(sys.argv[2], 'w') as outf, open(sys.argv[3], 'r') as ifp:
76 outf.write('fake_cc.py: %s\n' % sys.argv)
88 with open(sys.argv[1], 'w') as outf, open(sys.argv[2], 'r') as ifp:
89 outf.write('fake_link.py: %s\n' % sys.argv)
90 outf.write(ifp.read())
96 test
.chmod(fake_cc_py
, 0o755)
97 test
.chmod(fake_link_py
, 0o755)
99 # Note: We don't use os.path.join() representations of the file names
100 # in the expected output because paths in the .sconsign files are
101 # canonicalized to use / as the separator.
103 sub1_hello_c
= 'sub1/hello.c'
104 sub1_hello_obj
= 'sub1/hello.obj'
105 sub2_hello_c
= 'sub2/hello.c'
106 sub2_hello_obj
= 'sub2/hello.obj'
107 sub2_inc1_h
= 'sub2/inc1.h'
108 sub2_inc2_h
= 'sub2/inc2.h'
114 _ = DefaultEnvironment(tools=[])
118 CCCOM=[[r'{fake_cc_py}', 'sub2', '$TARGET', '$SOURCE']],
119 LINKCOM=[[r'{fake_link_py}', '$TARGET', '$SOURCE']],
121 env1.PrependENVPath('PATHEXT', '.PY')
122 env1.Program('sub1/hello.c')
123 env2 = env1.Clone(CPPPATH=['sub2'])
124 env2.Program('sub2/hello.c')
127 # TODO in the above, we would normally want to run a python program
128 # using "our python" like this:
129 # CCCOM=[[r'{_python_}', r'{fake_cc_py}', 'sub2', '$TARGET', '$SOURCE']],
130 # LINKCOM=[[r'{_python_}', r'{fake_link_py}', '$TARGET', '$SOURCE']],
131 # however we're looking at dependencies with sconsign, so that breaks things.
132 # It still breaks things on Windows if something else is registered as the
133 # handler for .py files, as Visual Studio Code installs itself.
135 test
.write(['sub1', 'hello.c'], r
"""
139 test
.write(['sub2', 'hello.c'], r
"""
143 main(int argc, char *argv[])
146 printf("sub2/goodbye.c\n");
151 test
.write(['sub2', 'inc1.h'], r
"""
152 #define STRING1 "inc1.h"
155 test
.write(['sub2', 'inc2.h'], r
"""
156 #define STRING2 "inc2.h"
159 test
.run(arguments
='--implicit-cache .')
161 sig_re
= r
'[0-9a-fA-F]{32,64}'
163 database_name
= test
.get_sconsignname()
165 test
.run_sconsign(arguments
=database_name
,
167 SConstruct: None \d+ \d+
168 fake_cc\.py: %(sig_re)s \d+ \d+
169 fake_link\.py: %(sig_re)s \d+ \d+
171 hello.c: %(sig_re)s \d+ \d+
172 hello.exe: %(sig_re)s \d+ \d+
173 %(sub1_hello_obj)s: %(sig_re)s \d+ \d+
174 fake_link\.py: %(sig_re)s \d+ \d+
176 hello.obj: %(sig_re)s \d+ \d+
177 %(sub1_hello_c)s: %(sig_re)s \d+ \d+
178 fake_cc\.py: %(sig_re)s \d+ \d+
181 hello.c: %(sig_re)s \d+ \d+
182 hello.exe: %(sig_re)s \d+ \d+
183 %(sub2_hello_obj)s: %(sig_re)s \d+ \d+
184 fake_link\.py: %(sig_re)s \d+ \d+
186 hello.obj: %(sig_re)s \d+ \d+
187 %(sub2_hello_c)s: %(sig_re)s \d+ \d+
188 %(sub2_inc1_h)s: %(sig_re)s \d+ \d+
189 %(sub2_inc2_h)s: %(sig_re)s \d+ \d+
190 fake_cc\.py: %(sig_re)s \d+ \d+
192 inc1.h: %(sig_re)s \d+ \d+
193 inc2.h: %(sig_re)s \d+ \d+
196 test
.run_sconsign(arguments
="--raw " + database_name
,
198 SConstruct: {'csig': None, 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
199 fake_cc\.py: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
200 fake_link\.py: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
202 hello.c: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
203 hello.exe: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
204 %(sub1_hello_obj)s: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
205 fake_link\.py: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
207 hello.obj: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
208 %(sub1_hello_c)s: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
209 fake_cc\.py: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
212 hello.c: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
213 hello.exe: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
214 %(sub2_hello_obj)s: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
215 fake_link\.py: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
217 hello.obj: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
218 %(sub2_hello_c)s: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
219 %(sub2_inc1_h)s: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
220 %(sub2_inc2_h)s: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
221 fake_cc\.py: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
223 inc1.h: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
224 inc2.h: {'csig': '%(sig_re)s', 'timestamp': \d+L?, 'size': \d+L?, '_version_id': 2}
258 action: %(sig_re)s \[.*\]
272 action: %(sig_re)s \[.*\]
291 action: %(sig_re)s \[.*\]
313 action: %(sig_re)s \[.*\]
324 test
.run_sconsign(arguments
="-v " + database_name
, stdout
=expect
)
326 test
.run_sconsign(arguments
="-c -v " + database_name
,
354 test
.run_sconsign(arguments
="-s -v " + database_name
,
382 test
.run_sconsign(arguments
="-t -v " + database_name
,
410 test
.run_sconsign(arguments
="-e hello.obj " + database_name
,
413 hello.obj: %(sig_re)s \d+ \d+
414 %(sub1_hello_c)s: %(sig_re)s \d+ \d+
415 fake_cc\.py: %(sig_re)s \d+ \d+
418 hello.obj: %(sig_re)s \d+ \d+
419 %(sub2_hello_c)s: %(sig_re)s \d+ \d+
420 %(sub2_inc1_h)s: %(sig_re)s \d+ \d+
421 %(sub2_inc2_h)s: %(sig_re)s \d+ \d+
422 fake_cc\.py: %(sig_re)s \d+ \d+
425 stderr
=r
"""sconsign: no entry `hello\.obj' in `\.'
428 test
.run_sconsign(arguments
="-e hello.obj -e hello.exe -e hello.obj " + database_name
,
431 hello.obj: %(sig_re)s \d+ \d+
432 %(sub1_hello_c)s: %(sig_re)s \d+ \d+
433 fake_cc\.py: %(sig_re)s \d+ \d+
435 hello.exe: %(sig_re)s \d+ \d+
436 %(sub1_hello_obj)s: %(sig_re)s \d+ \d+
437 fake_link\.py: %(sig_re)s \d+ \d+
439 hello.obj: %(sig_re)s \d+ \d+
440 %(sub1_hello_c)s: %(sig_re)s \d+ \d+
441 fake_cc\.py: %(sig_re)s \d+ \d+
444 hello.obj: %(sig_re)s \d+ \d+
445 %(sub2_hello_c)s: %(sig_re)s \d+ \d+
446 %(sub2_inc1_h)s: %(sig_re)s \d+ \d+
447 %(sub2_inc2_h)s: %(sig_re)s \d+ \d+
448 fake_cc\.py: %(sig_re)s \d+ \d+
450 hello.exe: %(sig_re)s \d+ \d+
451 %(sub2_hello_obj)s: %(sig_re)s \d+ \d+
452 fake_link\.py: %(sig_re)s \d+ \d+
454 hello.obj: %(sig_re)s \d+ \d+
455 %(sub2_hello_c)s: %(sig_re)s \d+ \d+
456 %(sub2_inc1_h)s: %(sig_re)s \d+ \d+
457 %(sub2_inc2_h)s: %(sig_re)s \d+ \d+
458 fake_cc\.py: %(sig_re)s \d+ \d+
461 stderr
=r
"""sconsign: no entry `hello\.obj' in `\.'
462 sconsign: no entry `hello\.exe' in `\.'
463 sconsign: no entry `hello\.obj' in `\.'
466 #test.run_sconsign(arguments="-i -v " + database_name,
467 # stdout=r"""=== sub1:
470 # hello.obj: %(sig_re)s
473 # hello.c: %(sig_re)s
477 # hello.obj: %(sig_re)s
480 # hello.c: %(sig_re)s
491 # indent-tabs-mode:nil
493 # vim: set expandtab tabstop=4 shiftwidth=4: