-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add --experimental_java_classpath=bazel_no_fallback
option
#24876
base: master
Are you sure you want to change the base?
Conversation
does this mean that the change would need to be back-compatible with versions of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some notes in the bug
classpathLine.add("--reduce_classpath_mode", fallback ? "BAZEL_FALLBACK" : "BAZEL_REDUCED"); | ||
classpathLine.add("--reduce_classpath_mode", | ||
fallback ? "BAZEL_FALLBACK" | ||
: (classpathMode == JavaClasspathMode.BAZEL ? "BAZEL_REDUCED" : "BAZEL_REDUCED_NO_FALLBACK")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding the new --reduce_classpath_mode=BAZEL_REDUCED_NO_FALLBACK
mode, did you consider having Bazel invoke JavaBuilder with a reduced classpath and pass --reduce_classpath_mode=NONE
, and then handle not doing fallback on the Bazel side? I think that would provide equivalent behaviour without JavaBuilder changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx, that's much better. Pushed the change.
There is still 1 test failure, but seems unrelated to the change:
test_size_less_than_385MB FAILED: terminated because this command returned a non-zero status:
/private/var/tmp/_bazel_buildkite/1198ee8566c303641c6d358da6949c16/sandbox/darwin-sandbox/4799/execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/src/test/shell/integration/minimal_jdk_test.runfiles/_main/src/test/shell/integration/minimal_jdk_test:50: in call to test_size_less_than_385MB
@cushon could you please merge this? |
Would it be possible to add a test for the scenario where the build fails when it otherwise would succeeded with fallback? |
Setting up a sample project that requires fallback to succeed would be challenging since fallback only occurs in rare compiler edge cases. Is there an existing Java test project that relies on fallback and that I could use?. The test for
If a test is necessary, I can look into creating one. |
|
@hvadehra added the test, the window's failures seem unrelated to my change |
Thanks for adding the test!
But the failures are all in the newly added |
Oh sorry, I got confused looking only at the main log. The test failure is because on windows the reduced classpath compilation fails with:
instead of with:
this seems to imply that the reduced classpath calculation in windows may be incorrect in general, e.g. that for windows |
@rsalvador Great find! Looks like this line is problematic on Windows: |
Tried submitting a windows fix, but still fails with the same problem. I don't have a windows machine and can't debug this. |
Could you try this patch? Some tests should still fail as they need a new rules_java / java_tools release. ---a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java
@@ -46,6 +46,7 @@ import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Log.WriterKind;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;
+import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
@@ -337,13 +338,11 @@ public final class StrictJavaDepsPlugin extends BlazeJavaCompilerPlugin {
// Also update the dependency proto
Dependency dep =
Dependency.newBuilder()
- // Path.toString uses the platform separator (`\` on Windows) which may not
- // match the format in params files (which currently always use `/`, see
- // bazelbuild/bazel#4108). JavaBuilder should always parse Path strings into
- // java.nio.file.Paths before comparing them.
+ // Path.toString uses the platform separator (`\` on Windows), but the proto must
+ // use the same separator as in the arguments.
//
// An empty path is OK in the cases we produce it. See readJarOwnerFromManifest.
- .setPath(jar.pathOrEmpty().toString())
+ .setPath(jar.pathOrEmpty().toString().replace(File.separatorChar, '/'))
.setKind(Dependency.Kind.EXPLICIT)
.build();
directDependenciesMap.put(jar.pathOrEmpty(), dep); |
It is failing with the same errors. |
I ran this with some debug prints on a separate branch (#25435) and got this output:
Some paths correctly use forward slashes, others don't. I wonder whether that is because of this line in Turbine. |
re: the removed 'JavaBuilder should always parse Path strings into java.nio.file.Paths before comparing them' logic To check my understanding, is the issue we were seeing here that it wasn't doing that, or that the logic in Bazel that doing reduced classpaths would have needed to do that but wasn't? Either way, normalizing the jdeps to be consistent and to match the format in params files, instead of having to work around it downstream, seems like a good thing to do. |
The comment only referred to the reduced classpath logic in JavaBuilder, which does parse the string into a |
Work towards bazelbuild/bazel#24876 (comment) Fixes #363 FUTURE_COPYBARA_INTEGRATE_REVIEW=#363 from fmeum:patch-1 311cb80 PiperOrigin-RevId: 732940097
Work towards bazelbuild/bazel#24876 (comment) Fixes #363 FUTURE_COPYBARA_INTEGRATE_REVIEW=#363 from fmeum:patch-1 311cb80 PiperOrigin-RevId: 732940097
Work towards bazelbuild/bazel#24876 (comment) Fixes #363 FUTURE_COPYBARA_INTEGRATE_REVIEW=#363 from fmeum:patch-1 311cb80 PiperOrigin-RevId: 732940097
Work towards bazelbuild/bazel#24876 (comment) Fixes #363 FUTURE_COPYBARA_INTEGRATE_REVIEW=#363 from fmeum:patch-1 311cb80 PiperOrigin-RevId: 732940097
Work towards bazelbuild/bazel#24876 (comment) Fixes #363 FUTURE_COPYBARA_INTEGRATE_REVIEW=#363 from fmeum:patch-1 311cb80 PiperOrigin-RevId: 733040044
Work towards bazelbuild/bazel#24876 (comment) Fixes #363 FUTURE_COPYBARA_INTEGRATE_REVIEW=#363 from fmeum:patch-1 311cb80 PiperOrigin-RevId: 732940097
Work towards bazelbuild/bazel#24876 (comment) Fixes #363 COPYBARA_INTEGRATE_REVIEW=#363 from fmeum:patch-1 311cb80 PiperOrigin-RevId: 733047922
@rsalvador I sent #24876 with the Windows fixes. Once it has been merged, your new test should pass after you rebase and add this snippet to the top:
After the next rules_java update in Bazel, you could then send a follow-up PR to drop these lines. |
The reduced classpath computation for Java compilation actions with deps on jdeps files that were produced on Windows always resulted in an empty reduced classpath since both JavaBuilder and Turbine emitted backslash-separated paths into the jdeps proto, but Bazel matches them against slash-separated paths. This is fixed by changing JavaBuilder to always emit slash-separated paths and updating Turbine to a version that does so (google/turbine#363). Work towards #24876, which will also provide an integration test. Closes #25435. PiperOrigin-RevId: 733284003 Change-Id: Ide29965d4676fdd2bda4baaced50f984ee7284f0
4047475
to
0dc1476
Compare
@bazel-io fork 8.2.0 |
The reduced classpath computation for Java compilation actions with deps on jdeps files that were produced on Windows always resulted in an empty reduced classpath since both JavaBuilder and Turbine emitted backslash-separated paths into the jdeps proto, but Bazel matches them against slash-separated paths. This is fixed by changing JavaBuilder to always emit slash-separated paths and updating Turbine to a version that does so (google/turbine#363). Work towards bazelbuild#24876, which will also provide an integration test. Closes bazelbuild#25435. PiperOrigin-RevId: 733284003 Change-Id: Ide29965d4676fdd2bda4baaced50f984ee7284f0
The reduced classpath computation for Java compilation actions with deps on jdeps files that were produced on Windows always resulted in an empty reduced classpath since both JavaBuilder and Turbine emitted backslash-separated paths into the jdeps proto, but Bazel matches them against slash-separated paths. This is fixed by changing JavaBuilder to always emit slash-separated paths and updating Turbine to a version that does so (google/turbine#363). Work towards bazelbuild#24876, which will also provide an integration test. Closes bazelbuild#25435. PiperOrigin-RevId: 733284003 Change-Id: Ide29965d4676fdd2bda4baaced50f984ee7284f0 (cherry picked from commit 752f72b)
This change introduces a new option,
--experimental_java_classpath=bazel_no_fallback
, which operates similarly to--experimental_java_classpath=bazel
but does not fall back to the full transitive classpath. Instead, the build fails if javac cannot compile with the reduced classpath.Fixes #24875