Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/build/v2/test/searched_lib.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: 5.0 KB
Line 
1#!/usr/bin/python
2
3# Copyright 2003 Dave Abrahams
4# Copyright 2003, 2004, 2005, 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# Test usage of searched-libs: one which are found via -l
9# switch to the linker/compiler.
10
11from BoostBuild import Tester, get_toolset
12import string
13import os
14t = Tester()
15
16# To start with, we have to prepate a library to link with
17t.write("lib/project-root.jam", "")
18t.write("lib/Jamfile", "lib test_lib : test_lib.cpp ;")
19t.write("lib/test_lib.cpp", """
20#ifdef _WIN32
21__declspec(dllexport)
22#endif
23void foo() {}
24""");
25
26t.run_build_system(subdir="lib")
27t.expect_addition("lib/bin/$toolset/debug/test_lib.dll")
28
29# Auto adjusting of suffixes does not work, since we need to
30# change dll to lib.
31#
32if (os.name == 'nt' or os.uname()[0].lower().startswith('cygwin')) and get_toolset() != 'gcc':
33    t.copy("lib/bin/$toolset/debug/test_lib.lib", "lib/test_lib.lib")
34    t.copy("lib/bin/$toolset/debug/test_lib.dll", "lib/test_lib.dll")
35else:
36    t.copy("lib/bin/$toolset/debug/test_lib.dll", "lib/test_lib.dll")
37
38
39# Test that the simplest usage of searched library works.
40t.write('project-root.jam', '')
41t.write('Jamfile', """
42
43import path ;
44import project ;
45
46local here = [ project.attribute $(__name__) location ] ;
47here = [ path.root $(here) [ path.pwd ] ] ;
48
49exe main : main.cpp helper ;
50lib helper : helper.cpp test_lib ;
51lib test_lib : : <name>test_lib <search>lib ;
52""")
53t.write("main.cpp", """
54void helper();
55int main() { helper(); return 0; }
56""")
57t.write("helper.cpp", """
58void foo();
59
60void
61#if defined(_WIN32)
62__declspec(dllexport)
63#endif
64helper() { foo(); }
65""")
66t.run_build_system()
67t.expect_addition("bin/$toolset/debug/main.exe")
68t.rm("bin/$toolset/debug/main.exe")
69
70# Test that 'unit-test' will correctly add runtime paths
71# to searched libraries.
72t.write('Jamfile', """
73
74import path ;
75import project ;
76import testing ;
77
78project : requirements <hardcode-dll-paths>false ;
79
80local here = [ project.attribute $(__name__) location ] ;
81here = [ path.root $(here) [ path.pwd ] ] ;
82
83unit-test main : main.cpp helper ;
84lib helper : helper.cpp test_lib ;
85lib test_lib : : <name>test_lib <search>lib ;
86""")
87t.run_build_system()
88t.expect_addition("bin/$toolset/debug/main.passed")
89t.rm("bin/$toolset/debug/main.exe")
90
91
92# Now try using searched lib from static lib. Request shared version
93# of searched lib, since we don't have static one handy.
94t.write('Jamfile', """
95exe main : main.cpp helper ;
96lib helper : helper.cpp test_lib/<link>shared : <link>static ;
97lib test_lib : : <name>test_lib <search>lib ;
98""")
99t.run_build_system(stderr=None)
100t.expect_addition("bin/$toolset/debug/main.exe")
101t.expect_addition("bin/$toolset/debug/link-static/helper.lib")
102t.rm("bin/$toolset/debug/main.exe")
103
104# A regression test: <library>property referring to
105# searched-lib was mishandled. As the result, we were
106# putting target name to the command line!
107# Note that
108#    g++ ...... <.>z
109# works nicely in some cases, sending output from compiler
110# to file 'z'.
111# This problem shows up when searched libs are in usage
112# requirements.
113
114t.write('Jamfile', 'exe main : main.cpp d/d2//a ;')
115t.write('main.cpp',"""
116void foo();
117int main() { foo(); return 0; }
118
119""")
120t.write('d/d2/Jamfile', """
121lib test_lib : : <name>test_lib <search>../../lib ;
122lib a : a.cpp : : : <library>test_lib ;
123""")
124t.write('d/d2/a.cpp', """
125#ifdef _WIN32
126__declspec(dllexport) int force_library_creation_for_a;
127#endif
128""")
129
130t.run_build_system()
131
132# A regression test. Searched targets were not associated
133# with any properties. For that reason, if the same searched
134# lib is generated with two different properties, we had an
135# error saying they are actualized to the same Jam target name.
136
137t.write("project-root.jam", "")
138
139t.write("a.cpp", "")
140
141# The 'l' library will be built in two variants:
142# 'debug' (directly requested) and 'release' (requested
143# from 'a').
144t.write("Jamfile", """
145exe a : a.cpp l/<variant>release ;
146
147lib l : : <name>l_d <variant>debug ;
148lib l : : <name>l_r <variant>release ;
149""")
150
151t.run_build_system("-n")
152
153# A regression test. Two virtual target with the same properties
154# were created for 'l' target, which caused and error to be reported
155# when actualizing targets. The final error is correct, but we should
156# not create two duplicated targets. Thanks to Andre Hentz
157# for finding this bug.
158t.write("project-root.jam", "")
159
160t.write("a.cpp", "")
161
162t.write("Jamfile", """
163project a : requirements <runtime-link>static ;
164
165static-lib a : a.cpp l ;
166lib l : : <name>l_f ;
167""")
168
169t.run_build_system("-n")
170
171
172# Make sure that plain "lib foobar ; " works.
173t.write("Jamfile", """
174exe a : a.cpp foobar ;
175lib foobar ;
176""")
177t.run_build_system("-n -d2")
178t.fail_test(string.find(t.stdout(), "foobar") == -1)
179
180# Make sure that plain "lib foo bar ; " works.
181t.write("Jamfile", """
182exe a : a.cpp foo bar ;
183lib foo bar ;
184""")
185t.run_build_system("-n -d2")
186t.fail_test(string.find(t.stdout(), "foo") == -1)
187t.fail_test(string.find(t.stdout(), "bar") == -1)
188
189t.cleanup()
Note: See TracBrowser for help on using the repository browser.