File: upload_android_tools.sh

package info (click to toggle)
bazel-bootstrap 4.2.3%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 85,476 kB
  • sloc: java: 721,710; sh: 55,859; cpp: 35,359; python: 12,139; xml: 295; objc: 269; makefile: 113; ansic: 106; ruby: 3
file content (70 lines) | stat: -rwxr-xr-x 2,869 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/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.

# This script builds a new version of android_tools.tar.gz and uploads
# it to Google Cloud Storage. This script is non-destructive and idempotent.
#
# To run this script, call:
# `bazel run //tools/android/runtime_deps:upload_android_tools`
#
# android_tools.tar.gz contains runtime jars required by the Android rules. We unbundled
# these jars out from Bazel to keep its binary size small.
#
# If you make changes any tool bundled in android_tools.tar.gz and want them to be used for
# the next Bazel release, increment the version number and run this script.
#
# More context: https://github.com/bazelbuild/bazel/issues/1055

set -euo pipefail

# The version of android_tools.tar.gz
VERSION="0.21.0"
VERSIONED_FILENAME="android_tools_pkg-$VERSION.tar.gz"

# Create a temp directory to hold the versioned tarball, and clean it up when the script exits.
tmpdir=$(mktemp -d)
function cleanup {
  rm -rf "$tmpdir"
}
trap cleanup EXIT

# Add the version to the tarball.
android_tools_archive="tools/android/runtime_deps/android_tools.tar.gz"
versioned_android_tools_archive="$tmpdir/$VERSIONED_FILENAME"
cp $android_tools_archive $versioned_android_tools_archive

# Upload the tarball to GCS.
# -n for no-clobber, so we don't overwrite existing files
gsutil cp -n $versioned_android_tools_archive \
  gs://bazel-mirror/bazel_android_tools/$VERSIONED_FILENAME

checksum=$(sha256sum $versioned_android_tools_archive | cut -f 1 -d ' ')

echo
echo "Run this command to update Bazel to use the new version:"
echo

cat <<EOF
sed -i 's/android_tools_pkg.*\.tar\.gz/$VERSIONED_FILENAME/g' WORKSPACE  && \\
  sed -i 's/"[0-9a-fA-F]\{64\}", # DO_NOT_REMOVE_THIS_ANDROID_TOOLS_UPDATE_MARKER/"$checksum", # DO_NOT_REMOVE_THIS_ANDROID_TOOLS_UPDATE_MARKER/g' WORKSPACE && \\
  sed -i 's/"android_tools_pkg.*[0-9a-FA-F]\{64\}",.*/"$VERSIONED_FILENAME": "$checksum",/g' WORKSPACE && \\
  sed -i 's/android_tools_pkg.*\.tar\.gz/$VERSIONED_FILENAME/g' src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_remote_tools.WORKSPACE && \\
  sed -i 's/"[0-9a-fA-F]\{64\}",.*/"$checksum",/g' src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_remote_tools.WORKSPACE
EOF

echo
echo "Then, commit the changes and submit a pull request."
echo