summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-07-01 18:14:28 -0400
committerNick Mathewson <nickm@torproject.org>2018-07-01 18:14:28 -0400
commit83a4946e7b9d2bb75ab8dfa8073c5dd7b3f77bc9 (patch)
treeae3f82116b7fdebefca1e0ac8f913d40d1276df5 /scripts
parentadcd1d8b9ac09f3abc11e2e3187fe363ad3df2fd (diff)
downloadtor-83a4946e7b9d2bb75ab8dfa8073c5dd7b3f77bc9.tar.gz
tor-83a4946e7b9d2bb75ab8dfa8073c5dd7b3f77bc9.zip
Prune the .may_include files a bit; detect unused lines in them
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/maint/checkIncludes.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/scripts/maint/checkIncludes.py b/scripts/maint/checkIncludes.py
index 3c611675e4..9da15a2b9c 100755
--- a/scripts/maint/checkIncludes.py
+++ b/scripts/maint/checkIncludes.py
@@ -20,8 +20,10 @@ INCLUDE_PATTERN = re.compile(r'\s*#\s*include\s+"([^"]*)"')
RULES_FNAME = ".may_include"
class Rules(object):
- def __init__(self):
+ def __init__(self, dirpath):
+ self.dirpath = dirpath
self.patterns = []
+ self.usedPatterns = set()
def addPattern(self, pattern):
self.patterns.append(pattern)
@@ -29,6 +31,7 @@ class Rules(object):
def includeOk(self, path):
for pattern in self.patterns:
if fnmatch.fnmatchcase(path, pattern):
+ self.usedPatterns.add(pattern)
return True
return False
@@ -48,8 +51,13 @@ class Rules(object):
#print(fname)
self.applyToLines(iter(f), " of {}".format(fname))
+ def noteUnusedRules(self):
+ for p in self.patterns:
+ if p not in self.usedPatterns:
+ print("Pattern {} in {} was never used.".format(p, self.dirpath))
+
def load_include_rules(fname):
- result = Rules()
+ result = Rules(os.path.split(fname)[0])
with open(fname, 'r') as f:
for line in f:
line = line.strip()
@@ -58,12 +66,16 @@ def load_include_rules(fname):
result.addPattern(line)
return result
+list_unused = False
+
for dirpath, dirnames, fnames in os.walk("src"):
if ".may_include" in fnames:
rules = load_include_rules(os.path.join(dirpath, RULES_FNAME))
for fname in fnames:
if fname_is_c(fname):
rules.applyToFile(os.path.join(dirpath,fname))
+ if list_unused:
+ rules.noteUnusedRules()
if trouble:
err(