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 | |
Liz Kammer | 79effa5 | 2024-01-31 15:44:57 -0500 | [diff] [blame] | 24 | # getoutdir ensures paths are absolute. envsetup could be called from a |
| 25 | # directory other than the root of the source tree |
| 26 | local outdir=$(getoutdir) |
| 27 | if [[ -L "${outdir}" ]]; then |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 28 | return |
| 29 | fi |
Liz Kammer | 79effa5 | 2024-01-31 15:44:57 -0500 | [diff] [blame] | 30 | if [ -d "${outdir}" ]; then |
| 31 | echo -e "\tOutput directory ${outdir} cannot be present in a Cog workspace." |
| 32 | echo -e "\tDelete \"${outdir}\" or create a symlink from \"${outdir}\" to a directory outside your workspace." |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 33 | return 1 |
| 34 | fi |
| 35 | |
| 36 | DEFAULT_OUTPUT_DIR="${HOME}/.cog/android-build-out" |
| 37 | mkdir -p ${DEFAULT_OUTPUT_DIR} |
Liz Kammer | 79effa5 | 2024-01-31 15:44:57 -0500 | [diff] [blame] | 38 | ln -s ${DEFAULT_OUTPUT_DIR} ${outdir} |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 41 | # This function sets up the build environment to be appropriate for Cog. |
| 42 | function _setup_cog_env() { |
| 43 | _create_out_symlink_for_cog |
| 44 | if [ "$?" -eq "1" ]; then |
| 45 | echo -e "\e[0;33mWARNING:\e[00m Cog environment setup failed!" |
| 46 | return 1 |
| 47 | fi |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 48 | |
| 49 | export ANDROID_BUILD_ENVIRONMENT_CONFIG="googler-cog" |
| 50 | |
| 51 | # Running repo command within Cog workspaces is not supported, so override |
| 52 | # it with this function. If the user is running repo within a Cog workspace, |
| 53 | # we'll fail with an error, otherwise, we run the original repo command with |
| 54 | # the given args. |
Michael Merg | f3fae6b | 2024-04-26 07:09:41 +0000 | [diff] [blame] | 55 | if ! ORIG_REPO_PATH=`which repo`; then |
| 56 | return 0 |
| 57 | fi |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 58 | function repo { |
| 59 | if [[ "${PWD}" == /google/cog/* ]]; then |
| 60 | echo "\e[01;31mERROR:\e[0mrepo command is disallowed within Cog workspaces." |
| 61 | return 1 |
| 62 | fi |
| 63 | ${ORIG_REPO_PATH} "$@" |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if [[ "${PWD}" != /google/cog/* ]]; then |
| 68 | echo -e "\e[01;31mERROR:\e[0m This script must be run from a Cog workspace." |
| 69 | fi |
| 70 | |
Liz Kammer | 79effa5 | 2024-01-31 15:44:57 -0500 | [diff] [blame] | 71 | _setup_cog_env |