2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-16 01:12:13 +00:00

Warn on unused sources.

* new/targets.jam
    (basic-target.check-for-unused-sources): New rule.
    (basic-target.generate): Call the above.

* new/virtual-target.jam
    (traverse): New arguments 'include-roots' and 'include-sources'.

* test/unused.py: New test.


[SVN r17685]
This commit is contained in:
Vladimir Prus
2003-02-28 08:13:38 +00:00
parent 4e531ecc65
commit 5decdacc6b
8 changed files with 136 additions and 8 deletions

View File

@@ -569,7 +569,9 @@ rule basic-target ( name : project
local source-targets = [ generate-sources $(rproperties) ] ;
self.generated.$(property-set) =
[ construct $(source-targets) : $(rproperties) ] ;
[ construct $(source-targets) : $(rproperties) ] ;
check-for-unused-sources
$(self.generated.$(property-set)) : $(source-targets) ;
# Apply use requirement of this target to all generated
# virtual targets.
@@ -591,6 +593,27 @@ rule basic-target ( name : project
}
return $(self.generated.$(property-set)) ;
}
# Check that 'result' makes use of all the 'sources'. If not,
# issues a warning.
local rule check-for-unused-sources ( result + : sources * )
{
local used-sources ;
for local r in $(result)
{
used-sources += [ virtual-target.traverse $(r) : include-roots : 1 ] ; #: includes-sources ] ;
}
for local s in $(sources)
{
if ! $(s) in $(used-sources)
{
errors.warning "Unused source target" [ $(s).str ]
: "Main target is " [ full-name ] ;
}
}
}
# Constructs the virtual targets for this abstract targets and
# the dependecy graph. Returns the list of virtual targets.

View File

@@ -729,8 +729,10 @@ rule register ( target )
}
# Traverses the dependency graph of 'target' and return all targets that will
# be created before this one is created.
rule traverse ( target )
# be created before this one is created. If root of some dependency graph is
# found during traversal, it's either included or not, dependencing of the
# value of 'include-roots'. In either case, sources of root are not traversed.
rule traverse ( target : include-roots ? : include-sources ? )
{
local result ;
if [ $(target).action ]
@@ -743,10 +745,18 @@ rule traverse ( target )
{
if ! [ $(t).root ]
{
result += [ traverse $(t) ] ;
result += [ traverse $(t) : $(include-roots) : $(include-sources) ] ;
}
else if $(include-roots)
{
result += $(t) ;
}
}
}
else if $(include-sources)
{
result = $(target) ;
}
return $(result) ;
}

View File

@@ -83,6 +83,7 @@ tests = [ "project_test1",
"make_rule",
"alias",
"alternatives",
"unused",
]
if os.name == 'posix':

30
test/unused.py Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/python
# Test that unused sources are at least reported.
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.run_build_system()
t.fail_test(find(t.stdout(), "warning: Unused source target { a.H }") == -1)
t.cleanup()

View File

@@ -569,7 +569,9 @@ rule basic-target ( name : project
local source-targets = [ generate-sources $(rproperties) ] ;
self.generated.$(property-set) =
[ construct $(source-targets) : $(rproperties) ] ;
[ construct $(source-targets) : $(rproperties) ] ;
check-for-unused-sources
$(self.generated.$(property-set)) : $(source-targets) ;
# Apply use requirement of this target to all generated
# virtual targets.
@@ -591,6 +593,27 @@ rule basic-target ( name : project
}
return $(self.generated.$(property-set)) ;
}
# Check that 'result' makes use of all the 'sources'. If not,
# issues a warning.
local rule check-for-unused-sources ( result + : sources * )
{
local used-sources ;
for local r in $(result)
{
used-sources += [ virtual-target.traverse $(r) : include-roots : 1 ] ; #: includes-sources ] ;
}
for local s in $(sources)
{
if ! $(s) in $(used-sources)
{
errors.warning "Unused source target" [ $(s).str ]
: "Main target is " [ full-name ] ;
}
}
}
# Constructs the virtual targets for this abstract targets and
# the dependecy graph. Returns the list of virtual targets.

View File

@@ -729,8 +729,10 @@ rule register ( target )
}
# Traverses the dependency graph of 'target' and return all targets that will
# be created before this one is created.
rule traverse ( target )
# be created before this one is created. If root of some dependency graph is
# found during traversal, it's either included or not, dependencing of the
# value of 'include-roots'. In either case, sources of root are not traversed.
rule traverse ( target : include-roots ? : include-sources ? )
{
local result ;
if [ $(target).action ]
@@ -743,10 +745,18 @@ rule traverse ( target )
{
if ! [ $(t).root ]
{
result += [ traverse $(t) ] ;
result += [ traverse $(t) : $(include-roots) : $(include-sources) ] ;
}
else if $(include-roots)
{
result += $(t) ;
}
}
}
else if $(include-sources)
{
result = $(target) ;
}
return $(result) ;
}

View File

@@ -83,6 +83,7 @@ tests = [ "project_test1",
"make_rule",
"alias",
"alternatives",
"unused",
]
if os.name == 'posix':

30
v2/test/unused.py Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/python
# Test that unused sources are at least reported.
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.run_build_system()
t.fail_test(find(t.stdout(), "warning: Unused source target { a.H }") == -1)
t.cleanup()