-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·205 lines (164 loc) · 4.47 KB
/
build.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
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
201
202
203
204
205
# !/usr/bin/env bash
#
# Copyright (c) 2012, The Linux Foundation. All rights reserved.
# Copyright (C) 2023, StatiXOS
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
usage() {
cat <<USAGE
Usage:
bash $0 <TARGET_PRODUCT> [OPTIONS]
Description:
Builds Android tree for given TARGET_PRODUCT
OPTIONS:
-c, --clean_build
Clean build - build from scratch by removing entire out dir
-d, --debug
Enable debugging - captures all commands while doing the build
-h, --help
Display this help message
-i, --image
Specify image to be build/re-build (bootimg/sysimg/usrimg)
-j, --jobs
Specifies the number of jobs to run simultaneously (Default: 8)
-l, --log_file
Log file to store build logs (Default: <TARGET_PRODUCT>.log)
-m, --module
Module to be build
-p, --package-type
Specifies package type to build (Default: otapackage)
-u, --update-api
Update APIs
-v, --build_variant
Build variant (Default: userdebug)
USAGE
}
# Set release
RELEASE=ap2a
clean_build() {
echo -e "\nINFO: Removing entire out dir. . .\n"
m clobber
}
build_android() {
echo -e "\nINFO: Build Android tree for $TARGET\n"
m $@ | tee $LOG_FILE.log
}
build_bootimg() {
echo -e "\nINFO: Build bootimage for $TARGET\n"
m bootimage $@ | tee $LOG_FILE.log
}
build_sysimg() {
echo -e "\nINFO: Build systemimage for $TARGET\n"
m systemimage $@ | tee $LOG_FILE.log
}
build_usrimg() {
echo -e "\nINFO: Build userdataimage for $TARGET\n"
m userdataimage $@ | tee $LOG_FILE.log
}
build_module() {
echo -e "\nINFO: Build $MODULE for $TARGET\n"
m $MODULE $@ | tee $LOG_FILE.log
}
exit_on_error() {
exit_code=$1
if [ -d $exit_code ]; then
exit_code=1
fi
last_command=${@:2}
if [ $exit_code -ne 0 ]; then
>&2 echo "\"${last_command}\" command failed with exit code ${exit_code}."
exit $exit_code
fi
}
update_api() {
echo -e "\nINFO: Updating APIs\n"
m update-api | tee $LOG_FILE.log
}
# Set defaults
VARIANT="userdebug"
JOBS=8
# Setup getopt.
long_opts="clean_build,debug,help,image:,jobs:,log_file:,module:,"
long_opts+="package-type:,update-api,build_variant:"
getopt_cmd=$(getopt -o cdhi:j:k:l:m:p:s:uv: --long "$long_opts" \
-n $(basename $0) -- "$@") || \
{ echo -e "\nERROR: Getopt failed. Extra args\n"; usage; exit 1;}
eval set -- "$getopt_cmd"
while true; do
case "$1" in
-c|--clean_build) CLEAN_BUILD="true";;
-d|--debug) DEBUG="true";;
-h|--help) usage; exit 0;;
-i|--image) IMAGE="$2"; shift;;
-j|--jobs) JOBS="$2"; shift;;
-l|--log_file) LOG_FILE="$2"; shift;;
-m|--module) MODULE="$2"; shift;;
-p|--package-type) PKG="$2"; shift;;
-u|--update-api) UPDATE_API="true";;
-v|--build_variant) VARIANT="$2"; shift;;
--) shift; break;;
esac
shift
done
# Mandatory argument
if [ $# -eq 0 ]; then
echo -e "\nERROR: Missing mandatory argument: TARGET_PRODUCT\n"
usage
exit 1
fi
if [ $# -gt 1 ]; then
echo -e "\nERROR: Extra inputs. Need TARGET_PRODUCT only\n"
usage
exit 1
fi
case "$PKG" in
"")
PKG="bacon" ;;
"otapackage")
PKG="bacon" ;;
"updatepackage")
PKG="updatepackage" ;;
*)
echo "Unknown package type! Bailing out!" && exit 1 ;;
esac
TARGET="$1"; shift
if [ -z $LOG_FILE ]; then
LOG_FILE=$TARGET
fi
CMD="-j $JOBS"
if [ "$DEBUG" = "true" ]; then
CMD+=" showcommands"
fi
source build/envsetup.sh
if [ -d "device/*/$TARGET" ]; then
echo "Device tree found"
else
echo "Checking if tree exists in manifests"
if test -f "device/manifests/$TARGET.xml"; then
echo "Syncing $TARGET trees"
# Clear older manifests
if ! [ -d .repo/local_manifests ]; then
mkdir -p .repo/local_manifests/
else
rm -rf .repo/local_manifests/*.xml
fi
cp device/manifests/$TARGET.xml .repo/local_manifests/$TARGET.xml
grep -E 'path="[^"]+"' device/manifests/$TARGET.xml | awk -F'"' '{print $2}' | xargs -I {} echo -n "{} " > .device-sync
repo sync $(cat .device-sync)
fi
fi
lunch statix_$TARGET-$RELEASE-$VARIANT || exit_on_error
if [ "$CLEAN_BUILD" = "true" ]; then
clean_build
fi
if [ "$UPDATE_API" = "true" ]; then
update_api
fi
if [ -n "$MODULE" ]; then
build_module "$CMD"
fi
if [ -n "$IMAGE" ]; then
build_$IMAGE "$CMD"
fi
build_android "$PKG" "$CMD"