Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2023 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | |
| 17 | # This file is executed by build/envsetup.sh, and can use anything |
| 18 | # defined in envsetup.sh. |
| 19 | function _create_out_symlink_for_cog() { |
| 20 | if [[ "${OUT_DIR}" == "" ]]; then |
| 21 | OUT_DIR="out" |
| 22 | fi |
| 23 | |
| 24 | if [[ -L "${OUT_DIR}" ]]; then |
| 25 | return |
| 26 | fi |
| 27 | if [ -d "${OUT_DIR}" ]; then |
| 28 | echo -e "\tOutput directory ${OUT_DIR} cannot be present in a Cog workspace." |
| 29 | echo -e "\tDelete \"${OUT_DIR}\" or create a symlink from \"${OUT_DIR}\" to a directory outside your workspace." |
| 30 | return 1 |
| 31 | fi |
| 32 | |
| 33 | DEFAULT_OUTPUT_DIR="${HOME}/.cog/android-build-out" |
| 34 | mkdir -p ${DEFAULT_OUTPUT_DIR} |
| 35 | ln -s ${DEFAULT_OUTPUT_DIR} `pwd`/out |
| 36 | } |
| 37 | |
| 38 | # This function moves the reclient binaries into a directory that exists in a |
| 39 | # non-cog part of the overall filesystem. This is to workaround the problem |
| 40 | # described in b/289391270. |
| 41 | function _copy_reclient_binaries_from_cog() { |
Kousik Kumar | 798080b | 2023-09-28 17:46:59 +0000 | [diff] [blame] | 42 | if [[ "${OUT_DIR}" == "" ]]; then |
| 43 | OUT_DIR="out" |
| 44 | fi |
| 45 | local RECLIENT_VERSION=`readlink prebuilts/remoteexecution-client/live` |
| 46 | |
| 47 | local NONCOG_RECLIENT_BIN_DIR_BASE="${OUT_DIR}/.reclient" |
| 48 | local NONCOG_RECLIENT_BIN_DIR="${NONCOG_RECLIENT_BIN_DIR_BASE}/${RECLIENT_VERSION}" |
| 49 | |
| 50 | # Create the non cog directory and setup live symlink. |
| 51 | mkdir -p ${NONCOG_RECLIENT_BIN_DIR} |
| 52 | |
| 53 | if [ `ls ${NONCOG_RECLIENT_BIN_DIR} | wc -l` -lt 8 ]; then |
| 54 | # Not all binaries exist, copy them from the Cog directory. |
| 55 | local TOP=$(gettop) |
| 56 | cp ${TOP}/prebuilts/remoteexecution-client/live/* ${NONCOG_RECLIENT_BIN_DIR} |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 57 | fi |
| 58 | |
Kousik Kumar | 798080b | 2023-09-28 17:46:59 +0000 | [diff] [blame] | 59 | ln -sfn ${RECLIENT_VERSION} ${NONCOG_RECLIENT_BIN_DIR_BASE}/live |
| 60 | export RBE_DIR="${NONCOG_RECLIENT_BIN_DIR_BASE}/live" |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | # This function sets up the build environment to be appropriate for Cog. |
| 64 | function _setup_cog_env() { |
| 65 | _create_out_symlink_for_cog |
| 66 | if [ "$?" -eq "1" ]; then |
| 67 | echo -e "\e[0;33mWARNING:\e[00m Cog environment setup failed!" |
| 68 | return 1 |
| 69 | fi |
| 70 | _copy_reclient_binaries_from_cog |
| 71 | |
| 72 | export ANDROID_BUILD_ENVIRONMENT_CONFIG="googler-cog" |
| 73 | |
| 74 | # Running repo command within Cog workspaces is not supported, so override |
| 75 | # it with this function. If the user is running repo within a Cog workspace, |
| 76 | # we'll fail with an error, otherwise, we run the original repo command with |
| 77 | # the given args. |
| 78 | ORIG_REPO_PATH=`which repo` |
| 79 | function repo { |
| 80 | if [[ "${PWD}" == /google/cog/* ]]; then |
| 81 | echo "\e[01;31mERROR:\e[0mrepo command is disallowed within Cog workspaces." |
| 82 | return 1 |
| 83 | fi |
| 84 | ${ORIG_REPO_PATH} "$@" |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if [[ "${PWD}" != /google/cog/* ]]; then |
| 89 | echo -e "\e[01;31mERROR:\e[0m This script must be run from a Cog workspace." |
| 90 | fi |
| 91 | |
| 92 | _setup_cog_env |