blob: 6439af056e5d78902c9fede0e6d5f42783232b54 [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
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
Kousik Kumarec5416c2023-09-14 17:11:45 +000038# This function sets up the build environment to be appropriate for Cog.
39function _setup_cog_env() {
40 _create_out_symlink_for_cog
41 if [ "$?" -eq "1" ]; then
42 echo -e "\e[0;33mWARNING:\e[00m Cog environment setup failed!"
43 return 1
44 fi
Kousik Kumarec5416c2023-09-14 17:11:45 +000045
46 export ANDROID_BUILD_ENVIRONMENT_CONFIG="googler-cog"
47
48 # Running repo command within Cog workspaces is not supported, so override
49 # it with this function. If the user is running repo within a Cog workspace,
50 # we'll fail with an error, otherwise, we run the original repo command with
51 # the given args.
52 ORIG_REPO_PATH=`which repo`
53 function repo {
54 if [[ "${PWD}" == /google/cog/* ]]; then
55 echo "\e[01;31mERROR:\e[0mrepo command is disallowed within Cog workspaces."
56 return 1
57 fi
58 ${ORIG_REPO_PATH} "$@"
59 }
60}
61
62if [[ "${PWD}" != /google/cog/* ]]; then
63 echo -e "\e[01;31mERROR:\e[0m This script must be run from a Cog workspace."
64fi
65
66_setup_cog_env