blob: f2fdabcee1cd784c02ef8839efdd4e94bb654ccd [file] [log] [blame]
iirinae277b0c2019-04-16 05:25:01 -07001#!/bin/bash
2
3# Copyright 2019 The Bazel Authors. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# A script to upload a given java_tools zip on GCS. Used by the java_tools_binaries
18# Buildkite pipeline. It is not recommended to run this script manually.
iirinae277b0c2019-04-16 05:25:01 -070019
20# Script used by the "java_tools binaries" Buildkite pipeline to build the java tools archives
21# and upload them on GCS.
22#
23# The script has to be executed directly without invoking bazel:
24# $ src/upload_all_java_tools.sh
25#
26# The script cannot be invoked through a sh_binary using bazel because git
27# cannot be used through a sh_binary.
28
iirina1df16352019-05-09 05:48:58 -070029set -euo pipefail
30
31case "$(uname -s | tr [:upper:] [:lower:])" in
32msys*|mingw*|cygwin*)
Ivo Listd10013d2020-11-25 14:41:16 -080033 declare -r platform=windows
34 ;;
35linux*)
36 declare -r platform=linux
iirina1df16352019-05-09 05:48:58 -070037 ;;
38*)
Ivo Listd10013d2020-11-25 14:41:16 -080039 declare -r platform=other
iirina1df16352019-05-09 05:48:58 -070040 ;;
41esac
42
Ivo Listd10013d2020-11-25 14:41:16 -080043echo Platform: $platform
44
45if [[ "$platform" == "windows" ]]; then
iirina1df16352019-05-09 05:48:58 -070046 export MSYS_NO_PATHCONV=1
47 export MSYS2_ARG_CONV_EXCL="*"
48fi
49
iirinae277b0c2019-04-16 05:25:01 -070050commit_hash=$(git rev-parse HEAD)
51timestamp=$(date +%s)
52bazel_version=$(bazel info release | cut -d' ' -f2)
53
hvadehraa1ec09a2022-06-28 02:58:55 -070054JAVA_BUILD_OPTS="--tool_java_language_version=8 --java_language_version=8"
55
iirinae277b0c2019-04-16 05:25:01 -070056# Passing the same commit_hash and timestamp to all targets to mark all the artifacts
57# uploaded on GCS with the same identifier.
iirina1df16352019-05-09 05:48:58 -070058
hvadehraa1ec09a2022-06-28 02:58:55 -070059bazel build ${JAVA_BUILD_OPTS} //src:java_tools_zip
Ivo Listd10013d2020-11-25 14:41:16 -080060zip_path=${PWD}/bazel-bin/src/java_tools.zip
iirina1df16352019-05-09 05:48:58 -070061
hvadehraa1ec09a2022-06-28 02:58:55 -070062bazel build ${JAVA_BUILD_OPTS} //src:java_tools_prebuilt_zip
Ivo Listd10013d2020-11-25 14:41:16 -080063prebuilt_zip_path=${PWD}/bazel-bin/src/java_tools_prebuilt.zip
Ivo List23c44062020-10-19 07:30:47 -070064
Ivo Listd10013d2020-11-25 14:41:16 -080065if [[ "$platform" == "windows" ]]; then
66 # Windows needs "file:///c:/foo/bar".
67 file_url="file:///$(cygpath -m ${zip_path})"
68 prebuilt_file_url="file:///$(cygpath -m ${prebuilt_zip_path})"
69else
70 # Non-Windows needs "file:///foo/bar".
71 file_url="file://${zip_path}"
72 prebuilt_file_url="file://${prebuilt_zip_path}"
73fi
74
75# Skip for now, as the test is broken on Windows.
76# See https://github.com/bazelbuild/bazel/issues/12244 for details
77if [[ "$platform" != "windows" ]]; then
hvdb02458e2022-04-11 04:52:04 -070078 JAVA_VERSIONS=`cat src/test/shell/bazel/BUILD | grep '^JAVA_VERSIONS = ' | sed -e 's/JAVA_VERSIONS = //' | sed -e 's/["(),]//g'`
79 for java_version in $JAVA_VERSIONS; do
Ivo List23c44062020-10-19 07:30:47 -070080 bazel test --verbose_failures --test_output=all --nocache_test_results \
81 //src/test/shell/bazel:bazel_java_test_local_java_tools_jdk${java_version} \
Ivo Listd10013d2020-11-25 14:41:16 -080082 --define=LOCAL_JAVA_TOOLS_ZIP_URL="${file_url}" \
83 --define=LOCAL_JAVA_TOOLS_PREBUILT_ZIP_URL="${prebuilt_file_url}"
84 done
85fi
iirina1df16352019-05-09 05:48:58 -070086
hvadehraa1ec09a2022-06-28 02:58:55 -070087bazel run ${JAVA_BUILD_OPTS} //src:upload_java_tools_prebuilt -- \
Ivo Listd10013d2020-11-25 14:41:16 -080088 --commit_hash ${commit_hash} \
89 --timestamp ${timestamp} \
90 --bazel_version ${bazel_version}
91
92if [[ "$platform" == "linux" ]]; then
hvadehraa1ec09a2022-06-28 02:58:55 -070093 bazel run ${JAVA_BUILD_OPTS} //src:upload_java_tools -- \
iirina1df16352019-05-09 05:48:58 -070094 --commit_hash ${commit_hash} \
95 --timestamp ${timestamp} \
96 --bazel_version ${bazel_version}
97
hvadehraa1ec09a2022-06-28 02:58:55 -070098 bazel run ${JAVA_BUILD_OPTS} //src:upload_java_tools_dist -- \
iirina1df16352019-05-09 05:48:58 -070099 --commit_hash ${commit_hash} \
100 --timestamp ${timestamp} \
101 --bazel_version ${bazel_version}
Ivo Listd10013d2020-11-25 14:41:16 -0800102fi