1#!/usr/local/bin/python3.8
2
3# Copyright 2011 Steven Watanabe
4# Distributed under the Boost Software License, Version 1.0.
5# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7import BoostBuild
8import os
9
10
11def basic():
12    t = BoostBuild.Tester(pass_toolset=0)
13
14    t.write("file.jam", """\
15actions do-print
16{
17    echo updating $(<)
18}
19
20NOTFILE target1 ;
21ALWAYS target1 ;
22do-print target1 ;
23
24UPDATE_NOW target1 ;
25
26DEPENDS all : target1 ;
27""")
28
29    t.run_build_system(["-ffile.jam"], stdout="""\
30...found 1 target...
31...updating 1 target...
32do-print target1
33updating target1
34...updated 1 target...
35...found 1 target...
36""")
37
38    t.cleanup()
39
40
41def ignore_minus_n():
42    t = BoostBuild.Tester(pass_toolset=0)
43
44    t.write("file.jam", """\
45actions do-print
46{
47    echo updating $(<)
48}
49
50NOTFILE target1 ;
51ALWAYS target1 ;
52do-print target1 ;
53
54UPDATE_NOW target1 : : ignore-minus-n ;
55
56DEPENDS all : target1 ;
57""")
58
59    t.run_build_system(["-ffile.jam", "-n"], stdout="""\
60...found 1 target...
61...updating 1 target...
62do-print target1
63
64    echo updating target1
65
66updating target1
67...updated 1 target...
68...found 1 target...
69""")
70
71    t.cleanup()
72
73
74def failed_target():
75    t = BoostBuild.Tester(pass_toolset=0)
76
77    t.write("file.jam", """\
78actions fail
79{
80    exit 1
81}
82
83NOTFILE target1 ;
84ALWAYS target1 ;
85fail target1 ;
86
87actions do-print
88{
89    echo updating $(<)
90}
91
92NOTFILE target2 ;
93do-print target2 ;
94DEPENDS target2 : target1 ;
95
96UPDATE_NOW target1 : : ignore-minus-n ;
97
98DEPENDS all : target1 target2 ;
99""")
100
101    t.run_build_system(["-ffile.jam", "-n"], stdout="""\
102...found 1 target...
103...updating 1 target...
104fail target1
105
106    exit 1
107
108...failed fail target1...
109...failed updating 1 target...
110...found 2 targets...
111...updating 1 target...
112do-print target2
113
114    echo updating target2
115
116...updated 1 target...
117""")
118
119    t.cleanup()
120
121
122def missing_target():
123    t = BoostBuild.Tester(pass_toolset=0)
124
125    t.write("file.jam", """\
126actions do-print
127{
128    echo updating $(<)
129}
130
131NOTFILE target2 ;
132do-print target2 ;
133DEPENDS target2 : target1 ;
134
135UPDATE_NOW target1 : : ignore-minus-n ;
136
137DEPENDS all : target1 target2 ;
138""")
139
140    t.run_build_system(["-ffile.jam", "-n"], status=1, stdout="""\
141don't know how to make target1
142...found 1 target...
143...can't find 1 target...
144...found 2 targets...
145...can't make 1 target...
146""")
147
148    t.cleanup()
149
150
151def build_once():
152    """
153      Make sure that if we call UPDATE_NOW with ignore-minus-n, the target gets
154    updated exactly once regardless of previous calls to UPDATE_NOW with -n in
155    effect.
156
157    """
158    t = BoostBuild.Tester(pass_toolset=0)
159
160    t.write("file.jam", """\
161actions do-print
162{
163    echo updating $(<)
164}
165
166NOTFILE target1 ;
167ALWAYS target1 ;
168do-print target1 ;
169
170UPDATE_NOW target1 ;
171UPDATE_NOW target1 : : ignore-minus-n ;
172UPDATE_NOW target1 : : ignore-minus-n ;
173
174DEPENDS all : target1 ;
175""")
176
177    t.run_build_system(["-ffile.jam", "-n"], stdout="""\
178...found 1 target...
179...updating 1 target...
180do-print target1
181
182    echo updating target1
183
184...updated 1 target...
185do-print target1
186
187    echo updating target1
188
189updating target1
190...updated 1 target...
191...found 1 target...
192""")
193
194    t.cleanup()
195
196
197def return_status():
198    """
199    Make sure that UPDATE_NOW returns a failure status if
200    the target failed in a previous call to UPDATE_NOW
201    """
202    t = BoostBuild.Tester(pass_toolset=0)
203
204    t.write("file.jam", """\
205actions fail
206{
207    exit 1
208}
209
210NOTFILE target1 ;
211ALWAYS target1 ;
212fail target1 ;
213
214ECHO "update1:" [ UPDATE_NOW target1 ] ;
215ECHO "update2:" [ UPDATE_NOW target1 ] ;
216
217DEPENDS all : target1 ;
218""")
219
220    t.run_build_system(["-ffile.jam"], status=1, stdout="""\
221...found 1 target...
222...updating 1 target...
223fail target1
224
225    exit 1
226
227...failed fail target1...
228...failed updating 1 target...
229update1:
230update2:
231...found 1 target...
232""")
233
234    t.cleanup()
235
236
237def save_restore():
238    """Tests that ignore-minus-n and ignore-minus-q are
239    local to the call to UPDATE_NOW"""
240    t = BoostBuild.Tester(pass_toolset=0)
241
242    t.write("actions.jam", """\
243rule fail
244{
245    NOTFILE $(<) ;
246    ALWAYS $(<) ;
247}
248actions fail
249{
250    exit 1
251}
252
253rule pass
254{
255    NOTFILE $(<) ;
256    ALWAYS $(<) ;
257}
258actions pass
259{
260    echo updating $(<)
261}
262""")
263    t.write("file.jam", """
264include actions.jam ;
265fail target1 ;
266fail target2 ;
267UPDATE_NOW target1 target2 : : $(IGNORE_MINUS_N) : $(IGNORE_MINUS_Q) ;
268fail target3 ;
269fail target4 ;
270UPDATE_NOW target3 target4 ;
271UPDATE ;
272""")
273    t.run_build_system(['-n', '-sIGNORE_MINUS_N=1', '-ffile.jam'],
274                       stdout='''...found 2 targets...
275...updating 2 targets...
276fail target1
277
278    exit 1
279
280...failed fail target1...
281fail target2
282
283    exit 1
284
285...failed fail target2...
286...failed updating 2 targets...
287...found 2 targets...
288...updating 2 targets...
289fail target3
290
291    exit 1
292
293fail target4
294
295    exit 1
296
297...updated 2 targets...
298''')
299
300    t.run_build_system(['-q', '-sIGNORE_MINUS_N=1', '-ffile.jam'],
301                       status=1, stdout='''...found 2 targets...
302...updating 2 targets...
303fail target1
304
305    exit 1
306
307...failed fail target1...
308...failed updating 1 target...
309...found 2 targets...
310...updating 2 targets...
311fail target3
312
313    exit 1
314
315...failed fail target3...
316...failed updating 1 target...
317''')
318
319    t.run_build_system(['-n', '-sIGNORE_MINUS_Q=1', '-ffile.jam'],
320                       stdout='''...found 2 targets...
321...updating 2 targets...
322fail target1
323
324    exit 1
325
326fail target2
327
328    exit 1
329
330...updated 2 targets...
331...found 2 targets...
332...updating 2 targets...
333fail target3
334
335    exit 1
336
337fail target4
338
339    exit 1
340
341...updated 2 targets...
342''')
343
344    t.run_build_system(['-q', '-sIGNORE_MINUS_Q=1', '-ffile.jam'],
345                       status=1, stdout='''...found 2 targets...
346...updating 2 targets...
347fail target1
348
349    exit 1
350
351...failed fail target1...
352fail target2
353
354    exit 1
355
356...failed fail target2...
357...failed updating 2 targets...
358...found 2 targets...
359...updating 2 targets...
360fail target3
361
362    exit 1
363
364...failed fail target3...
365...failed updating 1 target...
366''')
367
368    t.cleanup()
369
370
371basic()
372ignore_minus_n()
373failed_target()
374missing_target()
375build_once()
376return_status()
377save_restore()
378