summaryrefslogtreecommitdiffstats
path: root/src/boost/tools/build/test/searched_lib.py
blob: 67fef4630ef8b6dcd87fb8c4f4ccb02eb844dcf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/python

# Copyright 2003 Dave Abrahams
# Copyright 2003, 2004, 2005, 2006 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)

# Test usage of searched-libs: one which are found via -l
# switch to the linker/compiler.

import BoostBuild
import os
import string

t = BoostBuild.Tester(use_test_config=False)


# To start with, we have to prepare a library to link with.
t.write("lib/jamroot.jam", "")
t.write("lib/jamfile.jam", "lib test_lib : test_lib.cpp ;")
t.write("lib/test_lib.cpp", """\
#ifdef _WIN32
__declspec(dllexport)
#endif
void foo() {}
""");

t.run_build_system(subdir="lib")
t.expect_addition("lib/bin/$toolset/debug*/test_lib.dll")


# Auto adjusting of suffixes does not work, since we need to
# change dll to lib.
if ( ( os.name == "nt" ) or os.uname()[0].lower().startswith("cygwin") ) and \
    ( BoostBuild.get_toolset() != "gcc" ):
    t.copy("lib/bin/$toolset/debug*/test_lib.implib", "lib/test_lib.implib")
    t.copy("lib/bin/$toolset/debug*/test_lib.dll", "lib/test_lib.dll")
else:
    t.copy("lib/bin/$toolset/debug*/test_lib.dll", "lib/test_lib.dll")


# Test that the simplest usage of searched library works.
t.write("jamroot.jam", "")

t.write("jamfile.jam", """\
import path ;
import project ;
exe main : main.cpp helper ;
lib helper : helper.cpp test_lib ;
lib test_lib : : <name>test_lib <search>lib ;
""")

t.write("main.cpp", """\
void helper();
int main() { helper(); }
""")

t.write("helper.cpp", """\
void foo();
void
#if defined(_WIN32)
__declspec(dllexport)
#endif
helper() { foo(); }
""")

t.run_build_system(["-d2"])
t.expect_addition("bin/$toolset/debug*/main.exe")
t.rm("bin/$toolset/debug/main.exe")
t.rm("bin/$toolset/debug/*/main.exe")


# Test that 'unit-test' will correctly add runtime paths to searched libraries.
t.write("jamfile.jam", """\
import path ;
import project ;
import testing ;

project : requirements <hardcode-dll-paths>false ;

unit-test main : main.cpp helper ;
lib helper : helper.cpp test_lib ;
lib test_lib : : <name>test_lib <search>lib ;
""")

t.run_build_system()
t.expect_addition("bin/$toolset/debug*/main.passed")
t.rm("bin/$toolset/debug/main.exe")
t.rm("bin/$toolset/debug/*/main.exe")


# Now try using searched lib from static lib. Request shared version of searched
# lib, since we do not have a static one handy.
t.write("jamfile.jam", """\
exe main : main.cpp helper ;
lib helper : helper.cpp test_lib/<link>shared : <link>static ;
lib test_lib : : <name>test_lib <search>lib ;
""")

t.run_build_system(stderr=None)
t.expect_addition("bin/$toolset/debug*/main.exe")
t.expect_addition("bin/$toolset/debug/link-static*/helper.lib")
t.rm("bin/$toolset/debug/main.exe")
t.rm("bin/$toolset/debug/*/main.exe")

# A regression test: <library>property referring to searched-lib was being
# mishandled. As the result, we were putting target name to the command line!
# Note that
#    g++ ...... <.>z
# works nicely in some cases, sending output from compiler to file 'z'. This
# problem shows up when searched libs are in usage requirements.
t.write("jamfile.jam", "exe main : main.cpp d/d2//a ;")
t.write("main.cpp", """\
void foo();
int main() { foo(); }
""")

t.write("d/d2/jamfile.jam", """\
lib test_lib : : <name>test_lib <search>../../lib ;
lib a : a.cpp : : : <library>test_lib ;
""")

t.write("d/d2/a.cpp", """\
#ifdef _WIN32
__declspec(dllexport) int force_library_creation_for_a;
#endif
""")

t.run_build_system()


# A regression test. Searched targets were not associated with any properties.
# For that reason, if the same searched lib is generated with two different
# properties, we had an error saying they are actualized to the same Jam target
# name.
t.write("jamroot.jam", "")

t.write("a.cpp", "")

# The 'l' library will be built in two variants: 'debug' (directly requested)
# and 'release' (requested from 'a').
t.write("jamfile.jam", """\
exe a : a.cpp l/<variant>release ;
lib l : : <name>l_d <variant>debug ;
lib l : : <name>l_r <variant>release ;
""")

t.run_build_system(["-n"])


# A regression test. Two virtual target with the same properties were created
# for 'l' target, which caused and error to be reported when actualizing
# targets. The final error is correct, but we should not create two duplicated
# targets. Thanks to Andre Hentz for finding this bug.
t.write("jamroot.jam", "")
t.write("a.cpp", "")
t.write("jamfile.jam", """\
project a : requirements <runtime-link>static ;
static-lib a : a.cpp l ;
lib l : : <name>l_f ;
""")

t.run_build_system(["-n"])


# A regression test. Virtual targets distinguished by their search paths were
# not differentiated when registered, which caused search paths to be selected
# incorrectly for build requests with multiple feature values.
t.write("jamroot.jam", "")
t.write("a.cpp", "")
t.write("jamfile.jam", """\
exe a : a.cpp l ;
lib l : : <name>l <search>lib32 <address-model>32 ;
lib l : : <name>l <search>lib64 <address-model>64 ;
""")

t.run_build_system(["-n","address-model=32,64"])
t.fail_test(t.stdout().find("lib32") == -1)
t.fail_test(t.stdout().find("lib64") == -1)


# Make sure plain "lib foobar ; " works.
t.write("jamfile.jam", """\
exe a : a.cpp foobar ;
lib foobar ;
""")

t.run_build_system(["-n", "-d2"])
t.fail_test(t.stdout().find("foobar") == -1)


# Make sure plain "lib foo bar ; " works.
t.write("jamfile.jam", """\
exe a : a.cpp foo bar ;
lib foo bar ;
""")

t.run_build_system(["-n", "-d2"])
t.fail_test(t.stdout().find("foo") == -1)
t.fail_test(t.stdout().find("bar") == -1)

t.cleanup()