Skip to content

feat: clang-tidy emit action per file to lint #512

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

molar
Copy link
Contributor

@molar molar commented Apr 3, 2025

Some cc_library/binary targets may contain 10+ files listed in sources and as clang-tidy runs single threaded, this can lead
to long running linting actions. This PR emits a clang-tidy action per source file, so they can be parallelised locally/remotely. The stdout/stderror is merged in unspecified order according to the order of the srcs using a simple
concatenation. The exit_code of the individual action, is merged by sorting them numerically and selecting the highest number.

I did also consider making the splitting optional, in case we are unsure of the impact of this change. Let me know if i should do that.

I also considered updated the progress message to use the source file short path instead, but decided to leave it out here. Currently the progress message will be the same for each individual action and makes it harder to see which source file is being linted.

Test plan

  • Covered by existing test cases
  • Manual testing was also done, both in our own bazel repo and in the examples folder. It has only been tested on linux, so there could be issues with the behaviour of sort and head on macOS.
  • I would like some guidance on testing the fix part as we do not use the aspect wrapper in-house

@molar molar changed the title clang-tidy emit action per file to lint and merge stdout and error codes [feat] clang-tidy emit action per file to lint and merge stdout and error codes Apr 3, 2025
@molar molar changed the title [feat] clang-tidy emit action per file to lint and merge stdout and error codes [feat] clang-tidy emit action per file to lint Apr 3, 2025
@molar molar changed the title [feat] clang-tidy emit action per file to lint feat: clang-tidy emit action per file to lint Apr 9, 2025
@molar
Copy link
Contributor Author

molar commented May 1, 2025

Friendly ping @alexeagle do you have some input or can you kindly suggest a reviewer?

@alexeagle
Copy link
Member

I'm sorry - I looked through this once and then got in my head that it was blocked on something.

It's a bit complex/gross to have to merge the exit codes back together this way. like you say, it's using non-hermetic system tools, plus space delimiting is risky when filenames can have spaces, so may need some quoting work.

Is it possible to move the splitting earlier? I'm imagining the aspect visits a cc_library target and produces an action per file at that point. Bazel sees all the actions and can react to the non-zero exit code(s) itself. I think there's no need to aggregate the results back to the library level, right?

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.

2 participants