iirina | 93e8073 | 2019-04-16 02:07:40 -0700 | [diff] [blame] | 1 | #!/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. |
| 19 | # |
| 20 | # Mandatory flags: |
| 21 | # --java_tools_zip The workspace-relative path of a java_tools zip. |
| 22 | # --gcs_java_tools_dir The directory under bazel_java_tools on GCS where the zip is uploaded. |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 23 | # --platform Optional: The name of the platform where the zip was built. (If empty the zip should be platform independent). |
iirina | 93e8073 | 2019-04-16 02:07:40 -0700 | [diff] [blame] | 24 | |
| 25 | set -euo pipefail |
| 26 | |
| 27 | # --- begin runfiles.bash initialization --- |
| 28 | if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then |
| 29 | if [[ -f "$0.runfiles_manifest" ]]; then |
| 30 | export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" |
| 31 | elif [[ -f "$0.runfiles/MANIFEST" ]]; then |
| 32 | export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" |
| 33 | elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then |
| 34 | export RUNFILES_DIR="$0.runfiles" |
| 35 | fi |
| 36 | fi |
| 37 | if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then |
| 38 | source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" |
| 39 | elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then |
| 40 | source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ |
| 41 | "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" |
| 42 | else |
| 43 | echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" |
| 44 | exit 1 |
| 45 | fi |
| 46 | # --- end runfiles.bash initialization --- |
| 47 | |
iirina | 1df1635 | 2019-05-09 05:48:58 -0700 | [diff] [blame] | 48 | case "$(uname -s | tr [:upper:] [:lower:])" in |
| 49 | msys*|mingw*|cygwin*) |
| 50 | declare -r is_windows=true |
| 51 | ;; |
| 52 | *) |
| 53 | declare -r is_windows=false |
| 54 | ;; |
| 55 | esac |
| 56 | |
| 57 | if "$is_windows"; then |
| 58 | export MSYS_NO_PATHCONV=1 |
| 59 | export MSYS2_ARG_CONV_EXCL="*" |
| 60 | fi |
| 61 | |
iirina | 93e8073 | 2019-04-16 02:07:40 -0700 | [diff] [blame] | 62 | # Parsing the flags. |
| 63 | while [[ -n "$@" ]]; do |
| 64 | arg="$1"; shift |
| 65 | val="$1"; shift |
| 66 | case "$arg" in |
| 67 | "--java_tools_zip") java_tools_zip_name="$val" ;; |
| 68 | "--gcs_java_tools_dir") gcs_java_tools_dir="$val" ;; |
iirina | 93e8073 | 2019-04-16 02:07:40 -0700 | [diff] [blame] | 69 | "--platform") platform="$val" ;; |
iirina | e277b0c | 2019-04-16 05:25:01 -0700 | [diff] [blame] | 70 | "--commit_hash") commit_hash="$val" ;; |
| 71 | "--timestamp") timestamp="$val" ;; |
| 72 | "--bazel_version") bazel_version="$val" ;; |
iirina | 93e8073 | 2019-04-16 02:07:40 -0700 | [diff] [blame] | 73 | *) echo "Flag $arg is not recognized." && exit 1 ;; |
| 74 | esac |
| 75 | done |
| 76 | |
| 77 | java_tools_zip=$(rlocation io_bazel/${java_tools_zip_name}) |
| 78 | |
iirina | e277b0c | 2019-04-16 05:25:01 -0700 | [diff] [blame] | 79 | # Create a temp directory and a writable temp zip file to add a README.md file to |
| 80 | # the initial zip. |
Googler | b0172be | 2020-06-09 05:05:08 -0700 | [diff] [blame] | 81 | tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXXX') |
iirina | e277b0c | 2019-04-16 05:25:01 -0700 | [diff] [blame] | 82 | trap "rm -fr $tmp_dir" EXIT |
| 83 | tmp_zip="$tmp_dir/archive.zip" |
| 84 | |
| 85 | # Copy the initial zip to the temp zip and make it writable to be able to add |
| 86 | # the README.md file. |
| 87 | cp $java_tools_zip $tmp_zip |
| 88 | chmod +w $tmp_zip |
| 89 | |
Noa Resare | 9004fc7 | 2022-04-08 04:31:39 -0700 | [diff] [blame] | 90 | target_basename=$(basename $java_tools_zip) |
| 91 | |
iirina | e277b0c | 2019-04-16 05:25:01 -0700 | [diff] [blame] | 92 | # Create the README.md file and add the re-build java tools instructions. |
| 93 | readme_file="README.md" |
| 94 | cat >${readme_file} <<EOF |
| 95 | This Java tools version was built from the bazel repository at commit hash ${commit_hash} |
Noa Resare | 9004fc7 | 2022-04-08 04:31:39 -0700 | [diff] [blame] | 96 | using bazel version ${bazel_version}${platform:+" on platform ${platform}"}. |
iirina | e277b0c | 2019-04-16 05:25:01 -0700 | [diff] [blame] | 97 | To build from source the same zip run the commands: |
| 98 | |
| 99 | $ git clone https://github.com/bazelbuild/bazel.git |
| 100 | $ git checkout ${commit_hash} |
Noa Resare | 9004fc7 | 2022-04-08 04:31:39 -0700 | [diff] [blame] | 101 | $ bazel build //src:${target_basename} |
iirina | e277b0c | 2019-04-16 05:25:01 -0700 | [diff] [blame] | 102 | EOF |
| 103 | |
| 104 | # Add the README.md file to the temp zip. |
| 105 | zip -rv "${tmp_zip}" "${readme_file}" |
| 106 | |
iirina | 93e8073 | 2019-04-16 02:07:40 -0700 | [diff] [blame] | 107 | gsutil_cmd="gsutil" |
Ivo List | d10013d | 2020-11-25 14:41:16 -0800 | [diff] [blame] | 108 | if "$is_windows"; then |
iirina | 93e8073 | 2019-04-16 02:07:40 -0700 | [diff] [blame] | 109 | gsutil_cmd="gsutil.cmd" |
| 110 | fi |
| 111 | |
iirina | 1df1635 | 2019-05-09 05:48:58 -0700 | [diff] [blame] | 112 | |
| 113 | if "$is_windows"; then |
| 114 | zip_url=$(cygpath -m ${tmp_zip}) |
| 115 | else |
| 116 | # Non-Windows needs "file:///foo/bar". |
| 117 | zip_url=${tmp_zip} |
| 118 | fi |
| 119 | |
iirina | e277b0c | 2019-04-16 05:25:01 -0700 | [diff] [blame] | 120 | # Upload the zip that contains the README.md to GCS. |
iirina | 1df1635 | 2019-05-09 05:48:58 -0700 | [diff] [blame] | 121 | "$gsutil_cmd" cp "$zip_url" \ |
Noa Resare | 9004fc7 | 2022-04-08 04:31:39 -0700 | [diff] [blame] | 122 | "gs://bazel-mirror/bazel_java_tools/${gcs_java_tools_dir}/${commit_hash}/java/java_tools${platform:+"_${platform}"}-${timestamp}.zip" |