feat(clang-tidy): Improve clang-tidy support#6843
Conversation
24bit-xjkp
commented
Sep 22, 2025
- Since clang-tidy doesn't support parallel analysis in a single process, use multi-process to support parallel analysis.
1. Improve "compdb" option, supporting the directory containing the json db file. This will shorten the command line since "compile_commands.json" is a long name.
2. Use `opt.compdb` instead of `option.get("compdb")` because `option.get` doesn't work and returns a nil in this scope. I don't know the reason.
3. Motivated by the python script `run-clang-tidy` in llvm project, each clang-tidy subprocess new only processes a source file and use multi-process to implement parallel analysis based on `async.runjobs`
4. Use `os.execv` instead of `os.vrunv` since diagnoses are always wanted in static analysis.
5. Add a timer for check action.
Summary of ChangesHello @24bit-xjkp, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces significant improvements to the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request improves clang-tidy support by enabling parallel analysis using multiple processes, with each process handling a single source file. This is a solid approach to speed up the checking process. The changes also include better handling of the compile_commands.json path. My review identified a critical issue where clang-tidy failures are ignored, a bug in the generation of compile_commands.json, and an unimplemented --verbose option. I've provided code suggestions to address these points. With these fixes, this will be a great enhancement.
| _run_clang_tidy(clang_tidy, tidy_argv, {curdir = projectdir}) | ||
| local sourcefile, tidy_argv = table.unpack(sourcefiles_jobs[index]) | ||
| progress.show(index * 100 / total, "clang-tidy.analyzing %s", sourcefile) | ||
| os.execv(clang_tidy.program, tidy_argv, {curdir = projectdir}) |
There was a problem hiding this comment.
The exit code of os.execv is not checked. If clang-tidy finds issues and returns a non-zero exit code, it will be ignored, and the check will misleadingly appear to succeed. You should check the exit code and raise an error on failure to ensure the xmake check command fails as expected.
local ok = os.execv(clang_tidy.program, tidy_argv, {curdir = projectdir})
if ok ~= 0 then
raise("clang-tidy failed on %s with exit code %d", sourcefile, ok)
end
| local filename = path.filename(db_path) | ||
| db_path = outputdir and path.join(outputdir, filename) or filename | ||
| task.run("project", {quiet = true, kind = "compile_commands", lsp = "clangd", outputdir = outputdir}) |
There was a problem hiding this comment.
The logic for generating compile_commands.json is incorrect when db_path is a directory that does not contain the file. The db_path is incorrectly recalculated, leading to opt.compdbfile pointing to the wrong location. After generating the file in a temporary directory, db_path should be explicitly set to the path of the generated compile_commands.json.
task.run("project", {quiet = true, kind = "compile_commands", lsp = "clangd", outputdir = outputdir})
db_path = path.join(outputdir, "compile_commands.json")
|
没看懂这要干嘛,原本就是多进程了,如果还要细粒度,直接改 32 数字就行了 |
I don't understand what I'm doing. It's just a lot of processes. If you still have fine-grained size, just change 32 numbers. |
clang-tidy对多个文件是串行检查的,一个进程处理32个文件是无法充分利用cpu核心的,因此llvm自带的run-clang-tidy就是一个进程处理一个文件。而且clang-tidy是一个耗时操作,串行执行会非常慢 |
clang-tidy checks multiple files in serial. One process can't make full use of the CPU core by processing 32 files. Therefore, the run-clang-tidy built into llvm is a process processing a file. Moreover, clang-tidy is a time-consuming operation, and serial execution will be very slow |
那直接改下 32 -> 1 不就好了么 |
Then just change it 32 -> 1 Isn't it okay |
1. Remove `verbose` option 2. Use `sourcefiles` directly