1#!/usr/bin/python 2 3# Copyright (C) Steven Watanabe 2018 4# Distributed under the Boost Software License, Version 1.0. (See 5# accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt) 7 8# Tests the check-has-flag rule 9 10import BoostBuild 11 12t = BoostBuild.Tester(use_test_config=False) 13 14# We need an object file before we can run the actual test. 15t.write('input.cpp', 'void f() {}\n') 16t.write('Jamroot.jam', 'obj input : input.cpp ;') 17t.run_build_system() 18 19linker_input = t.glob_file('bin/$toolset/debug*/input.obj') 20 21# Check every possible result of pass or fail. 22t.write('Jamroot.jam', ''' 23import flags ; 24import modules ; 25OBJECT_FILE = [ modules.peek : OBJECT_FILE ] ; 26obj fail_cpp : test.cpp : [ check-has-flag <cxxflags>--illegal-flag-cpp 27 : <define>ERROR : <define>OK ] ; 28obj pass_cpp : test.cpp : [ check-has-flag <cxxflags>-DMACRO_CPP 29 : <define>OK : <define>ERROR ] ; 30obj fail_c : test.cpp : [ check-has-flag <cflags>--illegal-flag-c 31 : <define>ERROR : <define>OK ] ; 32obj pass_c : test.cpp : [ check-has-flag <cflags>-DMACRO_C 33 : <define>OK : <define>ERROR ] ; 34obj fail_link : test.cpp : [ check-has-flag <linkflags>--illegal-flag-link 35 : <define>ERROR : <define>OK ] ; 36# The only thing that we can be certain the linker 37# will accept is the name of an object file. 38obj pass_link : test.cpp : [ check-has-flag <linkflags>$(OBJECT_FILE) 39 : <define>OK : <define>ERROR ] ; 40''') 41 42t.write('test.cpp', ''' 43#ifdef ERROR 44#error ERROR defined 45#endif 46#ifndef OK 47#error ERROR not defined 48#endif 49''') 50 51# Don't check the status immediately, so that we have a chance 52# to print config.log. Also, we need a minimum of d2 to make 53# sure that we always see the commands and output. 54t.run_build_system(['-sOBJECT_FILE=' + linker_input, '-d2'], status=None) 55 56if t.status != 0: 57 log_file = t.read('bin/config.log') 58 BoostBuild.annotation("config.log", log_file) 59 t.fail_test(True) 60 61t.expect_output_lines([' - has --illegal-flag-cpp : no', 62 ' - has -DMACRO_CPP : yes', 63 ' - has --illegal-flag-c : no', 64 ' - has -DMACRO_C : yes', 65 ' - has --illegal-flag-link : no', 66 ' - has *bin*/input.* : yes']) 67t.expect_addition('bin/$toolset/debug*/fail_cpp.obj') 68t.expect_addition('bin/$toolset/debug*/pass_cpp.obj') 69t.expect_addition('bin/$toolset/debug*/fail_c.obj') 70t.expect_addition('bin/$toolset/debug*/pass_c.obj') 71t.expect_addition('bin/$toolset/debug*/fail_link.obj') 72t.expect_addition('bin/$toolset/debug*/pass_link.obj') 73 74t.cleanup() 75