Skip to content

feat(clang-tidy): Improve clang-tidy support#6843

Merged
waruqi merged 2 commits intoxmake-io:devfrom
24bit-xjkp:dev
Sep 28, 2025
Merged

feat(clang-tidy): Improve clang-tidy support#6843
waruqi merged 2 commits intoxmake-io:devfrom
24bit-xjkp:dev

Conversation

@24bit-xjkp
Copy link
Contributor

  1. 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.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 clang-tidy integration, primarily by implementing a multi-process parallel analysis strategy. This change directly addresses a core limitation of clang-tidy and is expected to boost analysis speed. Additionally, it enhances the flexibility of specifying compilation database paths and provides a new option for verbose output, making the analysis process more robust and user-friendly.

Highlights

  • Multi-process Parallel Analysis for Clang-Tidy: The clang-tidy integration now utilizes a multi-process approach, running a separate clang-tidy instance for each source file. This addresses the limitation of clang-tidy not supporting parallel analysis within a single process, significantly improving performance for large projects.
  • Enhanced compdb Path Handling: The --compdb option has been improved to accept not only the direct path to a compile_commands.json file but also a directory that contains the file, offering greater flexibility in specifying the compilation database.
  • New Verbose Output Option: A new --verbose option has been added to clang-tidy checks, allowing users to display more detailed output during the analysis process.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

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

Comment on lines +163 to 165
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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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")

@waruqi
Copy link
Member

waruqi commented Sep 22, 2025

没看懂这要干嘛,原本就是多进程了,如果还要细粒度,直接改 32 数字就行了

@waruqi waruqi closed this Sep 22, 2025
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


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.

@24bit-xjkp
Copy link
Contributor Author

没看懂这要干嘛,原本就是多进程了,如果还要细粒度,直接改 32 数字就行了

clang-tidy对多个文件是串行检查的,一个进程处理32个文件是无法充分利用cpu核心的,因此llvm自带的run-clang-tidy就是一个进程处理一个文件。而且clang-tidy是一个耗时操作,串行执行会非常慢

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


I didn't understand what I was doing. It was originally a multi-process. If I had to be fine-grained, just change 32 numbers directly

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

@waruqi
Copy link
Member

waruqi commented Sep 22, 2025

没看懂这要干嘛,原本就是多进程了,如果还要细粒度,直接改 32 数字就行了

clang-tidy对多个文件是串行检查的,一个进程处理32个文件是无法充分利用cpu核心的,因此llvm自带的run-clang-tidy就是一个进程处理一个文件。而且clang-tidy是一个耗时操作,串行执行会非常慢

那直接改下 32 -> 1 不就好了么

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If you don't understand what you are doing, it's just a lot of processes. If you still have to be fine-grained, just change 32 numbers.

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

Then just change it 32 -> 1 Isn't it okay

@waruqi waruqi reopened this Sep 22, 2025
1. Remove `verbose` option
2. Use `sourcefiles` directly
@waruqi waruqi added this to the v3.0.4 milestone Sep 28, 2025
@waruqi waruqi merged commit 2f4d778 into xmake-io:dev Sep 28, 2025
17 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants