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