Skip to content
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

[Self-Filed] [Feature] Running clang-tidy from the command line #52

Open
cpsauer opened this issue May 24, 2022 · 3 comments
Open

[Self-Filed] [Feature] Running clang-tidy from the command line #52

cpsauer opened this issue May 24, 2022 · 3 comments

Comments

@cpsauer
Copy link
Contributor

cpsauer commented May 24, 2022

Hey all! Self-filing an issue to collect interest and feedback.

Some people have been using this tool and compile_commands.json to run clang-tidy from the command line. [Clang-tidy can also run as part of clangd while editing.] Sounds like other tools have some issues around headers, which we can solve.

Doing this well would probably involve creating a target that builds a script that runs a bazel-cached clang-tidy aspect over the codebase.

LMK if interested. Would love some help on this one. I do think it'd be much easier to build well within the context of this tool than standalone.

@cpsauer cpsauer changed the title [Feature] Running clang-tidy from the command line [Self-Filed] [Feature] Running clang-tidy from the command line Oct 5, 2022
@aminya
Copy link

aminya commented Nov 3, 2022

An issue that I have with the solution I specified in this comment is that clang-tidy runs sequentially for each code, and It has no caching. So it is very slow for a large project.

So, I guess a Bazel-based solution would be useful here. How hard is it to make bazel-clang-tidy aware of this package? I think it is a matter of checking the existence of compile_command.json and using that.

@cpsauer
Copy link
Contributor Author

cpsauer commented Nov 3, 2022

Right o. Yeah, I think the trickiness here is that you need aspects to get the caching, but you need to use aquery (not aspects) to get the right build command.
[The old extra_action interface had both...but it's deprecated and was slow/had other issues.]

@cpsauer
Copy link
Contributor Author

cpsauer commented Nov 3, 2022

My quick take on the best way to break down each part:

  1. Dump a compile_commands.json using this tool, presumably with exclude_headers = "all", exclude_external_sources = True. It should be very fast with those settings, so we can probably afford to do it every time.
  2. Add caching to the clang-tidy run, having it reference compile_commands.json.
    i. It might be easier to just cache with a third party solution like this one or (likely even better) this one, rather than wrangling with bazel, but I'm not sure. Maybe better to do with Bazel.
    ii. If we did want to do it with Bazel, I think the move would be to do the following: Have an aspect, like the other project, but that depends on the compile_commands.json. It would then have a first set of actions that filters the compile_commands.json down to just the entries for each file--probably sorting them for stability. And then a second set of actions that runs clang_tidy on the files with the commands for that file as a side input. The first action could run really fast--and the second slow one have a high cache hit rate. (We'd need to be careful here about headers and header discovery.)

I probably shouldn't take the lead on this one right now, given everything else going on. But if you take a shot, I'd be down to help!

In short: Would recommend using this tool with exclude_headers = "all", exclude_external_sources = True to generate compile_commands.json. Then experimenting first with piping that into https://github.com/Ericsson/codechecker. If that works well, let's document it so everyone else can benefit, too!

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

No branches or pull requests

2 participants