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