Patrice Arruda | 96a3f9d | 2020-09-28 21:52:15 +0000 | [diff] [blame] | 1 | function _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 |
Kousik Kumar | 721533e | 2021-07-12 13:55:13 -0400 | [diff] [blame] | 27 | # using the envsetup.sh defined functions. Skip this part if this script is already |
| 28 | # being invoked from envsetup.sh. |
| 29 | if [[ "$1" != "--skip-envsetup" ]]; then |
| 30 | _source_env_setup_script || return |
| 31 | fi |
Kousik Kumar | 4faa2a5 | 2020-03-05 14:08:09 -0800 | [diff] [blame] | 32 | |
| 33 | # This function prefixes the given command with appropriate variables needed |
| 34 | # for the build to be executed with RBE. |
| 35 | function use_rbe() { |
Luca Stefani | cf82af2 | 2020-06-13 22:38:56 +0200 | [diff] [blame] | 36 | local RBE_BINARIES_DIR="prebuilts/remoteexecution-client/latest" |
Anas Sulaiman | 5dacf0f | 2023-11-15 20:22:31 +0000 | [diff] [blame] | 37 | local DOCKER_IMAGE="gcr.io/androidbuild-re-dockerimage/android-build-remoteexec-image@sha256:1eb7f64b9e17102b970bd7a1af7daaebdb01c3fb777715899ef462d6c6d01a45" |
Kousik Kumar | 4faa2a5 | 2020-03-05 14:08:09 -0800 | [diff] [blame] | 38 | |
| 39 | # Do not set an invocation-ID and let reproxy auto-generate one. |
| 40 | USE_RBE="true" \ |
Kousik Kumar | 4faa2a5 | 2020-03-05 14:08:09 -0800 | [diff] [blame] | 41 | FLAG_exec_root="$(gettop)" \ |
| 42 | FLAG_platform="container-image=docker://${DOCKER_IMAGE}" \ |
| 43 | RBE_use_application_default_credentials="true" \ |
Kousik Kumar | 4faa2a5 | 2020-03-05 14:08:09 -0800 | [diff] [blame] | 44 | RBE_reproxy_wait_seconds="20" \ |
Kousik Kumar | 4faa2a5 | 2020-03-05 14:08:09 -0800 | [diff] [blame] | 45 | RBE_CXX_EXEC_STRATEGY="remote_local_fallback" \ |
| 46 | RBE_cpp_dependency_scanner_plugin="${RBE_BINARIES_DIR}/dependency_scanner_go_plugin.so" \ |
| 47 | RBE_DIR=${RBE_BINARIES_DIR} \ |
| 48 | RBE_re_proxy="${RBE_BINARIES_DIR}/reproxy" \ |
| 49 | $@ |
| 50 | } |
Patrice Arruda | d990f70 | 2020-07-10 23:22:49 +0000 | [diff] [blame] | 51 | |
| 52 | # This function detects if the uploader is available and sets the path of it to |
| 53 | # ANDROID_ENABLE_METRICS_UPLOAD. |
| 54 | function _export_metrics_uploader() { |
| 55 | local uploader_path="$(gettop)/vendor/google/misc/metrics_uploader_prebuilt/metrics_uploader.sh" |
Patrice Arruda | 96a3f9d | 2020-09-28 21:52:15 +0000 | [diff] [blame] | 56 | if [[ -x "${uploader_path}" ]]; then |
Patrice Arruda | d990f70 | 2020-07-10 23:22:49 +0000 | [diff] [blame] | 57 | export ANDROID_ENABLE_METRICS_UPLOAD="${uploader_path}" |
| 58 | fi |
| 59 | } |
| 60 | |
Ramy Medhat | 3491bbd | 2020-08-13 14:41:32 -0400 | [diff] [blame] | 61 | # This function sets RBE specific environment variables needed for the build to |
| 62 | # executed by RBE. This file should be sourced once per checkout of Android code. |
| 63 | function _set_rbe_vars() { |
Ramy Medhat | fe66d39 | 2020-08-26 05:47:33 -0400 | [diff] [blame] | 64 | unset USE_GOMA |
Ramy Medhat | 3491bbd | 2020-08-13 14:41:32 -0400 | [diff] [blame] | 65 | export USE_RBE="true" |
Kousik Kumar | f16d798 | 2020-11-25 12:14:16 -0500 | [diff] [blame] | 66 | export RBE_CXX_EXEC_STRATEGY="racing" |
| 67 | export RBE_JAVAC_EXEC_STRATEGY="racing" |
| 68 | export RBE_R8_EXEC_STRATEGY="racing" |
| 69 | export RBE_D8_EXEC_STRATEGY="racing" |
Kousik Kumar | aa79007 | 2020-11-24 10:55:47 -0500 | [diff] [blame] | 70 | export RBE_use_unified_cas_ops="true" |
Ramy Medhat | 3491bbd | 2020-08-13 14:41:32 -0400 | [diff] [blame] | 71 | export RBE_JAVAC=1 |
| 72 | export RBE_R8=1 |
| 73 | export RBE_D8=1 |
| 74 | } |
| 75 | |
Patrice Arruda | d990f70 | 2020-07-10 23:22:49 +0000 | [diff] [blame] | 76 | _export_metrics_uploader |
Ramy Medhat | 3491bbd | 2020-08-13 14:41:32 -0400 | [diff] [blame] | 77 | _set_rbe_vars |