]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Prune the .may_include files a bit; detect unused lines in them
authorNick Mathewson <nickm@torproject.org>
Sun, 1 Jul 2018 22:14:28 +0000 (18:14 -0400)
committerNick Mathewson <nickm@torproject.org>
Sun, 1 Jul 2018 22:14:28 +0000 (18:14 -0400)
scripts/maint/checkIncludes.py
src/common/.may_include
src/lib/crypt_ops/.may_include
src/lib/process/.may_include
src/lib/tls/.may_include

index 3c611675e406f7c7bbc6cac3a537c51df6f06ffe..9da15a2b9ca61f48096bc00912ede486c70e68b7 100755 (executable)
@@ -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(
index fab9ad0da89ac0778322a1861955681f164951d4..a01a9db0b9e056ff01a6e82c2dec45a31f90f366 100644 (file)
@@ -3,9 +3,6 @@ common/*.h
 lib/*/*.h
 
 # XXXX These all belong somewhere else
-ht.h
-linux_syscalls.inc
 siphash.h
 src/ext/timeouts/timeout.c
 tor_queue.h
-tor_readpassphrase.h
index 6ca06f590e10574c5c881cd093b38ddbb54f5a37..a0fa4ec05c65564cef20c665f792475ff1c7c063 100644 (file)
@@ -9,7 +9,6 @@ lib/encoding/*.h
 lib/fs/*.h
 lib/lock/*.h
 lib/malloc/*.h
-lib/err/*.h
 lib/intmath/*.h
 lib/sandbox/*.h
 lib/string/*.h
index c02e7fddb2caeb7ff0f53a8a95a956f4d93b9523..05414d2a965e4f65660af6d58908383d428513a2 100644 (file)
@@ -4,6 +4,7 @@ lib/cc/*.h
 lib/container/*.h
 lib/ctime/*.h
 lib/err/*.h
+lib/intmath/*.h
 lib/fs/*.h
 lib/log/*.h
 lib/malloc/*.h
index 1a4b8ca521cb631672754ce9c881c43289955493..ca7cb455e4f27ab67658d11eb4499d102f9db49f 100644 (file)
@@ -1,16 +1,16 @@
 orconfig.h
+
 lib/arch/*.h
 lib/cc/*.h
-lib/ctime/*.h
 lib/container/*.h
 lib/crypt_ops/*.h
-lib/intmath/*.h
+lib/ctime/*.h
 lib/encoding/*.h
-lib/err/*.h
+lib/intmath/*.h
+lib/log/*.h
 lib/net/*.h
 lib/string/*.h
 lib/testsupport/testsupport.h
 lib/tls/*.h
-lib/log/*.h
 
 ciphers.inc