1#!/usr/bin/python 2 3# Copyright 2008 Jurko Gospodnetic 4# Distributed under the Boost Software License, Version 1.0. 5# (See accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt) 7 8# Test that the expected default toolset is used when no toolset is explicitly 9# specified on the command line or used from code via the using rule. Test that 10# the default toolset is correctly used just like any other explicitly used 11# toolset (e.g. toolset prerequisites, properties conditioned on toolset 12# related features, etc.). 13# 14# Note that we need to ignore regular site/user/test configuration files to 15# avoid them marking any toolsets not under our control as used. 16 17import BoostBuild 18 19 20# Line displayed by Boost Build when using the default toolset. 21configuring_default_toolset_message = \ 22 'warning: Configuring default toolset "%s".' 23 24 25############################################################################### 26# 27# test_conditions_on_default_toolset() 28# ------------------------------------ 29# 30############################################################################### 31 32def test_conditions_on_default_toolset(): 33 """Test that toolset and toolset subfeature conditioned properties get 34 applied correctly when the toolset is selected by default. Implicitly tests 35 that we can use the set-default-toolset rule to set the default toolset to 36 be used by Boost Build. 37 """ 38 39 t = BoostBuild.Tester("--user-config= --ignore-site-config", 40 pass_toolset=False, use_test_config=False) 41 42 toolset_name = "myCustomTestToolset" 43 toolset_version = "v" 44 toolset_version_unused = "v_unused" 45 message_loaded = "Toolset '%s' loaded." % toolset_name 46 message_initialized = "Toolset '%s' initialized." % toolset_name ; 47 48 # Custom toolset. 49 t.write(toolset_name + ".jam", """ 50import feature ; 51ECHO "%(message_loaded)s" ; 52feature.extend toolset : %(toolset_name)s ; 53feature.subfeature toolset %(toolset_name)s : version : %(toolset_version)s %(toolset_version_unused)s ; 54rule init ( version ) { ECHO "%(message_initialized)s" ; } 55""" % {'message_loaded' : message_loaded , 56 'message_initialized' : message_initialized, 57 'toolset_name' : toolset_name , 58 'toolset_version' : toolset_version , 59 'toolset_version_unused': toolset_version_unused}) 60 61 # Main Boost Build project script. 62 t.write("jamroot.jam", """ 63import build-system ; 64import errors ; 65import feature ; 66import notfile ; 67 68build-system.set-default-toolset %(toolset_name)s : %(toolset_version)s ; 69 70feature.feature description : : free incidental ; 71 72# We use a rule instead of an action to avoid problems with action output not 73# getting piped to stdout by the testing system. 74rule buildRule ( names : targets ? : properties * ) 75{ 76 local descriptions = [ feature.get-values description : $(properties) ] ; 77 ECHO "descriptions:" /$(descriptions)/ ; 78 local toolset = [ feature.get-values toolset : $(properties) ] ; 79 ECHO "toolset:" /$(toolset)/ ; 80 local toolset-version = [ feature.get-values "toolset-$(toolset):version" : $(properties) ] ; 81 ECHO "toolset-version:" /$(toolset-version)/ ; 82} 83 84notfile testTarget 85 : @buildRule 86 : 87 : 88 <description>stand-alone 89 <toolset>%(toolset_name)s:<description>toolset 90 <toolset>%(toolset_name)s-%(toolset_version)s:<description>toolset-version 91 <toolset>%(toolset_name)s-%(toolset_version_unused)s:<description>toolset-version-unused ; 92""" % {'toolset_name' : toolset_name , 93 'toolset_version' : toolset_version, 94 'toolset_version_unused': toolset_version_unused}) 95 96 t.run_build_system() 97 t.expect_output_lines(configuring_default_toolset_message % toolset_name) 98 t.expect_output_lines(message_loaded) 99 t.expect_output_lines(message_initialized) 100 t.expect_output_lines("descriptions: /stand-alone/ /toolset/ " 101 "/toolset-version/") 102 t.expect_output_lines("toolset: /%s/" % toolset_name) 103 t.expect_output_lines("toolset-version: /%s/" % toolset_version) 104 105 t.cleanup() 106 107 108############################################################################### 109# 110# test_default_toolset_on_os() 111# ---------------------------- 112# 113############################################################################### 114 115def test_default_toolset_on_os( os, expected_toolset ): 116 """Test that the given toolset is used as the default toolset on the given 117 os. Uses hardcoded knowledge of how Boost Build decides on which host OS it 118 is currently running. Note that we must not do much after tricking Boost 119 Build into believing it has a specific host OS as this might mess up other 120 important internal Boost Build state. 121 """ 122 123 t = BoostBuild.Tester("--user-config= --ignore-site-config", 124 pass_toolset=False, use_test_config=False) 125 126 t.write("jamroot.jam", "modules.poke os : .name : %s ;" % os) 127 128 # We need to tell the test system to ignore stderr output as attempting to 129 # load missing toolsets might cause random failures with which we are not 130 # concerned in this test. 131 t.run_build_system(stderr=None) 132 t.expect_output_lines(configuring_default_toolset_message % 133 expected_toolset) 134 135 t.cleanup() 136 137 138############################################################################### 139# 140# test_default_toolset_requirements() 141# ----------------------------------- 142# 143############################################################################### 144 145def test_default_toolset_requirements(): 146 """Test that default toolset's requirements get applied correctly. 147 """ 148 149 t = BoostBuild.Tester("--user-config= --ignore-site-config", 150 pass_toolset=False, use_test_config=False, 151 ignore_toolset_requirements=False) 152 153 toolset_name = "customTestToolsetWithRequirements" 154 155 # Custom toolset. 156 t.write(toolset_name + ".jam", """ 157import feature ; 158import toolset ; 159feature.extend toolset : %(toolset_name)s ; 160toolset.add-requirements <description>toolset-requirement ; 161rule init ( ) { } 162""" % {'toolset_name': toolset_name}) 163 164 # Main Boost Build project script. 165 t.write("jamroot.jam", """ 166import build-system ; 167import errors ; 168import feature ; 169import notfile ; 170 171build-system.set-default-toolset %(toolset_name)s ; 172 173feature.feature description : : free incidental ; 174 175# We use a rule instead of an action to avoid problems with action output not 176# getting piped to stdout by the testing system. 177rule buildRule ( names : targets ? : properties * ) 178{ 179 local descriptions = [ feature.get-values description : $(properties) ] ; 180 ECHO "descriptions:" /$(descriptions)/ ; 181 local toolset = [ feature.get-values toolset : $(properties) ] ; 182 ECHO "toolset:" /$(toolset)/ ; 183} 184 185notfile testTarget 186 : @buildRule 187 : 188 : 189 <description>target-requirement 190 <description>toolset-requirement:<description>conditioned-requirement 191 <description>unrelated-condition:<description>unrelated-description ; 192""" % {'toolset_name': toolset_name}) 193 194 t.run_build_system() 195 t.expect_output_lines(configuring_default_toolset_message % toolset_name) 196 t.expect_output_lines("descriptions: /conditioned-requirement/ " 197 "/target-requirement/ /toolset-requirement/") 198 t.expect_output_lines("toolset: /%s/" % toolset_name) 199 200 t.cleanup() 201 202 203############################################################################### 204# 205# main() 206# ------ 207# 208############################################################################### 209 210test_default_toolset_on_os("NT" , "msvc") 211test_default_toolset_on_os("LINUX" , "gcc" ) 212test_default_toolset_on_os("CYGWIN" , "gcc" ) 213test_default_toolset_on_os("SomeOtherOS", "gcc" ) 214test_default_toolset_requirements() 215test_conditions_on_default_toolset() 216