1#!/usr/local/bin/python3.8 2 3# Copyright 2003 Vladimir Prus 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 unused sources are at least reported. 9 10import BoostBuild 11 12t = BoostBuild.Tester(["-d+2"], use_test_config=False) 13 14t.write("a.cpp", "int main() {}\n") 15t.write("b.cpp", "\n") 16t.write("b.xyz", "") 17t.write("jamroot.jam", """\ 18import "class" : new ; 19import modules ; 20import project ; 21import targets ; 22import type ; 23import virtual-target ; 24 25type.register X : xyz ; 26 27class test-target-class : basic-target 28{ 29 rule construct ( name : source-targets * : property-set ) 30 { 31 local result = [ property-set.empty ] ; 32 if ! [ modules.peek : GENERATE_NOTHING ] 33 { 34 result += [ virtual-target.from-file b.xyz : . : $(self.project) ] ; 35 if ! [ modules.peek : GENERATE_ONLY_UNUSABLE ] 36 { 37 result += [ virtual-target.from-file b.cpp : . : $(self.project) 38 ] ; 39 } 40 } 41 return $(result) ; 42 } 43 44 rule compute-usage-requirements ( rproperties : targets * ) 45 { 46 return [ property-set.create <define>FOO ] ; 47 } 48} 49 50rule make-b-main-target 51{ 52 local project = [ project.current ] ; 53 targets.main-target-alternative [ new test-target-class b : $(project) ] ; 54} 55 56exe a : a.cpp b c ; 57make-b-main-target ; 58alias c ; # Expands to nothing, intentionally. 59""") 60 61t.run_build_system() 62 63# The second invocation should do nothing, and produce no warning. The previous 64# invocation might have printed executed actions and other things, so it is not 65# easy to check if a warning was issued or not. 66t.run_build_system(stdout="") 67 68t.run_build_system(["-sGENERATE_ONLY_UNUSABLE=1"], stdout="") 69 70# Check that even if main target generates nothing, its usage requirements are 71# still propagated to dependants. 72t.write("a.cpp", """\ 73#ifndef FOO 74 #error We refuse to compile without FOO being defined! 75 We_refuse_to_compile_without_FOO_being_defined 76#endif 77int main() {} 78""") 79t.run_build_system(["-sGENERATE_NOTHING=1"]) 80 81t.cleanup() 82