Run tests after building java tools.
This PR adds a shell integration test for the java rules that is run with the java toolchain of the java tools build from head. The test is created and run by `src/upload_java_tools.sh` which is used by the Buildkite pipeline to generate the java tools zip.
The generated java tools zip is uploaded to GCS only if the test succeeded. This provides testing before creating release candidates for the java tools.
Closes #8205.
PiperOrigin-RevId: 247408063
diff --git a/src/upload_all_java_tools.sh b/src/upload_all_java_tools.sh
index b560e08..ccdd024 100755
--- a/src/upload_all_java_tools.sh
+++ b/src/upload_all_java_tools.sh
@@ -16,12 +16,6 @@
# A script to upload a given java_tools zip on GCS. Used by the java_tools_binaries
# Buildkite pipeline. It is not recommended to run this script manually.
-#
-# Mandatory flags:
-# --java_tools_zip The workspace-relative path of a java_tools zip.
-# --gcs_java_tools_dir The directory under bazel_java_tools on GCS where the zip is uploaded.
-# --java_version The version of the javac the given zip embeds.
-# --platform The name of the platform where the zip was built.
# Script used by the "java_tools binaries" Buildkite pipeline to build the java tools archives
# and upload them on GCS.
@@ -32,6 +26,22 @@
# The script cannot be invoked through a sh_binary using bazel because git
# cannot be used through a sh_binary.
+set -euo pipefail
+
+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
+
commit_hash=$(git rev-parse HEAD)
timestamp=$(date +%s)
bazel_version=$(bazel info release | cut -d' ' -f2)
@@ -39,7 +49,29 @@
# Passing the same commit_hash and timestamp to all targets to mark all the artifacts
# uploaded on GCS with the same identifier.
for java_version in 9 10; do
- for target in src:upload_java_tools_java${java_version} src:upload_java_tools_dist_java${java_version}; do
- bazel run ${target} -- --commit_hash ${commit_hash} --timestamp ${timestamp} --bazel_version ${bazel_version}
- done
+
+ bazel build //src:java_tools_java${java_version}_zip
+ zip_path=${PWD}/bazel-bin/src/java_tools_java${java_version}.zip
+
+ if "$is_windows"; then
+ # Windows needs "file:///c:/foo/bar".
+ file_url="file:///$(cygpath -m ${zip_path})"
+ else
+ # Non-Windows needs "file:///foo/bar".
+ file_url="file://${zip_path}"
+ fi
+ bazel test --verbose_failures --test_output=all --nocache_test_results \
+ //src/test/shell/bazel:bazel_java_test_local_java_tools_jdk${java_version} \
+ --define=LOCAL_JAVA_TOOLS_ZIP_URL="${file_url}"
+
+ bazel run //src:upload_java_tools_java${java_version} -- \
+ --java_tools_zip src/java_tools_java${java_version}.zip \
+ --commit_hash ${commit_hash} \
+ --timestamp ${timestamp} \
+ --bazel_version ${bazel_version}
+
+ bazel run //src:upload_java_tools_dist_java${java_version} -- \
+ --commit_hash ${commit_hash} \
+ --timestamp ${timestamp} \
+ --bazel_version ${bazel_version}
done