|
@@ -5,7 +5,7 @@ Tor code best-practices tracker
|
|
|
|
|
|
Go through the various .c files and collect metrics about them. If the metrics
|
|
|
violate some of our best practices and they are not found in the optional
|
|
|
-exceptions file ("./exceptions.txt"), then log a violation about them.
|
|
|
+exceptions file ("./exceptions.txt"), then log a problem about them.
|
|
|
|
|
|
The exceptions file is meant to be initialized with the current state of the
|
|
|
source code as follows: ./practracker.py > ./exceptions.txt
|
|
@@ -22,6 +22,7 @@ import os, sys
|
|
|
|
|
|
import metrics
|
|
|
import util
|
|
|
+import problem
|
|
|
|
|
|
|
|
|
|
|
@@ -41,76 +42,74 @@ MAX_INCLUDE_COUNT = 50
|
|
|
|
|
|
|
|
|
|
|
|
-def print_violation_if_not_exception(violation_str, exceptions_str):
|
|
|
-
|
|
|
- if exceptions_str and violation_str in exceptions_str:
|
|
|
- return
|
|
|
-
|
|
|
- print violation_str
|
|
|
+ProblemVault = None
|
|
|
|
|
|
|
|
|
|
|
|
-def consider_file_size(fname, f, exceptions_str):
|
|
|
+def consider_file_size(fname, f):
|
|
|
file_size = metrics.file_len(f)
|
|
|
if file_size > MAX_FILE_SIZE:
|
|
|
- violation_str = "violation file-size %s %d" % (fname, file_size)
|
|
|
- print_violation_if_not_exception(violation_str, exceptions_str)
|
|
|
+ v = problem.FileSizeProblem(fname, file_size)
|
|
|
+ ProblemVault.register_problem(v)
|
|
|
|
|
|
-def consider_includes(fname, f, exceptions_str):
|
|
|
+def consider_includes(fname, f):
|
|
|
include_count = metrics.get_include_count(f)
|
|
|
|
|
|
if include_count > MAX_INCLUDE_COUNT:
|
|
|
- violation_str = "violation include-count %s %d" % (fname, include_count)
|
|
|
- print_violation_if_not_exception(violation_str, exceptions_str)
|
|
|
+ v = problem.IncludeCountProblem(fname, include_count)
|
|
|
+ ProblemVault.register_problem(v)
|
|
|
|
|
|
-def consider_function_size(fname, f, exceptions_str):
|
|
|
+def consider_function_size(fname, f):
|
|
|
for name, lines in metrics.function_lines(f):
|
|
|
|
|
|
if lines <= MAX_FUNCTION_SIZE:
|
|
|
continue
|
|
|
|
|
|
-
|
|
|
+
|
|
|
canonical_function_name = "%s:%s()" % (fname,name)
|
|
|
- violation_str = "violation function-size %s %s" % (lines, canonical_function_name)
|
|
|
- print_violation_if_not_exception(violation_str, exceptions_str)
|
|
|
+ v = problem.FunctionSizeProblem(canonical_function_name, lines)
|
|
|
+ ProblemVault.register_problem(v)
|
|
|
|
|
|
|
|
|
|
|
|
-def consider_all_metrics(files_list, exceptions_str):
|
|
|
+def consider_all_metrics(files_list):
|
|
|
"""Consider metrics for all files"""
|
|
|
for fname in files_list:
|
|
|
with open(fname, 'r') as f:
|
|
|
- consider_metrics_for_file(fname, f, exceptions_str)
|
|
|
+ consider_metrics_for_file(fname, f)
|
|
|
|
|
|
-def consider_metrics_for_file(fname, f, exceptions_str):
|
|
|
+def consider_metrics_for_file(fname, f):
|
|
|
"""
|
|
|
Get metrics for file with filename 'fname' and file descriptor 'f'.
|
|
|
"""
|
|
|
|
|
|
- consider_file_size(fname, f, exceptions_str)
|
|
|
+ consider_file_size(fname, f)
|
|
|
|
|
|
|
|
|
f.seek(0)
|
|
|
- consider_includes(fname, f, exceptions_str)
|
|
|
+ consider_includes(fname, f)
|
|
|
|
|
|
|
|
|
f.seek(0)
|
|
|
- consider_function_size(fname, f, exceptions_str)
|
|
|
+ consider_function_size(fname, f)
|
|
|
|
|
|
def main():
|
|
|
+ global ProblemVault
|
|
|
+
|
|
|
|
|
|
files_list = util.get_tor_c_files(TOR_TOPDIR, EXCLUDE_SOURCE_DIRS)
|
|
|
|
|
|
-
|
|
|
- exceptions_str = None
|
|
|
+
|
|
|
+
|
|
|
try:
|
|
|
with open(EXCEPTIONS_FILE, 'r') as exception_f:
|
|
|
- exceptions_str = exception_f.read()
|
|
|
+ ProblemVault = problem.ProblemVault(exception_f)
|
|
|
except IOError:
|
|
|
print "No exception file provided"
|
|
|
+ ProblemVault = problem.ProblemVault(None)
|
|
|
|
|
|
-
|
|
|
- consider_all_metrics(files_list, exceptions_str)
|
|
|
+
|
|
|
+ consider_all_metrics(files_list)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
main()
|