]>
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. | |
5 | # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | |
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") | |
7c673cae FG |
191 | t.expect_nothing_more() |
192 | ||
193 | t.touch("header3.in") | |
194 | t.run_build_system(["-j2", "test"]) | |
11fdf7f2 | 195 | t.expect_touch("bin/header3.h") |
b32b8144 FG |
196 | t.expect_touch("bin/$toolset/debug*/test1.obj") |
197 | t.expect_touch("bin/$toolset/debug*/test2.obj") | |
198 | t.expect_touch("bin/$toolset/debug*/test.exe") | |
7c673cae FG |
199 | t.expect_nothing_more() |
200 | ||
201 | t.rm(".") | |
202 | ||
203 | # Test a loop that includes a generated header | |
204 | t.write("test1.cpp", '#include "header1.h"\n') | |
205 | t.write("test2.cpp", """\ | |
206 | #include "header2.h" | |
207 | int main() {} | |
208 | """) | |
209 | ||
210 | t.write("header1.h", """\ | |
211 | #ifndef HEADER1_H | |
212 | #define HEADER1_H | |
213 | #include "header2.h" | |
214 | #endif | |
215 | """) | |
216 | ||
217 | t.write("header2.in", """\ | |
218 | #ifndef HEADER2_H | |
219 | #define HEADER2_H | |
220 | #include "header3.h" | |
221 | #endif | |
222 | """) | |
223 | ||
224 | t.write("header3.h", """\ | |
225 | #ifndef HEADER3_H | |
226 | #define HEADER3_H | |
227 | #include "header1.h" | |
228 | #endif | |
229 | """) | |
230 | ||
231 | t.write("sleep.bat", """\ | |
232 | ::@timeout /T %1 /NOBREAK >nul | |
233 | @ping 127.0.0.1 -n 2 -w 1000 >nul | |
234 | @ping 127.0.0.1 -n %1 -w 1000 >nul | |
235 | @exit /B 0 | |
236 | """) | |
237 | ||
238 | t.write("jamroot.jam", """\ | |
239 | import common ; | |
240 | import os ; | |
241 | ||
242 | if [ os.name ] = NT | |
243 | { | |
244 | SLEEP = call sleep.bat ; | |
245 | } | |
246 | else | |
247 | { | |
248 | SLEEP = sleep ; | |
249 | } | |
250 | ||
251 | rule copy { common.copy $(<) : $(>) ; } | |
252 | actions copy { $(SLEEP) 1 } | |
253 | ||
254 | make header2.h : header2.in : @copy ; | |
255 | exe test : test2.cpp test1.cpp : <implicit-dependency>header2.h <include>. ; | |
256 | """) | |
257 | ||
258 | t.run_build_system(["-j2", "test"]) | |
11fdf7f2 | 259 | t.expect_addition("bin/header2.h") |
b32b8144 FG |
260 | t.expect_addition("bin/$toolset/debug*/test1.obj") |
261 | t.expect_addition("bin/$toolset/debug*/test2.obj") | |
262 | t.expect_addition("bin/$toolset/debug*/test.exe") | |
7c673cae FG |
263 | t.expect_nothing_more() |
264 | ||
265 | t.cleanup() |