Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/build/v2/test/use_requirements.py @ 32

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

updated boost from 1_33_1 to 1_34_1

File size: 6.1 KB
Line 
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
8from BoostBuild import Tester
9t = 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)
14t.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.
18t.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
28t.write(
29    "b.cpp",
30"""
31void
32#if defined(_WIN32) && defined(SHARED_B)
33__declspec(dllexport)
34#endif
35foo() {}\n
36""")
37
38t.write(
39    "c.cpp",
40"""
41void
42#if defined(_WIN32) && defined(SHARED_B)
43__declspec(dllexport)
44#endif
45create_lib_please() {}\n
46""")
47
48
49t.write(
50    "a.cpp",
51"""
52#ifdef FOO
53void
54# if defined(_WIN32) && defined(SHARED_B)
55__declspec(dllexport)
56# endif
57foo() {}
58#endif
59
60int main() { foo(); }
61""")
62
63t.run_build_system()
64
65t.run_build_system("--clean")
66
67# Test that use requirements on main target work, when they are referred using
68# 'dependency' features.
69t.write("project-root.jam", "import gcc ;")
70
71t.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
80t.write(
81    "b.cpp",
82"""
83void
84#if defined(_WIN32) && defined(SHARED_B)
85__declspec(dllexport)
86#endif
87foo() {}
88""")
89
90t.write(
91    "a.cpp",
92"""
93#ifdef FOO
94int main() { return 0; }
95#endif
96""")
97
98t.run_build_system()
99
100t.run_build_system("--clean")
101
102
103# Test that use requirement on project work
104t.write("Jamfile", "exe a : a.cpp lib//b ;")
105
106t.write(
107    "lib/Jamfile", 
108"""
109project
110   : requirements <link>shared:<define>SHARED_B
111   : usage-requirements <define>FOO <link>shared:<define>SHARED_B
112    ;
113lib b : b.cpp ;
114""")
115
116t.write(
117    "lib/b.cpp", 
118"""
119void
120#if defined(_WIN32) && defined(SHARED_B)
121__declspec(dllexport)
122#endif
123foo() {}\n
124""")
125
126t.run_build_system()
127
128# Test that use requirements are inherited correctly
129
130t.write("Jamfile", "exe a : a.cpp lib/1//b ;")
131
132t.write(
133    "a.cpp", 
134"""
135#if defined(FOO) && defined(ZOO)
136void foo() {}
137#endif
138
139int main() { foo(); }
140""")
141
142t.write(
143    "lib/Jamfile", 
144"""
145project
146   : requirements
147   : usage-requirements <define>FOO
148    ;
149""")
150
151t.write(
152    "lib/1/Jamfile", 
153"""
154project
155   : requirements <link>shared:<define>SHARED_B
156   : usage-requirements <define>ZOO <link>shared:<define>SHARED_B
157   ;
158lib b : b.cpp ;
159""")
160
161t.write(
162    "lib/1/b.cpp", 
163"""
164void
165#if defined(_WIN32) && defined(SHARED_B)
166__declspec(dllexport)
167#endif
168foo() {}\n
169""")
170
171t.run_build_system()
172t.run_build_system("--clean")
173
174# Test that we correctly handle dependency features
175# in use requirements on target
176
177t.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
194t.write(
195    "a.cpp", 
196"""
197#ifdef FOO
198void
199# if defined(_WIN32) && defined(SHARED_B)
200__declspec(dllexport)
201# endif
202foo();
203#endif
204
205int main() { foo(); }
206""")
207
208t.write(
209    "c.cpp",
210"""
211int
212#if defined(_WIN32) && defined(SHARED_C)
213__declspec(dllexport)
214#endif
215must_export_something;
216""")
217
218t.run_build_system()
219t.run_build_system("--clean")
220
221# Test correct handling of dependency features in
222# project requirements.
223t.write(
224    "Jamfile",
225"""
226    exe a : a.cpp lib1//cc ;
227""")
228
229t.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
240t.write(
241    "lib1/c.cpp", 
242"""
243int
244#if defined(_WIN32) && defined(SHARED_C)
245__declspec(dllexport)
246#endif
247must_export_something;
248""")
249
250t.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
257t.copy("b.cpp", "lib2/b.cpp")
258
259t.run_build_system()
260
261# Test that dependency feature in use requirements are built
262# with the correct properties
263t.rm(".")
264
265t.write(
266    "Jamfile", 
267"""
268lib main : main.cpp : <use>libs//lib1 : : <library>libs//lib1 ;
269exe hello : hello.cpp main : ;
270""")
271
272t.write(
273    "main.cpp", 
274"""
275void
276#if defined(_WIN32) && defined(SHARED_LIB1)
277__declspec(dllimport)
278#endif
279foo();
280
281int main() { foo(); return 0; }
282""")
283
284t.write("hello.cpp", "\n")
285
286t.write(
287    "project-root.jam",
288"""
289import gcc ;
290""")
291
292t.write(
293    "libs/a.cpp", 
294"""
295void
296#if defined(_WIN32) && defined(SHARED_LIB1)
297__declspec(dllexport)
298#endif
299foo() {}
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.
305t.write(
306    "libs/Jamfile", 
307"""
308lib lib1 : a_d.cpp : <variant>debug <link>shared:<define>SHARED_LIB1
309: : <link>shared:<define>SHARED_LIB1 ;
310
311lib lib1 : a.cpp : <variant>release <link>shared:<define>SHARED_LIB1
312: : <link>shared:<define>SHARED_LIB1 ;
313""")
314
315t.write(
316    "libs/a_d.cpp", 
317"""
318void
319#if defined(_WIN32) && defined(SHARED_LIB1)
320__declspec(dllexport)
321#endif
322foo() {}
323""")
324
325t.run_build_system("link=static")
326t.expect_addition("libs/bin/$toolset/debug/link-static/a_d.obj")
327
328
329# Test that indirect conditionals are respected in
330# usage requirements.
331t.rm(".")
332
333t.write("Jamroot", """
334rule has-foo ( properties * )
335{
336    return <define>HAS_FOO ;
337}
338
339exe a : a.cpp b ;
340lib b : b.cpp : <link>static : : <conditional>@has-foo ;
341""")
342t.write("a.cpp", """
343#ifdef HAS_FOO
344void foo();
345int main() { foo(); }
346#endif
347""")
348t.write("b.cpp", """
349void
350#if defined(_WIN32) && defined(SHARED_B)
351__declspec(dllexport)
352#endif
353foo() {}\n
354""")
355t.run_build_system()
356t.expect_addition("bin/$toolset/debug/a.exe")
357
358
359t.cleanup()
Note: See TracBrowser for help on using the repository browser.