aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-08-05 11:58:12 -0400
committerNick Mathewson <nickm@torproject.org>2019-08-05 13:40:59 -0400
commit47d9bcfef8cff23225850545400f60a93fe18f49 (patch)
tree5ff6fdde08b0a914ea016f0dca5916da57d5ddc9
parent65a69f861e192ae77c7edafe46bc2674bc39b9ea (diff)
downloadtor-47d9bcfef8cff23225850545400f60a93fe18f49.tar.gz
tor-47d9bcfef8cff23225850545400f60a93fe18f49.zip
checkIncludes: Separate file-handling from rule-handling
This is our shift from directory-at-a-time processing to file-at-a-time processing.
-rwxr-xr-xscripts/maint/checkIncludes.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/scripts/maint/checkIncludes.py b/scripts/maint/checkIncludes.py
index c4e77c71e7..9daaf13632 100755
--- a/scripts/maint/checkIncludes.py
+++ b/scripts/maint/checkIncludes.py
@@ -126,9 +126,14 @@ class Rules(object):
include_rules_cache = {}
def load_include_rules(fname):
- """ Read a rules file from 'fname', and return it as a Rules object. """
+ """ Read a rules file from 'fname', and return it as a Rules object.
+ Return 'None' if fname does not exist.
+ """
if fname in include_rules_cache:
return include_rules_cache[fname]
+ if not os.path.exists(fname):
+ include_rules_cache[fname] = None
+ return None
result = Rules(os.path.split(fname)[0])
with open_file(fname) as f:
for line in f:
@@ -139,6 +144,11 @@ def load_include_rules(fname):
include_rules_cache[fname] = result
return result
+def get_all_include_rules():
+ return [ rules for (fname,rules) in
+ sorted(include_rules_cache.items())
+ if rules is not None ]
+
def remove_self_edges(graph):
"""Takes a directed graph in as an adjacency mapping (a mapping from
node to a list of the nodes to which it connects).
@@ -187,18 +197,12 @@ if __name__ == '__main__':
list_unused = False
log_sorted_levels = False
- uses_dirs = { }
-
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):
+ for fname in fnames:
+ if fname_is_c(fname):
+ rules = load_include_rules(os.path.join(dirpath, RULES_FNAME))
+ if rules is not None:
rules.applyToFile(os.path.join(dirpath,fname))
- if list_unused:
- rules.noteUnusedRules()
-
- uses_dirs[rules.incpath] = rules.getAllowedDirectories()
if trouble:
err(
@@ -206,6 +210,14 @@ if __name__ == '__main__':
files in its enclosing directory.""".format(RULES_FNAME))
sys.exit(1)
+ if list_unused:
+ for rules in get_all_include_rules():
+ rules.noteUnusedRules()
+
+ uses_dirs = { }
+ for rules in get_all_include_rules():
+ uses_dirs[rules.incpath] = rules.getAllowedDirectories()
+
remove_self_edges(uses_dirs)
all_levels = toposort(uses_dirs)