Update tests for now discovering dependencies on quoted commands
[scons.git] / test / sconsign / script / Signatures.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 a .sconsign file in
29 each subdirectory (SConsignFile(None)) written with the non-default
30 value of Decider('timestamp-newer').
31
32 This used to test the non-default combination of
33 SourceSignatures('timestamp') with TargetSignatures('content').
34 """
35
36 import TestSCons
37 import TestSConsign
38
39 python = TestSCons.python
40 _python_ = TestSCons._python_
41
42 test = TestSConsign.TestSConsign(match = TestSConsign.match_re)
43
44 # Note:  We don't use os.path.join() representations of the file names
45 # in the expected output because paths in the .sconsign files are
46 # canonicalized to use / as the separator.
47
48 sub1_hello_c    = 'sub1/hello.c'
49 sub1_hello_obj  = 'sub1/hello.obj'
50
51 test.subdir('sub1', 'sub2')
52
53 test.write('fake_cc.py', r"""
54 import os
55 import re
56 import string
57 import sys
58
59 path = string.split(sys.argv[1])
60 output = open(sys.argv[2], 'wb')
61 input = open(sys.argv[3], 'rb')
62
63 output.write('fake_cc.py:  %s\n' % sys.argv)
64
65 def find_file(f):
66     for dir in path:
67         p = dir + os.sep + f
68         if os.path.exists(p):
69             return open(p, 'rb')
70     return None
71
72 def process(infp, outfp):
73     for line in infp.readlines():
74         m = re.match('#include <(.*)>', line)
75         if m:
76             file = m.group(1)
77             process(find_file(file), outfp)
78         else:
79             outfp.write(line)
80
81 process(input, output)
82
83 sys.exit(0)
84 """)
85
86 test.write('fake_link.py', r"""
87 import sys
88
89 output = open(sys.argv[1], 'wb')
90 input = open(sys.argv[2], 'rb')
91
92 output.write('fake_link.py:  %s\n' % sys.argv)
93
94 output.write(input.read())
95
96 sys.exit(0)
97 """)
98
99 test.write('SConstruct', """
100 SConsignFile(None)
101 Decider('timestamp-newer')
102 env1 = Environment(PROGSUFFIX = '.exe',
103                    OBJSUFFIX = '.obj',
104                    CCCOM = r'%(_python_)s fake_cc.py sub2 $TARGET $SOURCE',
105                    LINKCOM = r'%(_python_)s fake_link.py $TARGET $SOURCE')
106 env1.Program('sub1/hello.c')
107 env2 = env1.Clone(CPPPATH = ['sub2'])
108 env2.Program('sub2/hello.c')
109 """ % locals())
110
111 test.write(['sub1', 'hello.c'], r"""\
112 sub1/hello.c
113 """)
114
115 test.write(['sub2', 'hello.c'], r"""\
116 #include <inc1.h>
117 #include <inc2.h>
118 sub2/hello.c
119 """)
120
121 test.write(['sub2', 'inc1.h'], r"""\
122 #define STRING1 "inc1.h"
123 """)
124
125 test.write(['sub2', 'inc2.h'], r"""\
126 #define STRING2 "inc2.h"
127 """)
128
129 test.sleep()
130
131 test.run(arguments = '. --max-drift=1')
132
133 sig_re = r'[0-9a-fA-F]{32}'
134 date_re = r'\S+ \S+ [ \d]\d \d\d:\d\d:\d\d \d\d\d\d'
135
136 test.run_sconsign(arguments = "-e hello.exe -e hello.obj sub1/.sconsign",
137          stdout = r"""hello.exe: %(sig_re)s \d+ \d+
138         %(sub1_hello_obj)s: %(sig_re)s \d+ \d+
139         %(python)s: None \d+ \d+
140         %(sig_re)s \[.*\]
141 hello.obj: %(sig_re)s \d+ \d+
142         %(sub1_hello_c)s: None \d+ \d+
143         %(python)s: None \d+ \d+
144         %(sig_re)s \[.*\]
145 """ % locals())
146
147 test.run_sconsign(arguments = "-e hello.exe -e hello.obj -r sub1/.sconsign",
148          stdout = r"""hello.exe: %(sig_re)s '%(date_re)s' \d+
149         %(sub1_hello_obj)s: %(sig_re)s '%(date_re)s' \d+
150         %(python)s: None '%(date_re)s' \d+
151         %(sig_re)s \[.*\]
152 hello.obj: %(sig_re)s '%(date_re)s' \d+
153         %(sub1_hello_c)s: None '%(date_re)s' \d+
154         %(python)s: None '%(date_re)s' \d+
155         %(sig_re)s \[.*\]
156 """ % locals())
157
158 test.pass_test()