bazel-contrib / bazel-gazelle

Gazelle is a Bazel build file generator for Bazel projects. It natively supports Go and protobuf, and it may be extended to support new languages and custom rule sets.
Apache License 2.0
1.19k stars 378 forks source link

feat: add option to persist rule index #1880

Open jbedard opened 1 month ago

jbedard commented 1 month ago

What type of PR is this? Feature

What package or component does this PR mostly affect? cmd/gazelle

What does this PR do? Why is it needed?

Add the ability to persist the RuleIndex across runs to allow updating only the specified directories when indexing is required.

Which issues(s) does this PR fix?

Ref: #1181

jbedard commented 1 month ago

Just to re-iterate a few points and limitations of this:

This is EXPERIMENTAL with no api guarantees. 99% chance there will be breaking changes. You should never commit this file to source-control.

When this EXPERIMENTAL feature is used:

If resolver.Imports/Embeds() have side-effects then this won't work very well when they are cached and not invoked. Don't do that.

There is no cache invalidation here. It is entirely up to the user to pass the correct list of dirs that require reprocessing.

FUTURE: if those updated dirs changed what rules they generate and the Imports/Embeds() of those rules change it is possible that other rules outside dirs are now referencing something incorrect. I think if Imports/Embeds() of those dirs change we might want to re-run Fix + GenerateRules for all directories.