1#!/usr/local/bin/python3.8
2
3# Copyright 2003 Dave Abrahams
4# Copyright 2006 Rene Rivera
5# Copyright 2003 Vladimir Prus
6# Distributed under the Boost Software License, Version 1.0.
7# (See accompanying file LICENSE_1_0.txt or copy at
8# http://www.boost.org/LICENSE_1_0.txt)
9
10# Demonstration that module variables have the correct effect in actions.
11
12import BoostBuild
13import os
14import re
15
16t = BoostBuild.Tester(["-d+1"], pass_toolset=0)
17
18t.write("boost-build.jam", "boost-build . ;")
19t.write("bootstrap.jam", """\
20# Top-level rule causing a target to be built by invoking the specified action.
21rule make ( target : sources * : act )
22{
23    DEPENDS all : $(target) ;
24    DEPENDS $(target) : $(sources) ;
25    $(act) $(target) : $(sources) ;
26}
27
28X1 = X1-global ;
29X2 = X2-global ;
30X3 = X3-global ;
31
32module A
33{
34    X1 = X1-A ;
35
36    rule act ( target )
37    {
38        NOTFILE $(target) ;
39        ALWAYS $(target) ;
40    }
41
42    actions act { echo A.act $(<): $(X1) $(X2) $(X3) }
43
44    make t1 : : A.act ;
45    make t2 : : A.act ;
46    make t3 : : A.act ;
47}
48
49module B
50{
51    X2 = X2-B ;
52
53    actions act { echo B.act $(<): $(X1) $(X2) $(X3) }
54
55    make t1 : : B.act ;
56    make t2 : : B.act ;
57    make t3 : : B.act ;
58}
59
60actions act { echo act $(<): $(X1) $(X2) $(X3) }
61
62make t1 : : act ;
63make t2 : : act ;
64make t3 : : act ;
65
66X1 on t1 = X1-t1 ;
67X2 on t2 = X2-t2 ;
68X3 on t3 = X3-t3 ;
69
70DEPENDS all : t1 t2 t3 ;
71""")
72
73expected_lines = [
74    "...found 4 targets...",
75    "...updating 3 targets...",
76    "A.act t1",
77    "A.act t1: X1-t1   ",
78    "B.act t1",
79    "B.act t1: X1-t1 X2-B  ",
80    "act t1",
81    "act t1: X1-t1 X2-global X3-global ",
82    "A.act t2",
83    "A.act t2: X1-A X2-t2  ",
84    "B.act t2",
85    "B.act t2:  X2-t2  ",
86    "act t2",
87    "act t2: X1-global X2-t2 X3-global ",
88    "A.act t3",
89    "A.act t3: X1-A  X3-t3 ",
90    "B.act t3",
91    "B.act t3:  X2-B X3-t3 ",
92    "act t3",
93    "act t3: X1-global X2-global X3-t3 ",
94    "...updated 3 targets...",
95    ""]
96
97# Accommodate for the fact that on Unixes, a call to 'echo 1   2     3  '
98# produces '1 2 3' (note the spacing).
99if os.name != 'nt':
100    expected_lines = [re.sub("  +", " ", x.rstrip()) for x in expected_lines]
101
102t.run_build_system()
103t.expect_output_lines(expected_lines)
104t.expect_nothing_more()
105t.cleanup()
106