From a5de6953beb210aa1bdb48756ac219e0f848fcc9 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sun, 17 May 2020 12:31:35 +0200 Subject: [PATCH] Add incompatible_use_java_tools_beta_release option Fixes #11446. Java tools are decoupled from Bazel distribution and downloaded from java_tools repository. If some of the tools is updated, the archive name is changed in Bazel and new Bazel release is conducted. If, however, new tool has some breaking changes, then the upgrade needs to be rolled back. To make user experience with upgrading tools less disruptive but still not unnecessary procrastinate releases of important Java tools like javac and Error Prone --incompatible_use_java_tools_beta_release is added and CI-job should be set up to check all downstream projects against upcoming java_tools release. Test Plan: 1. Upgrade Error Prone version to 2.3.4 Bazel that is known to have breaking changes and will break all Bazel users who rely on cross compilation use case. There are ongoing efforts to demote the offensive EP checks to warning severity instead of error, though: [1]. 2. Bump java_tools in beta_release archive to new java_tools distribution that includes Error Prone 2.3.4 3. Build rules_closure with --incompatible_use_java_tools_beta_release would fail with the known issue, because of unsatisfied dependency on javax.annotation: ERROR: /home/davido/projects/rules_closoure/java/io/bazel/rules/closure/BUILD:41:13: Building java/io/bazel/rules/closure/libtarjan.jar (1 source file) and running annotation processors (AutoAnnotationProcessor, AutoOneOfProcessor, AutoValueProcessor) failed (Exit 1) bazel-out/host/bin/java/io/bazel/rules/closure/_javac/tarjan/libtarjan_sourcegenfiles/io/bazel/rules/closure/AutoValue_Tarjan_Result.java:6: error: [ExtendsAutoValue] Do not extend an @AutoValue/@AutoOneOf class in non-generated code. final class AutoValue_Tarjan_Result extends Tarjan.Result { ^ (see https://errorprone.info/bugpattern/ExtendsAutoValue) See also upstream issue with in depth explanation what is going on there: [2] 4. Build rules_closure without the incompatible option: all is fine. That would mean, that all broken downstream projects would have enough time to adapt their build tool chains for upgraded dependencies in java_tools distribution. [1] https://github.com/google/error-prone/issues/1619 [2] https://github.com/bazelbuild/rules_closure/issues/483 Change-Id: I352297a8d0d86cecf30821c132c7871383e49b50 --- WORKSPACE | 43 +++++++++++++++++-- src/BUILD | 3 ++ .../build/lib/bazel/rules/java/jdk.WORKSPACE | 29 +++++++++++++ .../lib/rules/java/JavaConfiguration.java | 7 ++- .../build/lib/rules/java/JavaOptions.java | 19 +++++++- src/test/py/bazel/test_base.py | 3 ++ src/test/shell/testenv.sh | 3 ++ tools/jdk/BUILD | 11 +++++ 8 files changed, 111 insertions(+), 7 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 0ab394dc64e9cd..40922d56ea3fea 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -578,15 +578,15 @@ load("//scripts/docs:doc_versions.bzl", "DOC_VERSIONS") # Load shared base CSS theme from bazelbuild/bazel-website http_archive( name = "bazel_website", - urls = ["https://github.com/bazelbuild/bazel-website/archive/c174fa288aa079b68416d2ce2cc97268fa172f42.tar.gz"], - strip_prefix = "bazel-website-c174fa288aa079b68416d2ce2cc97268fa172f42", - sha256 = "a5f531dd1d62e6947dcfc279656ffc2fdf6f447c163914c5eabf7961b4cb6eb4", # TODO(https://github.com/bazelbuild/bazel/issues/10793) # - Export files from bazel-website's BUILD, instead of doing it here. # - Share more common stylesheets, like footer and navbar. build_file_content = """ exports_files(["_sass/style.scss"]) -""" +""", + sha256 = "a5f531dd1d62e6947dcfc279656ffc2fdf6f447c163914c5eabf7961b4cb6eb4", + strip_prefix = "bazel-website-c174fa288aa079b68416d2ce2cc97268fa172f42", + urls = ["https://github.com/bazelbuild/bazel-website/archive/c174fa288aa079b68416d2ce2cc97268fa172f42.tar.gz"], ) # Skydoc recommends declaring its dependencies via "*_dependencies" functions. @@ -715,6 +715,17 @@ http_archive( ], ) +# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. +http_archive( + name = "remote_java_tools_beta_linux_for_testing", + patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE, + patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN, + sha256 = "74d30ccf161c58bb69db9b2171c954a0563b2d1ff6f5831debbe71ced105c388", + urls = [ + "https://github.com/davido/java_tools/releases/download/javac11-v11.0/java_tools_javac11_linux-v11.0.zip", + ], +) + # This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. http_archive( name = "remote_java_tools_windows_for_testing", @@ -727,6 +738,18 @@ http_archive( ], ) +# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. +http_archive( + name = "remote_java_tools_windows_beta_for_testing", + patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE, + patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN, + sha256 = "444c391977e50af4e10549a28d021069d2ca7745a0e7b9b968a7b153fe3ea430", + urls = [ + "https://mirror.bazel.build/bazel_java_tools/releases/javac11/v8.0/java_tools_javac11_windows-v8.0.zip", + "https://github.com/bazelbuild/java_tools/releases/download/javac11_v8.0/java_tools_javac11_windows-v8.0.zip", + ], +) + # This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. http_archive( name = "remote_java_tools_darwin_for_testing", @@ -739,6 +762,17 @@ http_archive( ], ) +# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. +http_archive( + name = "remote_java_tools_darwin_beta_for_testing", + patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE, + patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN, + sha256 = "252520f0cd5dd7e9b18062dc731f8ae248993650f12a9b613fcd9ebda591d242", + urls = [ + "https://github.com/davido/java_tools/releases/download/javac11-v11.0/java_tools_javac11_darwin-v11.0.zip", + ], +) + # This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives. http_archive( name = "remote_java_tools_javac11_test_linux", @@ -921,4 +955,5 @@ register_local_rc_exe_toolchains() register_toolchains("//src/main/res:empty_rc_toolchain") load("//tools/distributions/debian:deps.bzl", "debian_deps") + debian_deps() diff --git a/src/BUILD b/src/BUILD index 0d46818463b214..6b53e7236b229b 100644 --- a/src/BUILD +++ b/src/BUILD @@ -747,6 +747,7 @@ filegroup( "@openjdk_macos_minimal//file", "@openjdk_win_minimal//file", "@remote_coverage_tools_for_testing//:WORKSPACE", + "@remote_java_tools_darwin_beta_for_testing//:WORKSPACE", "@remote_java_tools_darwin_for_testing//:WORKSPACE", "@remote_java_tools_javac11_test_darwin//:WORKSPACE", "@remote_java_tools_javac11_test_linux//:WORKSPACE", @@ -754,7 +755,9 @@ filegroup( "@remote_java_tools_javac12_test_darwin//:WORKSPACE", "@remote_java_tools_javac12_test_linux//:WORKSPACE", "@remote_java_tools_javac12_test_windows//:WORKSPACE", + "@remote_java_tools_linux_beta_for_testing//:WORKSPACE", "@remote_java_tools_linux_for_testing//:WORKSPACE", + "@remote_java_tools_windows_beta_for_testing//:WORKSPACE", "@remote_java_tools_windows_for_testing//:WORKSPACE", "@remotejdk11_linux_aarch64_for_testing//:WORKSPACE", "@remotejdk11_linux_for_testing//:WORKSPACE", diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE index 95f7f0b797803e..65755a22b17e0f 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE @@ -152,6 +152,15 @@ maybe( ], ) +maybe( + http_archive, + name = "remote_java_tools_linux_beta", + sha256 = "74d30ccf161c58bb69db9b2171c954a0563b2d1ff6f5831debbe71ced105c388", + urls = [ + "https://github.com/davido/java_tools/releases/download/javac11-v11.0/java_tools_javac11_linux-v11.0.zip", + ], +) + # This must be kept in sync with the top-level WORKSPACE file. maybe( http_archive, @@ -163,6 +172,17 @@ maybe( ], ) +# TODO(davido): Build java_tools beta release on "other" platform +maybe( + http_archive, + name = "remote_java_tools_windows_beta", + sha256 = "444c391977e50af4e10549a28d021069d2ca7745a0e7b9b968a7b153fe3ea430", + urls = [ + "https://mirror.bazel.build/bazel_java_tools/releases/javac11/v8.0/java_tools_javac11_windows-v8.0.zip", + "https://github.com/bazelbuild/java_tools/releases/download/javac11_v8.0/java_tools_javac11_windows-v8.0.zip", + ], +) + # This must be kept in sync with the top-level WORKSPACE file. maybe( http_archive, @@ -174,6 +194,15 @@ maybe( ], ) +maybe( + http_archive, + name = "remote_java_tools_darwin_beta", + sha256 = "252520f0cd5dd7e9b18062dc731f8ae248993650f12a9b613fcd9ebda591d242", + urls = [ + "https://github.com/davido/java_tools/releases/download/javac11-v11.0/java_tools_javac11_darwin-v11.0.zip", + ], +) + maybe( http_archive, "rules_java", diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java index 022fd64cd05e7e..d5bfee00fa4bcb 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java @@ -39,7 +39,6 @@ /** A java compiler configuration containing the flags required for compilation. */ @Immutable public final class JavaConfiguration extends Fragment implements JavaConfigurationApi { - /** Values for the --java_classpath option */ public enum JavaClasspathMode { /** Use full transitive classpaths, the default behavior. */ @@ -213,6 +212,11 @@ public enum ImportDepsCheckingLevel { javaOptions.hostJavaToolchain)); } } + if (javaOptions.useJavaToolsBetaRelease) { + // TODO(davido): Add some checks, that mutual exclusive options are not allowed. + javaOptions.javaToolchain = + javaOptions.hostJavaToolchain = javaOptions.defaultJavaToolchainBeta(); + } } @Override @@ -371,7 +375,6 @@ public boolean useLegacyBazelJavaTest() { return useLegacyBazelJavaTest; } - /** * Make it mandatory for java_test targets to explicitly declare any JUnit or Hamcrest * dependencies instead of accidentally obtaining them from the TestRunner's dependencies. diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java index 29aec10a1d3fe1..132d665707cb4e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java @@ -86,6 +86,8 @@ public ImportDepsCheckingLevelConverter() { public Label javaBase; private static final String DEFAULT_JAVA_TOOLCHAIN = "@bazel_tools//tools/jdk:remote_toolchain"; + private static final String DEFAULT_JAVA_TOOLCHAIN_BETA = + "@bazel_tools//tools/jdk:remote_toolchain_beta"; @Option( name = "java_toolchain", @@ -580,6 +582,18 @@ public ImportDepsCheckingLevelConverter() { "Disables the resource_jars attribute; use java_import and deps or runtime_deps instead.") public boolean disallowResourceJars; + @Option( + name = "incompatible_use_java_tools_beta_release", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.UNKNOWN}, + metadataTags = { + OptionMetadataTag.INCOMPATIBLE_CHANGE, + OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES + }, + help = "Activates java_tools beta release.") + public boolean useJavaToolsBetaRelease; + @Option( name = "incompatible_load_java_rules_from_bzl", defaultValue = "false", @@ -629,6 +643,10 @@ Label defaultJavaToolchain() { return Label.parseAbsoluteUnchecked(DEFAULT_JAVA_TOOLCHAIN); } + Label defaultJavaToolchainBeta() { + return Label.parseAbsoluteUnchecked(DEFAULT_JAVA_TOOLCHAIN_BETA); + } + @Override public FragmentOptions getHost() { JavaOptions host = (JavaOptions) getDefault(); @@ -679,5 +697,4 @@ public FragmentOptions getHost() { return host; } - } diff --git a/src/test/py/bazel/test_base.py b/src/test/py/bazel/test_base.py index 8f92c52b38e334..907a39d49af4fc 100644 --- a/src/test/py/bazel/test_base.py +++ b/src/test/py/bazel/test_base.py @@ -61,8 +61,11 @@ class TestBase(unittest.TestCase): 'remotejdk11_macos_for_testing', 'remotejdk11_win_for_testing', 'remote_java_tools_darwin_for_testing', + 'remote_java_tools_darwin_beta_for_testing', 'remote_java_tools_linux_for_testing', + 'remote_java_tools_linux_beta_for_testing', 'remote_java_tools_windows_for_testing', + 'remote_java_tools_windows_beta_for_testing', 'remote_coverage_tools_for_testing', ) diff --git a/src/test/shell/testenv.sh b/src/test/shell/testenv.sh index cd447779bd4f26..bc33db5a3930ff 100755 --- a/src/test/shell/testenv.sh +++ b/src/test/shell/testenv.sh @@ -299,6 +299,7 @@ EOF "openjdk_win_minimal" "remote_coverage_tools_for_testing" "remote_java_tools_darwin_for_testing" + "remote_java_tools_darwin_beta_for_testing" "remote_java_tools_javac11_test_darwin" "remote_java_tools_javac11_test_linux" "remote_java_tools_javac11_test_windows" @@ -306,7 +307,9 @@ EOF "remote_java_tools_javac12_test_linux" "remote_java_tools_javac12_test_windows" "remote_java_tools_linux_for_testing" + "remote_java_tools_linux_beta_for_testing" "remote_java_tools_windows_for_testing" + "remote_java_tools_windows_beta_for_testing" "remotejdk11_linux_for_testing" "remotejdk11_linux_aarch64_for_testing" "remotejdk11_macos_for_testing" diff --git a/tools/jdk/BUILD b/tools/jdk/BUILD index cbcff60be3e0de..0c7eddb3179396 100644 --- a/tools/jdk/BUILD +++ b/tools/jdk/BUILD @@ -387,6 +387,17 @@ alias( }), ) +alias( + name = "remote_toolchain_beta", + actual = select({ + "//src/conditions:darwin": "@remote_java_tools_darwin_beta//:toolchain", + "//src/conditions:darwin_x86_64": "@remote_java_tools_darwin_beta//:toolchain", + "//src/conditions:windows": "@remote_java_tools_windows_beta//:toolchain", + "//src/conditions:linux_x86_64": "@remote_java_tools_linux_beta//:toolchain", + "//conditions:default": "@bazel_tools//tools/jdk:legacy_toolchain", + }), +) + # The 'vanilla' toolchain is an unsupported alternative to the default. # # It does not provider any of the following features: