Skip to content

Commit 8727648

Browse files
committed
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<V> extends Tarjan.Result<V> { ^ (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] google/error-prone#1619 [2] bazelbuild/rules_closure#483 Change-Id: I352297a8d0d86cecf30821c132c7871383e49b50
1 parent 01e0d23 commit 8727648

File tree

8 files changed

+111
-7
lines changed

8 files changed

+111
-7
lines changed

WORKSPACE

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,15 +578,15 @@ load("//scripts/docs:doc_versions.bzl", "DOC_VERSIONS")
578578
# Load shared base CSS theme from bazelbuild/bazel-website
579579
http_archive(
580580
name = "bazel_website",
581-
urls = ["https://github.com/bazelbuild/bazel-website/archive/c174fa288aa079b68416d2ce2cc97268fa172f42.tar.gz"],
582-
strip_prefix = "bazel-website-c174fa288aa079b68416d2ce2cc97268fa172f42",
583-
sha256 = "a5f531dd1d62e6947dcfc279656ffc2fdf6f447c163914c5eabf7961b4cb6eb4",
584581
# TODO(https://github.com/bazelbuild/bazel/issues/10793)
585582
# - Export files from bazel-website's BUILD, instead of doing it here.
586583
# - Share more common stylesheets, like footer and navbar.
587584
build_file_content = """
588585
exports_files(["_sass/style.scss"])
589-
"""
586+
""",
587+
sha256 = "a5f531dd1d62e6947dcfc279656ffc2fdf6f447c163914c5eabf7961b4cb6eb4",
588+
strip_prefix = "bazel-website-c174fa288aa079b68416d2ce2cc97268fa172f42",
589+
urls = ["https://github.com/bazelbuild/bazel-website/archive/c174fa288aa079b68416d2ce2cc97268fa172f42.tar.gz"],
590590
)
591591

592592
# Skydoc recommends declaring its dependencies via "*_dependencies" functions.
@@ -715,6 +715,17 @@ http_archive(
715715
],
716716
)
717717

718+
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
719+
http_archive(
720+
name = "remote_java_tools_linux_beta_for_testing",
721+
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
722+
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
723+
sha256 = "74d30ccf161c58bb69db9b2171c954a0563b2d1ff6f5831debbe71ced105c388",
724+
urls = [
725+
"https://github.com/davido/java_tools/releases/download/javac11-v11.0/java_tools_javac11_linux-v11.0.zip",
726+
],
727+
)
728+
718729
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
719730
http_archive(
720731
name = "remote_java_tools_windows_for_testing",
@@ -727,6 +738,18 @@ http_archive(
727738
],
728739
)
729740

741+
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
742+
http_archive(
743+
name = "remote_java_tools_windows_beta_for_testing",
744+
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
745+
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
746+
sha256 = "444c391977e50af4e10549a28d021069d2ca7745a0e7b9b968a7b153fe3ea430",
747+
urls = [
748+
"https://mirror.bazel.build/bazel_java_tools/releases/javac11/v8.0/java_tools_javac11_windows-v8.0.zip",
749+
"https://github.com/bazelbuild/java_tools/releases/download/javac11_v8.0/java_tools_javac11_windows-v8.0.zip",
750+
],
751+
)
752+
730753
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
731754
http_archive(
732755
name = "remote_java_tools_darwin_for_testing",
@@ -739,6 +762,17 @@ http_archive(
739762
],
740763
)
741764

765+
# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
766+
http_archive(
767+
name = "remote_java_tools_darwin_beta_for_testing",
768+
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_FILE,
769+
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_FILE_WIN,
770+
sha256 = "252520f0cd5dd7e9b18062dc731f8ae248993650f12a9b613fcd9ebda591d242",
771+
urls = [
772+
"https://github.com/davido/java_tools/releases/download/javac11-v11.0/java_tools_javac11_darwin-v11.0.zip",
773+
],
774+
)
775+
742776
# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
743777
http_archive(
744778
name = "remote_java_tools_javac11_test_linux",
@@ -921,4 +955,5 @@ register_local_rc_exe_toolchains()
921955
register_toolchains("//src/main/res:empty_rc_toolchain")
922956

923957
load("//tools/distributions/debian:deps.bzl", "debian_deps")
958+
924959
debian_deps()

src/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,14 +747,17 @@ filegroup(
747747
"@openjdk_macos_minimal//file",
748748
"@openjdk_win_minimal//file",
749749
"@remote_coverage_tools_for_testing//:WORKSPACE",
750+
"@remote_java_tools_darwin_beta_for_testing//:WORKSPACE",
750751
"@remote_java_tools_darwin_for_testing//:WORKSPACE",
751752
"@remote_java_tools_javac11_test_darwin//:WORKSPACE",
752753
"@remote_java_tools_javac11_test_linux//:WORKSPACE",
753754
"@remote_java_tools_javac11_test_windows//:WORKSPACE",
754755
"@remote_java_tools_javac12_test_darwin//:WORKSPACE",
755756
"@remote_java_tools_javac12_test_linux//:WORKSPACE",
756757
"@remote_java_tools_javac12_test_windows//:WORKSPACE",
758+
"@remote_java_tools_linux_beta_for_testing//:WORKSPACE",
757759
"@remote_java_tools_linux_for_testing//:WORKSPACE",
760+
"@remote_java_tools_windows_beta_for_testing//:WORKSPACE",
758761
"@remote_java_tools_windows_for_testing//:WORKSPACE",
759762
"@remotejdk11_linux_aarch64_for_testing//:WORKSPACE",
760763
"@remotejdk11_linux_for_testing//:WORKSPACE",

src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ maybe(
152152
],
153153
)
154154

155+
maybe(
156+
http_archive,
157+
name = "remote_java_tools_linux_beta",
158+
sha256 = "74d30ccf161c58bb69db9b2171c954a0563b2d1ff6f5831debbe71ced105c388",
159+
urls = [
160+
"https://github.com/davido/java_tools/releases/download/javac11-v11.0/java_tools_javac11_linux-v11.0.zip",
161+
],
162+
)
163+
155164
# This must be kept in sync with the top-level WORKSPACE file.
156165
maybe(
157166
http_archive,
@@ -163,6 +172,17 @@ maybe(
163172
],
164173
)
165174

175+
# TODO(davido): Build java_tools beta release on "other" platform
176+
maybe(
177+
http_archive,
178+
name = "remote_java_tools_windows_beta",
179+
sha256 = "444c391977e50af4e10549a28d021069d2ca7745a0e7b9b968a7b153fe3ea430",
180+
urls = [
181+
"https://mirror.bazel.build/bazel_java_tools/releases/javac11/v8.0/java_tools_javac11_windows-v8.0.zip",
182+
"https://github.com/bazelbuild/java_tools/releases/download/javac11_v8.0/java_tools_javac11_windows-v8.0.zip",
183+
],
184+
)
185+
166186
# This must be kept in sync with the top-level WORKSPACE file.
167187
maybe(
168188
http_archive,
@@ -174,6 +194,15 @@ maybe(
174194
],
175195
)
176196

197+
maybe(
198+
http_archive,
199+
name = "remote_java_tools_darwin_beta",
200+
sha256 = "252520f0cd5dd7e9b18062dc731f8ae248993650f12a9b613fcd9ebda591d242",
201+
urls = [
202+
"https://github.com/davido/java_tools/releases/download/javac11-v11.0/java_tools_javac11_darwin-v11.0.zip",
203+
],
204+
)
205+
177206
maybe(
178207
http_archive,
179208
"rules_java",

src/main/java/com/google/devtools/build/lib/rules/java/JavaConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
/** A java compiler configuration containing the flags required for compilation. */
4040
@Immutable
4141
public final class JavaConfiguration extends Fragment implements JavaConfigurationApi {
42-
4342
/** Values for the --java_classpath option */
4443
public enum JavaClasspathMode {
4544
/** Use full transitive classpaths, the default behavior. */
@@ -213,6 +212,11 @@ public enum ImportDepsCheckingLevel {
213212
javaOptions.hostJavaToolchain));
214213
}
215214
}
215+
if (javaOptions.useJavaToolsBetaRelease) {
216+
// TODO(davido): Add some checks, that mutual exclusive options are not allowed.
217+
javaOptions.javaToolchain =
218+
javaOptions.hostJavaToolchain = javaOptions.defaultJavaToolchainBeta();
219+
}
216220
}
217221

218222
@Override
@@ -371,7 +375,6 @@ public boolean useLegacyBazelJavaTest() {
371375
return useLegacyBazelJavaTest;
372376
}
373377

374-
375378
/**
376379
* Make it mandatory for java_test targets to explicitly declare any JUnit or Hamcrest
377380
* dependencies instead of accidentally obtaining them from the TestRunner's dependencies.

src/main/java/com/google/devtools/build/lib/rules/java/JavaOptions.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public ImportDepsCheckingLevelConverter() {
8686
public Label javaBase;
8787

8888
private static final String DEFAULT_JAVA_TOOLCHAIN = "@bazel_tools//tools/jdk:remote_toolchain";
89+
private static final String DEFAULT_JAVA_TOOLCHAIN_BETA =
90+
"@bazel_tools//tools/jdk:remote_toolchain_beta";
8991

9092
@Option(
9193
name = "java_toolchain",
@@ -580,6 +582,18 @@ public ImportDepsCheckingLevelConverter() {
580582
"Disables the resource_jars attribute; use java_import and deps or runtime_deps instead.")
581583
public boolean disallowResourceJars;
582584

585+
@Option(
586+
name = "incompatible_use_java_tools_beta_release",
587+
defaultValue = "false",
588+
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
589+
effectTags = {OptionEffectTag.UNKNOWN},
590+
metadataTags = {
591+
OptionMetadataTag.INCOMPATIBLE_CHANGE,
592+
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
593+
},
594+
help = "Activates java_tools beta release.")
595+
public boolean useJavaToolsBetaRelease;
596+
583597
@Option(
584598
name = "incompatible_load_java_rules_from_bzl",
585599
defaultValue = "false",
@@ -629,6 +643,10 @@ Label defaultJavaToolchain() {
629643
return Label.parseAbsoluteUnchecked(DEFAULT_JAVA_TOOLCHAIN);
630644
}
631645

646+
Label defaultJavaToolchainBeta() {
647+
return Label.parseAbsoluteUnchecked(DEFAULT_JAVA_TOOLCHAIN_BETA);
648+
}
649+
632650
@Override
633651
public FragmentOptions getHost() {
634652
JavaOptions host = (JavaOptions) getDefault();
@@ -679,5 +697,4 @@ public FragmentOptions getHost() {
679697

680698
return host;
681699
}
682-
683700
}

src/test/py/bazel/test_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ class TestBase(unittest.TestCase):
6161
'remotejdk11_macos_for_testing',
6262
'remotejdk11_win_for_testing',
6363
'remote_java_tools_darwin_for_testing',
64+
'remote_java_tools_darwin_beta_for_testing',
6465
'remote_java_tools_linux_for_testing',
66+
'remote_java_tools_linux_beta_for_testing',
6567
'remote_java_tools_windows_for_testing',
68+
'remote_java_tools_windows_beta_for_testing',
6669
'remote_coverage_tools_for_testing',
6770
)
6871

src/test/shell/testenv.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,17 @@ EOF
299299
"openjdk_win_minimal"
300300
"remote_coverage_tools_for_testing"
301301
"remote_java_tools_darwin_for_testing"
302+
"remote_java_tools_darwin_beta_for_testing"
302303
"remote_java_tools_javac11_test_darwin"
303304
"remote_java_tools_javac11_test_linux"
304305
"remote_java_tools_javac11_test_windows"
305306
"remote_java_tools_javac12_test_darwin"
306307
"remote_java_tools_javac12_test_linux"
307308
"remote_java_tools_javac12_test_windows"
308309
"remote_java_tools_linux_for_testing"
310+
"remote_java_tools_linux_beta_for_testing"
309311
"remote_java_tools_windows_for_testing"
312+
"remote_java_tools_windows_beta_for_testing"
310313
"remotejdk11_linux_for_testing"
311314
"remotejdk11_linux_aarch64_for_testing"
312315
"remotejdk11_macos_for_testing"

tools/jdk/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,17 @@ alias(
387387
}),
388388
)
389389

390+
alias(
391+
name = "remote_toolchain_beta",
392+
actual = select({
393+
"//src/conditions:darwin": "@remote_java_tools_darwin_beta//:toolchain",
394+
"//src/conditions:darwin_x86_64": "@remote_java_tools_darwin_beta//:toolchain",
395+
"//src/conditions:windows": "@remote_java_tools_windows_beta//:toolchain",
396+
"//src/conditions:linux_x86_64": "@remote_java_tools_linux_beta//:toolchain",
397+
"//conditions:default": "@bazel_tools//tools/jdk:legacy_toolchain",
398+
}),
399+
)
400+
390401
# The 'vanilla' toolchain is an unsupported alternative to the default.
391402
#
392403
# It does not provider any of the following features:

0 commit comments

Comments
 (0)