blob: 71ee4422118182adac6efdec811c6fa0a7945b74 [file] [log] [blame]
Jackeagled6811aa2019-09-24 08:26:40 +02001function __print_bliss_functions_help() {
Michael Bestas3952f6c2016-08-26 01:12:08 +03002cat <<EOF
Jackeagled6811aa2019-09-24 08:26:40 +02003Additional BlissRoms functions:
Michael Bestas3952f6c2016-08-26 01:12:08 +03004- cout: Changes directory to out.
5- mmp: Builds all of the modules in the current directory and pushes them to the device.
6- mmap: Builds all of the modules in the current directory and its dependencies, then pushes the package to the device.
7- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Jackeagled6811aa2019-09-24 08:26:40 +02008- blissgerrit: A Git wrapper that fetches/pushes patch from/to BlissRoms Gerrit Review.
9- blissrebase: Rebase a Gerrit change and push it again.
10- blissremote: Add git remote for BlissRoms Gerrit Review.
Michael Bestas3952f6c2016-08-26 01:12:08 +030011- aospremote: Add git remote for matching AOSP repository.
12- cafremote: Add git remote for matching CodeAurora repository.
Jackeagled6811aa2019-09-24 08:26:40 +020013- githubremote: Add git remote for BlissRoms Github.
Michael Bestas3952f6c2016-08-26 01:12:08 +030014- mka: Builds using SCHED_BATCH on all processors.
15- mkap: Builds the module(s) using mka and pushes them to the device.
16- cmka: Cleans and builds using mka.
17- repodiff: Diff 2 different branches or tags within the same repo
18- repolastsync: Prints date and time of last repo sync.
19- reposync: Parallel repo sync using ionice and SCHED_BATCH.
20- repopick: Utility to fetch changes from Gerrit.
Michael Bestas656f7e52022-06-09 18:50:47 +030021- sort-blobs-list: Sort proprietary-files.txt sections with LC_ALL=C.
Michael Bestas3952f6c2016-08-26 01:12:08 +030022- installboot: Installs a boot.img to the connected device.
23- installrecovery: Installs a recovery.img to the connected device.
Jackeagle305db7c2020-01-23 10:35:22 +010024- blissify: Sets up build environment using breakfast(),
25 and then compiles using mka() against blissify target.
Michael Bestas3952f6c2016-08-26 01:12:08 +030026EOF
27}
28
Jackeagle911602f2021-12-06 05:17:55 +010029function checkofficial()
30{
31 codenames=$(curl -s 'https://api.blissroms.org/api/maintainers')
32 for row in $(echo "${codenames}" | jq -r '.[] | @base64'); do
33 _jq() {
34 echo ${row} | base64 --decode | jq -r ${1}
35 }
36 if [ "$(_jq '.codename')" == "$1" ]; then
37 export BLISS_BUILDTYPE=OFFICIAL
38 break
39 else
40 export BLISS_BUILDTYPE=UNOFFICIAL
41 fi
42 done
43}
44
Luca Stefani076c27b2017-08-17 20:30:00 +020045function mk_timer()
46{
47 local start_time=$(date +"%s")
48 $@
49 local ret=$?
50 local end_time=$(date +"%s")
51 local tdiff=$(($end_time-$start_time))
52 local hours=$(($tdiff / 3600 ))
53 local mins=$((($tdiff % 3600) / 60))
54 local secs=$(($tdiff % 60))
55 local ncolors=$(tput colors 2>/dev/null)
56 echo
57 if [ $ret -eq 0 ] ; then
58 echo -n "#### make completed successfully "
59 else
60 echo -n "#### make failed to build some targets "
61 fi
62 if [ $hours -gt 0 ] ; then
63 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
64 elif [ $mins -gt 0 ] ; then
65 printf "(%02g:%02g (mm:ss))" $mins $secs
66 elif [ $secs -gt 0 ] ; then
67 printf "(%s seconds)" $secs
68 fi
69 echo " ####"
70 echo
71 return $ret
72}
73
Michael Bestas3952f6c2016-08-26 01:12:08 +030074function breakfast()
75{
76 target=$1
77 local variant=$2
Jackeagle911602f2021-12-06 05:17:55 +010078
79 checkofficial $target
Michael Bestas3952f6c2016-08-26 01:12:08 +030080 if [ $# -eq 0 ]; then
81 # No arguments, so let's have the full menu
82 lunch
83 else
84 echo "z$target" | grep -q "-"
85 if [ $? -eq 0 ]; then
86 # A buildtype was specified, assume a full device name
87 lunch $target
88 else
Jackeagled6811aa2019-09-24 08:26:40 +020089 # This is probably just the BlissRoms model name
Michael Bestas3952f6c2016-08-26 01:12:08 +030090 if [ -z "$variant" ]; then
91 variant="userdebug"
92 fi
Matt Mowered8c2482017-01-02 02:26:01 -060093
Jackeagled6811aa2019-09-24 08:26:40 +020094 lunch bliss_$target-$variant
Michael Bestas3952f6c2016-08-26 01:12:08 +030095 fi
96 fi
97 return $?
98}
99
100alias bib=breakfast
101
102function eat()
103{
104 if [ "$OUT" ] ; then
Jackeagled6811aa2019-09-24 08:26:40 +0200105 ZIPPATH=`ls -tr "$OUT"/Bliss-*.zip | tail -1`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300106 if [ ! -f $ZIPPATH ] ; then
107 echo "Nothing to eat"
108 return 1
109 fi
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200110 echo "Waiting for device..."
Luca Stefani3d548072020-03-11 12:24:26 +0100111 adb wait-for-device-recovery
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200112 echo "Found device"
Jackeagled6811aa2019-09-24 08:26:40 +0200113 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD"); then
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200114 echo "Rebooting to sideload for install"
115 adb reboot sideload-auto-reboot
116 adb wait-for-sideload
117 adb sideload $ZIPPATH
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800118 else
Jackeagled6811aa2019-09-24 08:26:40 +0200119 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300120 fi
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800121 return $?
Michael Bestas3952f6c2016-08-26 01:12:08 +0300122 else
123 echo "Nothing to eat"
124 return 1
125 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300126}
127
128function omnom()
129{
Jackeagle305db7c2020-01-23 10:35:22 +0100130 blissify $*
Michael Bestas3952f6c2016-08-26 01:12:08 +0300131 eat
132}
133
134function cout()
135{
136 if [ "$OUT" ]; then
137 cd $OUT
138 else
139 echo "Couldn't locate out directory. Try setting OUT."
140 fi
141}
142
143function dddclient()
144{
145 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
146 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
147 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
148 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
149 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
150 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
151 local ARCH=$(get_build_var TARGET_ARCH)
152 local GDB
153 case "$ARCH" in
154 arm) GDB=arm-linux-androideabi-gdb;;
155 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
156 mips|mips64) GDB=mips64el-linux-android-gdb;;
157 x86) GDB=x86_64-linux-android-gdb;;
158 x86_64) GDB=x86_64-linux-android-gdb;;
159 *) echo "Unknown arch $ARCH"; return 1;;
160 esac
161
162 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
163 local EXE="$1"
164 if [ "$EXE" ] ; then
165 EXE=$1
166 if [[ $EXE =~ ^[^/].* ]] ; then
167 EXE="system/bin/"$EXE
168 fi
169 else
170 EXE="app_process"
171 fi
172
173 local PORT="$2"
174 if [ "$PORT" ] ; then
175 PORT=$2
176 else
177 PORT=":5039"
178 fi
179
180 local PID="$3"
181 if [ "$PID" ] ; then
182 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
183 PID=`pid $3`
184 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
185 # that likely didn't work because of returning multiple processes
186 # try again, filtering by root processes (don't contain colon)
187 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
188 if [[ ! "$PID" =~ ^[0-9]+$ ]]
189 then
190 echo "Couldn't resolve '$3' to single PID"
191 return 1
192 else
193 echo ""
194 echo "WARNING: multiple processes matching '$3' observed, using root process"
195 echo ""
196 fi
197 fi
198 fi
199 adb forward "tcp$PORT" "tcp$PORT"
200 local USE64BIT="$(is64bit $PID)"
201 adb shell gdbserver$USE64BIT $PORT --attach $PID &
202 sleep 2
203 else
204 echo ""
205 echo "If you haven't done so already, do this first on the device:"
206 echo " gdbserver $PORT /system/bin/$EXE"
207 echo " or"
208 echo " gdbserver $PORT --attach <PID>"
209 echo ""
210 fi
211
212 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
213 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
214
215 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
216 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl"
217 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
218 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
219 # Enable special debugging for ART processes.
220 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
221 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
222 fi
223 echo >>"$OUT_ROOT/gdbclient.cmds" ""
224
225 local WHICH_GDB=
226 # 64-bit exe found
227 if [ "$USE64BIT" != "" ] ; then
228 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
229 # 32-bit exe / 32-bit platform
230 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
231 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
232 # 32-bit exe / 64-bit platform
233 else
234 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
235 fi
236
237 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
238 else
239 echo "Unable to determine build system output dir."
240 fi
241}
242
Jackeagled6811aa2019-09-24 08:26:40 +0200243function blissremote()
Michael Bestas3952f6c2016-08-26 01:12:08 +0300244{
245 if ! git rev-parse --git-dir &> /dev/null
246 then
247 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
248 return 1
249 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200250 git remote rm bliss 2> /dev/null
Michael Bestas9e6bde52018-04-02 19:54:45 +0300251 local REMOTE=$(git config --get remote.github.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100252 local BLISS="true"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300253 if [ -z "$REMOTE" ]
Michael Bestasaf3532b2017-08-23 17:40:40 +0300254 then
Michael Bestas9e6bde52018-04-02 19:54:45 +0300255 REMOTE=$(git config --get remote.aosp.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100256 BLISS="false"
Michael Bestasaf3532b2017-08-23 17:40:40 +0300257 fi
Michael Bestas9e6bde52018-04-02 19:54:45 +0300258 if [ -z "$REMOTE" ]
259 then
260 REMOTE=$(git config --get remote.caf.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100261 BLISS="false"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300262 fi
263
Jackeagle305db7c2020-01-23 10:35:22 +0100264 if [ $BLISS = "false" ]
Michael Bestas9e6bde52018-04-02 19:54:45 +0300265 then
266 local PROJECT=$(echo $REMOTE | sed -e "s#platform/#android/#g; s#/#_#g")
Jackeagle305db7c2020-01-23 10:35:22 +0100267 local PFX="BLISS/"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300268 else
269 local PROJECT=$REMOTE
270 fi
271
Jackeagle305db7c2020-01-23 10:35:22 +0100272 local BLISS_USER=$(git config --get review.review.blissroms.com.username)
273 if [ -z "$BLISS_USER" ]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300274 then
Jackeagled6811aa2019-09-24 08:26:40 +0200275 git remote add bliss ssh://review.blissroms.com:29418/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300276 else
Jackeagle305db7c2020-01-23 10:35:22 +0100277 git remote add bliss ssh://$BLISS_USER@review.blissroms.com:29418/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300278 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200279 echo "Remote 'bliss' created"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300280}
281
282function aospremote()
283{
284 if ! git rev-parse --git-dir &> /dev/null
285 then
286 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
287 return 1
288 fi
289 git remote rm aosp 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300290 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400291 # Google moved the repo location in Oreo
292 if [ $PROJECT = "build/make" ]
293 then
294 PROJECT="build"
295 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300296 if (echo $PROJECT | grep -qv "^device")
297 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300298 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300299 fi
300 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
301 echo "Remote 'aosp' created"
302}
303
304function cafremote()
305{
306 if ! git rev-parse --git-dir &> /dev/null
307 then
308 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
309 return 1
310 fi
311 git remote rm caf 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300312 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400313 # Google moved the repo location in Oreo
314 if [ $PROJECT = "build/make" ]
315 then
316 PROJECT="build"
317 fi
Rashed Abdel-Tawabb52c7082017-12-24 22:40:31 +0200318 if [[ $PROJECT =~ "qcom/opensource" ]];
319 then
320 PROJECT=$(echo $PROJECT | sed -e "s#qcom\/opensource#qcom-opensource#")
321 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300322 if (echo $PROJECT | grep -qv "^device")
323 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300324 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300325 fi
Zhao Wei Liewfb4b8c52017-01-08 09:03:01 +0800326 git remote add caf https://source.codeaurora.org/quic/la/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300327 echo "Remote 'caf' created"
328}
329
Michael Bestasa504aa42018-08-10 22:51:37 +0300330function githubremote()
331{
332 if ! git rev-parse --git-dir &> /dev/null
333 then
334 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
335 return 1
336 fi
337 git remote rm github 2> /dev/null
338 local REMOTE=$(git config --get remote.aosp.projectname)
339
340 if [ -z "$REMOTE" ]
341 then
342 REMOTE=$(git config --get remote.caf.projectname)
343 fi
344
345 local PROJECT=$(echo $REMOTE | sed -e "s#platform/#android/#g; s#/#_#g")
346
347 git remote add github https://github.com/LineageOS/$PROJECT
348 echo "Remote 'github' created"
349}
350
Michael Bestas3952f6c2016-08-26 01:12:08 +0300351function installboot()
352{
Alessandro Astonef8f48772019-09-06 13:07:03 +0200353 if [ ! -e "$OUT/recovery/root/system/etc/recovery.fstab" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300354 then
355 echo "No recovery.fstab found. Build recovery first."
356 return 1
357 fi
358 if [ ! -e "$OUT/boot.img" ];
359 then
360 echo "No boot.img found. Run make bootimage first."
361 return 1
362 fi
Alessandro Astonef8f48772019-09-06 13:07:03 +0200363 PARTITION=`grep "^\/boot" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300364 if [ -z "$PARTITION" ];
365 then
366 # Try for RECOVERY_FSTAB_VERSION = 2
Alessandro Astonef8f48772019-09-06 13:07:03 +0200367 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $1'}`
368 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300369 if [ -z "$PARTITION" ];
370 then
371 echo "Unable to determine boot partition."
372 return 1
373 fi
374 fi
Luca Stefani3d548072020-03-11 12:24:26 +0100375 adb wait-for-device-recovery
Michael Bestas3952f6c2016-08-26 01:12:08 +0300376 adb root
Luca Stefani3d548072020-03-11 12:24:26 +0100377 adb wait-for-device-recovery
Jackeagled6811aa2019-09-24 08:26:40 +0200378 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300379 then
380 adb push $OUT/boot.img /cache/
Michael Bestas3952f6c2016-08-26 01:12:08 +0300381 adb shell dd if=/cache/boot.img of=$PARTITION
Michael W2e203942018-01-14 18:46:02 +0100382 adb shell rm -rf /cache/boot.img
Michael Bestas3952f6c2016-08-26 01:12:08 +0300383 echo "Installation complete."
384 else
Jackeagled6811aa2019-09-24 08:26:40 +0200385 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300386 fi
387}
388
389function installrecovery()
390{
Alessandro Astonef8f48772019-09-06 13:07:03 +0200391 if [ ! -e "$OUT/recovery/root/system/etc/recovery.fstab" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300392 then
393 echo "No recovery.fstab found. Build recovery first."
394 return 1
395 fi
396 if [ ! -e "$OUT/recovery.img" ];
397 then
398 echo "No recovery.img found. Run make recoveryimage first."
399 return 1
400 fi
Alessandro Astonef8f48772019-09-06 13:07:03 +0200401 PARTITION=`grep "^\/recovery" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300402 if [ -z "$PARTITION" ];
403 then
404 # Try for RECOVERY_FSTAB_VERSION = 2
Alessandro Astonef8f48772019-09-06 13:07:03 +0200405 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $1'}`
406 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300407 if [ -z "$PARTITION" ];
408 then
409 echo "Unable to determine recovery partition."
410 return 1
411 fi
412 fi
Luca Stefani3d548072020-03-11 12:24:26 +0100413 adb wait-for-device-recovery
Michael Bestas3952f6c2016-08-26 01:12:08 +0300414 adb root
Luca Stefani3d548072020-03-11 12:24:26 +0100415 adb wait-for-device-recovery
Jackeagled6811aa2019-09-24 08:26:40 +0200416 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300417 then
418 adb push $OUT/recovery.img /cache/
419 adb shell dd if=/cache/recovery.img of=$PARTITION
Michael W2e203942018-01-14 18:46:02 +0100420 adb shell rm -rf /cache/recovery.img
Michael Bestas3952f6c2016-08-26 01:12:08 +0300421 echo "Installation complete."
422 else
Jackeagled6811aa2019-09-24 08:26:40 +0200423 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300424 fi
425}
426
427function makerecipe() {
428 if [ -z "$1" ]
429 then
430 echo "No branch name provided."
431 return 1
432 fi
433 cd android
434 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
435 git commit -a -m "$1"
436 cd ..
437
438 repo forall -c '
439
440 if [ "$REPO_REMOTE" = "github" ]
441 then
442 pwd
Jackeagled6811aa2019-09-24 08:26:40 +0200443 blissremote
444 git push bliss HEAD:refs/heads/'$1'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300445 fi
446 '
447}
448
Jackeagled6811aa2019-09-24 08:26:40 +0200449function blissgerrit() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300450 if [ "$(__detect_shell)" = "zsh" ]; then
451 # zsh does not define FUNCNAME, derive from funcstack
452 local FUNCNAME=$funcstack[1]
453 fi
454
455 if [ $# -eq 0 ]; then
456 $FUNCNAME help
457 return 1
458 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200459 local user=`git config --get review.review.blissroms.com.username`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300460 local review=`git config --get remote.github.review`
461 local project=`git config --get remote.github.projectname`
462 local command=$1
463 shift
464 case $command in
465 help)
466 if [ $# -eq 0 ]; then
467 cat <<EOF
468Usage:
469 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
470
471Commands:
472 fetch Just fetch the change as FETCH_HEAD
473 help Show this help, or for a specific command
474 pull Pull a change into current branch
475 push Push HEAD or a local branch to Gerrit for a specific branch
476
477Any other Git commands that support refname would work as:
478 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
479
480See '$FUNCNAME help COMMAND' for more information on a specific command.
481
482Example:
483 $FUNCNAME checkout -b topic 1234/5
484works as:
485 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
486 && git checkout -b topic FETCH_HEAD
487will checkout a new branch 'topic' base on patch-set 5 of change 1234.
488Patch-set 1 will be fetched if omitted.
489EOF
490 return
491 fi
492 case $1 in
493 __cmg_*) echo "For internal use only." ;;
494 changes|for)
Jackeagled6811aa2019-09-24 08:26:40 +0200495 if [ "$FUNCNAME" = "blissgerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300496 echo "'$FUNCNAME $1' is deprecated."
497 fi
498 ;;
499 help) $FUNCNAME help ;;
500 fetch|pull) cat <<EOF
501usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
502
503works as:
504 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
505 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
506
507Example:
508 $FUNCNAME $1 1234
509will $1 patch-set 1 of change 1234
510EOF
511 ;;
512 push) cat <<EOF
513usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
514
515works as:
516 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
517 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
518
519Example:
520 $FUNCNAME push fix6789:gingerbread
521will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
522HEAD will be pushed from local if omitted.
523EOF
524 ;;
525 *)
526 $FUNCNAME __cmg_err_not_supported $1 && return
527 cat <<EOF
528usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
529
530works as:
531 git fetch http://DOMAIN/p/PROJECT \\
532 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
533 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
534EOF
535 ;;
536 esac
537 ;;
538 __cmg_get_ref)
539 $FUNCNAME __cmg_err_no_arg $command $# && return 1
540 local change_id patchset_id hash
541 case $1 in
542 */*)
543 change_id=${1%%/*}
544 patchset_id=${1#*/}
545 ;;
546 *)
547 change_id=$1
548 patchset_id=1
549 ;;
550 esac
551 hash=$(($change_id % 100))
552 case $hash in
553 [0-9]) hash="0$hash" ;;
554 esac
555 echo "refs/changes/$hash/$change_id/$patchset_id"
556 ;;
557 fetch|pull)
558 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
559 $FUNCNAME __cmg_err_not_repo && return 1
560 local change=$1
561 shift
562 git $command $@ http://$review/p/$project \
563 $($FUNCNAME __cmg_get_ref $change) || return 1
564 ;;
565 push)
566 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
567 $FUNCNAME __cmg_err_not_repo && return 1
568 if [ -z "$user" ]; then
569 echo >&2 "Gerrit username not found."
570 return 1
571 fi
572 local local_branch remote_branch
573 case $1 in
574 *:*)
575 local_branch=${1%:*}
576 remote_branch=${1##*:}
577 ;;
578 *)
579 local_branch=HEAD
580 remote_branch=$1
581 ;;
582 esac
583 shift
584 git push $@ ssh://$user@$review:29418/$project \
585 $local_branch:refs/for/$remote_branch || return 1
586 ;;
587 changes|for)
Jackeagled6811aa2019-09-24 08:26:40 +0200588 if [ "$FUNCNAME" = "blissgerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300589 echo >&2 "'$FUNCNAME $command' is deprecated."
590 fi
591 ;;
592 __cmg_err_no_arg)
593 if [ $# -lt 2 ]; then
594 echo >&2 "'$FUNCNAME $command' missing argument."
595 elif [ $2 -eq 0 ]; then
596 if [ -n "$3" ]; then
597 $FUNCNAME help $1
598 else
599 echo >&2 "'$FUNCNAME $1' missing argument."
600 fi
601 else
602 return 1
603 fi
604 ;;
605 __cmg_err_not_repo)
606 if [ -z "$review" -o -z "$project" ]; then
607 echo >&2 "Not currently in any reviewable repository."
608 else
609 return 1
610 fi
611 ;;
612 __cmg_err_not_supported)
613 $FUNCNAME __cmg_err_no_arg $command $# && return
614 case $1 in
615 #TODO: filter more git commands that don't use refname
616 init|add|rm|mv|status|clone|remote|bisect|config|stash)
617 echo >&2 "'$FUNCNAME $1' is not supported."
618 ;;
619 *) return 1 ;;
620 esac
621 ;;
622 #TODO: other special cases?
623 *)
624 $FUNCNAME __cmg_err_not_supported $command && return 1
625 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
626 $FUNCNAME __cmg_err_not_repo && return 1
627 local args="$@"
628 local change pre_args refs_arg post_args
629 case "$args" in
630 *--\ *)
631 pre_args=${args%%-- *}
632 post_args="-- ${args#*-- }"
633 ;;
634 *) pre_args="$args" ;;
635 esac
636 args=($pre_args)
637 pre_args=
638 if [ ${#args[@]} -gt 0 ]; then
639 change=${args[${#args[@]}-1]}
640 fi
641 if [ ${#args[@]} -gt 1 ]; then
642 pre_args=${args[0]}
643 for ((i=1; i<${#args[@]}-1; i++)); do
644 pre_args="$pre_args ${args[$i]}"
645 done
646 fi
647 while ((1)); do
648 case $change in
649 ""|--)
650 $FUNCNAME help $command
651 return 1
652 ;;
653 *@*)
654 if [ -z "$refs_arg" ]; then
655 refs_arg="@${change#*@}"
656 change=${change%%@*}
657 fi
658 ;;
659 *~*)
660 if [ -z "$refs_arg" ]; then
661 refs_arg="~${change#*~}"
662 change=${change%%~*}
663 fi
664 ;;
665 *^*)
666 if [ -z "$refs_arg" ]; then
667 refs_arg="^${change#*^}"
668 change=${change%%^*}
669 fi
670 ;;
671 *:*)
672 if [ -z "$refs_arg" ]; then
673 refs_arg=":${change#*:}"
674 change=${change%%:*}
675 fi
676 ;;
677 *) break ;;
678 esac
679 done
680 $FUNCNAME fetch $change \
681 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
682 || return 1
683 ;;
684 esac
685}
686
Jackeagled6811aa2019-09-24 08:26:40 +0200687function blissrebase() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300688 local repo=$1
689 local refs=$2
690 local pwd="$(pwd)"
691 local dir="$(gettop)/$repo"
692
693 if [ -z $repo ] || [ -z $refs ]; then
Dan Pasanen03447712016-12-19 11:22:55 -0600694 echo "LineageOS Gerrit Rebase Usage: "
Jackeagled6811aa2019-09-24 08:26:40 +0200695 echo " blissrebase <path to project> <patch IDs on Gerrit>"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300696 echo " The patch IDs appear on the Gerrit commands that are offered."
697 echo " They consist on a series of numbers and slashes, after the text"
698 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
699 echo ""
700 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
701 echo ""
702 return
703 fi
704
705 if [ ! -d $dir ]; then
706 echo "Directory $dir doesn't exist in tree."
707 return
708 fi
709 cd $dir
710 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
711 echo "Starting branch..."
712 repo start tmprebase .
713 echo "Bringing it up to date..."
714 repo sync .
715 echo "Fetching change..."
Jackeagled6811aa2019-09-24 08:26:40 +0200716 git fetch "https://review.blissroms.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Michael Bestas3952f6c2016-08-26 01:12:08 +0300717 if [ "$?" != "0" ]; then
718 echo "Error cherry-picking. Not uploading!"
719 return
720 fi
721 echo "Uploading..."
722 repo upload .
723 echo "Cleaning up..."
724 repo abandon tmprebase .
725 cd $pwd
726}
727
728function mka() {
Luca Stefani085af722017-08-17 20:34:44 +0200729 m -j "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300730}
731
732function cmka() {
733 if [ ! -z "$1" ]; then
734 for i in "$@"; do
735 case $i in
736 bacon|otapackage|systemimage)
737 mka installclean
738 mka $i
739 ;;
740 *)
741 mka clean-$i
742 mka $i
743 ;;
744 esac
745 done
746 else
747 mka clean
748 mka
749 fi
750}
751
Michael Bestas3952f6c2016-08-26 01:12:08 +0300752function repolastsync() {
753 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
754 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
755 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
756 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
757}
758
759function reposync() {
Luca Stefani085af722017-08-17 20:34:44 +0200760 repo sync -j 4 "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300761}
762
763function repodiff() {
764 if [ -z "$*" ]; then
765 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
766 return
767 fi
768 diffopts=$* repo forall -c \
769 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
770}
771
772# Return success if adb is up and not in recovery
773function _adb_connected {
774 {
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200775 if [[ "$(adb get-state)" == device ]]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300776 then
777 return 0
778 fi
779 } 2>/dev/null
780
781 return 1
782};
783
784# Credit for color strip sed: http://goo.gl/BoIcm
785function dopush()
786{
787 local func=$1
788 shift
789
790 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
791 if ! _adb_connected; then
792 echo "No device is online. Waiting for one..."
793 echo "Please connect USB and/or enable USB debugging"
794 until _adb_connected; do
795 sleep 1
796 done
797 echo "Device Found."
798 fi
799
Jackeagled6811aa2019-09-24 08:26:40 +0200800 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD") || [ "$FORCE_PUSH" = "true" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300801 then
802 # retrieve IP and PORT info if we're using a TCP connection
Marc K2be9cac2016-10-20 10:27:35 +0200803 TCPIPPORT=$(adb devices \
804 | egrep '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]):[0-9]+[^0-9]+' \
Michael Bestas3952f6c2016-08-26 01:12:08 +0300805 | head -1 | awk '{print $1}')
806 adb root &> /dev/null
807 sleep 0.3
808 if [ -n "$TCPIPPORT" ]
809 then
810 # adb root just killed our connection
811 # so reconnect...
812 adb connect "$TCPIPPORT"
813 fi
814 adb wait-for-device &> /dev/null
Michael Bestas3952f6c2016-08-26 01:12:08 +0300815 adb remount &> /dev/null
816
817 mkdir -p $OUT
818 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
819 ret=$?;
820 if [ $ret -ne 0 ]; then
821 rm -f $OUT/.log;return $ret
822 fi
823
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500824 is_gnu_sed=`sed --version | head -1 | grep -c GNU`
825
Michael Bestas3952f6c2016-08-26 01:12:08 +0300826 # Install: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500827 if [ $is_gnu_sed -gt 0 ]; then
Marc K97b035d2016-10-20 10:27:44 +0200828 LOC="$(cat $OUT/.log | sed -r -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' -e 's/^\[ {0,2}[0-9]{1,3}% [0-9]{1,6}\/[0-9]{1,6}\] +//' \
829 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300830 else
Marc K97b035d2016-10-20 10:27:44 +0200831 LOC="$(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" -E "s/^\[ {0,2}[0-9]{1,3}% [0-9]{1,6}\/[0-9]{1,6}\] +//" \
832 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300833 fi
834
835 # Copy: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500836 if [ $is_gnu_sed -gt 0 ]; then
Marc K97b035d2016-10-20 10:27:44 +0200837 LOC="$LOC $(cat $OUT/.log | sed -r -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' -e 's/^\[ {0,2}[0-9]{1,3}% [0-9]{1,6}\/[0-9]{1,6}\] +//' \
838 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300839 else
Marc K97b035d2016-10-20 10:27:44 +0200840 LOC="$LOC $(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" -E 's/^\[ {0,2}[0-9]{1,3}% [0-9]{1,6}\/[0-9]{1,6}\] +//' \
841 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300842 fi
843
844 # If any files are going to /data, push an octal file permissions reader to device
845 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
846 CHKPERM="/data/local/tmp/chkfileperm.sh"
847(
848cat <<'EOF'
Bruno Martins5bc28e22022-02-08 19:35:40 +0000849#!/system/bin/sh
Michael Bestas3952f6c2016-08-26 01:12:08 +0300850FILE=$@
851if [ -e $FILE ]; then
852 ls -l $FILE | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' | cut -d ' ' -f1
853fi
854EOF
855) > $OUT/.chkfileperm.sh
856 echo "Pushing file permissions checker to device"
857 adb push $OUT/.chkfileperm.sh $CHKPERM
858 adb shell chmod 755 $CHKPERM
859 rm -f $OUT/.chkfileperm.sh
860 fi
861
Sam Mortimerc3865952019-10-12 02:14:13 -0700862 RELOUT=$(echo $OUT | sed "s#^${ANDROID_BUILD_TOP}/##")
863
Michael Bestas3952f6c2016-08-26 01:12:08 +0300864 stop_n_start=false
Sam Mortimerc3865952019-10-12 02:14:13 -0700865 for TARGET in $(echo $LOC | tr " " "\n" | sed "s#.*${RELOUT}##" | sort | uniq); do
Roman Birgd51094c2018-03-28 09:47:30 -0700866 # Make sure file is in $OUT/system, $OUT/data, $OUT/odm, $OUT/oem, $OUT/product, $OUT/product_services or $OUT/vendor
Adrian DCa8e06d32018-06-17 00:15:00 +0200867 case $TARGET in
Roman Birgd51094c2018-03-28 09:47:30 -0700868 /system/*|/data/*|/odm/*|/oem/*|/product/*|/product_services/*|/vendor/*)
Adrian DCa8e06d32018-06-17 00:15:00 +0200869 # Get out file from target (i.e. /system/bin/adb)
870 FILE=$OUT$TARGET
Michael Bestas3952f6c2016-08-26 01:12:08 +0300871 ;;
872 *) continue ;;
873 esac
874
875 case $TARGET in
876 /data/*)
877 # fs_config only sets permissions and se labels for files pushed to /system
878 if [ -n "$CHKPERM" ]; then
879 OLDPERM=$(adb shell $CHKPERM $TARGET)
880 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
881 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
882 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
883 fi
884 echo "Pushing: $TARGET"
885 adb push $FILE $TARGET
886 if [ -n "$OLDPERM" ]; then
887 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
888 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
889 adb shell chmod "$OLDPERM" $TARGET
890 else
891 echo "$TARGET did not exist previously, you should set file permissions manually"
892 fi
893 adb shell restorecon "$TARGET"
894 ;;
Michael Wec0363e2020-06-17 17:37:09 +0200895 */SystemUI.apk|*/framework/*)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300896 # Only need to stop services once
897 if ! $stop_n_start; then
898 adb shell stop
899 stop_n_start=true
900 fi
901 echo "Pushing: $TARGET"
902 adb push $FILE $TARGET
903 ;;
904 *)
905 echo "Pushing: $TARGET"
906 adb push $FILE $TARGET
907 ;;
908 esac
909 done
910 if [ -n "$CHKPERM" ]; then
911 adb shell rm $CHKPERM
912 fi
913 if $stop_n_start; then
914 adb shell start
915 fi
916 rm -f $OUT/.log
917 return 0
918 else
Jackeagled6811aa2019-09-24 08:26:40 +0200919 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300920 fi
921}
922
923alias mmp='dopush mm'
924alias mmmp='dopush mmm'
925alias mmap='dopush mma'
Zhao Wei Liew64fc5ae2016-12-10 16:48:27 +0800926alias mmmap='dopush mmma'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300927alias mkap='dopush mka'
928alias cmkap='dopush cmka'
929
930function repopick() {
931 T=$(gettop)
Jackeagled6811aa2019-09-24 08:26:40 +0200932 $T/vendor/bliss/build/tools/repopick.py $@
Michael Bestas3952f6c2016-08-26 01:12:08 +0300933}
934
Michael Bestas656f7e52022-06-09 18:50:47 +0300935function sort-blobs-list() {
936 T=$(gettop)
937 $T/tools/extract-utils/sort-blobs-list.py $@
938}
939
Michael Bestas3952f6c2016-08-26 01:12:08 +0300940function fixup_common_out_dir() {
941 common_out_dir=$(get_build_var OUT_DIR)/target/common
942 target_device=$(get_build_var TARGET_DEVICE)
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700943 common_target_out=common-${target_device}
Jackeagle305db7c2020-01-23 10:35:22 +0100944 if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300945 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
946 mv ${common_out_dir} ${common_out_dir}-${target_device}
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700947 ln -s ${common_target_out} ${common_out_dir}
Michael Bestas3952f6c2016-08-26 01:12:08 +0300948 else
949 [ -L ${common_out_dir} ] && rm ${common_out_dir}
950 mkdir -p ${common_out_dir}-${target_device}
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700951 ln -s ${common_target_out} ${common_out_dir}
Michael Bestas3952f6c2016-08-26 01:12:08 +0300952 fi
953 else
954 [ -L ${common_out_dir} ] && rm ${common_out_dir}
955 mkdir -p ${common_out_dir}
956 fi
957}
Jackeagle305db7c2020-01-23 10:35:22 +0100958
959function blissify()
960{
Jon West6f429fa2021-04-24 18:09:38 -0400961 abt="$ANDROID_BUILD_TOP"
962 cd $abt
963 clean="n"
964 deviceclean="n"
965 export BLISS_BUILD_VARIANT=vanilla
966 while test $# -gt 0
967 do
968 case $1 in
969
970 # Normal option processing
971 -h | --help)
972 echo "Usage: $0 options deviceCodename "
973 echo "options: -h | --help: Shows this dialog"
974 echo " -c | --clean: Clean up before running the build"
975 echo " -d | --devclean: Clean up device tree before running the build"
976 echo " -v | --vanilla: Build with no added app store solution **default option** "
977 echo " -g | --gapps: Build with Google Play Services added"
978 echo " -f | --fossa: build with FOSS (arm64-v8a) app store solutions added"
979 echo " -F | --fossx: build with FOSS (x86_64) app store solutions added"
980 echo ""
981 echo "deviceCodename: "
982 echo "your device codename, without the 'bliss_' in front"
983 echo ""
984 ;;
985 -c | --clean)
986 clean="y";
987 echo "Cleaning build and device tree selected."
988 ;;
989 -d | --devclean)
990 deviceclean="y";
991 echo "Cleaning device tree selected."
992 ;;
993 -v | --vanilla)
994 echo "Building as stock (no gapps) **DEFAULT**"
995 export BLISS_BUILD_VARIANT=vanilla
996 ;;
997 -g | --gapps)
998 echo "Building with gapps"
999 export BLISS_BUILD_VARIANT=gapps
1000 ;;
1001 -f | --fossa)
1002 echo "Building with FOSS apps for arm64-v8a support"
1003 export BLISS_BUILD_VARIANT=foss
1004 cd vendor/foss
1005 bash update.sh 2
1006 cd $abt
1007 ;;
1008 -F | --fossx)
1009 echo "Building with FOSS apps for x86_64 support"
1010 export BLISS_BUILD_VARIANT=foss
1011 cd vendor/foss
1012 bash update.sh 1
1013 cd $abt
1014 ;;
Jon West68fe7e52021-06-02 15:24:20 -04001015 -u | --userdebug)
1016 echo "Building userdebug variant"
1017 TARGET_BUILD_VARIANT=userdebug
1018 ;;
1019 -U | --user)
1020 echo "Building user variant"
1021 TARGET_BUILD_VARIANT=user
1022 ;;
1023 -e | --eng)
1024 echo "Building eng variant"
1025 TARGET_BUILD_VARIANT=eng
1026 ;;
1027
Jon West6f429fa2021-04-24 18:09:38 -04001028
1029 # ...
1030
1031 # Special cases
1032 --)
1033 echo "Please use --help to verify correct usage"
1034 break
1035 ;;
1036 --*)
1037 # error unknown (long) option $1
1038 echo "Please use --help to verify correct usage"
1039 break
1040 ;;
1041 -?)
1042 echo "Please use --help to verify correct usage"
1043 # error unknown (short) option $1
1044 break
1045 ;;
1046
1047 # FUN STUFF HERE:
1048 # Split apart combined short options
1049 -*)
1050 split=$1
1051 shift
1052 set -- $(echo "$split" | cut -c 2- | sed 's/./-& /g') "$@"
1053 continue
1054 ;;
1055
1056 # Done with options
1057 *)
1058 break
1059 ;;
1060 esac
1061
1062 # for testing purposes:
1063 shift
1064 done
Jon West6f429fa2021-04-24 18:09:38 -04001065 if [ "$1" == "" ]; then
1066 echo "No device name specified. Please use --help to verify correct usage"
1067 return 0
1068 fi
Jackeagle911602f2021-12-06 05:17:55 +01001069
1070 checkofficial $1
1071
Jon West68fe7e52021-06-02 15:24:20 -04001072 # Breakfast extension
1073 if [ $TARGET_BUILD_VARIANT == "user" ];then
1074 breakfast $* user
1075 elif [ $TARGET_BUILD_VARIANT == "eng" ];then
1076 breakfast $* eng
1077 else
1078 breakfast $*
1079 fi
Jackeagled52fd812021-09-10 23:21:00 -04001080
1081 if [ $clean == "y" ];then
1082 echo "Cleaning up a bit"
1083 make clean && make clobber
1084 fi
1085
1086 if [ $deviceclean == "y" ];then
1087 echo "Doing some device cleanup"
1088 make deviceclean
1089 fi
1090
Jackeagle305db7c2020-01-23 10:35:22 +01001091 if [ $? -eq 0 ]; then
1092 mka blissify
1093 else
Jon West6f429fa2021-04-24 18:09:38 -04001094 echo "No such item in brunch menu. Try 'breakfast' or verify your product is added to AndroidProducts.mk"
Jackeagle305db7c2020-01-23 10:35:22 +01001095 return 1
1096 fi
1097 return $?
1098}
Danny Line0ece602021-11-12 11:25:02 +00001099
1100# Override host metadata to make builds more reproducible and avoid leaking info
1101export BUILD_USERNAME=nobody
1102export BUILD_HOSTNAME=android-build