Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/tools/build/v2/test/searched_lib.py @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1#!/usr/bin/python
2
3# Test usage of searched-libs: one which are found via -l
4# switch to the linker/compiler.
5
6from BoostBuild import Tester, get_toolset
7import string
8import os
9t = Tester()
10
11# To start with, we have to prepate a library to link with
12t.write("lib/project-root.jam", "")
13t.write("lib/Jamfile", "lib test_lib : test_lib.cpp ;")
14t.write("lib/test_lib.cpp", """
15#ifdef _WIN32
16__declspec(dllexport)
17#endif
18void foo() {}
19""");
20
21t.run_build_system(subdir="lib")
22t.expect_addition("lib/bin/$toolset/debug/test_lib.dll")
23
24# Auto adjusting of suffixes does not work, since we need to
25# change dll to lib.
26#
27if (os.name == 'nt' or os.uname()[0].lower().startswith('cygwin')) and get_toolset() != 'gcc':
28    t.copy("lib/bin/$toolset/debug/test_lib.lib", "lib/test_lib.lib")
29else:
30    t.copy("lib/bin/$toolset/debug/test_lib.dll", "lib/test_lib.dll")
31
32
33# Test that the simplest usage of searched library works.
34t.write('project-root.jam', '')
35t.write('Jamfile', """
36
37import path ;
38import project ;
39
40local here = [ project.attribute $(__name__) location ] ;
41here = [ path.root $(here) [ path.pwd ] ] ;
42
43exe main : main.cpp helper ;
44lib helper : helper.cpp test_lib : <dll-path>$(here)/lib ;
45lib test_lib : : <name>test_lib <search>lib ;
46""")
47t.write("main.cpp", """
48void helper();
49int main() { helper(); return 0; }
50""")
51t.write("helper.cpp", """
52void foo();
53
54void
55#if defined(_WIN32)
56__declspec(dllexport)
57#endif
58helper() { foo(); }
59""")
60t.run_build_system(stderr=None) # gcc warns about libraries which are not in -rpath.
61t.expect_addition("bin/$toolset/debug/main.exe")
62t.rm("bin/$toolset/debug/main.exe")
63
64# Now try using searched lib from static lib. Request shared version
65# of searched lib, since we don't have static one handy.
66t.write('Jamfile', """
67exe main : main.cpp helper ;
68lib helper : helper.cpp test_lib/<link>shared : <link>static ;
69lib test_lib : : <name>test_lib <search>lib ;
70""")
71t.run_build_system(stderr=None)
72t.expect_addition("bin/$toolset/debug/main.exe")
73t.expect_addition("bin/$toolset/debug/link-static/helper.lib")
74t.rm("bin/$toolset/debug/main.exe")
75
76# A regression test: <library>property referring to
77# searched-lib was mishandled. As the result, we were
78# putting target name to the command line!
79# Note that
80#    g++ ...... <.>z
81# works nicely in some cases, sending output from compiler
82# to file 'z'.
83# This problem shows up when searched libs are in usage
84# requirements.
85
86t.write('Jamfile', 'exe main : main.cpp d/d2//a ;')
87t.write('main.cpp',"""
88void foo();
89int main() { foo(); return 0; }
90
91""")
92t.write('d/d2/Jamfile', """
93lib test_lib : : <name>test_lib <search>../../lib ;
94lib a : a.cpp : : : <library>test_lib ;
95""")
96t.write('d/d2/a.cpp', """
97#ifdef _WIN32
98__declspec(dllexport) int force_library_creation_for_a;
99#endif
100""")
101
102t.run_build_system()
103
104# A regression test. Searched targets were not associated
105# with any properties. For that reason, if the same searched
106# lib is generated with two different properties, we had an
107# error saying they are actualized to the same Jam target name.
108
109t.write("project-root.jam", "")
110
111t.write("a.cpp", "")
112
113# The 'l' library will be built in two variants:
114# 'debug' (directly requested) and 'release' (requested
115# from 'a').
116t.write("Jamfile", """
117exe a : a.cpp l/<variant>release ;
118
119lib l : : <name>l_d <variant>debug ;
120lib l : : <name>l_r <variant>release ;
121""")
122
123t.run_build_system("-n")
124
125# A regression test. Two virtual target with the same properties
126# were created for 'l' target, which caused and error to be reported
127# when actualizing targets. The final error is correct, but we should
128# not create two duplicated targets. Thanks to Andre Hentz
129# for finding this bug.
130t.write("project-root.jam", "")
131
132t.write("a.cpp", "")
133
134t.write("Jamfile", """
135project a : requirements <runtime-link>static ;
136
137static-lib a : a.cpp l ;
138lib l : : <name>l_f ;
139""")
140
141t.run_build_system("-n")
142
143t.cleanup()
Note: See TracBrowser for help on using the repository browser.