From 21ea3db0f55e9f63115337aecaedbd5cc4ccc482 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Thu, 15 May 2003 15:52:26 +0000 Subject: [PATCH] Improve the way unused sources are detected/reported. * new/targets.jam (basic-target.generate-source): Separate virtual targets that come from different sources. (basic-target.check-for-unused-targets): Warn only if not virtual target from a given source is comsumed. [SVN r18403] --- new/targets.jam | 42 +++++++++++++++++++++++++++++++++--------- test/unused.py | 25 ++++++++----------------- v2/build/targets.jam | 42 +++++++++++++++++++++++++++++++++--------- v2/test/unused.py | 25 ++++++++----------------- 4 files changed, 82 insertions(+), 52 deletions(-) diff --git a/new/targets.jam b/new/targets.jam index d7482e8e2..395deeb9f 100644 --- a/new/targets.jam +++ b/new/targets.jam @@ -73,6 +73,7 @@ import property ; import errors ; import common ; import property-set ; +import utility : ungrist ; # Base class for all abstract targets. @@ -540,7 +541,10 @@ rule basic-target ( name : project return $(rproperties) ; } - # Generate all sources for this target + # Generate all sources for this target. For each source, the return value will + # contain a list of virtual targets generated from the source, followed by + # <@>source-name element. + # IOW, virtual targets which come from different sources are separated local rule generate-sources ( property-set ) { local source-targets ; @@ -560,6 +564,7 @@ rule basic-target ( name : project source-targets += [ virtual-target.from-file $(s) : $(self.project) ] ; } + source-targets += <@>$(s) ; } return $(source-targets) ; } @@ -591,8 +596,16 @@ rule basic-target ( name : project [ targets.generate-dependencies $(rproperties) : $(self.project) : $(rproperties) ] ; - local source-targets = [ generate-sources $(rproperties) ] ; - + local source-target-groups = [ generate-sources $(rproperties) ] ; + local source-targets = ; + for local s in $(source-target-groups) + { + if $(s:G) != <@> + { + source-targets += $(s) ; + } + } + local usage-requirements = [ get-usage-requirements $(source-targets) [ $(rproperties).dependency ] @@ -604,7 +617,7 @@ rule basic-target ( name : project local result = [ construct $(source-targets) : $(rproperties) ] ; check-for-unused-sources - $(result) : $(source-targets) ; + $(result) : $(source-target-groups) ; set-usage-requirements $(result) : $(rproperties) ; @@ -670,7 +683,7 @@ rule basic-target ( name : project # alias platform-sources ; # alias platform-sources : a.cpp : NT ; # result will be empty in the first case. - local rule check-for-unused-sources ( result * : sources * ) + local rule check-for-unused-sources ( result * : source-groups * ) { local used-sources ; for local r in $(result) @@ -678,13 +691,24 @@ rule basic-target ( name : project used-sources += [ virtual-target.traverse $(r) : include-roots : 1 ] ; #: includes-sources ] ; } - for local s in $(sources) + local group ; + for local s in $(source-groups) { - if ! $(s) in $(used-sources) + if $(s:G) != <@> { - errors.warning "Unused source target" [ $(s).str ] - : "Main target is " [ full-name ] ; + group += $(s) ; } + else + { + # We've collected a group of targets that originates from single + # dependency main target, and must check that at least one of them + # is used. + if ! [ set.intersection $(group) : $(used-sources) ] + { + errors.warning "Unused source" $(s:G=) "in main target" [ full-name ] ; + } + group = ; + } } } diff --git a/test/unused.py b/test/unused.py index 59199ffca..cc16fb026 100644 --- a/test/unused.py +++ b/test/unused.py @@ -6,25 +6,16 @@ from BoostBuild import Tester from string import find t = Tester() -t.write("a.h", """ -""") - -t.write("a.cpp", """ -int main() -{ - return 0; -} -""") - -t.write("Jamfile", """ -exe a : a.cpp a.h ; -""") - -t.write("project-root.jam", """ -""") +t.set_tree("unused") t.run_build_system() -t.fail_test(find(t.stdout(), "warning: Unused source target { a.H }") == -1) +# The second invocation should do nothing, and produce +# no warning. +t.run_build_system() +t.fail_test(t.stdout() != '') + +t.run_build_system("-sGENERATE_ONLY_UNUSABLE=1") +t.fail_test(find(t.stdout(), "warning: Unused source b in main target ./a") == -1) t.cleanup() diff --git a/v2/build/targets.jam b/v2/build/targets.jam index d7482e8e2..395deeb9f 100644 --- a/v2/build/targets.jam +++ b/v2/build/targets.jam @@ -73,6 +73,7 @@ import property ; import errors ; import common ; import property-set ; +import utility : ungrist ; # Base class for all abstract targets. @@ -540,7 +541,10 @@ rule basic-target ( name : project return $(rproperties) ; } - # Generate all sources for this target + # Generate all sources for this target. For each source, the return value will + # contain a list of virtual targets generated from the source, followed by + # <@>source-name element. + # IOW, virtual targets which come from different sources are separated local rule generate-sources ( property-set ) { local source-targets ; @@ -560,6 +564,7 @@ rule basic-target ( name : project source-targets += [ virtual-target.from-file $(s) : $(self.project) ] ; } + source-targets += <@>$(s) ; } return $(source-targets) ; } @@ -591,8 +596,16 @@ rule basic-target ( name : project [ targets.generate-dependencies $(rproperties) : $(self.project) : $(rproperties) ] ; - local source-targets = [ generate-sources $(rproperties) ] ; - + local source-target-groups = [ generate-sources $(rproperties) ] ; + local source-targets = ; + for local s in $(source-target-groups) + { + if $(s:G) != <@> + { + source-targets += $(s) ; + } + } + local usage-requirements = [ get-usage-requirements $(source-targets) [ $(rproperties).dependency ] @@ -604,7 +617,7 @@ rule basic-target ( name : project local result = [ construct $(source-targets) : $(rproperties) ] ; check-for-unused-sources - $(result) : $(source-targets) ; + $(result) : $(source-target-groups) ; set-usage-requirements $(result) : $(rproperties) ; @@ -670,7 +683,7 @@ rule basic-target ( name : project # alias platform-sources ; # alias platform-sources : a.cpp : NT ; # result will be empty in the first case. - local rule check-for-unused-sources ( result * : sources * ) + local rule check-for-unused-sources ( result * : source-groups * ) { local used-sources ; for local r in $(result) @@ -678,13 +691,24 @@ rule basic-target ( name : project used-sources += [ virtual-target.traverse $(r) : include-roots : 1 ] ; #: includes-sources ] ; } - for local s in $(sources) + local group ; + for local s in $(source-groups) { - if ! $(s) in $(used-sources) + if $(s:G) != <@> { - errors.warning "Unused source target" [ $(s).str ] - : "Main target is " [ full-name ] ; + group += $(s) ; } + else + { + # We've collected a group of targets that originates from single + # dependency main target, and must check that at least one of them + # is used. + if ! [ set.intersection $(group) : $(used-sources) ] + { + errors.warning "Unused source" $(s:G=) "in main target" [ full-name ] ; + } + group = ; + } } } diff --git a/v2/test/unused.py b/v2/test/unused.py index 59199ffca..cc16fb026 100644 --- a/v2/test/unused.py +++ b/v2/test/unused.py @@ -6,25 +6,16 @@ from BoostBuild import Tester from string import find t = Tester() -t.write("a.h", """ -""") - -t.write("a.cpp", """ -int main() -{ - return 0; -} -""") - -t.write("Jamfile", """ -exe a : a.cpp a.h ; -""") - -t.write("project-root.jam", """ -""") +t.set_tree("unused") t.run_build_system() -t.fail_test(find(t.stdout(), "warning: Unused source target { a.H }") == -1) +# The second invocation should do nothing, and produce +# no warning. +t.run_build_system() +t.fail_test(t.stdout() != '') + +t.run_build_system("-sGENERATE_ONLY_UNUSABLE=1") +t.fail_test(find(t.stdout(), "warning: Unused source b in main target ./a") == -1) t.cleanup()