|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2024 The Bazel Authors. All rights reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -o errexit -o nounset -o pipefail |
| 17 | + |
| 18 | +# Set by GH actions, see |
| 19 | +# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables |
| 20 | +TAG=${GITHUB_REF_NAME} |
| 21 | +# The prefix is chosen to match what GitHub generates for source archives |
| 22 | +# This guarantees that users can easily switch from a released artifact to a source archive |
| 23 | +# with minimal differences in their code (e.g. strip_prefix remains the same) |
| 24 | +PREFIX="rules_android-${TAG:1}" |
| 25 | +ARCHIVE="rules_android-$TAG.tar.gz" |
| 26 | + |
| 27 | +# NB: configuration for 'git archive' is in /.gitattributes |
| 28 | +git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE |
| 29 | +SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') |
| 30 | + |
| 31 | +cat << EOF |
| 32 | +## Using Bzlmod with Bazel 6 or greater |
| 33 | +
|
| 34 | +1. (Bazel 6 only) Enable with \`common --enable_bzlmod\` in \`.bazelrc\`. |
| 35 | +2. Add to your \`MODULE.bazel\` file: |
| 36 | +
|
| 37 | +\`\`\`starlark |
| 38 | +bazel_dep(name = "rules_android", version = "${TAG:1}") |
| 39 | +\`\`\` |
| 40 | +
|
| 41 | +## Using WORKSPACE |
| 42 | +
|
| 43 | +Paste this snippet into your \`WORKSPACE.bazel\` file: |
| 44 | +
|
| 45 | +\`\`\`starlark |
| 46 | +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| 47 | +http_archive( |
| 48 | + name = "rules_android", |
| 49 | + sha256 = "${SHA}", |
| 50 | + strip_prefix = "${PREFIX}", |
| 51 | + url = "https://github.com/bazelbuild/rules_android/releases/download/${TAG}/${ARCHIVE}", |
| 52 | +) |
| 53 | +EOF |
| 54 | + |
| 55 | +awk 'f;/--SNIP--/{f=1}' examples/basicapp/WORKSPACE |
| 56 | +echo "\`\`\`" |
0 commit comments