You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Optionally respect java_export during resolution (#347)
Implement support for `java_export`s. See #344 for a description of the
problem.
Constraints we have to work with:
- We make no attempt to modify `java_export` targets. They are meant to
be hand-crafted by the user.
- `java_export` uses an aspect to accumulate transitive dependency
information about its dependencies. We need this transitive dependency
information, and the Gazelle index doesn't give it to us. Therefore, we
have to store it out of band, in `java_export_index.go`. The community
seems to agree that the Gazelle API doesn't allow for this ([GH
Issue](bazel-contrib/bazel-gazelle#2123),
[Slack
discussion](https://bazelbuild.slack.com/archives/C01HMGN77Q8/p1750412735065129)).
- It's possible for a `java_export` to depend on a package that is _not_
in a subdirectory. Therefore, we can't rely on the `Imports` or `Embeds`
phase to operate on the transitive dependency information, because some
relevant packages may not have been analyzed by the time we get to a
`java_export`. There is a test case covering this. As a result, the
`java_export_index` is split into two phases:
- The first phase happens during `GenerateRules`, we note down
information about all `java_exports`, as well as information to resolve
their transitive dependencies.
- At the end of `GenerateRules`, in the `DoneGeneratingRules` hook, we
traverse the information we've collected to figure out which Java
packages are accessible from a given `java_export`.
- The second phase happens during `Resolve`, where we use the data we've
collected to resolve to a `java_export`, if possible.
- This feature can only be turned on via the `#
gazelle:java_resolve_to_java_exports` directive. This directive can only
be set once, and it has to be set at the root of the repository.
- It can only be set once to avoid edge cases where a package opts out
of resolving to `java_exports`, but it is inside a `java_export` itself.
- It can only be set at the root of the repository because we need to
run Gazelle over the entire repository, to make sure we capture all the
transitive dependencies.
[This
commit](https://bazelbuild.slack.com/archives/C01HMGN77Q8/p1750412735065129)
is an example of running this Gazelle extension in the Selenium
repository after massaging the BUILD files a bit to fit the constraints
of `java_exports`.
Closes#344
0 commit comments