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

[tor-commits] [tor/master] Make includes interface more like the rest of practracker



commit 2a3c727dfed7465090c2b9bae2f5ac88b3c6dca0
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Mon Aug 5 17:31:49 2019 -0400

    Make includes interface more like the rest of practracker
    
    Everything else assumes that somebody else will open the file for it.
---
 scripts/maint/practracker/includes.py    | 17 ++++++++---------
 scripts/maint/practracker/practracker.py |  4 +++-
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/scripts/maint/practracker/includes.py b/scripts/maint/practracker/includes.py
index fbd68f4f5..fcc527c98 100755
--- a/scripts/maint/practracker/includes.py
+++ b/scripts/maint/practracker/includes.py
@@ -103,11 +103,9 @@ class Rules(object):
                                 "Forbidden include of {}".format(include),
                                 is_advisory=self.is_advisory)
 
-    def applyToFile(self, fname):
-        with open_file(fname) as f:
-            #print(fname)
-            for error in self.applyToLines(iter(f), "{}:".format(fname)):
-                yield error
+    def applyToFile(self, fname, f):
+        for error in self.applyToLines(iter(f), "{}:".format(fname)):
+            yield error
 
     def noteUnusedRules(self):
         for p in self.patterns:
@@ -200,14 +198,14 @@ def toposort(graph, limit=100):
 
     return all_levels
 
-def consider_include_rules(fname):
+def consider_include_rules(fname, f):
     dirpath = os.path.split(fname)[0]
     rules_fname = os.path.join(dirpath, RULES_FNAME)
     rules = load_include_rules(os.path.join(dirpath, RULES_FNAME))
     if rules is None:
         return
 
-    for err in rules.applyToFile(fname):
+    for err in rules.applyToFile(fname, f):
         yield err
 
     list_unused = False
@@ -221,8 +219,9 @@ def walk_c_files(topdir="src"):
         for fname in fnames:
             if fname_is_c(fname):
                 fullpath = os.path.join(dirpath,fname)
-                for err in consider_include_rules(fullpath):
-                    yield err
+                with open(fullpath) as f:
+                    for err in consider_include_rules(fullpath, f):
+                        yield err
 
 def run_check_includes(topdir, list_unused=False, log_sorted_levels=False,
                        list_advisories=False):
diff --git a/scripts/maint/practracker/practracker.py b/scripts/maint/practracker/practracker.py
index 66ebb1277..20c8bb5b4 100755
--- a/scripts/maint/practracker/practracker.py
+++ b/scripts/maint/practracker/practracker.py
@@ -117,8 +117,10 @@ def consider_metrics_for_file(fname, f):
     for item in consider_function_size(fname, f):
         yield item
 
+    # Check for "upward" includes
+    f.seek(0)
     n = 0
-    for item in includes.consider_include_rules(real_fname):
+    for item in includes.consider_include_rules(real_fname, f):
         n += 1
     if n:
         yield problem.DependencyViolationItem(fname, n)



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