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

Include clang-tidy binary in the cache fingerprint #4

Merged
merged 2 commits into from
Oct 30, 2021

Conversation

dean0x7d
Copy link
Contributor

@dean0x7d dean0x7d commented Sep 5, 2021

Hi @ejfitzgerald, thanks for this project! I've found it incredibly useful!

The speedup is amazing and I'm looking to integrate the cache in a CI pipeline but I've run into a couple of things that don't quite fit into our CI workflow. This PR resolves that and I'm hoping that these changes will be useful for all users.

clang-tidy binary in the cache fingerprint

Let's say that you run clang-tidy-cache with clang-tidy-11 on a project and warm up the cache. Then you upgrade to clang-tidy-12 and run it again. Currently, that results in all cache hits but that isn't correct: clang-tidy-12 has new checks that must run. The old cache entries aren't valid for this version. This is an important issue for correctness in CI with a shared cache where clang-tidy upgrades can happen on any branch/repo (so it's not practical to wipe the cache).

The fix proposed by this PR is to add the clang-tidy binary itself to the cache fingerprint. This ensures that any changes in the executable (like version upgrades) will miss old cache entries. Adding clang-tidy --version could have been another option, but SHA256 felt both simpler and more robust.

Config defaults and environment variable overrides

This one's just about ease of use. It's simpler for users to get started if they don't need to create a config file at all, so this PR provides a default: if there's no config file, simply use the clang-tidy that's on the path.

It's also often useful to be able to override the config via env variables without touching the config file: CLANG_TIDY_CACHE_BINARY makes that possible. I find the variable easier to automate in CI than writing to a config file.

The priority of the configuration is set up the same way as ccache. From highest to lowest priority: 1. Environment variables. 2. Config file. 3. Built-in defaults.

It's simpler for users to get started if they don't need to create
a config file at all, so this commit provides a default: simply use
the `clang-tidy` that's on the path.

It's also often useful to be able to override the config via env
variables without touching the config file: `CLANG_TIDY_CACHE_BINARY`
makes that possible.
Different clang-tidy versions affect the check results just like the
`.clang-tidy` config file. Add the contents of the binary ensures that
we don't get bad cache hits when upgrading clang-tidy versions.
@ejfitzgerald
Copy link
Owner

Sorry for the delay @dean0x7d - this looks like a good update. Will have a look over it today and will look to include it in a new build next week

@dean0x7d
Copy link
Contributor Author

Thanks, @ejfitzgerald! We've been running this on CI for the last month and it's been working great!

One other thing that we realized a bit later is that we needed a feature equivalent to CCACHE_BASEDIR to allow cache reuse on CI. I've added that here: dean0x7d@20d6dc6 I'd be happy to make another PR for that (or just add it to this one) if that sounds good to you. Let me know what you think.

@ejfitzgerald ejfitzgerald merged commit 9c9355b into ejfitzgerald:master Oct 30, 2021
@ejfitzgerald
Copy link
Owner

@dean0x7d I think the CCACHE_BASEDIR would be a good additional feature. Happy to accept another PR when you get time

mathstuf pushed a commit to mathstuf/clang-tidy-cache that referenced this pull request Jan 18, 2023
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