Skip to content

Commit

Permalink
Add an option to make JDK 10 the default --host_javabase
Browse files Browse the repository at this point in the history
RELNOTES[INC]: Add --incompatible_use_jdk10_as_host_javabase to make JDK 10 the default --host_javabase.

PiperOrigin-RevId: 216587956
  • Loading branch information
cushon authored and Copybara-Service committed Oct 10, 2018
1 parent 241b5fa commit 825c049
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,47 @@ new_http_archive(
build_file = __embedded_dir__ + "/jdk.BUILD",
strip_prefix = "jdk9-server-release-1708",
)

new_http_archive(
name = "remotejdk10_linux",
sha256 = "57fad3602e74c79587901d6966d3b54ef32cb811829a2552163185d5064fe9b5",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-linux_x64-allmodules.tar.gz",
],
build_file = __embedded_dir__ + "/jdk.BUILD",
strip_prefix = "zulu10.2+3-jdk10.0.1-linux_x64-allmodules",
)


new_http_archive(
name = "remotejdk10_macos",
sha256 = "e669c9a897413d855b550b4e39d79614392e6fb96f494e8ef99a34297d9d85d3",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-macosx_x64-allmodules.tar.gz",
],
build_file = __embedded_dir__ + "/jdk.BUILD",
strip_prefix = "zulu10.2+3-jdk10.0.1-macosx_x64-allmodules"
)

new_http_archive(
name = "remotejdk10_win",
sha256 = "c39e7700a8d41794d60985df5a20352435196e78ecbc6a2b30df7be8637bffd5",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-win_x64-allmodules.zip",
],
build_file = __embedded_dir__ + "/jdk.BUILD",
strip_prefix = "zulu10.2+3-jdk10.0.1-win_x64-allmodules",
)

# The source-code for this OpenJDK can be found at:
# https://openjdk.linaro.org/releases/jdk10-src-1804.tar.xz
new_http_archive(
name = "remotejdk10_linux_aarch64",
sha256 = "b7098b7aaf6ee1ffd4a2d0371a0be26c5a5c87f6aebbe46fe9a92c90583a84be",
urls = [
# When you update this, also update the link to the source-code above.
"http://openjdk.linaro.org/releases/jdk10-server-release-1804.tar.xz",
],
build_file = __embedded_dir__ + "/jdk.BUILD",
strip_prefix = "jdk10-server-release-1804",
)
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ public ImportDepsCheckingLevelConverter() {
"If enabled, uses a JDK downloaded from a remote repository instead of the embedded JDK.")
public boolean useRemoteJdkAsHostJavaBase;

@Option(
name = "incompatible_use_jdk10_as_host_javabase",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
metadataTags = {
OptionMetadataTag.INCOMPATIBLE_CHANGE,
OptionMetadataTag.TRIGGERED_BY_ALL_INCOMPATIBLE_CHANGES
},
help = "If enabled, the default --host_javabase is JDK 10.")
public boolean useJDK10AsHostJavaBase;

@Option(
name = "javacopt",
allowMultiple = true,
Expand Down Expand Up @@ -612,7 +624,9 @@ public ImportDepsCheckingLevelConverter() {

private Label getHostJavaBase() {
if (hostJavaBase == null) {
if (useRemoteJdkAsHostJavaBase) {
if (useJDK10AsHostJavaBase) {
return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:remote_jdk10");
} else if (useRemoteJdkAsHostJavaBase) {
return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:remote_jdk");
} else {
return Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:host_jdk");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public void setupMockClient(MockToolsConfig config) throws IOException {
")",
"java_runtime(name = 'jdk', srcs = [])",
"java_runtime(name = 'host_jdk', srcs = [])",
"java_runtime(name = 'remote_jdk', srcs = [])",
"java_runtime(name = 'remote_jdk10', srcs = [])",
"java_runtime_alias(name = 'current_java_runtime')",
// This isn't actually the host runtime, but will do. This way, we don't need to pull in the
// Skylark implementation of the java_host_runtime_alias rule.
Expand Down
28 changes: 23 additions & 5 deletions src/test/shell/integration/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ EOF
--incompatible_use_remotejdk_as_host_javabase //java:javalib >& $TEST_log
expect_log "exec .*foobar/bin/java"
expect_not_log "exec external/remotejdk_.*/bin/java"

bazel aquery --output=text --incompatible_use_jdk10_as_host_javabase \
//java:javalib >& $TEST_log
expect_log "exec external/remotejdk10_.*/bin/java"
}

function test_javabase() {
Expand Down Expand Up @@ -218,34 +222,48 @@ EOF
expect_not_log "foo"
expect_not_log "bar"
expect_not_log "embedded_jdk"
expect_not_log "remotejdk"
expect_not_log "remotejdk_"
expect_not_log "remotejdk10_"

bazel cquery --implicit_deps 'deps(//:with_java)' >& $TEST_log
expect_not_log "foo"
expect_log "bar"
expect_log "embedded_jdk"
expect_not_log "remotejdk"
expect_not_log "remotejdk_"
expect_not_log "remotejdk10_"

bazel cquery --implicit_deps 'deps(//:with_java)' --host_javabase=:foo_javabase >& $TEST_log
expect_log "foo"
expect_log "bar"
expect_not_log "embedded_jdk"
expect_not_log "remotejdk"
expect_not_log "remotejdk_"
expect_not_log "remotejdk10_"

bazel cquery --implicit_deps 'deps(//:with_java)' \
--incompatible_use_remotejdk_as_host_javabase >& $TEST_log
expect_not_log "foo"
expect_log "bar"
expect_not_log "embedded_jdk"
expect_log "remotejdk"
expect_log "remotejdk_"
expect_not_log "remotejdk10_"

bazel cquery --implicit_deps 'deps(//:with_java)' \
--host_javabase=:foo_javabase \
--incompatible_use_remotejdk_as_host_javabase >& $TEST_log
expect_log "foo"
expect_log "bar"
expect_not_log "embedded_jdk"
expect_not_log "remotejdk"
expect_not_log "remotejdk_"
expect_not_log "remotejdk10_"

bazel cquery --implicit_deps 'deps(//:with_java)' \
--incompatible_use_jdk10_as_host_javabase >& $TEST_log
expect_not_log "foo"
expect_log "bar"
expect_not_log "embedded_jdk"
expect_not_log "remotejdk_"
expect_log "remotejdk10_"

}

run_suite "Tests of specifying custom server_javabase/host_javabase and javabase."
17 changes: 17 additions & 0 deletions tools/jdk/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,20 @@ alias(
),
visibility = ["//visibility:public"],
)

# A JDK 10 for use as a --host_javabase.
alias(
name = "remote_jdk10",
actual = select(
{
"//src/conditions:darwin": "@remotejdk10_macos//:jdk",
"//src/conditions:darwin_x86_64": "@remotejdk10_macos//:jdk",
"//src/conditions:windows": "@remotejdk10_win//:jdk",
"//src/conditions:linux_aarch64": "@remotejdk10_linux_aarch64//:jdk",
"//src/conditions:linux_x86_64": "@remotejdk10_linux//:jdk",
},
no_match_error = "Could not find a JDK for host execution environment, please explicitly" +
" provide one using `--host_javabase.`",
),
visibility = ["//visibility:public"],
)

0 comments on commit 825c049

Please sign in to comment.