diff --git a/v2/build/alias.jam b/v2/build/alias.jam index 9df09f125..25344063f 100644 --- a/v2/build/alias.jam +++ b/v2/build/alias.jam @@ -49,6 +49,11 @@ class alias-target-class : basic-target rule check-for-link-compatibility ( * : * ) { } + + rule check-for-unused-sources ( * : * ) + { + } + rule compute-usage-requirements ( subvariant ) { diff --git a/v2/build/generators.jam b/v2/build/generators.jam index ce2642ebd..8908db008 100644 --- a/v2/build/generators.jam +++ b/v2/build/generators.jam @@ -451,6 +451,7 @@ class generator for local t in $(targets) { $(t).action $(a) ; + $(t).set-intermediate true ; } return [ sequence.transform virtual-target.register : $(targets) ] ; @@ -1007,7 +1008,20 @@ rule construct ( project name ? : target-type multiple ? : property-set * : sour { ensure-type $(sources) ; } - + + if ! $(.construct-stack) + { + local sources2 ; + for local s in $(sources) + { + if ! [ $(s).intermediate ] + { + sources2 += $(s) ; + } + } + sources = $(sources2) ; + } + .construct-stack += 1 ; increase-indent ; @@ -1037,6 +1051,7 @@ rule construct ( project name ? : target-type multiple ? : property-set * : sour .construct-stack = $(.construct-stack[2-]) ; + # For all targets of 'allowed-type', reset the 'intermediate' attribute. if ! $(.construct-stack) && $(allowed-type) != * # This is first invocation in stack { local result2 ; @@ -1052,14 +1067,12 @@ rule construct ( project name ? : target-type multiple ? : property-set * : sour # checking for unused sources a bit harder. if $(type) = $(target-type) || [ type.is-derived $(type) $(allowed-type) ] { - result2 += $(t) ; + $(t).set-intermediate ; } } - return $(result2) ; } - else - { - return $(result) ; - } + + + return $(result) ; } diff --git a/v2/build/targets.jam b/v2/build/targets.jam index ad039d7cf..233213cff 100644 --- a/v2/build/targets.jam +++ b/v2/build/targets.jam @@ -978,9 +978,12 @@ class basic-target : abstract-target } - # Check that each source virtual target is either directly present in the - # result, or is in dependency graph of some returned virtual target. - # If this is not the case, issues a warning. + # Check that each source virtual target which is not marked as intermediate + # is present dependency graph of 'result'. + # If this is not the case, issues a warning. + # Sources which are directly presentin result are not considered used, and + # a warning will be issued for them as well. + # # Note that 'result' *can* be empty. For # example, in this use case: # alias platform-sources ; @@ -988,18 +991,30 @@ class basic-target : abstract-target # result will be empty in the first case. local rule check-for-unused-sources ( result * : sources * ) { + local isources ; + for local i in $(sources) + { + if ! [ $(i).intermediate ] + { + isources += $(i) ; + } + } + sources = $(isources) ; + local used-sources ; for local r in $(result) { used-sources += [ virtual-target.traverse $(r) : include-roots : 1 ] ; } + # Consider sources which are bypassed as unused + used-sources = [ set.difference $(used-sources) : $(result) ] ; local unused = [ set.difference $(sources) : $(used-sources) ] ; if $(unused) { for local u in $(unused) { - errors.warning "Unused source" [ $(u).str ] "in main target" [ full-name ] ; + errors.warning "Unused source" [ $(u).str ] "in main target" [ full-name ] ; } } } diff --git a/v2/build/virtual-target.jam b/v2/build/virtual-target.jam index d07ee970f..2767ae3df 100644 --- a/v2/build/virtual-target.jam +++ b/v2/build/virtual-target.jam @@ -258,6 +258,18 @@ class abstract-file-target : virtual-target } return $(self.root) ; } + + rule set-intermediate ( value ? ) + { + self.intermediate = $(value) ; + } + + rule intermediate ( ) + { + return $(self.intermediate) ; + } + + # Gets or sets the subvariant which created this target. Subvariant # is set when target is brought into existance, and is never changed @@ -913,6 +925,7 @@ rule clone-template ( target dont-recurse ? : new-source : new-project ) { local cloned = [ new file-target $(new-name) : [ $(target).type ] : $(new-project) ] ; + $(cloned).set-intermediate [ $(target).intermediate ] ; if ! $(dont-recurse) && [ $(target).action ] { diff --git a/v2/tools/builtin.jam b/v2/tools/builtin.jam index fd291e155..b67e82a3b 100644 --- a/v2/tools/builtin.jam +++ b/v2/tools/builtin.jam @@ -631,6 +631,7 @@ class linking-generator : generator { local libs = [ $(property-set).get ] ; sources += $(libs:G=) ; + if [ $(property-set).get ] = true { diff --git a/v2/tools/stage.jam b/v2/tools/stage.jam index ce834e93c..9d45863bd 100644 --- a/v2/tools/stage.jam +++ b/v2/tools/stage.jam @@ -146,7 +146,7 @@ class stage-target-class : basic-target local result ; for local i in $(source-targets) { - if [ $(i).type ] != SEARCHED_LIB + if ! [ $(i).intermediate ] && [ $(i).type ] != SEARCHED_LIB { local staged-targets ;