Skip to content

Commit

Permalink
Java 16 toolchain support
Browse files Browse the repository at this point in the history
Closes #13270.

Change-Id: I215c2f86a35f87bea0102cf6da5248b19a319d3e
  • Loading branch information
davido committed Mar 30, 2021
1 parent 3211be8 commit 6706428
Show file tree
Hide file tree
Showing 11 changed files with 438 additions and 1 deletion.
108 changes: 108 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,58 @@ 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 = "remotejdk16_linux_for_testing",
build_file = "@local_jdk//:BUILD.bazel",
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
sha256 = "236b5ea97aff3cb312e743848d7efa77faf305170e41371a732ca93c1b797665",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-linux_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-linux_x64.tar.gz",
],
)

# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
http_archive(
name = "remotejdk16_macos_for_testing",
build_file = "@local_jdk//:BUILD.bazel",
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
sha256 = "6d47ef22dc56ce1f5a102ed39e21d9a97320f0bb786818e2c686393109d79bc5",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-macosx_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-macosx_x64.tar.gz",
],
)

# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
http_archive(
name = "remotejdk16_macos_aarch64_for_testing",
build_file = "@local_jdk//:BUILD.bazel",
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
sha256 = "c92131e83bc71474850e667bc4e05fca33662b8feb009a0547aa14e76b40e890",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-macosx_aarch64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-macosx_aarch64.tar.gz",
],
)

# This must be kept in sync with src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
http_archive(
name = "remotejdk16_win_for_testing",
build_file = "@local_jdk//:BUILD.bazel",
patch_cmds = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE,
patch_cmds_win = EXPORT_WORKSPACE_IN_BUILD_BAZEL_FILE_WIN,
sha256 = "6cbf98ada27476526a5f6dff79fd5f2c15e2f671818e503bdf741eb6c8fed3d4",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-win_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-win_x64.zip",
],
)

# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
dist_http_archive(
name = "remote_java_tools_for_testing",
Expand Down Expand Up @@ -791,6 +843,62 @@ exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
],
)

# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
http_archive(
name = "openjdk16_linux_archive",
build_file_content = """
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
""",
sha256 = "236b5ea97aff3cb312e743848d7efa77faf305170e41371a732ca93c1b797665",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-linux_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-linux_x64.tar.gz"
],
)

# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
http_archive(
name = "openjdk16_darwin_archive",
build_file_content = """
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
""",
sha256 = "6d47ef22dc56ce1f5a102ed39e21d9a97320f0bb786818e2c686393109d79bc5",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-macosx_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-macosx_x64.tar.gz",
],
)

# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
http_archive(
name = "openjdk16_darwin_aarch64_archive",
build_file_content = """
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
""",
sha256 = "c92131e83bc71474850e667bc4e05fca33662b8feb009a0547aa14e76b40e890",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-macosx_aarch64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-macosx_aarch64.tar.gz",
],
)

# This must be kept in sync with src/test/shell/bazel/testdata/jdk_http_archives.
http_archive(
name = "openjdk16_windows_archive",
build_file_content = """
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
""",
sha256 = "6cbf98ada27476526a5f6dff79fd5f2c15e2f671818e503bdf741eb6c8fed3d4",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-win_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-win_x64.zip",
],
)

