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

Annotation processor option with space breaks header compiler parsing #19360

Closed
guw opened this issue Aug 29, 2023 · 5 comments
Closed

Annotation processor option with space breaks header compiler parsing #19360

guw opened this issue Aug 29, 2023 · 5 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-Java Issues for Java rules type: support / not a bug (process)

Comments

@guw
Copy link
Contributor

guw commented Aug 29, 2023

Description of the bug:

Turbine header compiler fails to compile java_library with annotation processor because annotation processor options from javacopts are not passed to the header compiler.

java_library(
  name = "A",
  plugins = ["//some/plugin"],
  javacopts = [
    "-Asome.annotation.processor.option=vale1,value2, value3",
  ]
)

Bazel fails with:

ERROR: .. Compiling Java headers ... and running annotation processors (MyGenerator, ..., ...) failed: (Exit 1): java failed: error executing command ...

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
<>: error: An exception occurred in MyGenerator:
java.lang.IllegalArgumentException: Property some.annotation.processor.option invalid 
	at MyGenerator.init(...)
	at com.google.turbine.binder.Processing.process(Processing.java:131)
	at com.google.turbine.binder.Binder.bind(Binder.java:107)
	at com.google.turbine.main.Main.bind(Main.java:270)
	at com.google.turbine.main.Main.compile(Main.java:162)
	at com.google.turbine.main.Main.compile(Main.java:133)
	at com.google.turbine.main.Main.main(Main.java:89)

Inspecting the .param files show the javacopt are actually passed to the header compiler. It looks like the header compiler is not passing them to the annotation processor.

cat bazel-out/....-hjar.jar-0.params
...
--javacopts
-Asome.annotation.processor.option=vale1,value2, value3
...

This looks to be related to the space in the annotation processor option.
It's added as a single line in the .params file but the Turbine header compiler seems to parse it incorrectly.

Which category does this issue belong to?

Java Rules

What is the output of bazel info release?

6.3.2

@guw guw changed the title java_library javacopts not passed to header compiler java_library javacopts not passed to annotation processor from header compiler Aug 29, 2023
@guw guw changed the title java_library javacopts not passed to annotation processor from header compiler Annotation processor option with space breaks header compiler parsing Aug 29, 2023
guw added a commit to guw/turbine that referenced this issue Aug 29, 2023
@iancha1992 iancha1992 added the team-Rules-Java Issues for Java rules label Aug 29, 2023
copybara-service bot pushed a commit to google/turbine that referenced this issue Sep 11, 2023
Add a test to reproduce bazelbuild/bazel#19360

Fixes #272

FUTURE_COPYBARA_INTEGRATE_REVIEW=#272 from guw:main b2b7c2b
PiperOrigin-RevId: 564393335
copybara-service bot pushed a commit to google/turbine that referenced this issue Sep 11, 2023
Add a test to reproduce bazelbuild/bazel#19360

Fixes #272

COPYBARA_INTEGRATE_REVIEW=#272 from guw:main b2b7c2b
PiperOrigin-RevId: 564447484
@hvadehra
Copy link
Member

Considering that the java rules tokenize javacopts, I would expect

  javacopts = [
    "-Asome.annotation.processor.option=vale1,value2, value3",
  ]

to fail with an error like error: invalid flag: value3

@guw Does this need something more to reproduce?

@guw
Copy link
Contributor Author

guw commented Sep 13, 2023

@hvadehra Not that I am aware of. Which tokenization are you referring to? Do you have a link to the code?

@guw
Copy link
Contributor Author

guw commented Sep 13, 2023

Ah ... thanks for sharing that code. I omitted a tiny detail: '. Here is how the annotation processor option is actually being populated in our macro.

   javacopts.append("-Asome.annotation.processor.option='%s'" % generator.get("option"))

The correct value is:

  javacopts = [
    "-Asome.annotation.processor.option='vale1,value2, value3'",
  ]

This is handled/supported by the tokenization.

@hvadehra
Copy link
Member

Ah, thanks, that makes sense. Looks like JavaBuilder behaves as expected and it's only turbine that is splitting this incorrectly.

Presumably this has been fixed by google/turbine#272, so all we need now is a turbine release and updating that in Bazel.

@hvadehra hvadehra added type: support / not a bug (process) P2 We'll consider working on this in future. (Assignee optional) and removed more data needed type: bug labels Sep 13, 2023
cushon added a commit to cushon/bazel that referenced this issue Sep 22, 2023
cushon added a commit to cushon/bazel that referenced this issue Sep 25, 2023
treblereel pushed a commit to treblereel/turbine that referenced this issue Sep 28, 2023
Add a test to reproduce bazelbuild/bazel#19360

Fixes google#272

COPYBARA_INTEGRATE_REVIEW=google#272 from guw:main b2b7c2b
PiperOrigin-RevId: 564447484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-Java Issues for Java rules type: support / not a bug (process)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants