blob: d4ab77ca70e39b023d867215e606212ee14d2e13 [file] [log] [blame]
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +00001#!/bin/bash
2
3# TODO: Refactor build/make/envsetup.sh to make gettop() available elsewhere
4function gettop
5{
Justin Paupore05ce74a2021-02-02 06:03:15 +00006 local TOPFILE=build/bazel/bazel.sh
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +00007 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 Shuttleworth00d545a2020-10-27 04:05:06 +000031# TODO: Refactor build/soong/scripts/microfactory.bash to make getoutdir() available elsewhere
32function 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
48TOP="$(gettop)"
49if [ ! "$TOP" ]; then
Chris Parsonsfe211102020-11-04 18:53:00 -050050 >&2 echo "Couldn't locate the top of the tree. Try setting TOP."
51 exit 1
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +000052fi
53
54case $(uname -s) in
55 Darwin)
Rupert Shuttleworth00d545a2020-10-27 04:05:06 +000056 ANDROID_BAZEL_PATH="${TOP}/prebuilts/bazel/darwin-x86_64/bazel"
Justin Paupore6d4180c2021-02-17 08:50:17 +000057 ANDROID_BAZELRC_NAME="darwin.bazelrc"
Rupert Shuttleworth00d545a2020-10-27 04:05:06 +000058 ANDROID_BAZEL_JDK_PATH="${TOP}/prebuilts/jdk/jdk11/darwin-x86"
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +000059 ;;
60 Linux)
Rupert Shuttleworth00d545a2020-10-27 04:05:06 +000061 ANDROID_BAZEL_PATH="${TOP}/prebuilts/bazel/linux-x86_64/bazel"
Justin Paupore6d4180c2021-02-17 08:50:17 +000062 ANDROID_BAZELRC_NAME="linux.bazelrc"
Rupert Shuttleworth00d545a2020-10-27 04:05:06 +000063 ANDROID_BAZEL_JDK_PATH="${TOP}/prebuilts/jdk/jdk11/linux-x86"
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +000064 ;;
65 *)
66 ANDROID_BAZEL_PATH=
Justin Paupore6d4180c2021-02-17 08:50:17 +000067 ANDROID_BAZELRC_NAME=
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +000068 ANDROID_BAZEL_JDK_PATH=
69 ;;
70esac
71
Justin Paupore6d4180c2021-02-17 08:50:17 +000072case "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 ;;
85esac
86
87if [ -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}"
90fi
91
92
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +000093if [ -n "$ANDROID_BAZEL_PATH" -a -f "$ANDROID_BAZEL_PATH" ]; then
94 export ANDROID_BAZEL_PATH
95else
Chris Parsonsfe211102020-11-04 18:53:00 -050096 >&2 echo "Couldn't locate Bazel binary"
97 exit 1
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +000098fi
99
100if [ -n "$ANDROID_BAZELRC_PATH" -a -f "$ANDROID_BAZELRC_PATH" ]; then
101 export ANDROID_BAZELRC_PATH
102else
Chris Parsonsfe211102020-11-04 18:53:00 -0500103 >&2 echo "Couldn't locate bazelrc file for Bazel"
104 exit 1
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +0000105fi
106
107if [ -n "$ANDROID_BAZEL_JDK_PATH" -a -d "$ANDROID_BAZEL_JDK_PATH" ]; then
108 export ANDROID_BAZEL_JDK_PATH
109else
Chris Parsonsfe211102020-11-04 18:53:00 -0500110 >&2 echo "Couldn't locate JDK to use for Bazel"
111 exit 1
Rupert Shuttleworth2e2a9e32020-10-25 05:05:17 +0000112fi
113
Chris Parsonsfe211102020-11-04 18:53:00 -0500114>&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 Shuttleworth2e2a9e32020-10-25 05:05:17 +0000117
Jingwen Chen289ca852020-11-06 05:50:06 -0500118ABSOLUTE_OUT_DIR="$(getoutdir)" \
119 "${ANDROID_BAZEL_PATH}" \
Rupert Shuttleworth00d545a2020-10-27 04:05:06 +0000120 --server_javabase="${ANDROID_BAZEL_JDK_PATH}" \
121 --output_user_root="$(getoutdir)/bazel/output_user_root" \
122 --bazelrc="${ANDROID_BAZELRC_PATH}" \
123 "$@"