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 | |
---|
11 | from BoostBuild import Tester, get_toolset |
---|
12 | import string |
---|
13 | import os |
---|
14 | t = Tester() |
---|
15 | |
---|
16 | # To start with, we have to prepate a library to link with |
---|
17 | t.write("lib/project-root.jam", "") |
---|
18 | t.write("lib/Jamfile", "lib test_lib : test_lib.cpp ;") |
---|
19 | t.write("lib/test_lib.cpp", """ |
---|
20 | #ifdef _WIN32 |
---|
21 | __declspec(dllexport) |
---|
22 | #endif |
---|
23 | void foo() {} |
---|
24 | """); |
---|
25 | |
---|
26 | t.run_build_system(subdir="lib") |
---|
27 | t.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 | # |
---|
32 | if (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") |
---|
35 | else: |
---|
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. |
---|
40 | t.write('project-root.jam', '') |
---|
41 | t.write('Jamfile', """ |
---|
42 | |
---|
43 | import path ; |
---|
44 | import project ; |
---|
45 | |
---|
46 | local here = [ project.attribute $(__name__) location ] ; |
---|
47 | here = [ path.root $(here) [ path.pwd ] ] ; |
---|
48 | |
---|
49 | exe main : main.cpp helper ; |
---|
50 | lib helper : helper.cpp test_lib ; |
---|
51 | lib test_lib : : <name>test_lib <search>lib ; |
---|
52 | """) |
---|
53 | t.write("main.cpp", """ |
---|
54 | void helper(); |
---|
55 | int main() { helper(); return 0; } |
---|
56 | """) |
---|
57 | t.write("helper.cpp", """ |
---|
58 | void foo(); |
---|
59 | |
---|
60 | void |
---|
61 | #if defined(_WIN32) |
---|
62 | __declspec(dllexport) |
---|
63 | #endif |
---|
64 | helper() { foo(); } |
---|
65 | """) |
---|
66 | t.run_build_system() |
---|
67 | t.expect_addition("bin/$toolset/debug/main.exe") |
---|
68 | t.rm("bin/$toolset/debug/main.exe") |
---|
69 | |
---|
70 | # Test that 'unit-test' will correctly add runtime paths |
---|
71 | # to searched libraries. |
---|
72 | t.write('Jamfile', """ |
---|
73 | |
---|
74 | import path ; |
---|
75 | import project ; |
---|
76 | import testing ; |
---|
77 | |
---|
78 | project : requirements <hardcode-dll-paths>false ; |
---|
79 | |
---|
80 | local here = [ project.attribute $(__name__) location ] ; |
---|
81 | here = [ path.root $(here) [ path.pwd ] ] ; |
---|
82 | |
---|
83 | unit-test main : main.cpp helper ; |
---|
84 | lib helper : helper.cpp test_lib ; |
---|
85 | lib test_lib : : <name>test_lib <search>lib ; |
---|
86 | """) |
---|
87 | t.run_build_system() |
---|
88 | t.expect_addition("bin/$toolset/debug/main.passed") |
---|
89 | t.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. |
---|
94 | t.write('Jamfile', """ |
---|
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 | t.run_build_system(stderr=None) |
---|
100 | t.expect_addition("bin/$toolset/debug/main.exe") |
---|
101 | t.expect_addition("bin/$toolset/debug/link-static/helper.lib") |
---|
102 | t.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 | |
---|
114 | t.write('Jamfile', 'exe main : main.cpp d/d2//a ;') |
---|
115 | t.write('main.cpp',""" |
---|
116 | void foo(); |
---|
117 | int main() { foo(); return 0; } |
---|
118 | |
---|
119 | """) |
---|
120 | t.write('d/d2/Jamfile', """ |
---|
121 | lib test_lib : : <name>test_lib <search>../../lib ; |
---|
122 | lib a : a.cpp : : : <library>test_lib ; |
---|
123 | """) |
---|
124 | t.write('d/d2/a.cpp', """ |
---|
125 | #ifdef _WIN32 |
---|
126 | __declspec(dllexport) int force_library_creation_for_a; |
---|
127 | #endif |
---|
128 | """) |
---|
129 | |
---|
130 | t.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 | |
---|
137 | t.write("project-root.jam", "") |
---|
138 | |
---|
139 | t.write("a.cpp", "") |
---|
140 | |
---|
141 | # The 'l' library will be built in two variants: |
---|
142 | # 'debug' (directly requested) and 'release' (requested |
---|
143 | # from 'a'). |
---|
144 | t.write("Jamfile", """ |
---|
145 | exe a : a.cpp l/<variant>release ; |
---|
146 | |
---|
147 | lib l : : <name>l_d <variant>debug ; |
---|
148 | lib l : : <name>l_r <variant>release ; |
---|
149 | """) |
---|
150 | |
---|
151 | t.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. |
---|
158 | t.write("project-root.jam", "") |
---|
159 | |
---|
160 | t.write("a.cpp", "") |
---|
161 | |
---|
162 | t.write("Jamfile", """ |
---|
163 | project a : requirements <runtime-link>static ; |
---|
164 | |
---|
165 | static-lib a : a.cpp l ; |
---|
166 | lib l : : <name>l_f ; |
---|
167 | """) |
---|
168 | |
---|
169 | t.run_build_system("-n") |
---|
170 | |
---|
171 | |
---|
172 | # Make sure that plain "lib foobar ; " works. |
---|
173 | t.write("Jamfile", """ |
---|
174 | exe a : a.cpp foobar ; |
---|
175 | lib foobar ; |
---|
176 | """) |
---|
177 | t.run_build_system("-n -d2") |
---|
178 | t.fail_test(string.find(t.stdout(), "foobar") == -1) |
---|
179 | |
---|
180 | # Make sure that plain "lib foo bar ; " works. |
---|
181 | t.write("Jamfile", """ |
---|
182 | exe a : a.cpp foo bar ; |
---|
183 | lib foo bar ; |
---|
184 | """) |
---|
185 | t.run_build_system("-n -d2") |
---|
186 | t.fail_test(string.find(t.stdout(), "foo") == -1) |
---|
187 | t.fail_test(string.find(t.stdout(), "bar") == -1) |
---|
188 | |
---|
189 | t.cleanup() |
---|