-
Notifications
You must be signed in to change notification settings - Fork 80
Use the same version of clang-tidy and clang-format as clang #6006
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
+83
−66
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6e43ee6
Install clang-tidy-19
wujingyue 7866a83
WIP
wujingyue 6b72c78
WIP
wujingyue fb3fe7c
Add a TODO for CUDA include path
wujingyue 026f895
Fix clang-format
wujingyue 090a2a0
Remove windows support -- YAGNI
wujingyue 5625a5d
Proper setup for lintrunner
wujingyue f51af80
Install llvm-19 earlier
wujingyue 2676598
Fix clang-format
wujingyue e1f4919
Review
wujingyue 637b9c6
shell=False
wujingyue 759f66b
Merge branch 'main' into wjy/tidy
wujingyue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,6 @@ | |
| from typing import Any, List, NamedTuple, Optional | ||
|
|
||
|
|
||
| IS_WINDOWS: bool = os.name == "nt" | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. YAGNI |
||
|
|
||
|
|
||
| def eprint(*args: Any, **kwargs: Any) -> None: | ||
| print(*args, file=sys.stderr, flush=True, **kwargs) | ||
|
|
||
|
|
@@ -37,10 +34,6 @@ class LintMessage(NamedTuple): | |
| description: Optional[str] | ||
|
|
||
|
|
||
| def as_posix(name: str) -> str: | ||
| return name.replace("\\", "/") if IS_WINDOWS else name | ||
|
|
||
|
|
||
| def _run_command( | ||
| args: List[str], | ||
| *, | ||
|
|
@@ -53,7 +46,7 @@ def _run_command( | |
| args, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| shell=IS_WINDOWS, # So batch scripts are found. | ||
| shell=True, | ||
wujingyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| timeout=timeout, | ||
| check=True, | ||
| ) | ||
|
|
@@ -138,7 +131,7 @@ def check_file( | |
| "STDOUT\n{stdout}" | ||
| ).format( | ||
| returncode=err.returncode, | ||
| command=" ".join(as_posix(x) for x in err.cmd), | ||
| command=" ".join(err.cmd), | ||
| stderr=err.stderr.decode("utf-8").strip() or "(empty)", | ||
| stdout=err.stdout.decode("utf-8").strip() or "(empty)", | ||
| ) | ||
|
|
@@ -170,11 +163,6 @@ def main() -> None: | |
| description="Format files with clang-format.", | ||
| fromfile_prefix_chars="@", | ||
| ) | ||
| parser.add_argument( | ||
| "--binary", | ||
| required=True, | ||
| help="clang-format binary path", | ||
| ) | ||
| parser.add_argument( | ||
| "--retries", | ||
| default=3, | ||
|
|
@@ -209,8 +197,10 @@ def main() -> None: | |
| stream=sys.stderr, | ||
| ) | ||
|
|
||
| binary = os.path.normpath(args.binary) if IS_WINDOWS else args.binary | ||
| binary = os.path.expanduser(binary) | ||
| llvm_bindir = subprocess.check_output( | ||
| "llvm-config --bindir", text=True, shell=True | ||
| ).strip() | ||
wujingyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
wujingyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| binary = os.path.join(llvm_bindir, "clang-format") | ||
| if not Path(binary).exists(): | ||
| lint_message = LintMessage( | ||
| path=None, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,12 +129,16 @@ def clang_search_dirs() -> List[str]: | |
| return search_paths | ||
|
|
||
|
|
||
| include_args = [] | ||
| # NVFUSER_USE_PCH=ON somehow requires the CUDA include dir e.g. | ||
| # "/usr/local/cuda-13.0/targets/x86_64-linux/include". I'll try to add that in | ||
| # a future PR. | ||
| include_dir = [ | ||
| "/usr/lib/llvm-11/include/openmp", | ||
|
||
| get_python_include_dir(), | ||
| os.path.join(NVFUSER_ROOT, "third_party/pybind11/include"), | ||
| ] + clang_search_dirs() | ||
|
|
||
| include_args = [] | ||
| for dir in include_dir: | ||
| include_args += ["--extra-arg", f"-I{dir}"] | ||
|
|
||
|
|
@@ -197,11 +201,6 @@ def main() -> None: | |
| description="clang-tidy wrapper linter.", | ||
| fromfile_prefix_chars="@", | ||
| ) | ||
| parser.add_argument( | ||
| "--binary", | ||
| required=True, | ||
| help="clang-tidy binary path", | ||
| ) | ||
| parser.add_argument( | ||
| "--build-dir", | ||
| "--build_dir", | ||
|
|
@@ -233,8 +232,11 @@ def main() -> None: | |
| stream=sys.stderr, | ||
| ) | ||
|
|
||
| args.binary = os.path.expanduser(args.binary) | ||
| if not os.path.exists(args.binary): | ||
| llvm_bindir = subprocess.check_output( | ||
| "llvm-config --bindir", text=True, shell=True | ||
| ).strip() | ||
wujingyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
wujingyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
wujingyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
wujingyue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| binary_path = os.path.join(llvm_bindir, "clang-tidy") | ||
| if not os.path.exists(binary_path): | ||
| err_msg = LintMessage( | ||
| path="<none>", | ||
| line=None, | ||
|
|
@@ -245,7 +247,7 @@ def main() -> None: | |
| original=None, | ||
| replacement=None, | ||
| description=( | ||
| f"Could not find clang-tidy binary at {args.binary}," | ||
| f"Could not find clang-tidy binary at {binary_path}," | ||
| " you may need to run `lintrunner init`." | ||
| ), | ||
| ) | ||
|
|
@@ -254,14 +256,6 @@ def main() -> None: | |
|
|
||
| abs_build_dir = Path(args.build_dir).resolve() | ||
|
|
||
| # Get the absolute path to clang-tidy and use this instead of the relative | ||
| # path such as .lintbin/clang-tidy. The problem here is that os.chdir is | ||
| # per process, and the linter uses it to move between the current directory | ||
| # and the build folder. And there is no .lintbin directory in the latter. | ||
| # When it happens in a race condition, the linter command will fails with | ||
| # the following no such file or directory error: '.lintbin/clang-tidy' | ||
| binary_path = os.path.abspath(args.binary) | ||
|
|
||
| with concurrent.futures.ThreadPoolExecutor( | ||
| max_workers=os.cpu_count(), | ||
| thread_name_prefix="Thread", | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.