[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Teach include-checker about advisory rules



commit 720951f05664c38155a4515aa76b9c8d3a99269d
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Mon Aug 5 17:04:00 2019 -0400

    Teach include-checker about advisory rules
    
    A .may_includes file can be "advisory", which means that some
    violations of the rules are expected.  We will track these
    violations with practracker, not as automatic errors.
---
 scripts/maint/practracker/includes.py | 24 ++++++++++++++++------
 src/core/crypto/.may_include          | 10 +++++++++
 src/core/mainloop/.may_include        | 20 ++++++++++++++++++
 src/core/or/.may_include              | 38 +++++++++++++++++++++++++++++++++++
 src/core/proto/.may_include           | 10 +++++++++
 5 files changed, 96 insertions(+), 6 deletions(-)

diff --git a/scripts/maint/practracker/includes.py b/scripts/maint/practracker/includes.py
index c35fcfd85..fbd68f4f5 100755
--- a/scripts/maint/practracker/includes.py
+++ b/scripts/maint/practracker/includes.py
@@ -56,9 +56,10 @@ def pattern_is_normal(s):
     return False
 
 class Error(object):
-    def __init__(self, location, msg):
+    def __init__(self, location, msg, is_advisory=False):
         self.location = location
         self.msg = msg
+        self.is_advisory = is_advisory
 
     def __str__(self):
         return "{} at {}".format(self.msg, self.location)
@@ -73,8 +74,12 @@ class Rules(object):
             self.incpath = dirpath
         self.patterns = []
         self.usedPatterns = set()
+        self.is_advisory = False
 
     def addPattern(self, pattern):
+        if pattern == "!advisory":
+            self.is_advisory = True
+            return
         if not pattern_is_normal(pattern):
             warn("Unusual pattern {} in {}".format(pattern, self.dirpath))
         self.patterns.append(pattern)
@@ -95,7 +100,8 @@ class Rules(object):
                 include = m.group(1)
                 if not self.includeOk(include):
                     yield Error("{}{}".format(loc_prefix,str(lineno)),
-                                "Forbidden include of {}".format(include))
+                                "Forbidden include of {}".format(include),
+                                is_advisory=self.is_advisory)
 
     def applyToFile(self, fname):
         with open_file(fname) as f:
@@ -204,7 +210,6 @@ def consider_include_rules(fname):
     for err in rules.applyToFile(fname):
         yield err
 
-
     list_unused = False
     log_sorted_levels = False
 
@@ -219,12 +224,16 @@ def walk_c_files(topdir="src"):
                 for err in consider_include_rules(fullpath):
                     yield err
 
-def run_check_includes(topdir, list_unused=False, log_sorted_levels=False):
+def run_check_includes(topdir, list_unused=False, log_sorted_levels=False,
+                       list_advisories=False):
     trouble = False
 
     for err in walk_c_files(topdir):
+        if err.is_advisory and not list_advisories:
+            continue
         print(err, file=sys.stderr)
-        trouble = True
+        if not err.is_advisory:
+            trouble = True
 
     if trouble:
         err(
@@ -262,13 +271,16 @@ def main(argv):
                         help="Print a topologically sorted list of modules")
     parser.add_argument("--list-unused", action="store_true",
                         help="List unused lines in .may_include files.")
+    parser.add_argument("--list-advisories", action="store_true",
+                        help="List advisories as well as forbidden includes")
     parser.add_argument("topdir", default="src", nargs="?",
                         help="Top-level directory for the tor source")
     args = parser.parse_args(argv[1:])
 
     run_check_includes(topdir=args.topdir,
                        log_sorted_levels=args.toposort,
-                       list_unused=args.list_unused)
+                       list_unused=args.list_unused,
+                       list_advisories=args.list_advisories)
 
 if __name__ == '__main__':
     main(sys.argv)
diff --git a/src/core/crypto/.may_include b/src/core/crypto/.may_include
new file mode 100644
index 000000000..5782a3679
--- /dev/null
+++ b/src/core/crypto/.may_include
@@ -0,0 +1,10 @@
+!advisory
+
+orconfig.h
+
+lib/crypt_ops/*.h
+lib/ctime/*.h
+lib/cc/*.h
+lib/log/*.h
+
+core/crypto/*.h
diff --git a/src/core/mainloop/.may_include b/src/core/mainloop/.may_include
new file mode 100644
index 000000000..79d6a130a
--- /dev/null
+++ b/src/core/mainloop/.may_include
@@ -0,0 +1,20 @@
+!advisory
+
+orconfig.h
+
+lib/container/*.h
+lib/dispatch/*.h
+lib/evloop/*.h
+lib/pubsub/*.h
+lib/subsys/*.h
+lib/buf/*.h
+lib/crypt_ops/*.h
+lib/err/*.h
+lib/tls/*.h
+lib/net/*.h
+lib/evloop/*.h
+lib/geoip/*.h
+lib/sandbox/*.h
+lib/compress/*.h
+
+core/mainloop/*.h
\ No newline at end of file
diff --git a/src/core/or/.may_include b/src/core/or/.may_include
new file mode 100644
index 000000000..5173e8a2b
--- /dev/null
+++ b/src/core/or/.may_include
@@ -0,0 +1,38 @@
+!advisory
+
+orconfig.h
+
+lib/arch/*.h
+lib/buf/*.h
+lib/cc/*.h
+lib/compress/*.h
+lib/container/*.h
+lib/crypt_ops/*.h
+lib/ctime/*.h
+lib/defs/*.h
+lib/encoding/*.h
+lib/err/*.h
+lib/evloop/*.h
+lib/fs/*.h
+lib/geoip/*.h
+lib/intmath/*.h
+lib/log/*.h
+lib/malloc/*.h
+lib/math/*.h
+lib/net/*.h
+lib/pubsub/*.h
+lib/string/*.h
+lib/subsys/*.h
+lib/test/*.h
+lib/testsupport/*.h
+lib/thread/*.h
+lib/time/*.h
+lib/tls/*.h
+lib/wallclock/*.h
+
+trunnel/*.h
+
+core/mainloop/*.h
+core/proto/*.h
+core/crypto/*.h
+core/or/*.h
\ No newline at end of file
diff --git a/src/core/proto/.may_include b/src/core/proto/.may_include
new file mode 100644
index 000000000..c1647a5cf
--- /dev/null
+++ b/src/core/proto/.may_include
@@ -0,0 +1,10 @@
+!advisory
+
+orconfig.h
+
+lib/crypt_ops/*.h
+lib/buf/*.h
+
+trunnel/*.h
+
+core/proto/*.h
\ No newline at end of file



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits