Imported Upstream version 1.49.0
[platform/upstream/boost.git] / tools / build / v2 / test / library_chain.py
1 #!/usr/bin/python
2
3 # Copyright 2003, 2004, 2005, 2006 Vladimir Prus
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7 # Test that a chain of libraries works ok, no matter if we use static or shared
8 # linking.
9
10 import BoostBuild
11 import string
12 import os
13
14 t = BoostBuild.Tester()
15
16 t.write("jamfile.jam", """
17 # Stage the binary, so that it will be relinked without hardcode-dll-paths. That
18 # will chech that we pass correct -rpath-link, even if not passing -rpath.
19 stage dist : main ;
20 exe main : main.cpp b ;
21 """)
22
23 t.write("main.cpp", """
24 void foo();
25 int main() { foo(); }
26 """)
27
28 t.write("jamroot.jam", """
29 """)
30
31 t.write("a/a.cpp", """
32 void
33 #if defined(_WIN32)
34 __declspec(dllexport)
35 #endif
36 gee() {}
37 void
38 #if defined(_WIN32)
39 __declspec(dllexport)
40 #endif
41 geek() {}
42 """)
43
44 t.write("a/jamfile.jam", """
45 lib a : a.cpp ;
46 """)
47
48 t.write("b/b.cpp", """
49 void geek();
50 void
51 #if defined(_WIN32)
52 __declspec(dllexport)
53 #endif
54 foo() { geek(); }
55 """)
56
57 t.write("b/jamfile.jam", """
58 lib b : b.cpp ../a//a ;
59 """)
60
61 t.run_build_system("-d2", stderr=None)
62 t.expect_addition("bin/$toolset/debug/main.exe")
63 t.rm(["bin", "a/bin", "b/bin"])
64
65 t.run_build_system("link=static")
66 t.expect_addition("bin/$toolset/debug/link-static/main.exe")
67 t.rm(["bin", "a/bin", "b/bin"])
68
69
70 # Check that <library> works for static linking.
71 t.write("b/jamfile.jam", """
72 lib b : b.cpp : <library>../a//a ;
73 """)
74
75 t.run_build_system("link=static")
76 t.expect_addition("bin/$toolset/debug/link-static/main.exe")
77
78 t.rm(["bin", "a/bin", "b/bin"])
79
80 t.write("b/jamfile.jam", """
81 lib b : b.cpp ../a//a/<link>shared : <link>static ;
82 """)
83
84 t.run_build_system()
85 t.expect_addition("bin/$toolset/debug/main.exe")
86
87 t.rm(["bin", "a/bin", "b/bin"])
88
89
90 # Test that putting a library in sources of a searched library works.
91 t.write("jamfile.jam", """
92 exe main : main.cpp png ;
93 lib png : z : <name>png ;
94 lib z : : <name>zzz ;
95 """)
96
97 t.run_build_system("-a -d+2", status=None, stderr=None)
98 # Try to find the "zzz" string either in response file (for Windows compilers),
99 # or in the standard output.
100 rsp = t.adjust_names("bin/$toolset/debug/main.exe.rsp")[0]
101 if os.path.exists(rsp) and ( string.find(open(rsp).read(), "zzz") != -1 ):
102     pass
103 elif string.find(t.stdout(), "zzz") != -1:
104     pass
105 else:
106     t.fail_test(1)
107
108 # Test main -> libb -> liba chain in the case where liba is a file and not a
109 # Boost.Build target.
110 t.rm(".")
111
112 t.write("jamroot.jam", "")
113
114 t.write("a/jamfile.jam", """
115 lib a : a.cpp ;
116 install dist : a ;
117 """)
118
119 t.write("a/a.cpp", """
120 #if defined(_WIN32)
121 __declspec(dllexport)
122 #endif
123 void a() {}
124 """)
125
126 t.run_build_system(subdir="a")
127 t.expect_addition("a/dist/a.dll")
128
129 if ( ( os.name == 'nt' ) or os.uname()[0].lower().startswith('cygwin') ) and \
130     ( BoostBuild.get_toolset() != 'gcc' ):
131     # This is windows import library -- we know the exact name.
132     file = "a/dist/a.lib"
133 else:
134     file = t.adjust_names(["a/dist/a.dll"])[0]
135
136 t.write("b/jamfile.jam", """
137 lib b : b.cpp ../%s ;
138 """ % file)
139
140 t.write("b/b.cpp", """
141 #if defined(_WIN32)
142 __declspec(dllimport)
143 #endif
144 void a();
145 #if defined(_WIN32)
146 __declspec(dllexport)
147 #endif
148 void b() { a(); }
149 """)
150
151 t.write("jamroot.jam", """
152 exe main : main.cpp b//b ;
153 """)
154
155 t.write("main.cpp", """
156 #if defined(_WIN32)
157 __declspec(dllimport)
158 #endif
159 void b();
160 int main() { b(); }
161 """)
162
163 t.run_build_system()
164 t.expect_addition("bin/$toolset/debug/main.exe")
165
166 t.cleanup()