Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize clang-tidy hook #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions hooks/clang_tidy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python3
"""Wrapper script for clang-tidy."""
import re
import sys
from typing import List
import multiprocessing as mp

from hooks.utils import StaticAnalyzerCmd

Expand All @@ -18,21 +17,20 @@ def __init__(self, args: List[str]):
self.parse_args(args)
self.edit_in_place = "-fix" in self.args or "--fix-errors" in self.args

def tidy_file(self, filename: List[str]):
self.run_command([filename] + self.args)
# Warnings generated aren't important.
self.stderr = re.sub(rb"[\d,]+ warning \S+\s+", b"", self.stderr)
if len(self.stderr) > 0 and "--fix-errors" in self.args:
self.returncode = 1
return self.returncode, self.stderr

def run(self):
"""Run clang-tidy. If --fix-errors is passed in, then return code will be 0, even if there are errors."""
for filename in self.files:
self.run_command([filename] + self.args)
# Warnings generated aren't important.
self.stderr = re.sub(rb"[\d,]+ warning \S+\s+", b"", self.stderr)
if len(self.stderr) > 0 and "--fix-errors" in self.args:
self.returncode = 1
self.exit_on_error()

with mp.Pool(mp.cpu_count()) as p:
results = p.map(self.tidy_file, self.files)
ret_codes, stderrs = zip(*results)

def main(argv: List[str] = sys.argv):
cmd = ClangTidyCmd(argv)
cmd.run()


if __name__ == "__main__":
main()
self.returncode = max(ret_codes)
self.stderr = b"\n".join(stderrs)
self.exit_on_error()