• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# TODO: Refactor build/make/envsetup.sh to make gettop() available elsewhere
4function gettop
5{
6    local TOPFILE=build/bazel/bazel.sh
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
31# 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
50    >&2 echo "Couldn't locate the top of the tree.  Try setting TOP."
51    exit 1
52fi
53
54case $(uname -s) in
55    Darwin)
56        ANDROID_BAZEL_PATH="${TOP}/prebuilts/bazel/darwin-x86_64/bazel"
57        ANDROID_BAZELRC_NAME="darwin.bazelrc"
58        ANDROID_BAZEL_JDK_PATH="${TOP}/prebuilts/jdk/jdk11/darwin-x86"
59        ;;
60    Linux)
61        ANDROID_BAZEL_PATH="${TOP}/prebuilts/bazel/linux-x86_64/bazel"
62        ANDROID_BAZELRC_NAME="linux.bazelrc"
63        ANDROID_BAZEL_JDK_PATH="${TOP}/prebuilts/jdk/jdk11/linux-x86"
64        ;;
65    *)
66        ANDROID_BAZEL_PATH=
67        ANDROID_BAZELRC_NAME=
68        ANDROID_BAZEL_JDK_PATH=
69        ;;
70esac
71
72case "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
93if [ -n "$ANDROID_BAZEL_PATH" -a -f "$ANDROID_BAZEL_PATH" ]; then
94    export ANDROID_BAZEL_PATH
95else
96    >&2 echo "Couldn't locate Bazel binary"
97    exit 1
98fi
99
100if [ -n "$ANDROID_BAZELRC_PATH" -a -f "$ANDROID_BAZELRC_PATH" ]; then
101    export ANDROID_BAZELRC_PATH
102else
103    >&2 echo "Couldn't locate bazelrc file for Bazel"
104    exit 1
105fi
106
107if [ -n "$ANDROID_BAZEL_JDK_PATH" -a -d "$ANDROID_BAZEL_JDK_PATH" ]; then
108    export ANDROID_BAZEL_JDK_PATH
109else
110    >&2 echo "Couldn't locate JDK to use for Bazel"
111    exit 1
112fi
113
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
117
118ABSOLUTE_OUT_DIR="$(getoutdir)" \
119  "${ANDROID_BAZEL_PATH}" \
120  --server_javabase="${ANDROID_BAZEL_JDK_PATH}" \
121  --output_user_root="$(getoutdir)/bazel/output_user_root" \
122  --bazelrc="${ANDROID_BAZELRC_PATH}" \
123  "$@"
124