summaryrefslogtreecommitdiff
path: root/tools/build/v2/test/build_dir.py
blob: 50c2a906cd7926ae360a288f0fefc877be601193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python

# Copyright 2003 Dave Abrahams
# Copyright 2002, 2003, 2005 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)

# Test that we can change build directory using the 'build-dir' project
# attribute.

import BoostBuild
import string
import os

t = BoostBuild.Tester(use_test_config=False)


# Test that top-level project can affect build dir.
t.write("jamroot.jam", "import gcc ;")
t.write("jamfile.jam", """\
project : build-dir build ;
exe a : a.cpp ;
build-project src ;
""")

t.write("a.cpp", "int main() {}\n")

t.write("src/jamfile.jam", "exe b : b.cpp ; ")

t.write("src/b.cpp", "int main() {}\n")

t.run_build_system()

t.expect_addition(["build/$toolset/debug/a.exe",
                   "build/src/$toolset/debug/b.exe"])

# Test that building from child projects work.
t.run_build_system(subdir='src')
t.ignore("build/config.log")
t.ignore("build/project-cache.jam")
t.expect_nothing_more()

# Test that project can override build dir.
t.write("jamfile.jam", """\
exe a : a.cpp ;
build-project src ;
""")

t.write("src/jamfile.jam", """\
project : build-dir build ;
exe b : b.cpp ;
""")

t.run_build_system()
t.expect_addition(["bin/$toolset/debug/a.exe",
                   "src/build/$toolset/debug/b.exe"])

# Now test the '--build-dir' option.
t.rm(".")
t.write("jamroot.jam", "")

# Test that we get an error when no project id is specified.
t.run_build_system(["--build-dir=foo"])
t.fail_test(string.find(t.stdout(),
                   "warning: the --build-dir option will be ignored") == -1)

t.write("jamroot.jam", """\
project foo ;
exe a : a.cpp ;
build-project sub ;
""")
t.write("a.cpp", "int main() {}\n")
t.write("sub/jamfile.jam", "exe b : b.cpp ;\n")
t.write("sub/b.cpp", "int main() {}\n")

t.run_build_system(["--build-dir=build"])
t.expect_addition(["build/foo/$toolset/debug/a.exe",
                   "build/foo/sub/$toolset/debug/b.exe"])

t.write("jamroot.jam", """\
project foo : build-dir bin.v2 ;
exe a : a.cpp ;
build-project sub ;
""")

t.run_build_system(["--build-dir=build"])
t.expect_addition(["build/foo/bin.v2/$toolset/debug/a.exe",
                   "build/foo/bin.v2/sub/$toolset/debug/b.exe"])

# Try building in subdir. We expect that the entire build tree with be in
# 'sub/build'. Today, I am not sure if this is what the user expects, but let
# it be.
t.rm('build')
t.run_build_system(["--build-dir=build"], subdir="sub")
t.expect_addition(["sub/build/foo/bin.v2/sub/$toolset/debug/b.exe"])

t.write("jamroot.jam", """\
project foo : build-dir %s ;
exe a : a.cpp ;
build-project sub ;
""" % string.replace(os.getcwd(), '\\', '\\\\'))

t.run_build_system(["--build-dir=build"], status=1)
t.fail_test(string.find(t.stdout(),
    "Absolute directory specified via 'build-dir' project attribute") == -1)

t.cleanup()