forked from LineageOS/android_build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cogsetup.sh
71 lines (63 loc) · 2.28 KB
/
cogsetup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# Copyright (C) 2023 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file is executed by build/envsetup.sh, and can use anything
# defined in envsetup.sh.
function _create_out_symlink_for_cog() {
if [[ "${OUT_DIR}" == "" ]]; then
OUT_DIR="out"
fi
# getoutdir ensures paths are absolute. envsetup could be called from a
# directory other than the root of the source tree
local outdir=$(getoutdir)
if [[ -L "${outdir}" ]]; then
return
fi
if [ -d "${outdir}" ]; then
echo -e "\tOutput directory ${outdir} cannot be present in a Cog workspace."
echo -e "\tDelete \"${outdir}\" or create a symlink from \"${outdir}\" to a directory outside your workspace."
return 1
fi
DEFAULT_OUTPUT_DIR="${HOME}/.cog/android-build-out"
mkdir -p ${DEFAULT_OUTPUT_DIR}
ln -s ${DEFAULT_OUTPUT_DIR} ${outdir}
}
# This function sets up the build environment to be appropriate for Cog.
function _setup_cog_env() {
_create_out_symlink_for_cog
if [ "$?" -eq "1" ]; then
echo -e "\e[0;33mWARNING:\e[00m Cog environment setup failed!"
return 1
fi
export ANDROID_BUILD_ENVIRONMENT_CONFIG="googler-cog"
# Running repo command within Cog workspaces is not supported, so override
# it with this function. If the user is running repo within a Cog workspace,
# we'll fail with an error, otherwise, we run the original repo command with
# the given args.
if ! ORIG_REPO_PATH=`which repo`; then
return 0
fi
function repo {
if [[ "${PWD}" == /google/cog/* ]]; then
echo -e "\e[01;31mERROR:\e[0mrepo command is disallowed within Cog workspaces."
return 1
fi
${ORIG_REPO_PATH} "$@"
}
}
if [[ "${PWD}" != /google/cog/* ]]; then
echo -e "\e[01;31mERROR:\e[0m This script must be run from a Cog workspace."
fi
_setup_cog_env