Include a README.md in the java tools release with instructions on how to re-create from source the same release. Closes #8040. PiperOrigin-RevId: 243789723
diff --git a/src/upload_all_java_tools.sh b/src/upload_all_java_tools.sh new file mode 100755 index 0000000..b560e08 --- /dev/null +++ b/src/upload_all_java_tools.sh
@@ -0,0 +1,45 @@ +#!/bin/bash + +# Copyright 2019 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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. +# +# The script has to be executed directly without invoking bazel: +# $ src/upload_all_java_tools.sh +# +# The script cannot be invoked through a sh_binary using bazel because git +# cannot be used through a sh_binary. + +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 +done
diff --git a/src/upload_java_tools.sh b/src/upload_java_tools.sh index 64d344a..5dc0712 100755 --- a/src/upload_java_tools.sh +++ b/src/upload_java_tools.sh
@@ -55,16 +55,46 @@ "--gcs_java_tools_dir") gcs_java_tools_dir="$val" ;; "--java_version") java_version="$val" ;; "--platform") platform="$val" ;; + "--commit_hash") commit_hash="$val" ;; + "--timestamp") timestamp="$val" ;; + "--bazel_version") bazel_version="$val" ;; *) echo "Flag $arg is not recognized." && exit 1 ;; esac done java_tools_zip=$(rlocation io_bazel/${java_tools_zip_name}) +# Create a temp directory and a writable temp zip file to add a README.md file to +# the initial zip. +tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXX') +trap "rm -fr $tmp_dir" EXIT +tmp_zip="$tmp_dir/archive.zip" + +# Copy the initial zip to the temp zip and make it writable to be able to add +# the README.md file. +cp $java_tools_zip $tmp_zip +chmod +w $tmp_zip + +# Create the README.md file and add the re-build java tools instructions. +readme_file="README.md" +cat >${readme_file} <<EOF +This Java tools version was built from the bazel repository at commit hash ${commit_hash} +using bazel version ${bazel_version}. +To build from source the same zip run the commands: + +$ git clone https://github.com/bazelbuild/bazel.git +$ git checkout ${commit_hash} +$ bazel build //src:java_tools_java${java_version}.zip +EOF + +# Add the README.md file to the temp zip. +zip -rv "${tmp_zip}" "${readme_file}" + gsutil_cmd="gsutil" if [[ "$platform" == "windows" ]]; then gsutil_cmd="gsutil.cmd" fi -"$gsutil_cmd" cp "$java_tools_zip" \ - "gs://bazel-mirror/bazel_java_tools/${gcs_java_tools_dir}/java_tools_javac${java_version}_${platform}-$(date +%s).zip" +# Upload the zip that contains the README.md to GCS. +"$gsutil_cmd" cp "$tmp_zip" \ + "gs://bazel-mirror/bazel_java_tools/${gcs_java_tools_dir}/java_tools_javac${java_version}_${platform}-${commit_hash}-${timestamp}.zip"