Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # TODO: Refactor build/make/envsetup.sh to make gettop() available elsewhere |
| 4 | function gettop |
| 5 | { |
Justin Paupore | 05ce74a | 2021-02-02 06:03:15 +0000 | [diff] [blame] | 6 | local TOPFILE=build/bazel/bazel.sh |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 7 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
| 8 | # The following circumlocution ensures we remove symlinks from TOP. |
| 9 | (cd "$TOP"; PWD= /bin/pwd) |
| 10 | else |
| 11 | if [ -f $TOPFILE ] ; then |
| 12 | # The following circumlocution (repeated below as well) ensures |
| 13 | # that we record the true directory name and not one that is |
| 14 | # faked up with symlink names. |
| 15 | PWD= /bin/pwd |
| 16 | else |
| 17 | local HERE=$PWD |
| 18 | local T= |
| 19 | while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do |
| 20 | \cd .. |
| 21 | T=`PWD= /bin/pwd -P` |
| 22 | done |
| 23 | \cd "$HERE" |
| 24 | if [ -f "$T/$TOPFILE" ]; then |
| 25 | echo "$T" |
| 26 | fi |
| 27 | fi |
| 28 | fi |
| 29 | } |
| 30 | |
Rupert Shuttleworth | 00d545a | 2020-10-27 04:05:06 +0000 | [diff] [blame] | 31 | # TODO: Refactor build/soong/scripts/microfactory.bash to make getoutdir() available elsewhere |
| 32 | function getoutdir |
| 33 | { |
| 34 | local out_dir="${OUT_DIR-}" |
| 35 | if [ -z "${out_dir}" ]; then |
| 36 | if [ "${OUT_DIR_COMMON_BASE-}" ]; then |
| 37 | out_dir="${OUT_DIR_COMMON_BASE}/$(basename ${TOP})" |
| 38 | else |
| 39 | out_dir="out" |
| 40 | fi |
| 41 | fi |
| 42 | if [[ "${out_dir}" != /* ]]; then |
| 43 | out_dir="${TOP}/${out_dir}" |
| 44 | fi |
| 45 | echo "${out_dir}" |
| 46 | } |
| 47 | |
| 48 | TOP="$(gettop)" |
| 49 | if [ ! "$TOP" ]; then |
Chris Parsons | fe21110 | 2020-11-04 18:53:00 -0500 | [diff] [blame] | 50 | >&2 echo "Couldn't locate the top of the tree. Try setting TOP." |
| 51 | exit 1 |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 52 | fi |
| 53 | |
| 54 | case $(uname -s) in |
| 55 | Darwin) |
Rupert Shuttleworth | 00d545a | 2020-10-27 04:05:06 +0000 | [diff] [blame] | 56 | ANDROID_BAZEL_PATH="${TOP}/prebuilts/bazel/darwin-x86_64/bazel" |
Justin Paupore | 6d4180c | 2021-02-17 08:50:17 +0000 | [diff] [blame] | 57 | ANDROID_BAZELRC_NAME="darwin.bazelrc" |
Rupert Shuttleworth | 00d545a | 2020-10-27 04:05:06 +0000 | [diff] [blame] | 58 | ANDROID_BAZEL_JDK_PATH="${TOP}/prebuilts/jdk/jdk11/darwin-x86" |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 59 | ;; |
| 60 | Linux) |
Rupert Shuttleworth | 00d545a | 2020-10-27 04:05:06 +0000 | [diff] [blame] | 61 | ANDROID_BAZEL_PATH="${TOP}/prebuilts/bazel/linux-x86_64/bazel" |
Justin Paupore | 6d4180c | 2021-02-17 08:50:17 +0000 | [diff] [blame] | 62 | ANDROID_BAZELRC_NAME="linux.bazelrc" |
Rupert Shuttleworth | 00d545a | 2020-10-27 04:05:06 +0000 | [diff] [blame] | 63 | ANDROID_BAZEL_JDK_PATH="${TOP}/prebuilts/jdk/jdk11/linux-x86" |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 64 | ;; |
| 65 | *) |
| 66 | ANDROID_BAZEL_PATH= |
Justin Paupore | 6d4180c | 2021-02-17 08:50:17 +0000 | [diff] [blame] | 67 | ANDROID_BAZELRC_NAME= |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 68 | ANDROID_BAZEL_JDK_PATH= |
| 69 | ;; |
| 70 | esac |
| 71 | |
Justin Paupore | 6d4180c | 2021-02-17 08:50:17 +0000 | [diff] [blame] | 72 | case "x${ANDROID_BAZELRC_PATH}" in |
| 73 | x) |
| 74 | # Path not provided, use default. |
| 75 | ANDROID_BAZELRC_PATH="${TOP}/build/bazel" |
| 76 | ;; |
| 77 | x/*) |
| 78 | # Absolute path, take it as-is. |
| 79 | ANDROID_BAZELRC_PATH="${ANDROID_BAZELRC_PATH}" |
| 80 | ;; |
| 81 | x*) |
| 82 | # Relative path, consider it relative to TOP. |
| 83 | ANDROID_BAZELRC_PATH="${TOP}/${ANDROID_BAZELRC_PATH}" |
| 84 | ;; |
| 85 | esac |
| 86 | |
| 87 | if [ -d "${ANDROID_BAZELRC_PATH}" ]; then |
| 88 | # If we're given a directory, find the correct bazelrc file there. |
| 89 | ANDROID_BAZELRC_PATH="${ANDROID_BAZELRC_PATH}/${ANDROID_BAZELRC_NAME}" |
| 90 | fi |
| 91 | |
| 92 | |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 93 | if [ -n "$ANDROID_BAZEL_PATH" -a -f "$ANDROID_BAZEL_PATH" ]; then |
| 94 | export ANDROID_BAZEL_PATH |
| 95 | else |
Chris Parsons | fe21110 | 2020-11-04 18:53:00 -0500 | [diff] [blame] | 96 | >&2 echo "Couldn't locate Bazel binary" |
| 97 | exit 1 |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 98 | fi |
| 99 | |
| 100 | if [ -n "$ANDROID_BAZELRC_PATH" -a -f "$ANDROID_BAZELRC_PATH" ]; then |
| 101 | export ANDROID_BAZELRC_PATH |
| 102 | else |
Chris Parsons | fe21110 | 2020-11-04 18:53:00 -0500 | [diff] [blame] | 103 | >&2 echo "Couldn't locate bazelrc file for Bazel" |
| 104 | exit 1 |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 105 | fi |
| 106 | |
| 107 | if [ -n "$ANDROID_BAZEL_JDK_PATH" -a -d "$ANDROID_BAZEL_JDK_PATH" ]; then |
| 108 | export ANDROID_BAZEL_JDK_PATH |
| 109 | else |
Chris Parsons | fe21110 | 2020-11-04 18:53:00 -0500 | [diff] [blame] | 110 | >&2 echo "Couldn't locate JDK to use for Bazel" |
| 111 | exit 1 |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 112 | fi |
| 113 | |
Chris Parsons | fe21110 | 2020-11-04 18:53:00 -0500 | [diff] [blame] | 114 | >&2 echo "WARNING: Bazel support for the Android Platform is experimental and is undergoing development." |
| 115 | >&2 echo "WARNING: Currently, build stability is not guaranteed. Thank you." |
| 116 | >&2 echo |
Rupert Shuttleworth | 2e2a9e3 | 2020-10-25 05:05:17 +0000 | [diff] [blame] | 117 | |
Jingwen Chen | 289ca85 | 2020-11-06 05:50:06 -0500 | [diff] [blame] | 118 | ABSOLUTE_OUT_DIR="$(getoutdir)" \ |
| 119 | "${ANDROID_BAZEL_PATH}" \ |
Rupert Shuttleworth | 00d545a | 2020-10-27 04:05:06 +0000 | [diff] [blame] | 120 | --server_javabase="${ANDROID_BAZEL_JDK_PATH}" \ |
| 121 | --output_user_root="$(getoutdir)/bazel/output_user_root" \ |
| 122 | --bazelrc="${ANDROID_BAZELRC_PATH}" \ |
| 123 | "$@" |