Skip to content

Commit

Permalink
Run java test before uploading java tools zip to GCS.
Browse files Browse the repository at this point in the history
  • Loading branch information
iirina committed May 8, 2019
1 parent 2152154 commit cf87b44
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 26 deletions.
2 changes: 0 additions & 2 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,6 @@ genrule(
name = "upload_java_tools_java" + java_version,
srcs = ["upload_java_tools.sh"],
args = [
"--java_tools_zip",
"src/java_tools_java" + java_version + ".zip",
"--gcs_java_tools_dir",
"tmp/build",
"--java_version",
Expand Down
20 changes: 7 additions & 13 deletions src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ JAVA_TOOLCHAIN="$1"; shift
add_to_bazelrc "build --java_toolchain=${JAVA_TOOLCHAIN}"

JAVA_TOOLS_ZIP="$1"; shift

if [[ "${JAVA_TOOLS_ZIP}" != "released" ]]; then
if "$is_windows"; then
JAVA_TOOLS_ZIP_FILE_URL="file:///$(rlocation io_bazel/$JAVA_TOOLS_ZIP)"
if [[ "${JAVA_TOOLS_ZIP}" != file* ]]; then
if "$is_windows"; then
JAVA_TOOLS_ZIP_FILE_URL="file:///$(rlocation io_bazel/$JAVA_TOOLS_ZIP)"
else
JAVA_TOOLS_ZIP_FILE_URL="file://$(rlocation io_bazel/$JAVA_TOOLS_ZIP)"
fi
else
JAVA_TOOLS_ZIP_FILE_URL="file://$(rlocation io_bazel/$JAVA_TOOLS_ZIP)"
JAVA_TOOLS_ZIP_FILE_URL="${JAVA_TOOLS_ZIP}"
fi
fi
JAVA_TOOLS_ZIP_FILE_URL=${JAVA_TOOLS_ZIP_FILE_URL:-}
Expand Down Expand Up @@ -391,15 +394,6 @@ function test_strategy_picks_first_preferred_local() {
expect_log " processes: .*local"
}

# This test builds a simple java deploy jar using remote singlejar and ijar
# targets which compile them from source.
function test_build_hello_world_with_remote_embedded_tool_targets() {
write_hello_library_files

bazel build //java/main:main_deploy.jar --define EXECUTOR=remote \
&> $TEST_log || fail "build failed"
}

# This test verifies that jars named by deploy_env are excluded from the final
# deploy jar.
function test_build_with_deploy_env() {
Expand Down
12 changes: 11 additions & 1 deletion src/test/shell/bazel/bazel_java_test_no_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,14 @@ EOF
bazel build //java/com/google/runfiles:EchoRunfiles
# We're testing a formerly non-hermetic interaction, so disable the sandbox.
bazel test --spawn_strategy=standalone --test_output=errors :check_runfiles
}
}

# This test builds a simple java deploy jar using remote singlejar and ijar
# targets which compile them from source.
# This test fails on Windows only when invoked from the java_tools binaries pipeline.
function test_build_hello_world_with_remote_embedded_tool_targets() {
write_hello_library_files

bazel build //java/main:main_deploy.jar --define EXECUTOR=remote \
&> $TEST_log || fail "build failed"
}
74 changes: 65 additions & 9 deletions src/upload_all_java_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -32,14 +26,76 @@
# 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)

# 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

test_name="bazel_java_test_javac${java_version}_${commit_hash}_$(date +%s)"
cat >>src/test/shell/bazel/BUILD <<EOF
sh_test(
name = "${test_name}",
size = "large",
timeout = "eternal",
srcs = ["bazel_java_test.sh"],
args = [
# --java_toolchain
"@local_java_tools//:toolchain",
# location of java_tools
"${file_url}",
# --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",
"@bazel_tools//tools/bash/runfiles",
],
)
EOF
bazel test --verbose_failures --test_output=all //src/test/shell/bazel:${test_name}

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
24 changes: 23 additions & 1 deletion src/upload_java_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ else
fi
# --- end runfiles.bash initialization ---

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

# Parsing the flags.
while [[ -n "$@" ]]; do
arg="$1"; shift
Expand Down Expand Up @@ -95,6 +109,14 @@ if [[ "$platform" == "windows" ]]; then
gsutil_cmd="gsutil.cmd"
fi


if "$is_windows"; then
zip_url=$(cygpath -m ${tmp_zip})
else
# Non-Windows needs "file:///foo/bar".
zip_url=${tmp_zip}
fi

# Upload the zip that contains the README.md to GCS.
"$gsutil_cmd" cp "$tmp_zip" \
"$gsutil_cmd" cp "$zip_url" \
"gs://bazel-mirror/bazel_java_tools/${gcs_java_tools_dir}/${commit_hash}/java${java_version}/java_tools_javac${java_version}_${platform}-${timestamp}.zip"

0 comments on commit cf87b44

Please sign in to comment.