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

User-accessible JavaInfo constructor doesn't allow changing module_flags_info #20033

Closed
timothyg-stripe opened this issue Nov 2, 2023 · 8 comments

Comments

@timothyg-stripe
Copy link
Contributor

timothyg-stripe commented Nov 2, 2023

Description of the feature request:

The user-accessible JavaInfo constructor runs _javainfo_init, which does not allow customizing module_flags_info. This means that it's impossible to replicate some of the semantics of java_info_for_compilation that would be useful for third party rulesets (like rules_scala), like:

  1. It's impossible to make add_exports and add_opens attributes for a third-party rule
  2. It's impossible to merge in runtime_deps' add_exports and add_opens, since _javainfo_init only merges the module flags for deps and exports.

A few ways to resolve this are:

  1. The proper fix (IMO):
    1. Add some options to the JavaInfo constructor, like add_exports and add_opens (for "direct" rule attributes).
    2. Change the behavior of JavaInfo constructor so that add_exports and add_opens are merged for runtime_deps in addition to just deps & exports. This is IMO the right thing to do anyway, and reduces the delta between JavaInfo and java_info_for_compilation, though it changes some user-visible behavior and probably requires an --[no]incompatible_ flag.
  2. Provide a factory function for JavaInfo that simply wraps a module_flags_info. Then, users can call java_common.merge([JavaInfo(…), java_common.wrap_module_flags_info(…)]).
  3. Loosen java_common.merge input validation to allow JavaInfo-lookalikes rather than strictly JavaInfo objects. Then we can create a fake JavaInfo with module_flags_info set correctly, and call java_common.merge to legitimize it.
  4. Expose _java_common_internal.wrap_java_info to users so that they can legitimize their JavaInfo lookalikes.

I'm happy to provide a patch. Please let me know which approach seems the most reasonable.

cc @hvadehra @cushon

Which category does this issue belong to?

Java Rules, Rules API

What underlying problem are you trying to solve with this feature?

No response

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@timothyg-stripe
Copy link
Contributor Author

timothyg-stripe commented Nov 2, 2023

I've made two PRs that implement approach 1 above:

@iancha1992
Copy link
Member

iancha1992 commented Nov 2, 2023

@timothyg-stripe awesome! can you actually resubmit this one, timothyg-stripe#1 against the bazelbuild repo instead of your own, so that we can assign and review it?

@timothyg-stripe
Copy link
Contributor Author

@iancha1992 Done – I refrained from doing that at first since there's a merge conflict between the two PRs, but I can fix up the conflict later when one of the two PRs gets merged.

copybara-service bot pushed a commit that referenced this issue Nov 8, 2023
There is currently no non-hacky way for third-party rule implementations to add `add_exports` and `add_opens` to a `JavaInfo`, though hacky ways exist (like using a macro to generate a `java_library` with `add_exports` / `add_opens` and add it as a dependency).

Having an official way to create `JavaInfo`s with `add_exports` and `add_opens` helps third-party JVM rules better support JDK 9+ (and especially 17+, which requires `--add-opens` flags to access JDK internals through reflection).

Addresses half of #20033.

Closes #20036.

PiperOrigin-RevId: 580472097
Change-Id: I159e3410c5480ac683fd9af85bfd1d83ac0e6d8a
copybara-service bot pushed a commit that referenced this issue Nov 16, 2023
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x.

Second half of #20033

Closes #20037.

PiperOrigin-RevId: 582982387
Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
@timothyg-stripe
Copy link
Contributor Author

timothyg-stripe commented Nov 17, 2023

@iancha1992 Can we backport #20036 and #20037 to 7.0?

iancha1992 pushed a commit to iancha1992/bazel that referenced this issue Nov 17, 2023
There is currently no non-hacky way for third-party rule implementations to add `add_exports` and `add_opens` to a `JavaInfo`, though hacky ways exist (like using a macro to generate a `java_library` with `add_exports` / `add_opens` and add it as a dependency).

Having an official way to create `JavaInfo`s with `add_exports` and `add_opens` helps third-party JVM rules better support JDK 9+ (and especially 17+, which requires `--add-opens` flags to access JDK internals through reflection).

Addresses half of bazelbuild#20033.

Closes bazelbuild#20036.

PiperOrigin-RevId: 580472097
Change-Id: I159e3410c5480ac683fd9af85bfd1d83ac0e6d8a
iancha1992 pushed a commit to iancha1992/bazel that referenced this issue Nov 17, 2023
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x.

Second half of bazelbuild#20033

Closes bazelbuild#20037.

PiperOrigin-RevId: 582982387
Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
iancha1992 pushed a commit to iancha1992/bazel that referenced this issue Nov 17, 2023
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x.

Second half of bazelbuild#20033

Closes bazelbuild#20037.

PiperOrigin-RevId: 582982387
Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
@keertk
Copy link
Member

keertk commented Nov 18, 2023

Hi @timothyg-stripe would you mind just sending a PR against the release-7.0.0 branch with all the changes you need? Since we're cutting it very close to the final RC, this would save us the back and forth.
For now, I'm going to close the cherry-pick PRs we've opened.

@keertk
Copy link
Member

keertk commented Nov 18, 2023

@bazel-io fork 7.0.0

timothyg-stripe added a commit to timothyg-stripe/bazel that referenced this issue Nov 18, 2023
There is currently no non-hacky way for third-party rule implementations to add `add_exports` and `add_opens` to a `JavaInfo`, though hacky ways exist (like using a macro to generate a `java_library` with `add_exports` / `add_opens` and add it as a dependency).

Having an official way to create `JavaInfo`s with `add_exports` and `add_opens` helps third-party JVM rules better support JDK 9+ (and especially 17+, which requires `--add-opens` flags to access JDK internals through reflection).

Addresses half of bazelbuild#20033.

Closes bazelbuild#20036.

PiperOrigin-RevId: 580472097
Change-Id: I159e3410c5480ac683fd9af85bfd1d83ac0e6d8a
timothyg-stripe added a commit to timothyg-stripe/bazel that referenced this issue Nov 18, 2023
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x.

Second half of bazelbuild#20033

Closes bazelbuild#20037.

PiperOrigin-RevId: 582982387
Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
timothyg-stripe added a commit to timothyg-stripe/bazel that referenced this issue Nov 18, 2023
Change the behavior of `JavaInfo` constructor to be more like `java_info_for_compilation`, by merging in the `add_exports` and `add_opens` flags for `runtime_deps` in addition to just `deps` and `exports`. Guard it under an `--incompatible_` flag which defaults to false, but I'm hoping to make it default to true in 8.x.

Second half of bazelbuild#20033

Closes bazelbuild#20037.

PiperOrigin-RevId: 582982387
Change-Id: Ibff680f71efed82f20da7d9ee83f0bfa7e5f5697
@timothyg-stripe
Copy link
Contributor Author

@keertk Done: #20260

@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.0.0 RC5. Please test out the release candidate and report any issues as soon as possible. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants