Skip to content

Commit

Permalink
[lint] fix up clangtidy lintrunner integration (pytorch#68192)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#68192

- Run on exactly the same stuff as the existing linter checks.
- Exclude deploy interpreter headers from being reported.

Test Plan: Imported from OSS

Reviewed By: janeyx99

Differential Revision: D32364023

Pulled By: suo

fbshipit-source-id: c27eca4a802534875d609d004fa9f6fca59ae6a5
  • Loading branch information
suo authored and facebook-github-bot committed Nov 11, 2021
1 parent 6afb414 commit 9571eb5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ performance-*,
-performance-noexcept-move-constructor,
-performance-unnecessary-value-param,
'
HeaderFilterRegex: 'torch/csrc/.*'
HeaderFilterRegex: 'torch/csrc/(?!deploy/interpreter/cpython).*'
AnalyzeTemporaryDtors: false
WarningsAsErrors: '*'
CheckOptions:
Expand Down
28 changes: 27 additions & 1 deletion .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,39 @@ command = [
[[linter]]
code = 'CLANGTIDY'
include_patterns = [
'**/*.cpp',
'torch/csrc/fx/**/*.cpp',
'torch/csrc/utils/**/*.cpp',
'torch/csrc/generic/**/*.cpp',
'torch/csrc/deploy/**/*.cpp',
'torch/csrc/tensor/**/*.cpp',
]
exclude_patterns = [
# The negative filters below are to exclude files that include onnx_pb.h or
# caffe2_pb.h, otherwise we'd have to build protos as part of this CI job.
# FunctionsManual.cpp is excluded to keep this diff clean. It will be fixed
# in a follow up PR.
# /torch/csrc/generic/*.cpp is excluded because those files aren't actually built.
# deploy/interpreter files are excluded due to using macros and other techniquies
# that are not easily converted to accepted c++
'torch/csrc/jit/passes/onnx/helper.cpp',
'torch/csrc/jit/passes/onnx/shape_type_inference.cpp',
'torch/csrc/jit/serialization/onnx.cpp',
'torch/csrc/jit/serialization/export.cpp',
'torch/csrc/jit/serialization/import.cpp',
'torch/csrc/jit/serialization/import_legacy.cpp',
'torch/csrc/onnx/init.cpp',
'torch/csrc/cuda/nccl.*',
'torch/csrc/cuda/python_nccl.cpp',
'torch/csrc/autograd/FunctionsManual.cpp',
'torch/csrc/generic/*.cpp',
'torch/csrc/jit/codegen/cuda/runtime/*',
'torch/csrc/deploy/interactive_embedded_interpreter.cpp',
'torch/csrc/deploy/interpreter/**',
'torch/csrc/deploy/test_deploy_python_ext.cpp',
'torch/csrc/deploy/test_deploy_missing_interpreter.cpp',
'torch/csrc/deploy/test_deploy_gpu.cpp',
'torch/csrc/utils/disable_torch_function.cpp',
]
init_command = [
'python3',
'tools/linter/adapters/clangtidy_init.py',
Expand Down
6 changes: 4 additions & 2 deletions tools/linter/adapters/clangtidy_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def clang_search_dirs() -> List[str]:
def check_file(
filename: str,
binary: str,
build_dir: str,
build_dir: Path,
) -> List[LintMessage]:
try:
proc = run_command(
Expand Down Expand Up @@ -233,6 +233,8 @@ def main() -> None:
print(json.dumps(err_msg._asdict()), flush=True)
exit(0)

abs_build_dir = Path(args.build_dir).resolve()

with concurrent.futures.ThreadPoolExecutor(
max_workers=os.cpu_count(),
thread_name_prefix="Thread",
Expand All @@ -242,7 +244,7 @@ def main() -> None:
check_file,
filename,
args.binary,
args.build_dir,
abs_build_dir,
): filename
for filename in args.filenames
}
Expand Down

0 comments on commit 9571eb5

Please sign in to comment.