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