load("@io_bazel_skydoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()
Expand Down
8 changes: 8 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,10 @@ filegroup(
"@openjdk15_darwin_archive//:WORKSPACE",
"@openjdk15_linux_archive//:WORKSPACE",
"@openjdk15_windows_archive//:WORKSPACE",
"@openjdk16_darwin_aarch64_archive//:WORKSPACE",
"@openjdk16_darwin_archive//:WORKSPACE",
"@openjdk16_linux_archive//:WORKSPACE",
"@openjdk16_windows_archive//:WORKSPACE",
"@openjdk_linux_aarch64_minimal//file",
"@openjdk_linux_minimal//file",
"@openjdk_macos_aarch64_minimal//file",
Expand All @@ -740,6 +744,10 @@ filegroup(
"@remotejdk15_macos_aarch64_for_testing//:WORKSPACE",
"@remotejdk15_macos_for_testing//:WORKSPACE",
"@remotejdk15_win_for_testing//:WORKSPACE",
"@remotejdk16_linux_for_testing//:WORKSPACE",
"@remotejdk16_macos_aarch64_for_testing//:WORKSPACE",
"@remotejdk16_macos_for_testing//:WORKSPACE",
"@remotejdk16_win_for_testing//:WORKSPACE",
"@rules_cc//:WORKSPACE",
"@rules_java//:WORKSPACE",
"@rules_pkg//:WORKSPACE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,70 @@ maybe(
version = "15",
)

# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
name = "remotejdk16_linux",
exec_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
sha256 = "236b5ea97aff3cb312e743848d7efa77faf305170e41371a732ca93c1b797665",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-linux_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-linux_x64.tar.gz",
],
version = "16",
)

# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
name = "remotejdk16_macos",
exec_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
sha256 = "6d47ef22dc56ce1f5a102ed39e21d9a97320f0bb786818e2c686393109d79bc5",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-macosx_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-macosx_x64.tar.gz",
],
version = "16",
)

# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
name = "remotejdk16_macos_aarch64",
exec_compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
sha256 = "c92131e83bc71474850e667bc4e05fca33662b8feb009a0547aa14e76b40e890",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-macosx_aarch64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-macosx_aarch64.tar.gz",
],
version = "16",
)

# This must be kept in sync with the top-level WORKSPACE file.
maybe(
remote_java_repository,
name = "remotejdk16_win",
exec_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
sha256 = "6cbf98ada27476526a5f6dff79fd5f2c15e2f671818e503bdf741eb6c8fed3d4",
strip_prefix = "zulu16.28.11-ca-jdk16.0.0-win_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu16.28.11-ca-jdk16.0.0-win_x64.zip",
],
version = "16",
)

{remote_java_tools}
{remote_java_tools_linux}
{remote_java_tools_windows}
Expand Down
4 changes: 4 additions & 0 deletions src/test/py/bazel/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ class TestBase(unittest.TestCase):
'remotejdk15_macos_for_testing',
'remotejdk15_macos_aarch64_for_testing',
'remotejdk15_win_for_testing',
'remotejdk16_linux_for_testing',
'remotejdk16_macos_for_testing',
'remotejdk16_macos_aarch64_for_testing',
'remotejdk16_win_for_testing',
'remote_java_tools_for_testing',
'remote_java_tools_darwin_for_testing',
'remote_java_tools_linux_for_testing',
Expand Down
18 changes: 18 additions & 0 deletions src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,24 @@ sh_test(
tags = ["local"],
)

sh_test(
name = "bazel_java16_test",
srcs = ["bazel_java16_test.sh"],
args = [
# java_tools zip to test
"src/java_tools.zip",
"src/java_tools_prebuilt.zip",
],
data = [
":test-deps",
"//src:java_tools_prebuilt_zip",
"//src:java_tools_zip",
"//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
"@bazel_tools//tools/bash/runfiles",
],
tags = ["local"],
)

