Commit e7565855 authored by Nick Mathewson's avatar Nick Mathewson 🥄
Browse files

Merge branch 'ticket31578' into ticket31578_merged

parents 796a9b37 03040903
o Minor bugfixes (practracker):
- When running check-best-practices, only consider files in the
src subdirectory. Previously we had recursively considered
all subdirectories, which made us get confused by the
temporary directories made by "make distcheck". Fixes bug
31578; bugfix on 0.4.1.1-alpha.
...@@ -8,6 +8,7 @@ import re ...@@ -8,6 +8,7 @@ import re
def get_file_len(f): def get_file_len(f):
"""Get file length of file""" """Get file length of file"""
i = -1
for i, l in enumerate(f): for i, l in enumerate(f):
pass pass
return i + 1 return i + 1
......
...@@ -200,6 +200,9 @@ def main(argv): ...@@ -200,6 +200,9 @@ def main(argv):
help="Maximum lines per function") help="Maximum lines per function")
parser.add_argument("--max-dependency-violations", default=MAX_DEP_VIOLATIONS, parser.add_argument("--max-dependency-violations", default=MAX_DEP_VIOLATIONS,
help="Maximum number of dependency violations to allow") help="Maximum number of dependency violations to allow")
parser.add_argument("--include-dir", action="append",
default=["src"],
help="A directory (under topdir) to search for source")
parser.add_argument("topdir", default=".", nargs="?", parser.add_argument("topdir", default=".", nargs="?",
help="Top-level directory for the tor source") help="Top-level directory for the tor source")
args = parser.parse_args(argv[1:]) args = parser.parse_args(argv[1:])
...@@ -222,7 +225,7 @@ def main(argv): ...@@ -222,7 +225,7 @@ def main(argv):
filt.addThreshold(problem.DependencyViolationItem("*.h", int(args.max_dependency_violations))) filt.addThreshold(problem.DependencyViolationItem("*.h", int(args.max_dependency_violations)))
# 1) Get all the .c files we care about # 1) Get all the .c files we care about
files_list = util.get_tor_c_files(TOR_TOPDIR) files_list = util.get_tor_c_files(TOR_TOPDIR, args.include_dir)
# 2) Initialize problem vault and load an optional exceptions file so that # 2) Initialize problem vault and load an optional exceptions file so that
# we don't warn about the past # we don't warn about the past
......
...@@ -25,9 +25,13 @@ DATA="${PRACTRACKER_DIR}/testdata" ...@@ -25,9 +25,13 @@ DATA="${PRACTRACKER_DIR}/testdata"
run_practracker() { run_practracker() {
"${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker.py" \ "${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker.py" \
--max-include-count=0 --max-file-size=0 \ --include-dir "" \
--max-h-include-count=0 --max-h-file-size=0 \ --max-file-size=0 \
--max-function-size=0 --terse \ --max-function-size=0 \
--max-h-file-size=0 \
--max-h-include-count=0 \
--max-include-count=0 \
--terse \
"${DATA}/" "$@"; "${DATA}/" "$@";
} }
compare() { compare() {
......
...@@ -3,36 +3,41 @@ import os ...@@ -3,36 +3,41 @@ import os
# We don't want to run metrics for unittests, automatically-generated C files, # We don't want to run metrics for unittests, automatically-generated C files,
# external libraries or git leftovers. # external libraries or git leftovers.
EXCLUDE_SOURCE_DIRS = {"src/test/", "src/trunnel/", "src/rust/", EXCLUDE_SOURCE_DIRS = {"src/test/", "src/trunnel/", "src/rust/",
"src/ext/", ".git/"} "src/ext/" }
EXCLUDE_FILES = {"orconfig.h"} EXCLUDE_FILES = {"orconfig.h"}
def _norm(p): def _norm(p):
return os.path.normcase(os.path.normpath(p)) return os.path.normcase(os.path.normpath(p))
def get_tor_c_files(tor_topdir): def get_tor_c_files(tor_topdir, include_dirs=None):
""" """
Return a list with the .c and .h filenames we want to get metrics of. Return a list with the .c and .h filenames we want to get metrics of.
""" """
files_list = [] files_list = []
exclude_dirs = { _norm(os.path.join(tor_topdir, p)) for p in EXCLUDE_SOURCE_DIRS } exclude_dirs = { _norm(os.path.join(tor_topdir, p)) for p in EXCLUDE_SOURCE_DIRS }
if include_dirs is None:
for root, directories, filenames in os.walk(tor_topdir): topdirs = [ tor_topdir ]
# Remove all the directories that are excluded. else:
directories[:] = [ d for d in directories topdirs = [ os.path.join(tor_topdir, inc) for inc in include_dirs ]
if _norm(os.path.join(root,d)) not in exclude_dirs ]
directories.sort() for topdir in topdirs:
filenames.sort() for root, directories, filenames in os.walk(topdir):
for filename in filenames: # Remove all the directories that are excluded.
# We only care about .c and .h files directories[:] = [ d for d in directories
if not (filename.endswith(".c") or filename.endswith(".h")): if _norm(os.path.join(root,d)) not in exclude_dirs ]
continue directories.sort()
if filename in EXCLUDE_FILES: filenames.sort()
continue for filename in filenames:
# We only care about .c and .h files
full_path = os.path.join(root,filename) if not (filename.endswith(".c") or filename.endswith(".h")):
continue
files_list.append(full_path) if filename in EXCLUDE_FILES:
continue
full_path = os.path.join(root,filename)
files_list.append(full_path)
return files_list return files_list
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment