ソースを参照

Make includes interface more like the rest of practracker

Everything else assumes that somebody else will open the file for it.
Nick Mathewson 5 年 前
コミット
2a3c727dfe

+ 8 - 9
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):

+ 3 - 1
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)