diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-09-11 08:59:29 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-09-11 08:59:29 -0400 |
commit | e7565855c0105836857acf9c67363d1f6948e4ac (patch) | |
tree | ffe76dbaa5a3ea13339ae6f67320be405ef93774 /scripts | |
parent | 796a9b37ea346f413f6684505ca31879ddf3f0f1 (diff) | |
parent | 03040903e677172ce46319b83f9d00bafb33fad7 (diff) | |
download | tor-e7565855c0105836857acf9c67363d1f6948e4ac.tar.gz tor-e7565855c0105836857acf9c67363d1f6948e4ac.zip |
Merge branch 'ticket31578' into ticket31578_merged
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/maint/practracker/metrics.py | 1 | ||||
-rwxr-xr-x | scripts/maint/practracker/practracker.py | 5 | ||||
-rwxr-xr-x | scripts/maint/practracker/test_practracker.sh | 10 | ||||
-rw-r--r-- | scripts/maint/practracker/util.py | 43 |
4 files changed, 36 insertions, 23 deletions
diff --git a/scripts/maint/practracker/metrics.py b/scripts/maint/practracker/metrics.py index 9f69b2ac1f..4c62bc2425 100644 --- a/scripts/maint/practracker/metrics.py +++ b/scripts/maint/practracker/metrics.py @@ -8,6 +8,7 @@ import re def get_file_len(f): """Get file length of file""" + i = -1 for i, l in enumerate(f): pass return i + 1 diff --git a/scripts/maint/practracker/practracker.py b/scripts/maint/practracker/practracker.py index 78003fb786..ce9c5f5d82 100755 --- a/scripts/maint/practracker/practracker.py +++ b/scripts/maint/practracker/practracker.py @@ -200,6 +200,9 @@ def main(argv): help="Maximum lines per function") parser.add_argument("--max-dependency-violations", default=MAX_DEP_VIOLATIONS, 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="?", help="Top-level directory for the tor source") args = parser.parse_args(argv[1:]) @@ -222,7 +225,7 @@ def main(argv): filt.addThreshold(problem.DependencyViolationItem("*.h", int(args.max_dependency_violations))) # 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 # we don't warn about the past diff --git a/scripts/maint/practracker/test_practracker.sh b/scripts/maint/practracker/test_practracker.sh index 4f8b7e2047..bfbd0c6560 100755 --- a/scripts/maint/practracker/test_practracker.sh +++ b/scripts/maint/practracker/test_practracker.sh @@ -25,9 +25,13 @@ DATA="${PRACTRACKER_DIR}/testdata" run_practracker() { "${PYTHON:-python}" "${PRACTRACKER_DIR}/practracker.py" \ - --max-include-count=0 --max-file-size=0 \ - --max-h-include-count=0 --max-h-file-size=0 \ - --max-function-size=0 --terse \ + --include-dir "" \ + --max-file-size=0 \ + --max-function-size=0 \ + --max-h-file-size=0 \ + --max-h-include-count=0 \ + --max-include-count=0 \ + --terse \ "${DATA}/" "$@"; } compare() { diff --git a/scripts/maint/practracker/util.py b/scripts/maint/practracker/util.py index 695668f561..4b42565528 100644 --- a/scripts/maint/practracker/util.py +++ b/scripts/maint/practracker/util.py @@ -3,36 +3,41 @@ import os # We don't want to run metrics for unittests, automatically-generated C files, # external libraries or git leftovers. EXCLUDE_SOURCE_DIRS = {"src/test/", "src/trunnel/", "src/rust/", - "src/ext/", ".git/"} + "src/ext/" } EXCLUDE_FILES = {"orconfig.h"} def _norm(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. """ files_list = [] exclude_dirs = { _norm(os.path.join(tor_topdir, p)) for p in EXCLUDE_SOURCE_DIRS } - - for root, directories, filenames in os.walk(tor_topdir): - # Remove all the directories that are excluded. - directories[:] = [ d for d in directories - if _norm(os.path.join(root,d)) not in exclude_dirs ] - directories.sort() - filenames.sort() - for filename in filenames: - # We only care about .c and .h files - if not (filename.endswith(".c") or filename.endswith(".h")): - continue - if filename in EXCLUDE_FILES: - continue - - full_path = os.path.join(root,filename) - - files_list.append(full_path) + if include_dirs is None: + topdirs = [ tor_topdir ] + else: + topdirs = [ os.path.join(tor_topdir, inc) for inc in include_dirs ] + + for topdir in topdirs: + for root, directories, filenames in os.walk(topdir): + # Remove all the directories that are excluded. + directories[:] = [ d for d in directories + if _norm(os.path.join(root,d)) not in exclude_dirs ] + directories.sort() + filenames.sort() + for filename in filenames: + # We only care about .c and .h files + if not (filename.endswith(".c") or filename.endswith(".h")): + continue + if filename in EXCLUDE_FILES: + continue + + full_path = os.path.join(root,filename) + + files_list.append(full_path) return files_list |