]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/test/library_chain.py
8ac2115988d11d7cb368d93e464dcd850e6b25cc
[ceph.git] / ceph / src / boost / tools / build / 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 os
12 import string
13 import sys
14
15 t = BoostBuild.Tester(use_test_config=False)
16
17 # Stage the binary, so that it will be relinked without hardcode-dll-paths.
18 # That will check that we pass correct -rpath-link, even if not passing -rpath.
19 t.write("jamfile.jam", """\
20 stage dist : main ;
21 exe main : main.cpp b ;
22 """)
23
24 t.write("main.cpp", """\
25 void foo();
26 int main() { foo(); }
27 """)
28
29 t.write("jamroot.jam", "")
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", "lib a : a.cpp ;")
45
46 t.write("b/b.cpp", """\
47 void geek();
48 void
49 #if defined(_WIN32)
50 __declspec(dllexport)
51 #endif
52 foo() { geek(); }
53 """)
54
55 t.write("b/jamfile.jam", "lib b : b.cpp ../a//a ;")
56
57 t.run_build_system(["-d2"], stderr=None)
58 t.expect_addition("bin/$toolset/debug*/main.exe")
59 t.rm(["bin", "a/bin", "b/bin"])
60
61 t.run_build_system(["link=static"])
62 t.expect_addition("bin/$toolset/debug/link-static*/main.exe")
63 t.rm(["bin", "a/bin", "b/bin"])
64
65
66 # Check that <library> works for static linking.
67 t.write("b/jamfile.jam", "lib b : b.cpp : <library>../a//a ;")
68
69 t.run_build_system(["link=static"])
70 t.expect_addition("bin/$toolset/debug/link-static*/main.exe")
71
72 t.rm(["bin", "a/bin", "b/bin"])
73
74 t.write("b/jamfile.jam", "lib b : b.cpp ../a//a/<link>shared : <link>static ;")
75
76 t.run_build_system()
77 t.expect_addition("bin/$toolset/debug*/main.exe")
78
79 t.rm(["bin", "a/bin", "b/bin"])
80
81
82 # Test that putting a library in sources of a searched library works.
83 t.write("jamfile.jam", """\
84 exe main : main.cpp png ;
85 lib png : z : <name>png ;
86 lib z : : <name>zzz ;
87 """)
88
89 t.run_build_system(["-a", "-d+2"], status=None, stderr=None)
90 # Try to find the "zzz" string either in response file (for Windows compilers),
91 # or in the standard output.
92 rsp = t.adjust_names("bin/$toolset/debug*/main.exe.rsp")[0]
93 if os.path.exists(rsp) and ( open(rsp).read().find("zzz") != -1 ):
94 pass
95 elif t.stdout().find("zzz") != -1:
96 pass
97 else:
98 t.fail_test(1)
99
100 # Test main -> libb -> liba chain in the case where liba is a file and not a
101 # Boost.Build target.
102 t.rm(".")
103
104 t.write("jamroot.jam", "")
105 t.write("a/jamfile.jam", """\
106 lib a : a.cpp ;
107 install dist : a ;
108 """)
109
110 t.write("a/a.cpp", """\
111 #if defined(_WIN32)
112 __declspec(dllexport)
113 #endif
114 void a() {}
115 """)
116
117 t.run_build_system(subdir="a")
118 t.expect_addition("a/dist/a.dll")
119
120 if sys.platform == 'win32':
121 # This is a Windows import library.
122 file = t.adjust_name("a.implib")
123 else:
124 file = t.adjust_name("a.dll")
125
126 t.write("b/jamfile.jam", "lib b : b.cpp ../a/dist/%s ;" % file)
127
128 t.write("b/b.cpp", """\
129 #if defined(_WIN32)
130 __declspec(dllimport)
131 #endif
132 void a();
133 #if defined(_WIN32)
134 __declspec(dllexport)
135 #endif
136 void b() { a(); }
137 """)
138
139 t.write("jamroot.jam", "exe main : main.cpp b//b ;")
140
141 t.write("main.cpp", """\
142 #if defined(_WIN32)
143 __declspec(dllimport)
144 #endif
145 void b();
146 int main() { b(); }
147 """)
148
149 t.run_build_system()
150 t.expect_addition("bin/$toolset/debug*/main.exe")
151
152 t.cleanup()