1 | #!/usr/bin/python |
---|
2 | |
---|
3 | # Copyright 2003 Dave Abrahams |
---|
4 | # Copyright 2002, 2003, 2005 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 that we can change build directory using |
---|
9 | # the 'build-dir' project attribute. |
---|
10 | |
---|
11 | from BoostBuild import Tester |
---|
12 | import string |
---|
13 | import os |
---|
14 | |
---|
15 | t = Tester() |
---|
16 | |
---|
17 | |
---|
18 | # Test that top-level project can affect build dir |
---|
19 | t.write("project-root.jam", "import gcc ; ") |
---|
20 | t.write("Jamfile", """ |
---|
21 | project |
---|
22 | : build-dir build |
---|
23 | ; |
---|
24 | |
---|
25 | exe a : a.cpp ; |
---|
26 | build-project src ; |
---|
27 | """) |
---|
28 | t.write("a.cpp", "int main() { return 0; }\n") |
---|
29 | |
---|
30 | t.write("src/Jamfile", "exe b : b.cpp ; ") |
---|
31 | t.write("src/b.cpp", "int main() { return 0; }\n") |
---|
32 | |
---|
33 | t.run_build_system() |
---|
34 | |
---|
35 | t.expect_addition(["build/$toolset/debug/a.exe", |
---|
36 | "build/src/$toolset/debug/b.exe"]) |
---|
37 | |
---|
38 | # Test that building from child projects work |
---|
39 | t.run_build_system(subdir='src') |
---|
40 | t.expect_nothing_more() |
---|
41 | |
---|
42 | # Test that project can override build dir |
---|
43 | t.write("Jamfile", """ |
---|
44 | exe a : a.cpp ; |
---|
45 | build-project src ; |
---|
46 | """) |
---|
47 | |
---|
48 | t.write("src/Jamfile", """ |
---|
49 | project |
---|
50 | : build-dir build |
---|
51 | ; |
---|
52 | exe b : b.cpp ; |
---|
53 | """) |
---|
54 | |
---|
55 | t.run_build_system() |
---|
56 | t.expect_addition(["bin/$toolset/debug/a.exe", |
---|
57 | "src/build/$toolset/debug/b.exe"]) |
---|
58 | |
---|
59 | # Now test the '--build-dir' option. |
---|
60 | t.rm(".") |
---|
61 | t.write("Jamroot", "") |
---|
62 | |
---|
63 | # Test that we get an error when no project id is specified. |
---|
64 | t.run_build_system("--build-dir=foo") |
---|
65 | t.fail_test(string.find(t.stdout(), |
---|
66 | "warning: the --build-dir option will be ignored") == -1) |
---|
67 | |
---|
68 | t.write("Jamroot", """ |
---|
69 | project foo ; |
---|
70 | exe a : a.cpp ; |
---|
71 | build-project sub ; |
---|
72 | """) |
---|
73 | t.write("a.cpp", "int main() { return 0; }\n") |
---|
74 | t.write("sub/Jamfile", "exe b : b.cpp ;\n") |
---|
75 | t.write("sub/b.cpp", "int main() { return 0; }\n") |
---|
76 | |
---|
77 | t.run_build_system("--build-dir=build") |
---|
78 | t.expect_addition(["build/foo/$toolset/debug/a.exe", |
---|
79 | "build/foo/sub/$toolset/debug/b.exe"]) |
---|
80 | |
---|
81 | t.write("Jamroot", """ |
---|
82 | project foo : build-dir bin.v2 ; |
---|
83 | exe a : a.cpp ; |
---|
84 | build-project sub ; |
---|
85 | """) |
---|
86 | |
---|
87 | t.run_build_system("--build-dir=build") |
---|
88 | t.expect_addition(["build/foo/bin.v2/$toolset/debug/a.exe", |
---|
89 | "build/foo/bin.v2/sub/$toolset/debug/b.exe"]) |
---|
90 | |
---|
91 | # Try building in subdir |
---|
92 | t.rm('build') |
---|
93 | t.run_build_system("--build-dir=build", subdir="sub") |
---|
94 | t.expect_addition(["sub/build/foo/bin.v2/sub/$toolset/debug/b.exe"]) |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | t.write("Jamroot", """ |
---|
99 | project foo : build-dir %s ; |
---|
100 | exe a : a.cpp ; |
---|
101 | build-project sub ; |
---|
102 | """ % string.replace(os.getcwd(), '\\', '\\\\')) |
---|
103 | |
---|
104 | t.run_build_system("--build-dir=build", status=1) |
---|
105 | t.fail_test(string.find(t.stdout(), |
---|
106 | "Absolute directory specified via 'build-dir' project attribute") == -1) |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | t.cleanup() |
---|