Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/tools/build/v2/test/use_requirements.py @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1#!/usr/bin/python
2
3from BoostBuild import Tester
4t = 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)
9t.write("project-root.jam", "import gcc ;")
10
11t.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
21t.write(
22    "b.cpp",
23"""
24void
25#if defined(_WIN32) && defined(SHARED_B)
26__declspec(dllexport)
27#endif
28foo() {}\n
29""")
30
31t.write(
32    "c.cpp",
33"""
34void
35#if defined(_WIN32) && defined(SHARED_B)
36__declspec(dllexport)
37#endif
38create_lib_please() {}\n
39""")
40
41
42t.write(
43    "a.cpp",
44"""
45#ifdef FOO
46void
47# if defined(_WIN32) && defined(SHARED_B)
48__declspec(dllexport)
49# endif
50foo() {}
51#endif
52
53int main() { foo(); }
54""")
55
56t.run_build_system()
57
58t.run_build_system("--clean")
59
60# Test that use requirements on main target work, when they are referred using
61# 'dependency' features.
62t.write("project-root.jam", "import gcc ;")
63
64t.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
73t.write(
74    "b.cpp",
75"""
76void
77#if defined(_WIN32) && defined(SHARED_B)
78__declspec(dllexport)
79#endif
80foo() {}
81""")
82
83t.write(
84    "a.cpp",
85"""
86#ifdef FOO
87int main() { return 0; }
88#endif
89""")
90
91t.run_build_system()
92
93t.run_build_system("--clean")
94
95
96# Test that use requirement on project work
97t.write("Jamfile", "exe a : a.cpp lib//b ;")
98
99t.write(
100    "lib/Jamfile", 
101"""
102project
103   : requirements <link>shared:<define>SHARED_B
104   : usage-requirements <define>FOO <link>shared:<define>SHARED_B
105    ;
106lib b : b.cpp ;
107""")
108
109t.write(
110    "lib/b.cpp", 
111"""
112void
113#if defined(_WIN32) && defined(SHARED_B)
114__declspec(dllexport)
115#endif
116foo() {}\n
117""")
118
119t.run_build_system()
120
121# Test that use requirements are inherited correctly
122
123t.write("Jamfile", "exe a : a.cpp lib/1//b ;")
124
125t.write(
126    "a.cpp", 
127"""
128#if defined(FOO) && defined(ZOO)
129void foo() {}
130#endif
131
132int main() { foo(); }
133""")
134
135t.write(
136    "lib/Jamfile", 
137"""
138project
139   : requirements
140   : usage-requirements <define>FOO
141    ;
142""")
143
144t.write(
145    "lib/1/Jamfile", 
146"""
147project
148   : requirements <link>shared:<define>SHARED_B
149   : usage-requirements <define>ZOO <link>shared:<define>SHARED_B
150   ;
151lib b : b.cpp ;
152""")
153
154t.write(
155    "lib/1/b.cpp", 
156"""
157void
158#if defined(_WIN32) && defined(SHARED_B)
159__declspec(dllexport)
160#endif
161foo() {}\n
162""")
163
164t.run_build_system()
165t.run_build_system("--clean")
166
167# Test that we correctly handle dependency features
168# in use requirements on target
169
170t.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
187t.write(
188    "a.cpp", 
189"""
190#ifdef FOO
191void
192# if defined(_WIN32) && defined(SHARED_B)
193__declspec(dllexport)
194# endif
195foo();
196#endif
197
198int main() { foo(); }
199""")
200
201t.write(
202    "c.cpp",
203"""
204int
205#if defined(_WIN32) && defined(SHARED_C)
206__declspec(dllexport)
207#endif
208must_export_something;
209""")
210
211t.run_build_system()
212t.run_build_system("--clean")
213
214# Test correct handling of dependency features in
215# project requirements.
216t.write(
217    "Jamfile",
218"""
219    exe a : a.cpp lib1//c ;
220""")
221
222t.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
233t.write(
234    "lib1/c.cpp", 
235"""
236int
237#if defined(_WIN32) && defined(SHARED_C)
238__declspec(dllexport)
239#endif
240must_export_something;
241""")
242
243t.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
250t.copy("b.cpp", "lib2/b.cpp")
251
252t.run_build_system()
253
254# Test that dependency feature in use requirements are built
255# with the correct properties
256t.rm(".")
257
258t.write(
259    "Jamfile", 
260"""
261lib main : main.cpp : <use>libs//lib1 : : <library>libs//lib1 ;
262exe hello : hello.cpp main : ;
263""")
264
265t.write(
266    "main.cpp", 
267"""
268void
269#if defined(_WIN32) && defined(SHARED_LIB1)
270__declspec(dllimport)
271#endif
272foo();
273
274int main() { foo(); return 0; }
275""")
276
277t.write("hello.cpp", "\n")
278
279t.write(
280    "project-root.jam",
281"""
282import gcc ;
283""")
284
285t.write(
286    "libs/a.cpp", 
287"""
288void
289#if defined(_WIN32) && defined(SHARED_LIB1)
290__declspec(dllexport)
291#endif
292foo() {}
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.
298t.write(
299    "libs/Jamfile", 
300"""
301lib lib1 : a_d.cpp : <variant>debug <link>shared:<define>SHARED_LIB1
302: : <link>shared:<define>SHARED_LIB1 ;
303
304lib lib1 : a.cpp : <variant>release <link>shared:<define>SHARED_LIB1
305: : <link>shared:<define>SHARED_LIB1 ;
306""")
307
308t.write(
309    "libs/a_d.cpp", 
310"""
311void
312#if defined(_WIN32) && defined(SHARED_LIB1)
313__declspec(dllexport)
314#endif
315foo() {}
316""")
317
318t.run_build_system("link=static")
319t.expect_addition("libs/bin/$toolset/debug/link-static/a_d.obj")
320
321t.cleanup()
Note: See TracBrowser for help on using the repository browser.