blob: ef1485d5f279f7d7ed059a4654ae9110ca1a8dfa [file] [log] [blame]
Kousik Kumarec5416c2023-09-14 17:11:45 +00001#
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.
19function _create_out_symlink_for_cog() {
20 if [[ "${OUT_DIR}" == "" ]]; then
21 OUT_DIR="out"
22 fi
23
Liz Kammer79effa52024-01-31 15:44:57 -050024 # 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 Kumarec5416c2023-09-14 17:11:45 +000028 return
29 fi
Liz Kammer79effa52024-01-31 15:44:57 -050030 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 Kumarec5416c2023-09-14 17:11:45 +000033 return 1
34 fi
35
36 DEFAULT_OUTPUT_DIR="${HOME}/.cog/android-build-out"
37 mkdir -p ${DEFAULT_OUTPUT_DIR}
Liz Kammer79effa52024-01-31 15:44:57 -050038 ln -s ${DEFAULT_OUTPUT_DIR} ${outdir}
Kousik Kumarec5416c2023-09-14 17:11:45 +000039}
40
Kousik Kumarec5416c2023-09-14 17:11:45 +000041# This function sets up the build environment to be appropriate for Cog.
42function _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 Kumarec5416c2023-09-14 17:11:45 +000048
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 Mergf3fae6b2024-04-26 07:09:41 +000055 if ! ORIG_REPO_PATH=`which repo`; then
56 return 0
57 fi
Kousik Kumarec5416c2023-09-14 17:11:45 +000058 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
67if [[ "${PWD}" != /google/cog/* ]]; then
68 echo -e "\e[01;31mERROR:\e[0m This script must be run from a Cog workspace."
69fi
70
Liz Kammer79effa52024-01-31 15:44:57 -050071_setup_cog_env