First xut at reference-checking from a definitions file.
This commit is contained in:
parent
f1ff10acab
commit
4915c221ae
2 changed files with 24 additions and 10 deletions
|
@ -13,25 +13,25 @@ EXCLUDE = --exclude "(exploder|castle-cutter|UI)"
|
|||
|
||||
unresolved:
|
||||
@echo "# Report on unresolved macro calls and resource references"
|
||||
@macroscope --unresolved $(EXCLUDE) $(TOPDIR)
|
||||
@./macroscope --unresolved $(EXCLUDE) $(TOPDIR)
|
||||
|
||||
all:
|
||||
@echo "# Report on usage of all macros and resources"
|
||||
@macroscope --crossreference $(EXCLUDE) $(TOPDIR)
|
||||
@./macroscope --crossreference $(EXCLUDE) $(TOPDIR)
|
||||
|
||||
utils-unused:
|
||||
@echo "# Report on unused utility macros"
|
||||
@macroscope --crossreference --from data/utils --refcount 0 $(FAKE) $(EXCLUDE) $(TOPDIR)
|
||||
@./macroscope --crossreference --from data/utils --refcount 0 $(FAKE) $(EXCLUDE) $(TOPDIR)
|
||||
|
||||
all-unused:
|
||||
@echo "# Report on unused resource files"
|
||||
@macroscope --crossreference --refcount 0 $(FAKE) $(EXCLUDE) $(TOPDIR)
|
||||
@./macroscope --crossreference --refcount 0 $(FAKE) $(EXCLUDE) $(TOPDIR)
|
||||
|
||||
utils-macros:
|
||||
@echo "# Report on usage of utility macros"
|
||||
@macroscope --crossreference --from data/utils $(EXCLUDE) $(TOPDIR)
|
||||
@./macroscope --crossreference --from data/utils $(EXCLUDE) $(TOPDIR)
|
||||
|
||||
definitions:
|
||||
@macroscope --definitions --exclude data/scenarios --exclude data/campaigns $(EXCLUDE) $(TOPDIR)
|
||||
@./macroscope --definitions --exclude data/scenarios --exclude data/campaigns $(EXCLUDE) $(TOPDIR)
|
||||
|
||||
|
||||
|
|
|
@ -102,11 +102,14 @@ class CrossRef:
|
|||
self.fileref[key].append(fn, n)
|
||||
return key
|
||||
def __init__(self, filelist):
|
||||
# First, collect macro definitions from the specified filelist."
|
||||
"Build cross-reference object from the specified filelist."
|
||||
self.xref = {}
|
||||
self.fileref = {}
|
||||
self.noxref = False
|
||||
for filename in filelist:
|
||||
if filter(lambda x: x, map(lambda x: filename.endswith("." + x), resource_extensions)):
|
||||
# It's a resource file of some sort.
|
||||
#
|
||||
# The rule we're applying here is:
|
||||
# 1) If it's a sound file, its name is the part of
|
||||
# the path after "sounds/" or "music/".
|
||||
|
@ -126,6 +129,7 @@ class CrossRef:
|
|||
name = name[len("images")+1:]
|
||||
self.fileref[name] = reference(filename)
|
||||
elif iswml(filename):
|
||||
# It's a WML file, scan for macro defitions
|
||||
dfp = open(filename)
|
||||
for (n, line) in enumerate(dfp):
|
||||
if line.startswith("#define"):
|
||||
|
@ -137,6 +141,14 @@ class CrossRef:
|
|||
% (name, self.xref[name], here)
|
||||
self.xref[name] = here
|
||||
dfp.close()
|
||||
elif filename.endswith(".def"):
|
||||
# It's a list of names to be considered defined
|
||||
self.noxref = True
|
||||
dfp = open(filename)
|
||||
for line in dfp:
|
||||
self.xref[line.strip()] = True
|
||||
dfp.close()
|
||||
|
||||
# Next, decorate definitions with all references from the filelist.
|
||||
self.unresolved = []
|
||||
self.missing = []
|
||||
|
@ -215,7 +227,6 @@ class CrossRef:
|
|||
print "%s -> %s" % (reference, name)
|
||||
def deflist(self, pred=None):
|
||||
"List all resource definitions."
|
||||
print "#% definitions"
|
||||
for (name, defloc) in self.xref.items() + self.fileref.items():
|
||||
if pred and not pred(name, defloc):
|
||||
continue
|
||||
|
@ -248,7 +259,7 @@ Usage: macroscope [options] dirpath
|
|||
'force-used=',
|
||||
'from=',
|
||||
'help',
|
||||
'refcount='
|
||||
'refcount=',
|
||||
'unresolved',
|
||||
])
|
||||
crossreference = definitions = unresolved = False
|
||||
|
@ -293,7 +304,10 @@ Usage: macroscope [options] dirpath
|
|||
return False
|
||||
return True
|
||||
if crossreference:
|
||||
xref.xrefdump(predicate)
|
||||
if xref.noxref:
|
||||
print >>sys.stderr, "macroscope: can't make cross-reference, input included a definitions file."
|
||||
else:
|
||||
xref.xrefdump(predicate)
|
||||
if definitions:
|
||||
xref.deflist(predicate)
|
||||
if unresolved:
|
||||
|
|
Loading…
Add table
Reference in a new issue