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