sh_test(
name = "bazel_java_test",
# TODO(iirina): Investigate if the 'large' and 'eternal' values still apply.
Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_java15_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Tests that bazel runs projects with Java 14 features.
# Tests that bazel runs projects with Java 15 features.

# --- begin runfiles.bash initialization ---
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
Expand Down
139 changes: 139 additions & 0 deletions src/test/shell/bazel/bazel_java16_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash
#
# Copyright 2021 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Tests that bazel runs projects with Java 16 features.

# --- begin runfiles.bash initialization ---
if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
if [[ -f "$0.runfiles_manifest" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest"
elif [[ -f "$0.runfiles/MANIFEST" ]]; then
export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST"
elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
export RUNFILES_DIR="$0.runfiles"
fi
fi
if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then
source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then
source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \
"$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)"
else
echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash"
exit 1
fi
# --- end runfiles.bash initialization ---

source "$(rlocation "io_bazel/src/test/shell/integration_test_setup.sh")" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

case "$(uname -s | tr [:upper:] [:lower:])" in
msys*|mingw*|cygwin*)
declare -r is_windows=true
;;
*)
declare -r is_windows=false
;;
esac

if "$is_windows"; then
export MSYS_NO_PATHCONV=1
export MSYS2_ARG_CONV_EXCL="*"
fi

JAVA_TOOLS_ZIP="$1"; shift
JAVA_TOOLS_PREBUILT_ZIP="$1"; shift

echo "JAVA_TOOLS_ZIP=$JAVA_TOOLS_ZIP"


JAVA_TOOLS_RLOCATION=$(rlocation io_bazel/$JAVA_TOOLS_ZIP)

if "$is_windows"; then
JAVA_TOOLS_ZIP_FILE_URL="file:///${JAVA_TOOLS_RLOCATION}"
JAVA_TOOLS_PREBUILT_ZIP_FILE_URL="file:///$(rlocation io_bazel/$JAVA_TOOLS_PREBUILT_ZIP)"
else
JAVA_TOOLS_ZIP_FILE_URL="file://${JAVA_TOOLS_RLOCATION}"
JAVA_TOOLS_PREBUILT_ZIP_FILE_URL="file://$(rlocation io_bazel/$JAVA_TOOLS_PREBUILT_ZIP)"
fi
JAVA_TOOLS_ZIP_FILE_URL=${JAVA_TOOLS_ZIP_FILE_URL:-}
JAVA_TOOLS_PREBUILT_ZIP_FILE_URL=${JAVA_TOOLS_PREBUILT_ZIP_FILE_URL:-}


function set_up() {
cat >>WORKSPACE <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# java_tools versions only used to test Bazel with various JDK toolchains.
http_archive(
name = "remote_java_tools",
urls = ["${JAVA_TOOLS_ZIP_FILE_URL}"]
)
http_archive(
name = "remote_java_tools_linux",
urls = ["${JAVA_TOOLS_PREBUILT_ZIP_FILE_URL}"]
)
http_archive(
name = "remote_java_tools_windows",
urls = ["${JAVA_TOOLS_PREBUILT_ZIP_FILE_URL}"]
)
http_archive(
name = "remote_java_tools_darwin",
urls = ["${JAVA_TOOLS_PREBUILT_ZIP_FILE_URL}"]
)
EOF
cat $(rlocation io_bazel/src/test/shell/bazel/testdata/jdk_http_archives) >> WORKSPACE
}

# Java source files version shall match --java_language_version_flag version.
function test_java16_text_block() {
mkdir -p java/main
cat >java/main/BUILD <<EOF
java_binary(
name = 'Javac16Example',
srcs = ['Javac16Example.java'],
main_class = 'Javac16Example',
)
EOF

cat >java/main/Javac16Example.java <<EOF
public class Javac16Example {
static String textBlock = """
Hello,
World
""";
public static void main(String[] args) {
System.out.println(textBlock);
}
}
EOF
bazel run java/main:Javac16Example --java_language_version=14 --java_runtime_version=14 \
--test_output=all --verbose_failures &>"${TEST_log}" \
&& fail "Running with --java_language_version=14 unexpectedly succeeded."

bazel run java/main:Javac16Example --java_language_version=11 --java_runtime_version=11 \
--test_output=all --verbose_failures &>"${TEST_log}" \
&& fail "Running with --java_language_version=11 unexpectedly succeeded."

bazel run java/main:Javac16Example --java_language_version=16 --java_runtime_version=16 \
--test_output=all --verbose_failures &>"${TEST_log}" \
|| fail "Running with --java_language_version=16 failed"
expect_log "^Hello,\$"
expect_log "^World\$"
}


run_suite "Tests Java 16 language features"
Loading

0 comments on commit 6706428

Please sign in to comment.