1#!/usr/bin/python 2 3# Copyright 2003 Dave Abrahams 4# Copyright 2003, 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 main target alternatives. 9 10import BoostBuild 11import string 12 13t = BoostBuild.Tester(use_test_config=False) 14 15# Test that basic alternatives selection works. 16t.write("jamroot.jam", "") 17 18t.write("jamfile.jam", """ 19exe a : a_empty.cpp ; 20exe a : a.cpp : <variant>release ; 21""") 22 23t.write("a_empty.cpp", "") 24 25t.write("a.cpp", "int main() {}\n") 26 27t.run_build_system(["release"]) 28 29t.expect_addition("bin/$toolset/release*/a.exe") 30 31# Test that alternative selection works for ordinary properties, in particular 32# user-defined. 33t.write("jamroot.jam", "") 34 35t.write("jamfile.jam", """ 36import feature ; 37feature.feature X : off on : propagated ; 38exe a : b.cpp ; 39exe a : a.cpp : <X>on ; 40""") 41t.write("b.cpp", "int main() {}\n") 42 43t.rm("bin") 44 45t.run_build_system() 46t.expect_addition("bin/$toolset/debug*/b.obj") 47 48t.run_build_system(["X=on"]) 49t.expect_addition("bin/$toolset/debug/X-on*/a.obj") 50 51t.rm("bin") 52 53# Test that everything works ok even with the default build. 54t.write("jamfile.jam", """\ 55exe a : a_empty.cpp : <variant>release ; 56exe a : a.cpp : <variant>debug ; 57""") 58 59t.run_build_system() 60t.expect_addition("bin/$toolset/debug*/a.exe") 61 62# Test that only properties which are in the build request matter for 63# alternative selection. IOW, alternative with <variant>release is better than 64# one with <variant>debug when building the release variant. 65t.write("jamfile.jam", """\ 66exe a : a_empty.cpp : <variant>debug ; 67exe a : a.cpp : <variant>release ; 68""") 69 70t.run_build_system(["release"]) 71t.expect_addition("bin/$toolset/release*/a.exe") 72 73# Test that free properties do not matter. We really do not want <cxxflags> 74# property in build request to affect alternative selection. 75t.write("jamfile.jam", """ 76exe a : a_empty.cpp : <variant>debug <define>FOO <include>BAR ; 77exe a : a.cpp : <variant>release ; 78""") 79 80t.rm("bin/$toolset/release/a.exe") 81t.rm("bin/$toolset/release/*/a.exe") 82t.run_build_system(["release", "define=FOO"]) 83t.expect_addition("bin/$toolset/release*/a.exe") 84 85# Test that ambiguity is reported correctly. 86t.write("jamfile.jam", """\ 87exe a : a_empty.cpp ; 88exe a : a.cpp ; 89""") 90t.run_build_system(["--no-error-backtrace"], status=None) 91t.expect_output_lines("error: No best alternative for ./a") 92 93# Another ambiguity test: two matches properties in one alternative are neither 94# better nor worse than a single one in another alternative. 95t.write("jamfile.jam", """\ 96exe a : a_empty.cpp : <optimization>off <profiling>off ; 97exe a : a.cpp : <debug-symbols>on ; 98""") 99 100t.run_build_system(["--no-error-backtrace"], status=None) 101t.expect_output_lines("error: No best alternative for ./a") 102t.rm("bin") 103 104# Test that we can have alternative without sources. 105t.write("jamfile.jam", """\ 106alias specific-sources ; 107import feature ; 108feature.extend os : MAGIC ; 109alias specific-sources : b.cpp : <os>MAGIC ; 110exe a : a.cpp specific-sources ; 111""") 112t.run_build_system() 113t.expect_addition("bin/$toolset/debug*/a.exe") 114t.rm("bin") 115 116# Test that subfeatures are expanded in alternatives 117# and that unknown subfeatures fail to match instead of 118# causing errors. 119t.write("jamfile.jam", """\ 120import feature : feature subfeature ; 121feature X : off on : propagated ; 122subfeature X on : version : 1 : propagated ; 123exe a : a.cpp : <X>on-1 ; 124exe a : a_empty.cpp ; 125exe a : a_empty.cpp : <X>on-2 ; 126""") 127t.run_build_system(["X=on-1"]) 128 129t.cleanup() 130