Imported Upstream version 1.57.0
[platform/upstream/boost.git] / tools / build / test / stage.py
1 #!/usr/bin/python
2
3 # Copyright 2003 Dave Abrahams
4 # Copyright 2002, 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 staging.
9
10 import BoostBuild
11
12 t = BoostBuild.Tester(use_test_config=False)
13
14 t.write("jamroot.jam", "")
15 t.write("jamfile.jam", """\
16 lib a : a.cpp ;
17 stage dist : a a.h auxilliary/1 ;
18 """)
19 t.write("a.cpp", """\
20 int
21 #ifdef _WIN32
22 __declspec(dllexport)
23 #endif
24 must_export_something;
25 """)
26 t.write("a.h", "")
27 t.write("auxilliary/1", "")
28
29 t.run_build_system()
30 t.expect_addition(["dist/a.dll", "dist/a.h", "dist/1"])
31
32
33 # Regression test: the following was causing a "duplicate target name" error.
34 t.write("jamfile.jam", """\
35 project : requirements <hardcode-dll-paths>true ;
36 lib a : a.cpp ;
37 stage dist : a a.h auxilliary/1 ;
38 alias dist-alias : dist ;
39 """)
40
41 t.run_build_system()
42
43
44 # Test the <location> property.
45 t.write("jamfile.jam", """\
46 lib a : a.cpp ;
47 stage dist : a : <variant>debug:<location>ds <variant>release:<location>rs ;
48 """)
49
50 t.run_build_system()
51 t.expect_addition("ds/a.dll")
52
53 t.run_build_system(["release"])
54 t.expect_addition("rs/a.dll")
55
56
57 # Test the <location> property in subprojects. Thanks to Kirill Lapshin for the
58 # bug report.
59
60 t.write("jamroot.jam", "path-constant DIST : dist ;")
61 t.write("jamfile.jam", "build-project d ;")
62 t.write("d/jamfile.jam", """\
63 exe a : a.cpp ;
64 stage dist : a : <location>$(DIST) ;
65 """)
66 t.write("d/a.cpp", "int main() {}\n")
67
68 t.run_build_system()
69 t.expect_addition("dist/a.exe")
70
71 t.rm("dist")
72
73 # Workaround a BIG BUG: the response file is not deleted, even if application
74 # *is* deleted. We will try to use the same response file when building from
75 # subdir, with very bad results.
76 t.rm("d/bin")
77 t.run_build_system(subdir="d")
78 t.expect_addition("dist/a.exe")
79
80
81 # Check that 'stage' does not incorrectly reset target suffixes.
82 t.write("a.cpp", "int main() {}\n")
83 t.write("jamroot.jam", """\
84 import type ;
85 type.register MYEXE : : EXE ;
86 type.set-generated-target-suffix MYEXE : <optimization>off : myexe ;
87 """)
88
89 # Since <optimization>off is in properties when 'a' is built and staged, its
90 # suffix should be "myexe".
91 t.write("jamfile.jam", """\
92 stage dist : a ;
93 myexe a : a.cpp ;
94 """)
95
96 t.run_build_system()
97 t.expect_addition("dist/a.myexe")
98
99 # Test 'stage's ability to traverse dependencies.
100 t.write("a.cpp", "int main() {}\n")
101 t.write("l.cpp", """\
102 void
103 #if defined(_WIN32)
104 __declspec(dllexport)
105 #endif
106 foo() {}
107 """)
108 t.write("jamfile.jam", """\
109 lib l : l.cpp ;
110 exe a : a.cpp l ;
111 stage dist : a : <install-dependencies>on <install-type>EXE <install-type>LIB ;
112 """)
113 t.write("jamroot.jam", "")
114 t.rm("dist")
115
116 t.run_build_system()
117 t.expect_addition("dist/a.exe")
118 t.expect_addition("dist/l.dll")
119
120 # Check that <use> properties are ignored the traversing target for staging.
121 t.copy("l.cpp", "l2.cpp")
122 t.copy("l.cpp", "l3.cpp")
123 t.write("jamfile.jam", """\
124 lib l2 : l2.cpp ;
125 lib l3 : l3.cpp ;
126 lib l : l.cpp : <use>l2 <dependency>l3 ;
127 exe a : a.cpp l ;
128 stage dist : a : <install-dependencies>on <install-type>EXE <install-type>LIB ;
129 """)
130 t.rm("dist")
131
132 t.run_build_system()
133 t.expect_addition("dist/l3.dll")
134 t.expect_nothing("dist/l2.dll")
135
136 # Check if <dependency> on 'stage' works.
137 t.rm(".")
138 t.write("jamroot.jam", """\
139 stage a1 : a1.txt : <location>dist ;
140 stage a2 : a2.txt : <location>dist <dependency>a1 ;
141 """)
142 t.write("a1.txt", "")
143 t.write("a2.txt", "")
144 t.run_build_system(["a2"])
145 t.expect_addition(["dist/a1.txt", "dist/a2.txt"])
146
147 # Regression test: check that <location>. works.
148 t.rm(".")
149 t.write("jamroot.jam", "stage a1 : d/a1.txt : <location>. ;")
150 t.write("d/a1.txt", "")
151
152 t.run_build_system()
153 t.expect_addition("a1.txt")
154
155 # Test that relative paths of sources can be preserved.
156 t.rm(".")
157 t.write("jamroot.jam", "install dist : a/b/c.h : <install-source-root>. ;")
158 t.write("a/b/c.h", "")
159
160 t.run_build_system()
161 t.expect_addition("dist/a/b/c.h")
162
163 t.write("jamroot.jam", "install dist : a/b/c.h : <install-source-root>a ;")
164 t.write("a/b/c.h", "")
165
166 t.run_build_system()
167 t.expect_addition("dist/b/c.h")
168
169 t.rm(".")
170 t.write("build/jamroot.jam", """\
171 install dist : ../a/b/c.h : <location>../dist <install-source-root>../a ;
172 """)
173 t.write("a/b/c.h", "")
174
175 t.run_build_system(subdir="build")
176 t.expect_addition("dist/b/c.h")
177
178 t.write("jamroot.jam", "install dist2 : a/b/c.h : <install-source-root>a ;")
179 t.write("a/b/c.h", "")
180 t.write("sub/jamfile.jam", "alias h : ..//dist2 ;")
181
182 t.run_build_system(subdir="sub")
183 t.expect_addition("dist2/b/c.h")
184
185 # Test that when installing .cpp files, we do not scan include dependencies.
186 t.rm(".")
187 t.write("jamroot.jam", "install dist : a.cpp ;")
188 t.write("a.cpp", '#include "a.h"')
189 t.write("a.h", "")
190
191 t.run_build_system()
192 t.expect_addition("dist/a.cpp")
193
194 t.touch("a.h")
195
196 t.run_build_system()
197 t.expect_nothing("dist/a.cpp")
198
199 # Test that <name> property works, when there is just one file in sources.
200 t.rm(".")
201 t.write("jamroot.jam", "install dist : a.cpp : <name>b.cpp ;")
202 t.write("a.cpp", "test file")
203
204 t.run_build_system()
205 t.expect_addition("dist/b.cpp")
206
207 t.cleanup()