This repository was archived by the owner on Jan 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathbuildenv.sh
More file actions
200 lines (177 loc) · 5.62 KB
/
buildenv.sh
File metadata and controls
200 lines (177 loc) · 5.62 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#
# Copyright (C) 2025 Salvo Giangreco
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# [
# shellcheck disable=SC1007,SC2164
# https://android.googlesource.com/platform/build/+/refs/tags/android-15.0.0_r1/envsetup.sh#18
_GET_SRC_DIR()
{
local TOPFILE="unica/configs/version.sh"
if [ -n "$SRC_DIR" ] && [ -f "$SRC_DIR/$TOPFILE" ]; then
# The following circumlocution ensures we remove symlinks from SRC_DIR.
(cd "$SRC_DIR"; PWD= /bin/pwd)
else
if [ -f "$TOPFILE" ]; then
# The following circumlocution (repeated below as well) ensures
# that we record the true directory name and not one that is
# faked up with symlink names.
PWD= /bin/pwd
else
local HERE="$PWD"
local T=
while [ \( ! \( -f "$TOPFILE" \) \) ] && [ \( "$PWD" != "/" \) ]; do
\cd ..
T="$(PWD= /bin/pwd -P)"
done
\cd "$HERE"
if [ -f "$T/$TOPFILE" ]; then
echo "$T"
fi
fi
fi
}
_PRINT_USAGE()
{
echo "Usage: source buildenv.sh [--debug] <target>" >&2
echo "Available devices:" >&2
printf '%s\n' "${TARGETS[@]}" >&2
}
# https://android.googlesource.com/platform/build/+/refs/tags/android-15.0.0_r1/envsetup.sh#806
croot()
{
if [ -d "$SRC_DIR" ]; then
if [ "$1" ]; then
cd "$SRC_DIR/$1"
else
cd "$SRC_DIR"
fi
else
echo "Couldn't locate the top of the tree. Try setting SRC_DIR."
return 1
fi
}
run_cmd()
{
local CMD="$1"
if [ -x "$SRC_DIR/scripts/$CMD.sh" ]; then
shift
mkdir -p "$(dirname "$WORK_DIR")"
(set -o pipefail; "$SRC_DIR/scripts/$CMD.sh" "$@" |& tee \
>(sed -r -e "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" -e "/#/d" > "$(dirname "$WORK_DIR")/$CMD-$(date +%Y%m%d_%H%M%S).log"))
return $?
else
local CMDS=()
while IFS= read -r f; do
CMDS+=("$f")
done < <(find "$SRC_DIR/scripts" -maxdepth 1 ! -type d -printf '%f\n' | sort | sed "s/.sh//")
if [ "$CMD" ]; then
if [[ "$CMD" == "--help" ]] || [[ "$CMD" == "-h" ]]; then
echo "Available cmds:" >&2
for c in "${CMDS[@]}"; do
echo -e '\n\033[1;37m'"$c:"'\033[0m'
"$SRC_DIR/scripts/$c.sh" --help
done
return 0
else
echo -e '\033[0;31m'"\"$CMD\" is not a valid cmd."'\033[0m' >&2
fi
fi
echo "Available cmds:" >&2
printf '%s\n' "${CMDS[@]}" >&2
return 1
fi
}
alias unica=run_cmd
alias extremerom=run_cmd
alias erom=run_cmd
alias m="./scripts/make_rom.sh"
# https://android.googlesource.com/platform/build/+/refs/tags/android-15.0.0_r1/envsetup.sh#806
croot()
{
if [ -d "$SRC_DIR" ]; then
if [ "$1" ]; then
cd "$SRC_DIR/$1"
else
cd "$SRC_DIR"
fi
else
echo "Couldn't locate the top of the tree. Try setting SRC_DIR."
return 1
fi
}
# ]
SRC_DIR="$(_GET_SRC_DIR)"
if [ ! "$SRC_DIR" ]; then
echo "Couldn't locate the top of the tree. Always source buildenv.sh from the root of the tree." >&2
return 1
fi
unset -f _GET_SRC_DIR
export DEBUG=false
export SRC_DIR
export OUT_DIR="$SRC_DIR/out"
export TMP_DIR="$OUT_DIR/tmp"
export KERNEL_TMP_DIR="$OUT_DIR/kernel_tmp"
export ODIN_DIR="$OUT_DIR/odin"
export FW_DIR="$OUT_DIR/fw"
export TOOLS_DIR="$OUT_DIR/tools"
export PATH="$TOOLS_DIR/bin:$PATH"
TARGETS=()
while IFS= read -r t; do
TARGETS+=("$t")
done < <(find "$SRC_DIR/target" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | sort)
while [[ "$1" == "-"* ]]; do
if [[ "$1" == "--debug" ]]; then
export DEBUG=true
elif [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
_PRINT_USAGE
return 0
else
echo "Unknown option: $1" >&2
_PRINT_USAGE
return 1
fi
shift
done
if [ "$#" -ne 1 ]; then
echo "No target specified. Please choose from the available devices below:"
select SELECTED_TARGET in "${TARGETS[@]}"; do
if [ -n "$SELECTED_TARGET" ]; then
break
else
echo "Invalid selection. Please try again."
fi
done
else
SELECTED_TARGET="$1"
fi
if [ ! -d "$SRC_DIR/target/$SELECTED_TARGET" ]; then
echo "\"$SELECTED_TARGET\" is not a valid device." >&2
_PRINT_USAGE
return 1
fi
unset -f _PRINT_USAGE
export APKTOOL_DIR="$OUT_DIR/target/$SELECTED_TARGET/apktool"
export WORK_DIR="$OUT_DIR/target/$SELECTED_TARGET/work_dir"
mkdir -p "$OUT_DIR/target/$SELECTED_TARGET"
# shellcheck disable=SC2046
[ -f "$OUT_DIR/config.sh" ] && unset $(sed "/Automatically/d" "$OUT_DIR/config.sh" | cut -d "=" -f 1)
"$SRC_DIR/scripts/internal/gen_config_file.sh" "$SELECTED_TARGET" || return 1
set -o allexport; source "$OUT_DIR/config.sh"; set +o allexport
unset TARGETS SELECTED_TARGET
echo "=============================="
sed "/Automatically/d" "$OUT_DIR/config.sh"
echo "=============================="
return 0