blob: 8f65b2924d22b89b86dc1ce30163d7f1546bfa96 [file] [log] [blame]
Patrice Arrudaba9a28b2020-09-28 21:52:15 +00001function _source_env_setup_script() {
2 local -r ENV_SETUP_SCRIPT="build/make/envsetup.sh"
3 local -r TOP_DIR=$(
4 while [[ ! -f "${ENV_SETUP_SCRIPT}" ]] && [[ "${PWD}" != "/" ]]; do
5 \cd ..
6 done
7 if [[ -f "${ENV_SETUP_SCRIPT}" ]]; then
8 echo "$(PWD= /bin/pwd -P)"
9 fi
10 )
11
12 local -r FULL_PATH_ENV_SETUP_SCRIPT="${TOP_DIR}/${ENV_SETUP_SCRIPT}"
13 if [[ ! -f "${FULL_PATH_ENV_SETUP_SCRIPT}" ]]; then
14 echo "ERROR: Unable to source ${ENV_SETUP_SCRIPT}"
15 return 1
16 fi
17
18 # Need to change directory to the repo root so vendor scripts can be sourced
19 # as well.
20 local -r CUR_DIR=$PWD
21 \cd "${TOP_DIR}"
22 source "${FULL_PATH_ENV_SETUP_SCRIPT}"
23 \cd "${CUR_DIR}"
24}
25
26# This function needs to run first as the remaining defining functions may be
27# using the envsetup.sh defined functions.
28_source_env_setup_script || return
Kousik Kumar6a19b062020-03-05 14:08:09 -080029
30# This function prefixes the given command with appropriate variables needed
31# for the build to be executed with RBE.
32function use_rbe() {
33 local RBE_LOG_DIR="/tmp"
34 local RBE_BINARIES_DIR="prebuilts/remoteexecution-client/latest/"
35 local DOCKER_IMAGE="gcr.io/androidbuild-re-dockerimage/android-build-remoteexec-image@sha256:582efb38f0c229ea39952fff9e132ccbe183e14869b39888010dacf56b360d62"
36
37 # Do not set an invocation-ID and let reproxy auto-generate one.
38 USE_RBE="true" \
39 FLAG_server_address="unix:///tmp/reproxy_$RANDOM.sock" \
40 FLAG_exec_root="$(gettop)" \
41 FLAG_platform="container-image=docker://${DOCKER_IMAGE}" \
42 RBE_use_application_default_credentials="true" \
43 RBE_log_dir="${RBE_LOG_DIR}" \
44 RBE_reproxy_wait_seconds="20" \
45 RBE_output_dir="${RBE_LOG_DIR}" \
46 RBE_log_path="text://${RBE_LOG_DIR}/reproxy_log.txt" \
47 RBE_CXX_EXEC_STRATEGY="remote_local_fallback" \
48 RBE_cpp_dependency_scanner_plugin="${RBE_BINARIES_DIR}/dependency_scanner_go_plugin.so" \
49 RBE_DIR=${RBE_BINARIES_DIR} \
50 RBE_re_proxy="${RBE_BINARIES_DIR}/reproxy" \
51 $@
52}
Ramy Medhat4d158b52020-08-13 14:41:32 -040053
54# This function detects if the uploader is available and sets the path of it to
55# ANDROID_ENABLE_METRICS_UPLOAD.
56function _export_metrics_uploader() {
57 local uploader_path="$(gettop)/vendor/google/misc/metrics_uploader_prebuilt/metrics_uploader.sh"
Patrice Arrudaba9a28b2020-09-28 21:52:15 +000058 if [[ -x "${uploader_path}" ]]; then
Ramy Medhat4d158b52020-08-13 14:41:32 -040059 export ANDROID_ENABLE_METRICS_UPLOAD="${uploader_path}"
60 fi
61}
62
63# This function sets RBE specific environment variables needed for the build to
64# executed by RBE. This file should be sourced once per checkout of Android code.
65function _set_rbe_vars() {
66 export USE_RBE="true"
Kousik Kumar524428a2020-11-25 12:14:16 -050067 export RBE_CXX_EXEC_STRATEGY="racing"
68 export RBE_JAVAC_EXEC_STRATEGY="racing"
69 export RBE_R8_EXEC_STRATEGY="racing"
70 export RBE_D8_EXEC_STRATEGY="racing"
Kousik Kumara92f3e02020-11-24 10:55:47 -050071 export RBE_use_unified_cas_ops="true"
Ramy Medhat4d158b52020-08-13 14:41:32 -040072 export RBE_JAVAC=1
73 export RBE_R8=1
74 export RBE_D8=1
75}
76
77_export_metrics_uploader
78_set_rbe_vars