Skip to content

Do not provide default_javac_opts for java_common.compile #1685

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
fzakaria opened this issue Jan 24, 2025 · 0 comments · May be fixed by #1686
Open

Do not provide default_javac_opts for java_common.compile #1685

fzakaria opened this issue Jan 24, 2025 · 0 comments · May be fixed by #1686

Comments

@fzakaria
Copy link

fzakaria commented Jan 24, 2025

I've noticed a very odd thing where the javacopts are duplicated if any javacopts are provided for a scala_library.
This only affects if there are Java files in the target

Looking at the code, I can see that the default_javac_opts are being provided to the compile method (https://github.com/bazelbuild/rules_scala/blob/a8ae50ef8c6f9b4bf551e9d6ccf0b796dd07539d/scala/private/rule_impls.bzl#L160)

I can confirm this by looking at the params file (bazel-out/k8-fastbuild/bin/liba_java.jar-0.params)
) created for each JAR and I notice that the default javacopts are duplicated.

example

I created a scala_library

scala_library(
    name = "liba",
    srcs = [
        "LibraryA.scala",
        "LibraryB.java",
    ],
    javacopts = [
        "--release 21",
    ],
)

You can see the duplicate here.

--javacopts
-source
17
-target
17
-XDskipDuplicateBridges=true
-XDcompilePolicy=simple
--should-stop=ifError=FLOW
-g
-parameters
-Xep:ReturnValueIgnored:OFF
-Xep:IgnoredPureGetter:OFF
-Xep:EmptyTopLevelDeclaration:OFF
-Xep:LenientFormatStringValidation:OFF
-Xep:ReturnMissingNullable:OFF
-Xep:UseCorrectAssertInTests:OFF
--release
21
-source
17
-target
17
-XDskipDuplicateBridges=true
-XDcompilePolicy=simple
--should-stop=ifError=FLOW
-g
-parameters
-Xep:ReturnValueIgnored:OFF
-Xep:IgnoredPureGetter:OFF
-Xep:EmptyTopLevelDeclaration:OFF
-Xep:LenientFormatStringValidation:OFF
-Xep:ReturnMissingNullable:OFF
-Xep:UseCorrectAssertInTests:OFF

If I remove the javacopts from the scala_library we get (notice no duplicate)

scala_library(
    name = "liba",
    srcs = [
        "LibraryA.scala",
        "LibraryB.java",
    ],
    javacopts = [
    ],
)
--javacopts
-source
17
-target
17
-XDskipDuplicateBridges=true
-XDcompilePolicy=simple
--should-stop=ifError=FLOW
-g
-parameters
-Xep:ReturnValueIgnored:OFF
-Xep:IgnoredPureGetter:OFF
-Xep:EmptyTopLevelDeclaration:OFF
-Xep:LenientFormatStringValidation:OFF
-Xep:ReturnMissingNullable:OFF
-Xep:UseCorrectAssertInTests:OFF

How I am very stumped, is that given the code I linked, I would expect the duplicate javacopts to always be duplicated, yet if the list is empty, it's only present once.

I suspect this has something to do with depsets and strings but I'm not sure quite yet. 🤷

I've fixed it locally by removing the default inclusion. I think that's a worthwhile fix but I would sure love to understand what's causing this. java_library doesn't suffer from the same symptom but it's calling into the same code in rules_java.

Why is this all a problem?
By duplicating the default javacopts, we are having trouble overwriting toolchain values.

I think there is some similarity to #1550 but the duplication seems to be new/different.

@fzakaria fzakaria reopened this Jan 24, 2025
fzakaria added a commit to fzakaria/rules_scala that referenced this issue Jan 24, 2025
fzakaria added a commit to fzakaria/rules_scala that referenced this issue Jan 24, 2025
@fzakaria fzakaria linked a pull request Jan 24, 2025 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant