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:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
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.
26 Verify that a failed build action with -j works as expected.
29 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
33 _python_ = TestSCons._python_
38 # if threads are not supported, then
39 # there is nothing to test
44 test = TestSCons.TestSCons()
46 # Test that we can handle parallel builds with a dependency graph
48 # a) Some nodes have multiple parents
49 # b) Some targets fail building
50 # c) Some targets succeed building
51 # d) Some children are ignored
52 # e) Some children are pre-requesites
53 # f) Some children have side-effects
54 # g) Some sources are missing
55 # h) Builds that are interrupted
57 test.write('SConstruct', """
59 vars.Add( BoolVariable('interrupt', 'Interrupt the build.', 0 ) )
60 varEnv = Environment(variables=vars)
62 def fail_action(target = None, source = None, env = None):
65 def simulate_keyboard_interrupt(target = None, source = None, env = None):
66 # Directly invoked the SIGINT handler to simulate a
67 # KeyboardInterrupt. This hack is necessary because there is no
68 # easy way to get access to the current Job/Taskmaster object.
70 handler = signal.getsignal(signal.SIGINT)
71 handler(signal.SIGINT, None)
74 interrupt = Command(target='interrupt', source='', action=simulate_keyboard_interrupt)
77 failed0 = Command(target='failed00', source='', action=fail_action)
78 ok0 = Command(target=['ok00a', 'ok00b', 'ok00c'],
80 action=[Touch('${TARGETS[0]}'), Touch('${TARGETS[1]}'), Touch('${TARGETS[2]}')])
81 prereq0 = Command(target='prereq00', source='', action=Touch('${TARGET}'))
82 ignore0 = Command(target='ignore00', source='', action=Touch('${TARGET}'))
83 igreq0 = Command(target='igreq00', source='', action=Touch('${TARGET}'))
84 missing0 = Command(target='missing00', source='MissingSrc', action=Touch('${TARGET}'))
85 withSE0 = Command(target=['withSE00a', 'withSE00b', 'withSE00c'],
87 action=[Touch('${TARGETS[0]}'), Touch('${TARGETS[1]}'), Touch('${TARGETS[2]}'),
88 Touch('side_effect')])
89 SideEffect('side_effect', withSE0)
91 prev_level = failed0 + ok0 + ignore0 + missing0 + withSE0
96 if varEnv['interrupt']:
97 prev_level = prev_level + interrupt
101 failed = Command(target='failed%02d' % i, source='', action=fail_action)
102 ok = Command(target=['ok%02da' % i, 'ok%02db' % i, 'ok%02dc' % i],
104 action=[Touch('${TARGETS[0]}'), Touch('${TARGETS[1]}'), Touch('${TARGETS[2]}')])
105 prereq = Command(target='prereq%02d' % i, source='', action=Touch('${TARGET}'))
106 ignore = Command(target='ignore%02d' % i, source='', action=Touch('${TARGET}'))
107 igreq = Command(target='igreq%02d' % i, source='', action=Touch('${TARGET}'))
108 missing = Command(target='missing%02d' %i, source='MissingSrc', action=Touch('${TARGET}'))
109 withSE = Command(target=['withSE%02da' % i, 'withSE%02db' % i, 'withSE%02dc' % i],
111 action=[Touch('${TARGETS[0]}'), Touch('${TARGETS[1]}'), Touch('${TARGETS[2]}'),
112 Touch('side_effect')])
113 SideEffect('side_effect', withSE)
115 next_level = failed + ok + ignore + igreq + missing + withSE
117 for j in range(1,10):
118 a = Alias('a%02d%02d' % (i,j), prev_level)
120 Requires(a, prev_prereq)
121 Ignore(a, prev_ignore)
123 Requires(a, prev_igreq)
124 Ignore(a, prev_igreq)
126 next_level = next_level + a
128 prev_level = next_level
133 all = Alias('all', prev_level)
135 Requires(all, prev_prereq)
136 Ignore(all, prev_ignore)
138 Requires(all, prev_igreq)
139 Ignore(all, prev_igreq)
145 (scons: \\*\\*\\* \\[failed\\d+] Error 2\\n)|\
146 (scons: \\*\\*\\* \\[missing\\d+] Source `MissingSrc' not found, needed by target `missing\\d+'\\.( Stop\\.)?\\n)|\
147 (scons: \\*\\*\\* \\[\\w+] Build interrupted\.\\n)|\
148 (scons: Build interrupted\.\\n)\
151 re_errors = "(" + re_error + ")+"
153 test.run(arguments = 'all',
155 stderr = "scons: *** [failed19] Error 2\n")
156 test.must_not_exist(test.workpath('side_effect'))
158 test.must_not_exist(test.workpath('ok%02da' % i))
159 test.must_not_exist(test.workpath('ok%02db' % i))
160 test.must_not_exist(test.workpath('ok%02dc' % i))
161 test.must_not_exist(test.workpath('prereq%02d' % i))
162 test.must_not_exist(test.workpath('ignore%02d' % i))
163 test.must_not_exist(test.workpath('igreq%02d' % i))
164 test.must_not_exist(test.workpath('withSE%02da' % i))
165 test.must_not_exist(test.workpath('withSE%02db' % i))
166 test.must_not_exist(test.workpath('withSE%02dc' % i))
170 test.run(arguments = '-c all')
172 test.run(arguments = '-j8 all',
175 match=TestSCons.match_re_dotall)
179 test.run(arguments = '-c all')
181 test.run(arguments = '-j 8 -k all',
184 match=TestSCons.match_re_dotall)
185 test.must_exist(test.workpath('side_effect'))
187 test.must_exist(test.workpath('ok%02da' % i))
188 test.must_exist(test.workpath('ok%02db' % i))
189 test.must_exist(test.workpath('ok%02dc' % i))
190 test.must_exist(test.workpath('prereq%02d' % i))
191 test.must_not_exist(test.workpath('ignore%02d' % i))
192 test.must_exist(test.workpath('igreq%02d' % i))
193 test.must_exist(test.workpath('withSE%02da' % i))
194 test.must_exist(test.workpath('withSE%02db' % i))
195 test.must_exist(test.workpath('withSE%02dc' % i))
199 test.run(arguments = 'all --random',
202 match=TestSCons.match_re_dotall)
206 test.run(arguments = '-c all')
208 test.run(arguments = '-j8 --random all',
211 match=TestSCons.match_re_dotall)
215 test.run(arguments = '-c all')
217 test.run(arguments = '-j 8 -k --random all',
220 match=TestSCons.match_re_dotall)
221 test.must_exist(test.workpath('side_effect'))
223 test.must_exist(test.workpath('ok%02da' % i))
224 test.must_exist(test.workpath('ok%02db' % i))
225 test.must_exist(test.workpath('ok%02dc' % i))
226 test.must_exist(test.workpath('prereq%02d' % i))
227 test.must_not_exist(test.workpath('ignore%02d' % i))
228 test.must_exist(test.workpath('igreq%02d' % i))
229 test.must_exist(test.workpath('withSE%02da' % i))
230 test.must_exist(test.workpath('withSE%02db' % i))
231 test.must_exist(test.workpath('withSE%02dc' % i))
235 test.run(arguments = '-c all')
237 test.run(arguments = '-j 8 -k --random interrupt=yes all',
240 match=TestSCons.match_re_dotall)