blob: aa441ea8b084a647a507acf269ae879e5fd7070e [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
Luca Stefani076c27b2017-08-17 20:30:00 +020029function mk_timer()
30{
31 local start_time=$(date +"%s")
32 $@
33 local ret=$?
34 local end_time=$(date +"%s")
35 local tdiff=$(($end_time-$start_time))
36 local hours=$(($tdiff / 3600 ))
37 local mins=$((($tdiff % 3600) / 60))
38 local secs=$(($tdiff % 60))
39 local ncolors=$(tput colors 2>/dev/null)
40 echo
41 if [ $ret -eq 0 ] ; then
42 echo -n "#### make completed successfully "
43 else
44 echo -n "#### make failed to build some targets "
45 fi
46 if [ $hours -gt 0 ] ; then
47 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
48 elif [ $mins -gt 0 ] ; then
49 printf "(%02g:%02g (mm:ss))" $mins $secs
50 elif [ $secs -gt 0 ] ; then
51 printf "(%s seconds)" $secs
52 fi
53 echo " ####"
54 echo
55 return $ret
56}
57
Michael Bestas3952f6c2016-08-26 01:12:08 +030058function breakfast()
59{
60 target=$1
61 local variant=$2
Jackeagle86c04f32023-09-23 03:35:54 -040062
Michael Bestas3952f6c2016-08-26 01:12:08 +030063 if [ $# -eq 0 ]; then
64 # No arguments, so let's have the full menu
65 lunch
66 else
67 echo "z$target" | grep -q "-"
68 if [ $? -eq 0 ]; then
69 # A buildtype was specified, assume a full device name
70 lunch $target
71 else
Jackeagled6811aa2019-09-24 08:26:40 +020072 # This is probably just the BlissRoms model name
Michael Bestas3952f6c2016-08-26 01:12:08 +030073 if [ -z "$variant" ]; then
74 variant="userdebug"
75 fi
Matt Mowered8c2482017-01-02 02:26:01 -060076
Jis G Jacobe12a4eb2024-06-12 19:44:16 -040077 lunch bliss_$target-ap2a-$variant
Michael Bestas3952f6c2016-08-26 01:12:08 +030078 fi
79 fi
80 return $?
81}
82
83alias bib=breakfast
84
85function eat()
86{
87 if [ "$OUT" ] ; then
Jackeagled6811aa2019-09-24 08:26:40 +020088 ZIPPATH=`ls -tr "$OUT"/Bliss-*.zip | tail -1`
Michael Bestas3952f6c2016-08-26 01:12:08 +030089 if [ ! -f $ZIPPATH ] ; then
90 echo "Nothing to eat"
91 return 1
92 fi
Alessandro Astonecdf9ae82019-09-28 16:53:08 +020093 echo "Waiting for device..."
Luca Stefani3d548072020-03-11 12:24:26 +010094 adb wait-for-device-recovery
Alessandro Astonecdf9ae82019-09-28 16:53:08 +020095 echo "Found device"
Jackeagled6811aa2019-09-24 08:26:40 +020096 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD"); then
Alessandro Astonecdf9ae82019-09-28 16:53:08 +020097 echo "Rebooting to sideload for install"
98 adb reboot sideload-auto-reboot
99 adb wait-for-sideload
100 adb sideload $ZIPPATH
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800101 else
Jackeagled6811aa2019-09-24 08:26:40 +0200102 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300103 fi
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800104 return $?
Michael Bestas3952f6c2016-08-26 01:12:08 +0300105 else
106 echo "Nothing to eat"
107 return 1
108 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300109}
110
111function omnom()
112{
Jackeagle305db7c2020-01-23 10:35:22 +0100113 blissify $*
Michael Bestas3952f6c2016-08-26 01:12:08 +0300114 eat
115}
116
117function cout()
118{
119 if [ "$OUT" ]; then
120 cd $OUT
121 else
122 echo "Couldn't locate out directory. Try setting OUT."
123 fi
124}
125
126function dddclient()
127{
128 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
129 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
130 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
131 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
132 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
133 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
134 local ARCH=$(get_build_var TARGET_ARCH)
135 local GDB
136 case "$ARCH" in
137 arm) GDB=arm-linux-androideabi-gdb;;
138 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
139 mips|mips64) GDB=mips64el-linux-android-gdb;;
140 x86) GDB=x86_64-linux-android-gdb;;
141 x86_64) GDB=x86_64-linux-android-gdb;;
142 *) echo "Unknown arch $ARCH"; return 1;;
143 esac
144
145 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
146 local EXE="$1"
147 if [ "$EXE" ] ; then
148 EXE=$1
149 if [[ $EXE =~ ^[^/].* ]] ; then
150 EXE="system/bin/"$EXE
151 fi
152 else
153 EXE="app_process"
154 fi
155
156 local PORT="$2"
157 if [ "$PORT" ] ; then
158 PORT=$2
159 else
160 PORT=":5039"
161 fi
162
163 local PID="$3"
164 if [ "$PID" ] ; then
165 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
166 PID=`pid $3`
167 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
168 # that likely didn't work because of returning multiple processes
169 # try again, filtering by root processes (don't contain colon)
170 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
171 if [[ ! "$PID" =~ ^[0-9]+$ ]]
172 then
173 echo "Couldn't resolve '$3' to single PID"
174 return 1
175 else
176 echo ""
177 echo "WARNING: multiple processes matching '$3' observed, using root process"
178 echo ""
179 fi
180 fi
181 fi
182 adb forward "tcp$PORT" "tcp$PORT"
183 local USE64BIT="$(is64bit $PID)"
184 adb shell gdbserver$USE64BIT $PORT --attach $PID &
185 sleep 2
186 else
187 echo ""
188 echo "If you haven't done so already, do this first on the device:"
189 echo " gdbserver $PORT /system/bin/$EXE"
190 echo " or"
191 echo " gdbserver $PORT --attach <PID>"
192 echo ""
193 fi
194
195 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
196 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
197
198 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
199 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"
200 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
201 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
202 # Enable special debugging for ART processes.
203 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
204 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
205 fi
206 echo >>"$OUT_ROOT/gdbclient.cmds" ""
207
208 local WHICH_GDB=
209 # 64-bit exe found
210 if [ "$USE64BIT" != "" ] ; then
211 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
212 # 32-bit exe / 32-bit platform
213 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
214 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
215 # 32-bit exe / 64-bit platform
216 else
217 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
218 fi
219
220 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
221 else
222 echo "Unable to determine build system output dir."
223 fi
224}
225
Jackeagled6811aa2019-09-24 08:26:40 +0200226function blissremote()
Michael Bestas3952f6c2016-08-26 01:12:08 +0300227{
228 if ! git rev-parse --git-dir &> /dev/null
229 then
230 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
231 return 1
232 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200233 git remote rm bliss 2> /dev/null
Michael Bestas9e6bde52018-04-02 19:54:45 +0300234 local REMOTE=$(git config --get remote.github.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100235 local BLISS="true"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300236 if [ -z "$REMOTE" ]
Michael Bestasaf3532b2017-08-23 17:40:40 +0300237 then
Michael Bestas9e6bde52018-04-02 19:54:45 +0300238 REMOTE=$(git config --get remote.aosp.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100239 BLISS="false"
Michael Bestasaf3532b2017-08-23 17:40:40 +0300240 fi
Michael Bestas9e6bde52018-04-02 19:54:45 +0300241 if [ -z "$REMOTE" ]
242 then
243 REMOTE=$(git config --get remote.caf.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100244 BLISS="false"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300245 fi
246
Jackeagle305db7c2020-01-23 10:35:22 +0100247 if [ $BLISS = "false" ]
Michael Bestas9e6bde52018-04-02 19:54:45 +0300248 then
249 local PROJECT=$(echo $REMOTE | sed -e "s#platform/#android/#g; s#/#_#g")
Jackeagle305db7c2020-01-23 10:35:22 +0100250 local PFX="BLISS/"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300251 else
252 local PROJECT=$REMOTE
253 fi
254
Jackeagle305db7c2020-01-23 10:35:22 +0100255 local BLISS_USER=$(git config --get review.review.blissroms.com.username)
256 if [ -z "$BLISS_USER" ]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300257 then
Jackeagled6811aa2019-09-24 08:26:40 +0200258 git remote add bliss ssh://review.blissroms.com:29418/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300259 else
Jackeagle305db7c2020-01-23 10:35:22 +0100260 git remote add bliss ssh://$BLISS_USER@review.blissroms.com:29418/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300261 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200262 echo "Remote 'bliss' created"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300263}
264
265function aospremote()
266{
267 if ! git rev-parse --git-dir &> /dev/null
268 then
269 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
270 return 1
271 fi
272 git remote rm aosp 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300273 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400274 # Google moved the repo location in Oreo
275 if [ $PROJECT = "build/make" ]
276 then
277 PROJECT="build"
278 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300279 if (echo $PROJECT | grep -qv "^device")
280 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300281 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300282 fi
283 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
284 echo "Remote 'aosp' created"
285}
286
287function cafremote()
288{
289 if ! git rev-parse --git-dir &> /dev/null
290 then
291 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
292 return 1
293 fi
294 git remote rm caf 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300295 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400296 # Google moved the repo location in Oreo
297 if [ $PROJECT = "build/make" ]
298 then
299 PROJECT="build"
300 fi
Rashed Abdel-Tawabb52c7082017-12-24 22:40:31 +0200301 if [[ $PROJECT =~ "qcom/opensource" ]];
302 then
303 PROJECT=$(echo $PROJECT | sed -e "s#qcom\/opensource#qcom-opensource#")
304 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300305 if (echo $PROJECT | grep -qv "^device")
306 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300307 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300308 fi
Zhao Wei Liewfb4b8c52017-01-08 09:03:01 +0800309 git remote add caf https://source.codeaurora.org/quic/la/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300310 echo "Remote 'caf' created"
311}
312
Michael Bestasa504aa42018-08-10 22:51:37 +0300313function githubremote()
314{
315 if ! git rev-parse --git-dir &> /dev/null
316 then
317 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
318 return 1
319 fi
320 git remote rm github 2> /dev/null
321 local REMOTE=$(git config --get remote.aosp.projectname)
322
323 if [ -z "$REMOTE" ]
324 then
325 REMOTE=$(git config --get remote.caf.projectname)
326 fi
327
328 local PROJECT=$(echo $REMOTE | sed -e "s#platform/#android/#g; s#/#_#g")
329
330 git remote add github https://github.com/LineageOS/$PROJECT
331 echo "Remote 'github' created"
332}
333
Michael Bestas3952f6c2016-08-26 01:12:08 +0300334function installboot()
335{
Alessandro Astonef8f48772019-09-06 13:07:03 +0200336 if [ ! -e "$OUT/recovery/root/system/etc/recovery.fstab" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300337 then
338 echo "No recovery.fstab found. Build recovery first."
339 return 1
340 fi
341 if [ ! -e "$OUT/boot.img" ];
342 then
343 echo "No boot.img found. Run make bootimage first."
344 return 1
345 fi
Alessandro Astonef8f48772019-09-06 13:07:03 +0200346 PARTITION=`grep "^\/boot" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300347 if [ -z "$PARTITION" ];
348 then
349 # Try for RECOVERY_FSTAB_VERSION = 2
Alessandro Astonef8f48772019-09-06 13:07:03 +0200350 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $1'}`
351 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300352 if [ -z "$PARTITION" ];
353 then
354 echo "Unable to determine boot partition."
355 return 1
356 fi
357 fi
Luca Stefani3d548072020-03-11 12:24:26 +0100358 adb wait-for-device-recovery
Michael Bestas3952f6c2016-08-26 01:12:08 +0300359 adb root
Luca Stefani3d548072020-03-11 12:24:26 +0100360 adb wait-for-device-recovery
Jackeagled6811aa2019-09-24 08:26:40 +0200361 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300362 then
363 adb push $OUT/boot.img /cache/
Michael Bestas3952f6c2016-08-26 01:12:08 +0300364 adb shell dd if=/cache/boot.img of=$PARTITION
Michael W2e203942018-01-14 18:46:02 +0100365 adb shell rm -rf /cache/boot.img
Michael Bestas3952f6c2016-08-26 01:12:08 +0300366 echo "Installation complete."
367 else
Jackeagled6811aa2019-09-24 08:26:40 +0200368 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300369 fi
370}
371
372function installrecovery()
373{
Alessandro Astonef8f48772019-09-06 13:07:03 +0200374 if [ ! -e "$OUT/recovery/root/system/etc/recovery.fstab" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300375 then
376 echo "No recovery.fstab found. Build recovery first."
377 return 1
378 fi
379 if [ ! -e "$OUT/recovery.img" ];
380 then
381 echo "No recovery.img found. Run make recoveryimage first."
382 return 1
383 fi
Alessandro Astonef8f48772019-09-06 13:07:03 +0200384 PARTITION=`grep "^\/recovery" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300385 if [ -z "$PARTITION" ];
386 then
387 # Try for RECOVERY_FSTAB_VERSION = 2
Alessandro Astonef8f48772019-09-06 13:07:03 +0200388 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $1'}`
389 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300390 if [ -z "$PARTITION" ];
391 then
392 echo "Unable to determine recovery partition."
393 return 1
394 fi
395 fi
Luca Stefani3d548072020-03-11 12:24:26 +0100396 adb wait-for-device-recovery
Michael Bestas3952f6c2016-08-26 01:12:08 +0300397 adb root
Luca Stefani3d548072020-03-11 12:24:26 +0100398 adb wait-for-device-recovery
Jackeagled6811aa2019-09-24 08:26:40 +0200399 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300400 then
401 adb push $OUT/recovery.img /cache/
402 adb shell dd if=/cache/recovery.img of=$PARTITION
Michael W2e203942018-01-14 18:46:02 +0100403 adb shell rm -rf /cache/recovery.img
Michael Bestas3952f6c2016-08-26 01:12:08 +0300404 echo "Installation complete."
405 else
Jackeagled6811aa2019-09-24 08:26:40 +0200406 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300407 fi
408}
409
410function makerecipe() {
411 if [ -z "$1" ]
412 then
413 echo "No branch name provided."
414 return 1
415 fi
416 cd android
417 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
418 git commit -a -m "$1"
419 cd ..
420
421 repo forall -c '
422
423 if [ "$REPO_REMOTE" = "github" ]
424 then
425 pwd
Jackeagled6811aa2019-09-24 08:26:40 +0200426 blissremote
427 git push bliss HEAD:refs/heads/'$1'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300428 fi
429 '
430}
431
Jackeagled6811aa2019-09-24 08:26:40 +0200432function blissgerrit() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300433 if [ "$(__detect_shell)" = "zsh" ]; then
434 # zsh does not define FUNCNAME, derive from funcstack
435 local FUNCNAME=$funcstack[1]
436 fi
437
438 if [ $# -eq 0 ]; then
439 $FUNCNAME help
440 return 1
441 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200442 local user=`git config --get review.review.blissroms.com.username`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300443 local review=`git config --get remote.github.review`
444 local project=`git config --get remote.github.projectname`
445 local command=$1
446 shift
447 case $command in
448 help)
449 if [ $# -eq 0 ]; then
450 cat <<EOF
451Usage:
452 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
453
454Commands:
455 fetch Just fetch the change as FETCH_HEAD
456 help Show this help, or for a specific command
457 pull Pull a change into current branch
458 push Push HEAD or a local branch to Gerrit for a specific branch
459
460Any other Git commands that support refname would work as:
461 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
462
463See '$FUNCNAME help COMMAND' for more information on a specific command.
464
465Example:
466 $FUNCNAME checkout -b topic 1234/5
467works as:
468 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
469 && git checkout -b topic FETCH_HEAD
470will checkout a new branch 'topic' base on patch-set 5 of change 1234.
471Patch-set 1 will be fetched if omitted.
472EOF
473 return
474 fi
475 case $1 in
476 __cmg_*) echo "For internal use only." ;;
477 changes|for)
Jackeagled6811aa2019-09-24 08:26:40 +0200478 if [ "$FUNCNAME" = "blissgerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300479 echo "'$FUNCNAME $1' is deprecated."
480 fi
481 ;;
482 help) $FUNCNAME help ;;
483 fetch|pull) cat <<EOF
484usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
485
486works as:
487 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
488 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
489
490Example:
491 $FUNCNAME $1 1234
492will $1 patch-set 1 of change 1234
493EOF
494 ;;
495 push) cat <<EOF
496usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
497
498works as:
499 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
500 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
501
502Example:
503 $FUNCNAME push fix6789:gingerbread
504will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
505HEAD will be pushed from local if omitted.
506EOF
507 ;;
508 *)
509 $FUNCNAME __cmg_err_not_supported $1 && return
510 cat <<EOF
511usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
512
513works as:
514 git fetch http://DOMAIN/p/PROJECT \\
515 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
516 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
517EOF
518 ;;
519 esac
520 ;;
521 __cmg_get_ref)
522 $FUNCNAME __cmg_err_no_arg $command $# && return 1
523 local change_id patchset_id hash
524 case $1 in
525 */*)
526 change_id=${1%%/*}
527 patchset_id=${1#*/}
528 ;;
529 *)
530 change_id=$1
531 patchset_id=1
532 ;;
533 esac
534 hash=$(($change_id % 100))
535 case $hash in
536 [0-9]) hash="0$hash" ;;
537 esac
538 echo "refs/changes/$hash/$change_id/$patchset_id"
539 ;;
540 fetch|pull)
541 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
542 $FUNCNAME __cmg_err_not_repo && return 1
543 local change=$1
544 shift
545 git $command $@ http://$review/p/$project \
546 $($FUNCNAME __cmg_get_ref $change) || return 1
547 ;;
548 push)
549 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
550 $FUNCNAME __cmg_err_not_repo && return 1
551 if [ -z "$user" ]; then
552 echo >&2 "Gerrit username not found."
553 return 1
554 fi
555 local local_branch remote_branch
556 case $1 in
557 *:*)
558 local_branch=${1%:*}
559 remote_branch=${1##*:}
560 ;;
561 *)
562 local_branch=HEAD
563 remote_branch=$1
564 ;;
565 esac
566 shift
567 git push $@ ssh://$user@$review:29418/$project \
568 $local_branch:refs/for/$remote_branch || return 1
569 ;;
570 changes|for)
Jackeagled6811aa2019-09-24 08:26:40 +0200571 if [ "$FUNCNAME" = "blissgerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300572 echo >&2 "'$FUNCNAME $command' is deprecated."
573 fi
574 ;;
575 __cmg_err_no_arg)
576 if [ $# -lt 2 ]; then
577 echo >&2 "'$FUNCNAME $command' missing argument."
578 elif [ $2 -eq 0 ]; then
579 if [ -n "$3" ]; then
580 $FUNCNAME help $1
581 else
582 echo >&2 "'$FUNCNAME $1' missing argument."
583 fi
584 else
585 return 1
586 fi
587 ;;
588 __cmg_err_not_repo)
589 if [ -z "$review" -o -z "$project" ]; then
590 echo >&2 "Not currently in any reviewable repository."
591 else
592 return 1
593 fi
594 ;;
595 __cmg_err_not_supported)
596 $FUNCNAME __cmg_err_no_arg $command $# && return
597 case $1 in
598 #TODO: filter more git commands that don't use refname
599 init|add|rm|mv|status|clone|remote|bisect|config|stash)
600 echo >&2 "'$FUNCNAME $1' is not supported."
601 ;;
602 *) return 1 ;;
603 esac
604 ;;
605 #TODO: other special cases?
606 *)
607 $FUNCNAME __cmg_err_not_supported $command && return 1
608 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
609 $FUNCNAME __cmg_err_not_repo && return 1
610 local args="$@"
611 local change pre_args refs_arg post_args
612 case "$args" in
613 *--\ *)
614 pre_args=${args%%-- *}
615 post_args="-- ${args#*-- }"
616 ;;
617 *) pre_args="$args" ;;
618 esac
619 args=($pre_args)
620 pre_args=
621 if [ ${#args[@]} -gt 0 ]; then
622 change=${args[${#args[@]}-1]}
623 fi
624 if [ ${#args[@]} -gt 1 ]; then
625 pre_args=${args[0]}
626 for ((i=1; i<${#args[@]}-1; i++)); do
627 pre_args="$pre_args ${args[$i]}"
628 done
629 fi
630 while ((1)); do
631 case $change in
632 ""|--)
633 $FUNCNAME help $command
634 return 1
635 ;;
636 *@*)
637 if [ -z "$refs_arg" ]; then
638 refs_arg="@${change#*@}"
639 change=${change%%@*}
640 fi
641 ;;
642 *~*)
643 if [ -z "$refs_arg" ]; then
644 refs_arg="~${change#*~}"
645 change=${change%%~*}
646 fi
647 ;;
648 *^*)
649 if [ -z "$refs_arg" ]; then
650 refs_arg="^${change#*^}"
651 change=${change%%^*}
652 fi
653 ;;
654 *:*)
655 if [ -z "$refs_arg" ]; then
656 refs_arg=":${change#*:}"
657 change=${change%%:*}
658 fi
659 ;;
660 *) break ;;
661 esac
662 done
663 $FUNCNAME fetch $change \
664 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
665 || return 1
666 ;;
667 esac
668}
669
Jackeagled6811aa2019-09-24 08:26:40 +0200670function blissrebase() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300671 local repo=$1
672 local refs=$2
673 local pwd="$(pwd)"
674 local dir="$(gettop)/$repo"
675
676 if [ -z $repo ] || [ -z $refs ]; then
Dan Pasanen03447712016-12-19 11:22:55 -0600677 echo "LineageOS Gerrit Rebase Usage: "
Jackeagled6811aa2019-09-24 08:26:40 +0200678 echo " blissrebase <path to project> <patch IDs on Gerrit>"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300679 echo " The patch IDs appear on the Gerrit commands that are offered."
680 echo " They consist on a series of numbers and slashes, after the text"
681 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
682 echo ""
683 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
684 echo ""
685 return
686 fi
687
688 if [ ! -d $dir ]; then
689 echo "Directory $dir doesn't exist in tree."
690 return
691 fi
692 cd $dir
693 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
694 echo "Starting branch..."
695 repo start tmprebase .
696 echo "Bringing it up to date..."
697 repo sync .
698 echo "Fetching change..."
Jackeagled6811aa2019-09-24 08:26:40 +0200699 git fetch "https://review.blissroms.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Michael Bestas3952f6c2016-08-26 01:12:08 +0300700 if [ "$?" != "0" ]; then
701 echo "Error cherry-picking. Not uploading!"
702 return
703 fi
704 echo "Uploading..."
705 repo upload .
706 echo "Cleaning up..."
707 repo abandon tmprebase .
708 cd $pwd
709}
710
711function mka() {
Luca Stefani085af722017-08-17 20:34:44 +0200712 m -j "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300713}
714
715function cmka() {
716 if [ ! -z "$1" ]; then
717 for i in "$@"; do
718 case $i in
719 bacon|otapackage|systemimage)
720 mka installclean
721 mka $i
722 ;;
723 *)
724 mka clean-$i
725 mka $i
726 ;;
727 esac
728 done
729 else
730 mka clean
731 mka
732 fi
733}
734
Michael Bestas3952f6c2016-08-26 01:12:08 +0300735function repolastsync() {
736 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
737 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
738 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
739 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
740}
741
742function reposync() {
Luca Stefani085af722017-08-17 20:34:44 +0200743 repo sync -j 4 "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300744}
745
746function repodiff() {
747 if [ -z "$*" ]; then
748 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
749 return
750 fi
751 diffopts=$* repo forall -c \
752 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
753}
754
755# Return success if adb is up and not in recovery
756function _adb_connected {
757 {
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200758 if [[ "$(adb get-state)" == device ]]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300759 then
760 return 0
761 fi
762 } 2>/dev/null
763
764 return 1
765};
766
767# Credit for color strip sed: http://goo.gl/BoIcm
768function dopush()
769{
770 local func=$1
771 shift
772
773 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
774 if ! _adb_connected; then
775 echo "No device is online. Waiting for one..."
776 echo "Please connect USB and/or enable USB debugging"
777 until _adb_connected; do
778 sleep 1
779 done
780 echo "Device Found."
781 fi
782
Jackeagled6811aa2019-09-24 08:26:40 +0200783 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD") || [ "$FORCE_PUSH" = "true" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300784 then
785 # retrieve IP and PORT info if we're using a TCP connection
Marc K2be9cac2016-10-20 10:27:35 +0200786 TCPIPPORT=$(adb devices \
787 | 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 +0300788 | head -1 | awk '{print $1}')
789 adb root &> /dev/null
790 sleep 0.3
791 if [ -n "$TCPIPPORT" ]
792 then
793 # adb root just killed our connection
794 # so reconnect...
795 adb connect "$TCPIPPORT"
796 fi
797 adb wait-for-device &> /dev/null
Michael Bestas3952f6c2016-08-26 01:12:08 +0300798 adb remount &> /dev/null
799
800 mkdir -p $OUT
801 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
802 ret=$?;
803 if [ $ret -ne 0 ]; then
804 rm -f $OUT/.log;return $ret
805 fi
806
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500807 is_gnu_sed=`sed --version | head -1 | grep -c GNU`
808
Michael Bestas3952f6c2016-08-26 01:12:08 +0300809 # Install: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500810 if [ $is_gnu_sed -gt 0 ]; then
Dhina17dd2a6e72024-07-10 18:32:14 +0530811 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}( [0-9]{0,2}?h?[0-9]{0,2}?m?[0-9]{0,2}s remaining)?\] +//' \
Marc K97b035d2016-10-20 10:27:44 +0200812 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300813 else
Dhina17dd2a6e72024-07-10 18:32:14 +0530814 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}( [0-9]{0,2}?h?[0-9]{0,2}?m?[0-9]{0,2}s remaining)?\] +//" \
Marc K97b035d2016-10-20 10:27:44 +0200815 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300816 fi
817
818 # Copy: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500819 if [ $is_gnu_sed -gt 0 ]; then
Dhina17dd2a6e72024-07-10 18:32:14 +0530820 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}( [0-9]{0,2}?h?[0-9]{0,2}?m?[0-9]{0,2}s remaining)?\] +//' \
Marc K97b035d2016-10-20 10:27:44 +0200821 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300822 else
Dhina17dd2a6e72024-07-10 18:32:14 +0530823 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}( [0-9]{0,2}?h?[0-9]{0,2}?m?[0-9]{0,2}s remaining)?\] +//' \
Marc K97b035d2016-10-20 10:27:44 +0200824 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300825 fi
826
827 # If any files are going to /data, push an octal file permissions reader to device
828 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
829 CHKPERM="/data/local/tmp/chkfileperm.sh"
830(
831cat <<'EOF'
Bruno Martins5bc28e22022-02-08 19:35:40 +0000832#!/system/bin/sh
Michael Bestas3952f6c2016-08-26 01:12:08 +0300833FILE=$@
834if [ -e $FILE ]; then
835 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
836fi
837EOF
838) > $OUT/.chkfileperm.sh
839 echo "Pushing file permissions checker to device"
840 adb push $OUT/.chkfileperm.sh $CHKPERM
841 adb shell chmod 755 $CHKPERM
842 rm -f $OUT/.chkfileperm.sh
843 fi
844
Sam Mortimerc3865952019-10-12 02:14:13 -0700845 RELOUT=$(echo $OUT | sed "s#^${ANDROID_BUILD_TOP}/##")
846
Michael Bestas3952f6c2016-08-26 01:12:08 +0300847 stop_n_start=false
Sam Mortimerc3865952019-10-12 02:14:13 -0700848 for TARGET in $(echo $LOC | tr " " "\n" | sed "s#.*${RELOUT}##" | sort | uniq); do
Roman Birgd51094c2018-03-28 09:47:30 -0700849 # 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 +0200850 case $TARGET in
Roman Birgd51094c2018-03-28 09:47:30 -0700851 /system/*|/data/*|/odm/*|/oem/*|/product/*|/product_services/*|/vendor/*)
Adrian DCa8e06d32018-06-17 00:15:00 +0200852 # Get out file from target (i.e. /system/bin/adb)
853 FILE=$OUT$TARGET
Michael Bestas3952f6c2016-08-26 01:12:08 +0300854 ;;
855 *) continue ;;
856 esac
857
858 case $TARGET in
859 /data/*)
860 # fs_config only sets permissions and se labels for files pushed to /system
861 if [ -n "$CHKPERM" ]; then
862 OLDPERM=$(adb shell $CHKPERM $TARGET)
863 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
864 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
865 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
866 fi
867 echo "Pushing: $TARGET"
868 adb push $FILE $TARGET
869 if [ -n "$OLDPERM" ]; then
870 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
871 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
872 adb shell chmod "$OLDPERM" $TARGET
873 else
874 echo "$TARGET did not exist previously, you should set file permissions manually"
875 fi
876 adb shell restorecon "$TARGET"
877 ;;
Michael Wec0363e2020-06-17 17:37:09 +0200878 */SystemUI.apk|*/framework/*)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300879 # Only need to stop services once
880 if ! $stop_n_start; then
881 adb shell stop
882 stop_n_start=true
883 fi
884 echo "Pushing: $TARGET"
885 adb push $FILE $TARGET
886 ;;
887 *)
888 echo "Pushing: $TARGET"
889 adb push $FILE $TARGET
890 ;;
891 esac
892 done
893 if [ -n "$CHKPERM" ]; then
894 adb shell rm $CHKPERM
895 fi
896 if $stop_n_start; then
897 adb shell start
898 fi
899 rm -f $OUT/.log
900 return 0
901 else
Jackeagled6811aa2019-09-24 08:26:40 +0200902 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300903 fi
904}
905
906alias mmp='dopush mm'
907alias mmmp='dopush mmm'
908alias mmap='dopush mma'
Zhao Wei Liew64fc5ae2016-12-10 16:48:27 +0800909alias mmmap='dopush mmma'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300910alias mkap='dopush mka'
911alias cmkap='dopush cmka'
912
913function repopick() {
914 T=$(gettop)
Jackeagled6811aa2019-09-24 08:26:40 +0200915 $T/vendor/bliss/build/tools/repopick.py $@
Michael Bestas3952f6c2016-08-26 01:12:08 +0300916}
917
Michael Bestas656f7e52022-06-09 18:50:47 +0300918function sort-blobs-list() {
919 T=$(gettop)
920 $T/tools/extract-utils/sort-blobs-list.py $@
921}
922
Michael Bestas3952f6c2016-08-26 01:12:08 +0300923function fixup_common_out_dir() {
924 common_out_dir=$(get_build_var OUT_DIR)/target/common
925 target_device=$(get_build_var TARGET_DEVICE)
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700926 common_target_out=common-${target_device}
Jackeagle305db7c2020-01-23 10:35:22 +0100927 if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300928 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
929 mv ${common_out_dir} ${common_out_dir}-${target_device}
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700930 ln -s ${common_target_out} ${common_out_dir}
Michael Bestas3952f6c2016-08-26 01:12:08 +0300931 else
932 [ -L ${common_out_dir} ] && rm ${common_out_dir}
933 mkdir -p ${common_out_dir}-${target_device}
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700934 ln -s ${common_target_out} ${common_out_dir}
Michael Bestas3952f6c2016-08-26 01:12:08 +0300935 fi
936 else
937 [ -L ${common_out_dir} ] && rm ${common_out_dir}
938 mkdir -p ${common_out_dir}
939 fi
940}
Jackeagle305db7c2020-01-23 10:35:22 +0100941
942function blissify()
943{
Jon West6f429fa2021-04-24 18:09:38 -0400944 abt="$ANDROID_BUILD_TOP"
945 cd $abt
946 clean="n"
947 deviceclean="n"
948 export BLISS_BUILD_VARIANT=vanilla
949 while test $# -gt 0
950 do
951 case $1 in
952
953 # Normal option processing
954 -h | --help)
955 echo "Usage: $0 options deviceCodename "
956 echo "options: -h | --help: Shows this dialog"
957 echo " -c | --clean: Clean up before running the build"
958 echo " -d | --devclean: Clean up device tree before running the build"
959 echo " -v | --vanilla: Build with no added app store solution **default option** "
Jis G Jacob8114f942023-04-23 05:14:43 -0400960 echo " -g | --gapps: Build with Minimal Google Play Services added"
961 echo " -p | --pixelgapps: Build with Google Pixel Gapps added"
Jon West6f429fa2021-04-24 18:09:38 -0400962 echo " -f | --fossa: build with FOSS (arm64-v8a) app store solutions added"
963 echo " -F | --fossx: build with FOSS (x86_64) app store solutions added"
Jackeagle5256b752023-08-03 14:14:46 -0400964 echo " -m | --microg: Build with MicroG added"
Jon West6f429fa2021-04-24 18:09:38 -0400965 echo ""
966 echo "deviceCodename: "
967 echo "your device codename, without the 'bliss_' in front"
968 echo ""
969 ;;
970 -c | --clean)
971 clean="y";
972 echo "Cleaning build and device tree selected."
973 ;;
974 -d | --devclean)
975 deviceclean="y";
976 echo "Cleaning device tree selected."
977 ;;
978 -v | --vanilla)
979 echo "Building as stock (no gapps) **DEFAULT**"
980 export BLISS_BUILD_VARIANT=vanilla
981 ;;
982 -g | --gapps)
Jis G Jacob8114f942023-04-23 05:14:43 -0400983 echo "Building with Minimal Gapps"
Jon West6f429fa2021-04-24 18:09:38 -0400984 export BLISS_BUILD_VARIANT=gapps
985 ;;
Jis G Jacob8114f942023-04-23 05:14:43 -0400986 -p | --pixelgapps)
987 echo "Building with Pixel Gapps"
988 export BLISS_BUILD_VARIANT=pixelgapps
989 ;;
Jon West6f429fa2021-04-24 18:09:38 -0400990 -f | --fossa)
991 echo "Building with FOSS apps for arm64-v8a support"
992 export BLISS_BUILD_VARIANT=foss
993 cd vendor/foss
994 bash update.sh 2
995 cd $abt
996 ;;
997 -F | --fossx)
998 echo "Building with FOSS apps for x86_64 support"
999 export BLISS_BUILD_VARIANT=foss
1000 cd vendor/foss
1001 bash update.sh 1
1002 cd $abt
1003 ;;
Jackeagle5256b752023-08-03 14:14:46 -04001004 -m | --microg)
1005 echo "Building with MicroG"
1006 export BLISS_BUILD_VARIANT=microg
1007 ;;
Jon West68fe7e52021-06-02 15:24:20 -04001008 -u | --userdebug)
1009 echo "Building userdebug variant"
1010 TARGET_BUILD_VARIANT=userdebug
1011 ;;
1012 -U | --user)
1013 echo "Building user variant"
1014 TARGET_BUILD_VARIANT=user
1015 ;;
1016 -e | --eng)
1017 echo "Building eng variant"
1018 TARGET_BUILD_VARIANT=eng
1019 ;;
1020
Jon West6f429fa2021-04-24 18:09:38 -04001021
1022 # ...
1023
1024 # Special cases
1025 --)
1026 echo "Please use --help to verify correct usage"
1027 break
1028 ;;
1029 --*)
1030 # error unknown (long) option $1
1031 echo "Please use --help to verify correct usage"
1032 break
1033 ;;
1034 -?)
1035 echo "Please use --help to verify correct usage"
1036 # error unknown (short) option $1
1037 break
1038 ;;
1039
1040 # FUN STUFF HERE:
1041 # Split apart combined short options
1042 -*)
1043 split=$1
1044 shift
1045 set -- $(echo "$split" | cut -c 2- | sed 's/./-& /g') "$@"
1046 continue
1047 ;;
1048
1049 # Done with options
1050 *)
1051 break
1052 ;;
1053 esac
1054
1055 # for testing purposes:
1056 shift
1057 done
Jon West6f429fa2021-04-24 18:09:38 -04001058 if [ "$1" == "" ]; then
1059 echo "No device name specified. Please use --help to verify correct usage"
1060 return 0
1061 fi
Jackeagle911602f2021-12-06 05:17:55 +01001062
Jon West68fe7e52021-06-02 15:24:20 -04001063 # Breakfast extension
1064 if [ $TARGET_BUILD_VARIANT == "user" ];then
1065 breakfast $* user
1066 elif [ $TARGET_BUILD_VARIANT == "eng" ];then
1067 breakfast $* eng
1068 else
1069 breakfast $*
1070 fi
Jackeagled52fd812021-09-10 23:21:00 -04001071
1072 if [ $clean == "y" ];then
1073 echo "Cleaning up a bit"
1074 make clean && make clobber
1075 fi
1076
1077 if [ $deviceclean == "y" ];then
1078 echo "Doing some device cleanup"
1079 make deviceclean
1080 fi
1081
Jackeagle305db7c2020-01-23 10:35:22 +01001082 if [ $? -eq 0 ]; then
1083 mka blissify
1084 else
Jon West6f429fa2021-04-24 18:09:38 -04001085 echo "No such item in brunch menu. Try 'breakfast' or verify your product is added to AndroidProducts.mk"
Jackeagle305db7c2020-01-23 10:35:22 +01001086 return 1
1087 fi
1088 return $?
1089}
Danny Line0ece602021-11-12 11:25:02 +00001090
1091# Override host metadata to make builds more reproducible and avoid leaking info
1092export BUILD_USERNAME=nobody
1093export BUILD_HOSTNAME=android-build