Skip to content

Commit

Permalink
Add incompatible_use_java_tools_beta_release option
Browse files Browse the repository at this point in the history
Fixes bazelbuild#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
  • Loading branch information
davido committed May 21, 2020
1 parent 01e0d23 commit a5de695
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 7 deletions.
43 changes: 39 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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()
3 changes: 3 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -747,14 +747,17 @@ 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",
"@remote_java_tools_javac11_test_windows//:WORKSPACE",
"@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -679,5 +697,4 @@ public FragmentOptions getHost() {

return host;
}

}
3 changes: 3 additions & 0 deletions src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)

Expand Down
3 changes: 3 additions & 0 deletions src/test/shell/testenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,17 @@ 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"
"remote_java_tools_javac12_test_darwin"
"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"
Expand Down
11 changes: 11 additions & 0 deletions tools/jdk/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a5de695

Please sign in to comment.