]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/usr/bin/python |
2 | ||
3 | # Copyright 2012 Steven Watanabe | |
4 | # Distributed under the Boost Software License, Version 1.0. | |
1e59de90 | 5 | # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt) |
7c673cae FG |
6 | |
7 | import BoostBuild | |
8 | ||
9 | t = BoostBuild.Tester(use_test_config=False) | |
10 | ||
11 | # Test a header loop that depends on (but does not contain) a generated header. | |
12 | t.write("test.cpp", '#include "header1.h"\n') | |
13 | ||
14 | t.write("header1.h", """\ | |
15 | #ifndef HEADER1_H | |
16 | #define HEADER1_H | |
17 | #include "header2.h" | |
18 | #endif | |
19 | """) | |
20 | ||
21 | t.write("header2.h", """\ | |
22 | #ifndef HEADER2_H | |
23 | #define HEADER2_H | |
24 | #include "header1.h" | |
25 | #include "header3.h" | |
26 | #endif | |
27 | """) | |
28 | ||
29 | t.write("header3.in", "/* empty file */\n") | |
30 | ||
31 | t.write("jamroot.jam", """\ | |
32 | import common ; | |
33 | make header3.h : header3.in : @common.copy ; | |
34 | obj test : test.cpp : <implicit-dependency>header3.h ; | |
35 | """) | |
36 | ||
37 | t.run_build_system(["-j2"]) | |
11fdf7f2 | 38 | t.expect_addition("bin/header3.h") |
b32b8144 | 39 | t.expect_addition("bin/$toolset/debug*/test.obj") |
7c673cae FG |
40 | t.expect_nothing_more() |
41 | ||
42 | t.rm(".") | |
43 | ||
44 | # Test a linear sequence of generated headers. | |
45 | t.write("test.cpp", '#include "header1.h"\n') | |
46 | ||
47 | t.write("header1.in", """\ | |
48 | #ifndef HEADER1_H | |
49 | #define HEADER1_H | |
50 | #include "header2.h" | |
51 | #endif | |
52 | """) | |
53 | ||
54 | t.write("header2.in", """\ | |
55 | #ifndef HEADER2_H | |
56 | #define HEADER2_H | |
57 | #include "header3.h" | |
58 | #endif | |
59 | """) | |
60 | ||
61 | t.write("header3.in", "/* empty file */\n") | |
62 | ||
63 | t.write("jamroot.jam", """\ | |
64 | import common ; | |
65 | make header1.h : header1.in : @common.copy ; | |
66 | make header2.h : header2.in : @common.copy ; | |
67 | make header3.h : header3.in : @common.copy ; | |
68 | obj test : test.cpp : | |
69 | <implicit-dependency>header1.h | |
70 | <implicit-dependency>header2.h | |
71 | <implicit-dependency>header3.h ; | |
72 | """) | |
73 | ||
74 | t.run_build_system(["-j2", "test"]) | |
11fdf7f2 TL |
75 | t.expect_addition("bin/header1.h") |
76 | t.expect_addition("bin/header2.h") | |
77 | t.expect_addition("bin/header3.h") | |
b32b8144 | 78 | t.expect_addition("bin/$toolset/debug*/test.obj") |
7c673cae FG |
79 | t.expect_nothing_more() |
80 | ||
81 | t.rm(".") | |
82 | ||
83 | # Test a loop in generated headers. | |
84 | t.write("test.cpp", '#include "header1.h"\n') | |
85 | ||
86 | t.write("header1.in", """\ | |
87 | #ifndef HEADER1_H | |
88 | #define HEADER1_H | |
89 | #include "header2.h" | |
90 | #endif | |
91 | """) | |
92 | ||
93 | t.write("header2.in", """\ | |
94 | #ifndef HEADER2_H | |
95 | #define HEADER2_H | |
96 | #include "header3.h" | |
97 | #endif | |
98 | """) | |
99 | ||
100 | t.write("header3.in", """\ | |
101 | #ifndef HEADER2_H | |
102 | #define HEADER2_H | |
103 | #include "header1.h" | |
104 | #endif | |
105 | """) | |
106 | ||
107 | t.write("jamroot.jam", """\ | |
108 | import common ; | |
109 | ||
110 | actions copy { | |
111 | sleep 1 | |
112 | cp $(>) $(<) | |
113 | } | |
114 | ||
115 | make header1.h : header1.in : @common.copy ; | |
116 | make header2.h : header2.in : @common.copy ; | |
117 | make header3.h : header3.in : @common.copy ; | |
118 | obj test : test.cpp : | |
119 | <implicit-dependency>header1.h | |
120 | <implicit-dependency>header2.h | |
121 | <implicit-dependency>header3.h ; | |
122 | """) | |
123 | ||
124 | t.run_build_system(["-j2", "test"]) | |
11fdf7f2 TL |
125 | t.expect_addition("bin/header1.h") |
126 | t.expect_addition("bin/header2.h") | |
127 | t.expect_addition("bin/header3.h") | |
b32b8144 | 128 | t.expect_addition("bin/$toolset/debug*/test.obj") |
7c673cae FG |
129 | t.expect_nothing_more() |
130 | ||
131 | t.rm(".") | |
132 | ||
133 | # Test that all the dependencies of a loop are updated before any of the | |
134 | # dependents. | |
135 | t.write("test1.cpp", '#include "header1.h"\n') | |
136 | ||
137 | t.write("test2.cpp", """\ | |
138 | #include "header2.h" | |
139 | int main() {} | |
140 | """) | |
141 | ||
142 | t.write("header1.h", """\ | |
143 | #ifndef HEADER1_H | |
144 | #define HEADER1_H | |
145 | #include "header2.h" | |
146 | #endif | |
147 | """) | |
148 | ||
149 | t.write("header2.h", """\ | |
150 | #ifndef HEADER2_H | |
151 | #define HEADER2_H | |
152 | #include "header1.h" | |
153 | #include "header3.h" | |
154 | #endif | |
155 | """) | |
156 | ||
157 | t.write("header3.in", "\n") | |
158 | ||
159 | t.write("sleep.bat", """\ | |
160 | ::@timeout /T %1 /NOBREAK >nul | |
161 | @ping 127.0.0.1 -n 2 -w 1000 >nul | |
162 | @ping 127.0.0.1 -n %1 -w 1000 >nul | |
163 | @exit /B 0 | |
164 | """) | |
165 | ||
166 | t.write("jamroot.jam", """\ | |
167 | import common ; | |
168 | import os ; | |
169 | ||
170 | if [ os.name ] = NT | |
171 | { | |
172 | SLEEP = call sleep.bat ; | |
173 | } | |
174 | else | |
175 | { | |
176 | SLEEP = sleep ; | |
177 | } | |
178 | ||
179 | rule copy { common.copy $(<) : $(>) ; } | |
180 | actions copy { $(SLEEP) 1 } | |
181 | ||
182 | make header3.h : header3.in : @copy ; | |
183 | exe test : test2.cpp test1.cpp : <implicit-dependency>header3.h ; | |
184 | """) | |
185 | ||
186 | t.run_build_system(["-j2", "test"]) | |
11fdf7f2 | 187 | t.expect_addition("bin/header3.h") |
b32b8144 FG |
188 | t.expect_addition("bin/$toolset/debug*/test1.obj") |
189 | t.expect_addition("bin/$toolset/debug*/test2.obj") | |
190 | t.expect_addition("bin/$toolset/debug*/test.exe") | |
20effc67 | 191 | t.ignore_addition("bin/*/test.rsp") |
7c673cae FG |
192 | t.expect_nothing_more() |
193 | ||
194 | t.touch("header3.in") | |
195 | t.run_build_system(["-j2", "test"]) | |
11fdf7f2 | 196 | t.expect_touch("bin/header3.h") |
b32b8144 FG |
197 | t.expect_touch("bin/$toolset/debug*/test1.obj") |
198 | t.expect_touch("bin/$toolset/debug*/test2.obj") | |
199 | t.expect_touch("bin/$toolset/debug*/test.exe") | |
20effc67 | 200 | t.ignore_touch("bin/*/test.rsp") |
7c673cae FG |
201 | t.expect_nothing_more() |
202 | ||
203 | t.rm(".") | |
204 | ||
205 | # Test a loop that includes a generated header | |
206 | t.write("test1.cpp", '#include "header1.h"\n') | |
207 | t.write("test2.cpp", """\ | |
208 | #include "header2.h" | |
209 | int main() {} | |
210 | """) | |
211 | ||
212 | t.write("header1.h", """\ | |
213 | #ifndef HEADER1_H | |
214 | #define HEADER1_H | |
215 | #include "header2.h" | |
216 | #endif | |
217 | """) | |
218 | ||
219 | t.write("header2.in", """\ | |
220 | #ifndef HEADER2_H | |
221 | #define HEADER2_H | |
222 | #include "header3.h" | |
223 | #endif | |
224 | """) | |
225 | ||
226 | t.write("header3.h", """\ | |
227 | #ifndef HEADER3_H | |
228 | #define HEADER3_H | |
229 | #include "header1.h" | |
230 | #endif | |
231 | """) | |
232 | ||
233 | t.write("sleep.bat", """\ | |
234 | ::@timeout /T %1 /NOBREAK >nul | |
235 | @ping 127.0.0.1 -n 2 -w 1000 >nul | |
236 | @ping 127.0.0.1 -n %1 -w 1000 >nul | |
237 | @exit /B 0 | |
238 | """) | |
239 | ||
240 | t.write("jamroot.jam", """\ | |
241 | import common ; | |
242 | import os ; | |
243 | ||
244 | if [ os.name ] = NT | |
245 | { | |
246 | SLEEP = call sleep.bat ; | |
247 | } | |
248 | else | |
249 | { | |
250 | SLEEP = sleep ; | |
251 | } | |
252 | ||
253 | rule copy { common.copy $(<) : $(>) ; } | |
254 | actions copy { $(SLEEP) 1 } | |
255 | ||
256 | make header2.h : header2.in : @copy ; | |
257 | exe test : test2.cpp test1.cpp : <implicit-dependency>header2.h <include>. ; | |
258 | """) | |
259 | ||
260 | t.run_build_system(["-j2", "test"]) | |
11fdf7f2 | 261 | t.expect_addition("bin/header2.h") |
b32b8144 FG |
262 | t.expect_addition("bin/$toolset/debug*/test1.obj") |
263 | t.expect_addition("bin/$toolset/debug*/test2.obj") | |
264 | t.expect_addition("bin/$toolset/debug*/test.exe") | |
20effc67 | 265 | t.ignore_addition("bin/*/test.rsp") |
7c673cae FG |
266 | t.expect_nothing_more() |
267 | ||
268 | t.cleanup() |