1#!/usr/local/bin/python3.8
2
3# Copyright 2007 Rene Rivera.
4# Copyright 2011 Steven Watanabe
5# Distributed under the Boost Software License, Version 1.0.
6# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
7
8#   Added to guard against a bug causing targets to be used before they
9# themselves have finished building. This used to happen for targets built by a
10# multi-file action that got triggered by another target.
11#
12# Example:
13#   When target A and target B were declared as created by a single action and
14# target A triggered running that action then, while the action was still
15# running, target B was already reporting as being built causing other targets
16# depending on target A to be built prematurely.
17
18import BoostBuild
19
20t = BoostBuild.Tester(["-d1"], pass_toolset=0)
21
22t.write("sleep.bat", """\
23::@timeout /T %1 /NOBREAK >nul
24@ping 127.0.0.1 -n 2 -w 1000 >nul
25@ping 127.0.0.1 -n %1 -w 1000 >nul
26@exit /B 0
27""")
28
29t.write("file.jam", """\
30if $(NT)
31{
32    SLEEP = @call sleep.bat ;
33}
34else
35{
36    SLEEP = sleep ;
37}
38
39actions .gen.
40{
41    echo 001
42    $(SLEEP) 4
43    echo 002
44}
45rule .use.1 { DEPENDS $(<) : $(>) ; }
46actions .use.1
47{
48    echo 003
49}
50
51rule .use.2 { DEPENDS $(<) : $(>) ; }
52actions .use.2
53{
54    $(SLEEP) 1
55    echo 004
56}
57
58.gen. g1.generated g2.generated ;
59.use.1 u1.user : g1.generated ;
60.use.2 u2.user : g2.generated ;
61
62DEPENDS all : u1.user u2.user ;
63""")
64
65t.run_build_system(["-ffile.jam", "-j2"], stdout="""\
66...found 5 targets...
67...updating 4 targets...
68.gen. g1.generated
69001
70002
71.use.1 u1.user
72003
73.use.2 u2.user
74004
75...updated 4 targets...
76""")
77
78t.cleanup()
79