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

Fix reference to java_infos in compile.bzl #915

Merged
merged 4 commits into from
Jan 13, 2023

Conversation

avarun42
Copy link
Contributor

@avarun42 avarun42 commented Jan 13, 2023

compile.bzl was incorrectly referencing the variable java_info in cases where annotation processors were found, causing compilation to fail as this variable had not been assigned yet. We must first get the outputs from each java_info inside java_infos, and then use a nested list comprehension to get the jars list from each outputs, flatten the resulting list, and get the class_jar field of each jars object inside the flattened list.

Fixes #877

`compile.bzl` was incorrectly referencing `java_info` instead of `java_infos` in cases where annotation processors were found, causing compilation to fail with an opaque error (bazelbuild#877). This fixes the reference.
Fixing the typo resulted in the following error:

```
Traceback (most recent call last):
	File "/workdir/kotlin/internal/jvm/impl.bzl", line 219, column 36, in kt_jvm_library_impl
		_kt_jvm_produce_jar_actions(ctx, "kt_jvm_library") if ctx.attr.srcs or ctx.attr.resources else export_only_providers(
	File "/workdir/kotlin/internal/jvm/compile.bzl", line 493, column 50, in kt_jvm_produce_jar_actions
		outputs_struct = _run_kt_java_builder_actions(
	File "/workdir/kotlin/internal/jvm/compile.bzl", line 751, column 66, in _run_kt_java_builder_actions
		ap_class_jar = [jars.class_jar for jars in java_infos.outputs.jars][0],
Error: 'list' value has no field or method 'outputs'
```

`java_infos` is a list and thus doesn't have an `outputs` field, but each `java_info` inside the list does. Thus replacing `java_infos.outputs.jars` with the list comprehension `[java_info.outputs.jars for java_info in java_infos]` gets us a list of `jars` objects that can be used in the outer list comprehension.
@restingbull
Copy link
Collaborator

Oh, facepalm.

It didn't fail more often because of https://github.com/bazelbuild/rules_kotlin/blob/master/kotlin/internal/jvm/compile.bzl#L694.

I hate that about python scoping.

@restingbull restingbull merged commit d7cf3fd into bazelbuild:master Jan 13, 2023
@avarun42
Copy link
Contributor Author

Ah yes I was wondering why the tests only started failing after changing the reference. Python scoping is... not the greatest.

Any ETA on when a 1.7.2 can be cut with the fix?

@avarun42 avarun42 deleted the patch-1 branch January 17, 2023 15:52
@avarun42
Copy link
Contributor Author

bump on getting this fix released — we're currently unable to use any version of this package starting from 1.6.0 due to this bug

@restingbull

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.

_run_kt_java_builder_actions references unassigned java_info variable
2 participants