1 | #!/usr/bin/python |
---|
2 | |
---|
3 | # Copyright 2003 Dave Abrahams |
---|
4 | # Copyright 2002, 2003, 2004, 2006 Vladimir Prus |
---|
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 | from BoostBuild import Tester |
---|
9 | t = Tester() |
---|
10 | |
---|
11 | # Test that use requirements on main target work |
---|
12 | # (and a propagated all the way up, not only to direct |
---|
13 | # dependents) |
---|
14 | t.write("project-root.jam", "import gcc ;") |
---|
15 | |
---|
16 | # Note: 'lib cc ..', not 'lib c', If using 'lib c: ...' the HP-CXX |
---|
17 | # linker will confuse it with the system C runtime. |
---|
18 | t.write( |
---|
19 | "Jamfile", |
---|
20 | """ |
---|
21 | lib b : b.cpp : <link>shared:<define>SHARED_B |
---|
22 | : : <define>FOO <link>shared:<define>SHARED_B |
---|
23 | ; |
---|
24 | lib cc : c.cpp b ; |
---|
25 | exe a : a.cpp cc ; |
---|
26 | """) |
---|
27 | |
---|
28 | t.write( |
---|
29 | "b.cpp", |
---|
30 | """ |
---|
31 | void |
---|
32 | #if defined(_WIN32) && defined(SHARED_B) |
---|
33 | __declspec(dllexport) |
---|
34 | #endif |
---|
35 | foo() {}\n |
---|
36 | """) |
---|
37 | |
---|
38 | t.write( |
---|
39 | "c.cpp", |
---|
40 | """ |
---|
41 | void |
---|
42 | #if defined(_WIN32) && defined(SHARED_B) |
---|
43 | __declspec(dllexport) |
---|
44 | #endif |
---|
45 | create_lib_please() {}\n |
---|
46 | """) |
---|
47 | |
---|
48 | |
---|
49 | t.write( |
---|
50 | "a.cpp", |
---|
51 | """ |
---|
52 | #ifdef FOO |
---|
53 | void |
---|
54 | # if defined(_WIN32) && defined(SHARED_B) |
---|
55 | __declspec(dllexport) |
---|
56 | # endif |
---|
57 | foo() {} |
---|
58 | #endif |
---|
59 | |
---|
60 | int main() { foo(); } |
---|
61 | """) |
---|
62 | |
---|
63 | t.run_build_system() |
---|
64 | |
---|
65 | t.run_build_system("--clean") |
---|
66 | |
---|
67 | # Test that use requirements on main target work, when they are referred using |
---|
68 | # 'dependency' features. |
---|
69 | t.write("project-root.jam", "import gcc ;") |
---|
70 | |
---|
71 | t.write( |
---|
72 | "Jamfile", |
---|
73 | """ |
---|
74 | lib b : b.cpp : <link>shared:<define>SHARED_B |
---|
75 | : : <define>FOO <link>shared:<define>SHARED_B |
---|
76 | ; |
---|
77 | exe a : a.cpp : <use>b ; |
---|
78 | """) |
---|
79 | |
---|
80 | t.write( |
---|
81 | "b.cpp", |
---|
82 | """ |
---|
83 | void |
---|
84 | #if defined(_WIN32) && defined(SHARED_B) |
---|
85 | __declspec(dllexport) |
---|
86 | #endif |
---|
87 | foo() {} |
---|
88 | """) |
---|
89 | |
---|
90 | t.write( |
---|
91 | "a.cpp", |
---|
92 | """ |
---|
93 | #ifdef FOO |
---|
94 | int main() { return 0; } |
---|
95 | #endif |
---|
96 | """) |
---|
97 | |
---|
98 | t.run_build_system() |
---|
99 | |
---|
100 | t.run_build_system("--clean") |
---|
101 | |
---|
102 | |
---|
103 | # Test that use requirement on project work |
---|
104 | t.write("Jamfile", "exe a : a.cpp lib//b ;") |
---|
105 | |
---|
106 | t.write( |
---|
107 | "lib/Jamfile", |
---|
108 | """ |
---|
109 | project |
---|
110 | : requirements <link>shared:<define>SHARED_B |
---|
111 | : usage-requirements <define>FOO <link>shared:<define>SHARED_B |
---|
112 | ; |
---|
113 | lib b : b.cpp ; |
---|
114 | """) |
---|
115 | |
---|
116 | t.write( |
---|
117 | "lib/b.cpp", |
---|
118 | """ |
---|
119 | void |
---|
120 | #if defined(_WIN32) && defined(SHARED_B) |
---|
121 | __declspec(dllexport) |
---|
122 | #endif |
---|
123 | foo() {}\n |
---|
124 | """) |
---|
125 | |
---|
126 | t.run_build_system() |
---|
127 | |
---|
128 | # Test that use requirements are inherited correctly |
---|
129 | |
---|
130 | t.write("Jamfile", "exe a : a.cpp lib/1//b ;") |
---|
131 | |
---|
132 | t.write( |
---|
133 | "a.cpp", |
---|
134 | """ |
---|
135 | #if defined(FOO) && defined(ZOO) |
---|
136 | void foo() {} |
---|
137 | #endif |
---|
138 | |
---|
139 | int main() { foo(); } |
---|
140 | """) |
---|
141 | |
---|
142 | t.write( |
---|
143 | "lib/Jamfile", |
---|
144 | """ |
---|
145 | project |
---|
146 | : requirements |
---|
147 | : usage-requirements <define>FOO |
---|
148 | ; |
---|
149 | """) |
---|
150 | |
---|
151 | t.write( |
---|
152 | "lib/1/Jamfile", |
---|
153 | """ |
---|
154 | project |
---|
155 | : requirements <link>shared:<define>SHARED_B |
---|
156 | : usage-requirements <define>ZOO <link>shared:<define>SHARED_B |
---|
157 | ; |
---|
158 | lib b : b.cpp ; |
---|
159 | """) |
---|
160 | |
---|
161 | t.write( |
---|
162 | "lib/1/b.cpp", |
---|
163 | """ |
---|
164 | void |
---|
165 | #if defined(_WIN32) && defined(SHARED_B) |
---|
166 | __declspec(dllexport) |
---|
167 | #endif |
---|
168 | foo() {}\n |
---|
169 | """) |
---|
170 | |
---|
171 | t.run_build_system() |
---|
172 | t.run_build_system("--clean") |
---|
173 | |
---|
174 | # Test that we correctly handle dependency features |
---|
175 | # in use requirements on target |
---|
176 | |
---|
177 | t.write( |
---|
178 | "Jamfile", |
---|
179 | """ |
---|
180 | lib b : b.cpp : <link>shared:<define>SHARED_B |
---|
181 | : : <define>FOO <link>shared:<define>SHARED_B |
---|
182 | ; |
---|
183 | |
---|
184 | # Here's the test: we should correctly |
---|
185 | # handle dependency feature and get |
---|
186 | # use requirements from 'b'. |
---|
187 | lib cc : c.cpp : <link>shared:<define>SHARED_C : : <library>b ; |
---|
188 | |
---|
189 | # This will build only if <define>FOO |
---|
190 | # was propagated from 'c'. |
---|
191 | exe a : a.cpp cc ; |
---|
192 | """) |
---|
193 | |
---|
194 | t.write( |
---|
195 | "a.cpp", |
---|
196 | """ |
---|
197 | #ifdef FOO |
---|
198 | void |
---|
199 | # if defined(_WIN32) && defined(SHARED_B) |
---|
200 | __declspec(dllexport) |
---|
201 | # endif |
---|
202 | foo(); |
---|
203 | #endif |
---|
204 | |
---|
205 | int main() { foo(); } |
---|
206 | """) |
---|
207 | |
---|
208 | t.write( |
---|
209 | "c.cpp", |
---|
210 | """ |
---|
211 | int |
---|
212 | #if defined(_WIN32) && defined(SHARED_C) |
---|
213 | __declspec(dllexport) |
---|
214 | #endif |
---|
215 | must_export_something; |
---|
216 | """) |
---|
217 | |
---|
218 | t.run_build_system() |
---|
219 | t.run_build_system("--clean") |
---|
220 | |
---|
221 | # Test correct handling of dependency features in |
---|
222 | # project requirements. |
---|
223 | t.write( |
---|
224 | "Jamfile", |
---|
225 | """ |
---|
226 | exe a : a.cpp lib1//cc ; |
---|
227 | """) |
---|
228 | |
---|
229 | t.write( |
---|
230 | "lib1/Jamfile", |
---|
231 | """ |
---|
232 | project |
---|
233 | : requirements <link>shared:<define>SHARED_C |
---|
234 | : usage-requirements <library>../lib2//b <link>shared:<define>SHARED_C |
---|
235 | ; |
---|
236 | |
---|
237 | lib cc : c.cpp ; |
---|
238 | """) |
---|
239 | |
---|
240 | t.write( |
---|
241 | "lib1/c.cpp", |
---|
242 | """ |
---|
243 | int |
---|
244 | #if defined(_WIN32) && defined(SHARED_C) |
---|
245 | __declspec(dllexport) |
---|
246 | #endif |
---|
247 | must_export_something; |
---|
248 | """) |
---|
249 | |
---|
250 | t.write( |
---|
251 | "lib2/Jamfile", |
---|
252 | """ |
---|
253 | lib b : b.cpp : <link>shared:<define>SHARED_B |
---|
254 | : : <define>FOO <link>shared:<define>SHARED_B ; |
---|
255 | """) |
---|
256 | |
---|
257 | t.copy("b.cpp", "lib2/b.cpp") |
---|
258 | |
---|
259 | t.run_build_system() |
---|
260 | |
---|
261 | # Test that dependency feature in use requirements are built |
---|
262 | # with the correct properties |
---|
263 | t.rm(".") |
---|
264 | |
---|
265 | t.write( |
---|
266 | "Jamfile", |
---|
267 | """ |
---|
268 | lib main : main.cpp : <use>libs//lib1 : : <library>libs//lib1 ; |
---|
269 | exe hello : hello.cpp main : ; |
---|
270 | """) |
---|
271 | |
---|
272 | t.write( |
---|
273 | "main.cpp", |
---|
274 | """ |
---|
275 | void |
---|
276 | #if defined(_WIN32) && defined(SHARED_LIB1) |
---|
277 | __declspec(dllimport) |
---|
278 | #endif |
---|
279 | foo(); |
---|
280 | |
---|
281 | int main() { foo(); return 0; } |
---|
282 | """) |
---|
283 | |
---|
284 | t.write("hello.cpp", "\n") |
---|
285 | |
---|
286 | t.write( |
---|
287 | "project-root.jam", |
---|
288 | """ |
---|
289 | import gcc ; |
---|
290 | """) |
---|
291 | |
---|
292 | t.write( |
---|
293 | "libs/a.cpp", |
---|
294 | """ |
---|
295 | void |
---|
296 | #if defined(_WIN32) && defined(SHARED_LIB1) |
---|
297 | __declspec(dllexport) |
---|
298 | #endif |
---|
299 | foo() {} |
---|
300 | """) |
---|
301 | |
---|
302 | # This library should be build with the same properties as |
---|
303 | # 'main'. There were a bug when they were generated with |
---|
304 | # empty properties, and there were ambiguity between variants. |
---|
305 | t.write( |
---|
306 | "libs/Jamfile", |
---|
307 | """ |
---|
308 | lib lib1 : a_d.cpp : <variant>debug <link>shared:<define>SHARED_LIB1 |
---|
309 | : : <link>shared:<define>SHARED_LIB1 ; |
---|
310 | |
---|
311 | lib lib1 : a.cpp : <variant>release <link>shared:<define>SHARED_LIB1 |
---|
312 | : : <link>shared:<define>SHARED_LIB1 ; |
---|
313 | """) |
---|
314 | |
---|
315 | t.write( |
---|
316 | "libs/a_d.cpp", |
---|
317 | """ |
---|
318 | void |
---|
319 | #if defined(_WIN32) && defined(SHARED_LIB1) |
---|
320 | __declspec(dllexport) |
---|
321 | #endif |
---|
322 | foo() {} |
---|
323 | """) |
---|
324 | |
---|
325 | t.run_build_system("link=static") |
---|
326 | t.expect_addition("libs/bin/$toolset/debug/link-static/a_d.obj") |
---|
327 | |
---|
328 | |
---|
329 | # Test that indirect conditionals are respected in |
---|
330 | # usage requirements. |
---|
331 | t.rm(".") |
---|
332 | |
---|
333 | t.write("Jamroot", """ |
---|
334 | rule has-foo ( properties * ) |
---|
335 | { |
---|
336 | return <define>HAS_FOO ; |
---|
337 | } |
---|
338 | |
---|
339 | exe a : a.cpp b ; |
---|
340 | lib b : b.cpp : <link>static : : <conditional>@has-foo ; |
---|
341 | """) |
---|
342 | t.write("a.cpp", """ |
---|
343 | #ifdef HAS_FOO |
---|
344 | void foo(); |
---|
345 | int main() { foo(); } |
---|
346 | #endif |
---|
347 | """) |
---|
348 | t.write("b.cpp", """ |
---|
349 | void |
---|
350 | #if defined(_WIN32) && defined(SHARED_B) |
---|
351 | __declspec(dllexport) |
---|
352 | #endif |
---|
353 | foo() {}\n |
---|
354 | """) |
---|
355 | t.run_build_system() |
---|
356 | t.expect_addition("bin/$toolset/debug/a.exe") |
---|
357 | |
---|
358 | |
---|
359 | t.cleanup() |
---|