Skip to content

Commit

Permalink
Test java coverage with java_tools released and built at head.
Browse files Browse the repository at this point in the history
This follows the same setup in bazel_java_test.sh for configuring the java_toolchain and javabase.

Closes #8361.

PiperOrigin-RevId: 249057124
  • Loading branch information
iirina authored and copybara-github committed May 20, 2019
1 parent 3703a3d commit 51937e4
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 106 deletions.
73 changes: 72 additions & 1 deletion src/test/shell/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ sh_test(
],
data = [
":test-deps",
"//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
"@bazel_tools//tools/bash/runfiles",
],
)
Expand All @@ -184,6 +185,7 @@ sh_test(
}),
data = [
":test-deps",
"//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
"@bazel_tools//tools/bash/runfiles",
],
)
Expand Down Expand Up @@ -211,6 +213,7 @@ JAVA_VERSIONS = ("9", "10", "11")
data = [
":test-deps",
"//src:java_tools_java" + java_version + "_zip",
"//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
"@bazel_tools//tools/bash/runfiles",
],
)
Expand All @@ -237,6 +240,7 @@ JAVA_VERSIONS = ("9", "10", "11")
}),
data = [
":test-deps",
"//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
"@bazel_tools//tools/bash/runfiles",
],
# This test is only run by the java_tools binaries pipeline.
Expand Down Expand Up @@ -368,12 +372,79 @@ sh_test(
sh_test(
name = "bazel_coverage_java_test",
srcs = ["bazel_coverage_java_test.sh"],
data = [":test-deps"],
args = [
"@bazel_tools//tools/jdk:toolchain",
"released",
],
data = [
":test-deps",
"//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
],
tags = [
"no_windows",
],
)

# Test java coverage with the java_toolchain in the released java_tools versions.
[
sh_test(
name = "bazel_coverage_java_jdk" + java_version + "toolchain_released_test",
srcs = ["bazel_coverage_java_test.sh"],
args = select({
"//src/conditions:darwin": ["@remote_java_tools_javac" + java_version + "_test_darwin//:toolchain"],
"//src/conditions:darwin_x86_64": ["@remote_java_tools_javac" + java_version + "_test_darwin//:toolchain"],
"//src/conditions:windows": ["@remote_java_tools_javac" + java_version + "_test_windows//:toolchain"],
"//src/conditions:linux_x86_64": ["@remote_java_tools_javac" + java_version + "_test_linux//:toolchain"],
}) + [
# java_tools zip to test
"released",
# --javabase value
] + select({
"//src/conditions:darwin": ["@openjdk" + java_version + "_darwin_archive//:runtime"],
"//src/conditions:darwin_x86_64": ["@openjdk" + java_version + "_darwin_archive//:runtime"],
"//src/conditions:windows": ["@openjdk" + java_version + "_windows_archive//:runtime"],
"//src/conditions:linux_x86_64": ["@openjdk" + java_version + "_linux_archive//:runtime"],
}),
data = [
":test-deps",
"//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
],
tags = [
"no_windows",
],
)
for java_version in JAVA_VERSIONS
]

# Test java coverage with the java_toolchain in the java_tools zip built at head.
[
sh_test(
name = "bazel_coverage_java_jdk" + java_version + "_toolchain_head_test",
srcs = ["bazel_coverage_java_test.sh"],
args = [
# --java_toolchain
"@local_java_tools//:toolchain",
# java_tools zip to test
"src/java_tools_java" + java_version + ".zip",
# --javabase value
] + select({
"//src/conditions:darwin": ["@openjdk" + java_version + "_darwin_archive//:runtime"],
"//src/conditions:darwin_x86_64": ["@openjdk" + java_version + "_darwin_archive//:runtime"],
"//src/conditions:windows": ["@openjdk" + java_version + "_windows_archive//:runtime"],
"//src/conditions:linux_x86_64": ["@openjdk" + java_version + "_linux_archive//:runtime"],
}),
data = [
":test-deps",
"//src:java_tools_java" + java_version + "_zip",
"//src/test/shell/bazel/testdata:jdk_http_archives_filegroup",
],
tags = [
"no_windows",
],
)
for java_version in JAVA_VERSIONS
]

sh_test(
name = "bazel_coverage_sh_test",
srcs = ["bazel_coverage_sh_test.sh"],
Expand Down
36 changes: 36 additions & 0 deletions src/test/shell/bazel/bazel_coverage_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,42 @@ CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${CURRENT_DIR}/../integration_test_setup.sh" \
|| { echo "integration_test_setup.sh not found!" >&2; exit 1; }

JAVA_TOOLCHAIN="$1"; shift
add_to_bazelrc "build --java_toolchain=${JAVA_TOOLCHAIN}"

JAVA_TOOLS_ZIP="$1"; shift
if [[ "${JAVA_TOOLS_ZIP}" != "released" ]]; then
if [[ "${JAVA_TOOLS_ZIP}" == file* ]]; then
JAVA_TOOLS_ZIP_FILE_URL="${JAVA_TOOLS_ZIP}"
else
JAVA_TOOLS_ZIP_FILE_URL="file://$(rlocation io_bazel/$JAVA_TOOLS_ZIP)"
fi
fi
JAVA_TOOLS_ZIP_FILE_URL=${JAVA_TOOLS_ZIP_FILE_URL:-}

if [[ $# -gt 0 ]]; then
JAVABASE_VALUE="$1"; shift
add_to_bazelrc "build --javabase=${JAVABASE_VALUE}"
fi

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.
EOF

if [[ ! -z "${JAVA_TOOLS_ZIP_FILE_URL}" ]]; then
cat >>WORKSPACE <<EOF
http_archive(
name = "local_java_tools",
urls = ["${JAVA_TOOLS_ZIP_FILE_URL}"]
)
EOF
fi

cat $(rlocation io_bazel/src/test/shell/bazel/testdata/jdk_http_archives) >> WORKSPACE
}

# Asserts if the given expected coverage result is included in the given output
# file.
#
Expand Down
106 changes: 1 addition & 105 deletions src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,111 +90,7 @@ http_archive(
EOF
fi

cat >>WORKSPACE <<EOF
http_archive(
name = "remote_java_tools_javac9_test_linux",
urls = [
"https://mirror.bazel.build/bazel_java_tools/releases/javac9/v1.0/java_tools_javac9_linux-v1.0.zip",
],
)
http_archive(
name = "remote_java_tools_javac9_test_windows",
urls = [
"https://mirror.bazel.build/bazel_java_tools/releases/javac9/v1.0/java_tools_javac9_windows-v1.0.zip",
],
)
http_archive(
name = "remote_java_tools_javac9_test_darwin",
urls = [
"https://mirror.bazel.build/bazel_java_tools/releases/javac9/v1.0/java_tools_javac9_darwin-v1.0.zip",
],
)
http_archive(
name = "openjdk9_linux_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
sha256 = "45f2dfbee93b91b1468cf81d843fc6d9a47fef1f831c0b7ceff4f1eb6e6851c8",
strip_prefix = "zulu9.0.7.1-jdk9.0.7-linux_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-linux_x64.tar.gz",
],
)
http_archive(
name = "openjdk9_darwin_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
strip_prefix = "zulu9.0.7.1-jdk9.0.7-macosx_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-macosx_x64.tar.gz",
],
)
http_archive(
name = "openjdk9_windows_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
strip_prefix = "zulu9.0.7.1-jdk9.0.7-win_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu-9.0.7.1-jdk9.0.7/zulu9.0.7.1-jdk9.0.7-win_x64.zip",
],
)
http_archive(
name = "openjdk10_linux_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
sha256 = "b3c2d762091a615b0c1424ebbd05d75cc114da3bf4f25a0dec5c51ea7e84146f",
strip_prefix = "zulu10.2+3-jdk10.0.1-linux_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-linux_x64.tar.gz",
],
)
http_archive(
name = "openjdk10_darwin_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
strip_prefix = "zulu10.2+3-jdk10.0.1-macosx_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-macosx_x64.tar.gz",
],
)
http_archive(
name = "openjdk10_windows_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
strip_prefix = "zulu10.2+3-jdk10.0.1-win_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu10.2+3-jdk10.0.1/zulu10.2+3-jdk10.0.1-win_x64.zip",
],
)
http_archive(
name = "openjdk11_linux_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
strip_prefix = "zulu11.31.11-ca-jdk11.0.3-linux_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu11.31.11-ca-jdk11.0.3/zulu11.31.11-ca-jdk11.0.3-linux_x64.tar.gz",
],
)
http_archive(
name = "openjdk11_darwin_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
strip_prefix = "zulu11.31.11-ca-jdk11.0.3-macosx_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu11.31.11-ca-jdk11.0.3/zulu11.31.11-ca-jdk11.0.3-macosx_x64.tar.gz",
],
)
http_archive(
name = "openjdk11_windows_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
strip_prefix = "zulu11.31.11-ca-jdk11.0.3-win_x64",
urls = [
"https://mirror.bazel.build/openjdk/azul-zulu11.31.11-ca-jdk11.0.3/zulu11.31.11-ca-jdk11.0.3-win_x64.zip",
],
)
EOF
cat $(rlocation io_bazel/src/test/shell/bazel/testdata/jdk_http_archives) >> WORKSPACE
}

function write_hello_library_files() {
Expand Down
9 changes: 9 additions & 0 deletions src/test/shell/bazel/testdata/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ filegroup(
],
visibility = ["//src/test/shell/bazel:__pkg__"],
)

filegroup(
name = "jdk_http_archives_filegroup",
testonly = 1,
srcs = [
"//src/test/shell/bazel/testdata:jdk_http_archives",
],
visibility = ["//src/test/shell/bazel:__pkg__"],
)
Loading

0 comments on commit 51937e4

Please sign in to comment.