Commit 9f144f1e authored by Florian Sattler's avatar Florian Sattler Committed by Commit Bot

[tools] Restrict clang-tidy to src and test files

NOTRY=true

Change-Id: If305367e5971a596ea5b3cd665dc5a5771d925bf
Reviewed-on: https://chromium-review.googlesource.com/1219628
Commit-Queue: Florian Sattler <sattlerf@google.com>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55791}
parent f79caee2
...@@ -14,7 +14,7 @@ import sys ...@@ -14,7 +14,7 @@ import sys
CLANG_TIDY_WARNING = re.compile(r'(\/.*?)\ .*\[(.*)\]$') CLANG_TIDY_WARNING = re.compile(r'(\/.*?)\ .*\[(.*)\]$')
CLANG_TIDY_CMDLINE_OUT = re.compile(r'^clang-tidy.*\ .*|^\./\.\*') CLANG_TIDY_CMDLINE_OUT = re.compile(r'^clang-tidy.*\ .*|^\./\.\*')
THIRD_PARTY = re.compile(r'.*\/third_party\/.*') FILE_REGEXS = ['src/*', 'test/*']
THREADS = multiprocessing.cpu_count() THREADS = multiprocessing.cpu_count()
...@@ -29,7 +29,7 @@ class ClangTidyWarning(object): ...@@ -29,7 +29,7 @@ class ClangTidyWarning(object):
self.occurrences = set() self.occurrences = set()
def add_occurrence(self, file_path): def add_occurrence(self, file_path):
self.occurrences.add(file_path) self.occurrences.add(file_path.lstrip())
def __hash__(self): def __hash__(self):
return hash(self.warning_type) return hash(self.warning_type)
...@@ -97,7 +97,8 @@ def ClangTidyRunFull(build_folder, skip_output_filter, checks, auto_fix): ...@@ -97,7 +97,8 @@ def ClangTidyRunFull(build_folder, skip_output_filter, checks, auto_fix):
with open(os.devnull, 'w') as DEVNULL: with open(os.devnull, 'w') as DEVNULL:
ct_process = subprocess.Popen( ct_process = subprocess.Popen(
['run-clang-tidy', '-j' + str(THREADS), '-p', '.'] + extra_args, ['run-clang-tidy', '-j' + str(THREADS), '-p', '.'] + extra_args
+ FILE_REGEXS,
cwd=build_folder, cwd=build_folder,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=DEVNULL) stderr=DEVNULL)
...@@ -129,13 +130,13 @@ def ClangTidyRunFull(build_folder, skip_output_filter, checks, auto_fix): ...@@ -129,13 +130,13 @@ def ClangTidyRunFull(build_folder, skip_output_filter, checks, auto_fix):
sys.stdout.write(line) sys.stdout.write(line)
def ClangTidyRunAggregate(build_folder, print_files, show_third_party=False): def ClangTidyRunAggregate(build_folder, print_files):
""" """
Run clang-tidy on the full codebase and aggregate warnings into categories. Run clang-tidy on the full codebase and aggregate warnings into categories.
""" """
with open(os.devnull, 'w') as DEVNULL: with open(os.devnull, 'w') as DEVNULL:
ct_process = subprocess.Popen( ct_process = subprocess.Popen(
['run-clang-tidy', '-j' + str(THREADS), '-p', '.'], ['run-clang-tidy', '-j' + str(THREADS), '-p', '.'] + FILE_REGEXS,
cwd=build_folder, cwd=build_folder,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=DEVNULL) stderr=DEVNULL)
...@@ -147,11 +148,9 @@ def ClangTidyRunAggregate(build_folder, print_files, show_third_party=False): ...@@ -147,11 +148,9 @@ def ClangTidyRunAggregate(build_folder, print_files, show_third_party=False):
res = CLANG_TIDY_WARNING.search(line) res = CLANG_TIDY_WARNING.search(line)
if res is not None: if res is not None:
filter_match = THIRD_PARTY.search(line) warnings.setdefault(
if not filter_match or show_third_party: res.group(2),
warnings.setdefault( ClangTidyWarning(res.group(2))).add_occurrence(res.group(1))
res.group(2),
ClangTidyWarning(res.group(2))).add_occurrence(res.group(1))
for warning in sorted(warnings.values(), reverse=True): for warning in sorted(warnings.values(), reverse=True):
sys.stdout.write(warning.to_string(print_files)) sys.stdout.write(warning.to_string(print_files))
...@@ -307,8 +306,6 @@ def GetOptions(): ...@@ -307,8 +306,6 @@ def GetOptions():
agg_run_g.add_option('--show-loc', help='Show file locations when running '\ agg_run_g.add_option('--show-loc', help='Show file locations when running '\
'in aggregate mode', default=False, 'in aggregate mode', default=False,
action='store_true') action='store_true')
agg_run_g.add_option('--show-third-party', help='List third party warnings',
default=False, action='store_true')
result.add_option_group(agg_run_g) result.add_option_group(agg_run_g)
# Diff clang-tidy. # Diff clang-tidy.
...@@ -363,8 +360,7 @@ def main(): ...@@ -363,8 +360,7 @@ def main():
print 'Running clang-tidy - aggregating warnings' print 'Running clang-tidy - aggregating warnings'
if options.auto_fix: if options.auto_fix:
print 'Auto fix not working in aggregate mode, running without.' print 'Auto fix not working in aggregate mode, running without.'
ClangTidyRunAggregate(options.build_folder, options.show_loc, ClangTidyRunAggregate(options.build_folder, options.show_loc)
options.show_third_party)
elif options.single: elif options.single:
print 'Running clang-tidy - single on ' + options.file_name print 'Running clang-tidy - single on ' + options.file_name
if options.file_name is not None: if options.file_name is not None:
......
Markdown is supported
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