blob: 3ca2af3e050d61b2bf2b50e4dae085538e4175ba [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.
21- installboot: Installs a boot.img to the connected device.
22- installrecovery: Installs a recovery.img to the connected device.
Jackeagle305db7c2020-01-23 10:35:22 +010023- blissify: Sets up build environment using breakfast(),
24 and then compiles using mka() against blissify target.
Michael Bestas3952f6c2016-08-26 01:12:08 +030025EOF
26}
27
Jackeagle911602f2021-12-06 05:17:55 +010028function checkofficial()
29{
30 codenames=$(curl -s 'https://api.blissroms.org/api/maintainers')
31 for row in $(echo "${codenames}" | jq -r '.[] | @base64'); do
32 _jq() {
33 echo ${row} | base64 --decode | jq -r ${1}
34 }
35 if [ "$(_jq '.codename')" == "$1" ]; then
36 export BLISS_BUILDTYPE=OFFICIAL
37 break
38 else
39 export BLISS_BUILDTYPE=UNOFFICIAL
40 fi
41 done
42}
43
Luca Stefani076c27b2017-08-17 20:30:00 +020044function mk_timer()
45{
46 local start_time=$(date +"%s")
47 $@
48 local ret=$?
49 local end_time=$(date +"%s")
50 local tdiff=$(($end_time-$start_time))
51 local hours=$(($tdiff / 3600 ))
52 local mins=$((($tdiff % 3600) / 60))
53 local secs=$(($tdiff % 60))
54 local ncolors=$(tput colors 2>/dev/null)
55 echo
56 if [ $ret -eq 0 ] ; then
57 echo -n "#### make completed successfully "
58 else
59 echo -n "#### make failed to build some targets "
60 fi
61 if [ $hours -gt 0 ] ; then
62 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
63 elif [ $mins -gt 0 ] ; then
64 printf "(%02g:%02g (mm:ss))" $mins $secs
65 elif [ $secs -gt 0 ] ; then
66 printf "(%s seconds)" $secs
67 fi
68 echo " ####"
69 echo
70 return $ret
71}
72
Michael Bestas3952f6c2016-08-26 01:12:08 +030073function breakfast()
74{
75 target=$1
76 local variant=$2
Jackeagle911602f2021-12-06 05:17:55 +010077
78 checkofficial $target
Michael Bestas3952f6c2016-08-26 01:12:08 +030079 if [ $# -eq 0 ]; then
80 # No arguments, so let's have the full menu
81 lunch
82 else
83 echo "z$target" | grep -q "-"
84 if [ $? -eq 0 ]; then
85 # A buildtype was specified, assume a full device name
86 lunch $target
87 else
Jackeagled6811aa2019-09-24 08:26:40 +020088 # This is probably just the BlissRoms model name
Michael Bestas3952f6c2016-08-26 01:12:08 +030089 if [ -z "$variant" ]; then
90 variant="userdebug"
91 fi
Matt Mowered8c2482017-01-02 02:26:01 -060092
Jackeagled6811aa2019-09-24 08:26:40 +020093 lunch bliss_$target-$variant
Michael Bestas3952f6c2016-08-26 01:12:08 +030094 fi
95 fi
96 return $?
97}
98
99alias bib=breakfast
100
101function eat()
102{
103 if [ "$OUT" ] ; then
Jackeagled6811aa2019-09-24 08:26:40 +0200104 ZIPPATH=`ls -tr "$OUT"/Bliss-*.zip | tail -1`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300105 if [ ! -f $ZIPPATH ] ; then
106 echo "Nothing to eat"
107 return 1
108 fi
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200109 echo "Waiting for device..."
Luca Stefani3d548072020-03-11 12:24:26 +0100110 adb wait-for-device-recovery
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200111 echo "Found device"
Jackeagled6811aa2019-09-24 08:26:40 +0200112 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD"); then
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200113 echo "Rebooting to sideload for install"
114 adb reboot sideload-auto-reboot
115 adb wait-for-sideload
116 adb sideload $ZIPPATH
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800117 else
Jackeagled6811aa2019-09-24 08:26:40 +0200118 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300119 fi
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800120 return $?
Michael Bestas3952f6c2016-08-26 01:12:08 +0300121 else
122 echo "Nothing to eat"
123 return 1
124 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300125}
126
127function omnom()
128{
Jackeagle305db7c2020-01-23 10:35:22 +0100129 blissify $*
Michael Bestas3952f6c2016-08-26 01:12:08 +0300130 eat
131}
132
133function cout()
134{
135 if [ "$OUT" ]; then
136 cd $OUT
137 else
138 echo "Couldn't locate out directory. Try setting OUT."
139 fi
140}
141
142function dddclient()
143{
144 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
145 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
146 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
147 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
148 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
149 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
150 local ARCH=$(get_build_var TARGET_ARCH)
151 local GDB
152 case "$ARCH" in
153 arm) GDB=arm-linux-androideabi-gdb;;
154 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
155 mips|mips64) GDB=mips64el-linux-android-gdb;;
156 x86) GDB=x86_64-linux-android-gdb;;
157 x86_64) GDB=x86_64-linux-android-gdb;;
158 *) echo "Unknown arch $ARCH"; return 1;;
159 esac
160
161 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
162 local EXE="$1"
163 if [ "$EXE" ] ; then
164 EXE=$1
165 if [[ $EXE =~ ^[^/].* ]] ; then
166 EXE="system/bin/"$EXE
167 fi
168 else
169 EXE="app_process"
170 fi
171
172 local PORT="$2"
173 if [ "$PORT" ] ; then
174 PORT=$2
175 else
176 PORT=":5039"
177 fi
178
179 local PID="$3"
180 if [ "$PID" ] ; then
181 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
182 PID=`pid $3`
183 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
184 # that likely didn't work because of returning multiple processes
185 # try again, filtering by root processes (don't contain colon)
186 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
187 if [[ ! "$PID" =~ ^[0-9]+$ ]]
188 then
189 echo "Couldn't resolve '$3' to single PID"
190 return 1
191 else
192 echo ""
193 echo "WARNING: multiple processes matching '$3' observed, using root process"
194 echo ""
195 fi
196 fi
197 fi
198 adb forward "tcp$PORT" "tcp$PORT"
199 local USE64BIT="$(is64bit $PID)"
200 adb shell gdbserver$USE64BIT $PORT --attach $PID &
201 sleep 2
202 else
203 echo ""
204 echo "If you haven't done so already, do this first on the device:"
205 echo " gdbserver $PORT /system/bin/$EXE"
206 echo " or"
207 echo " gdbserver $PORT --attach <PID>"
208 echo ""
209 fi
210
211 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
212 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
213
214 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
215 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"
216 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
217 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
218 # Enable special debugging for ART processes.
219 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
220 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
221 fi
222 echo >>"$OUT_ROOT/gdbclient.cmds" ""
223
224 local WHICH_GDB=
225 # 64-bit exe found
226 if [ "$USE64BIT" != "" ] ; then
227 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
228 # 32-bit exe / 32-bit platform
229 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
230 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
231 # 32-bit exe / 64-bit platform
232 else
233 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
234 fi
235
236 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
237 else
238 echo "Unable to determine build system output dir."
239 fi
240}
241
Jackeagled6811aa2019-09-24 08:26:40 +0200242function blissremote()
Michael Bestas3952f6c2016-08-26 01:12:08 +0300243{
244 if ! git rev-parse --git-dir &> /dev/null
245 then
246 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
247 return 1
248 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200249 git remote rm bliss 2> /dev/null
Michael Bestas9e6bde52018-04-02 19:54:45 +0300250 local REMOTE=$(git config --get remote.github.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100251 local BLISS="true"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300252 if [ -z "$REMOTE" ]
Michael Bestasaf3532b2017-08-23 17:40:40 +0300253 then
Michael Bestas9e6bde52018-04-02 19:54:45 +0300254 REMOTE=$(git config --get remote.aosp.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100255 BLISS="false"
Michael Bestasaf3532b2017-08-23 17:40:40 +0300256 fi
Michael Bestas9e6bde52018-04-02 19:54:45 +0300257 if [ -z "$REMOTE" ]
258 then
259 REMOTE=$(git config --get remote.caf.projectname)
Jackeagle305db7c2020-01-23 10:35:22 +0100260 BLISS="false"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300261 fi
262
Jackeagle305db7c2020-01-23 10:35:22 +0100263 if [ $BLISS = "false" ]
Michael Bestas9e6bde52018-04-02 19:54:45 +0300264 then
265 local PROJECT=$(echo $REMOTE | sed -e "s#platform/#android/#g; s#/#_#g")
Jackeagle305db7c2020-01-23 10:35:22 +0100266 local PFX="BLISS/"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300267 else
268 local PROJECT=$REMOTE
269 fi
270
Jackeagle305db7c2020-01-23 10:35:22 +0100271 local BLISS_USER=$(git config --get review.review.blissroms.com.username)
272 if [ -z "$BLISS_USER" ]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300273 then
Jackeagled6811aa2019-09-24 08:26:40 +0200274 git remote add bliss ssh://review.blissroms.com:29418/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300275 else
Jackeagle305db7c2020-01-23 10:35:22 +0100276 git remote add bliss ssh://$BLISS_USER@review.blissroms.com:29418/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300277 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200278 echo "Remote 'bliss' created"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300279}
280
281function aospremote()
282{
283 if ! git rev-parse --git-dir &> /dev/null
284 then
285 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
286 return 1
287 fi
288 git remote rm aosp 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300289 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400290 # Google moved the repo location in Oreo
291 if [ $PROJECT = "build/make" ]
292 then
293 PROJECT="build"
294 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300295 if (echo $PROJECT | grep -qv "^device")
296 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300297 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300298 fi
299 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
300 echo "Remote 'aosp' created"
301}
302
303function cafremote()
304{
305 if ! git rev-parse --git-dir &> /dev/null
306 then
307 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
308 return 1
309 fi
310 git remote rm caf 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300311 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400312 # Google moved the repo location in Oreo
313 if [ $PROJECT = "build/make" ]
314 then
315 PROJECT="build"
316 fi
Rashed Abdel-Tawabb52c7082017-12-24 22:40:31 +0200317 if [[ $PROJECT =~ "qcom/opensource" ]];
318 then
319 PROJECT=$(echo $PROJECT | sed -e "s#qcom\/opensource#qcom-opensource#")
320 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300321 if (echo $PROJECT | grep -qv "^device")
322 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300323 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300324 fi
Zhao Wei Liewfb4b8c52017-01-08 09:03:01 +0800325 git remote add caf https://source.codeaurora.org/quic/la/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300326 echo "Remote 'caf' created"
327}
328
Michael Bestasa504aa42018-08-10 22:51:37 +0300329function githubremote()
330{
331 if ! git rev-parse --git-dir &> /dev/null
332 then
333 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
334 return 1
335 fi
336 git remote rm github 2> /dev/null
337 local REMOTE=$(git config --get remote.aosp.projectname)
338
339 if [ -z "$REMOTE" ]
340 then
341 REMOTE=$(git config --get remote.caf.projectname)
342 fi
343
344 local PROJECT=$(echo $REMOTE | sed -e "s#platform/#android/#g; s#/#_#g")
345
346 git remote add github https://github.com/LineageOS/$PROJECT
347 echo "Remote 'github' created"
348}
349
Michael Bestas3952f6c2016-08-26 01:12:08 +0300350function installboot()
351{
Alessandro Astonef8f48772019-09-06 13:07:03 +0200352 if [ ! -e "$OUT/recovery/root/system/etc/recovery.fstab" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300353 then
354 echo "No recovery.fstab found. Build recovery first."
355 return 1
356 fi
357 if [ ! -e "$OUT/boot.img" ];
358 then
359 echo "No boot.img found. Run make bootimage first."
360 return 1
361 fi
Alessandro Astonef8f48772019-09-06 13:07:03 +0200362 PARTITION=`grep "^\/boot" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300363 if [ -z "$PARTITION" ];
364 then
365 # Try for RECOVERY_FSTAB_VERSION = 2
Alessandro Astonef8f48772019-09-06 13:07:03 +0200366 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $1'}`
367 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300368 if [ -z "$PARTITION" ];
369 then
370 echo "Unable to determine boot partition."
371 return 1
372 fi
373 fi
Luca Stefani3d548072020-03-11 12:24:26 +0100374 adb wait-for-device-recovery
Michael Bestas3952f6c2016-08-26 01:12:08 +0300375 adb root
Luca Stefani3d548072020-03-11 12:24:26 +0100376 adb wait-for-device-recovery
Jackeagled6811aa2019-09-24 08:26:40 +0200377 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300378 then
379 adb push $OUT/boot.img /cache/
Michael Bestas3952f6c2016-08-26 01:12:08 +0300380 adb shell dd if=/cache/boot.img of=$PARTITION
Michael W2e203942018-01-14 18:46:02 +0100381 adb shell rm -rf /cache/boot.img
Michael Bestas3952f6c2016-08-26 01:12:08 +0300382 echo "Installation complete."
383 else
Jackeagled6811aa2019-09-24 08:26:40 +0200384 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300385 fi
386}
387
388function installrecovery()
389{
Alessandro Astonef8f48772019-09-06 13:07:03 +0200390 if [ ! -e "$OUT/recovery/root/system/etc/recovery.fstab" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300391 then
392 echo "No recovery.fstab found. Build recovery first."
393 return 1
394 fi
395 if [ ! -e "$OUT/recovery.img" ];
396 then
397 echo "No recovery.img found. Run make recoveryimage first."
398 return 1
399 fi
Alessandro Astonef8f48772019-09-06 13:07:03 +0200400 PARTITION=`grep "^\/recovery" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300401 if [ -z "$PARTITION" ];
402 then
403 # Try for RECOVERY_FSTAB_VERSION = 2
Alessandro Astonef8f48772019-09-06 13:07:03 +0200404 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $1'}`
405 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300406 if [ -z "$PARTITION" ];
407 then
408 echo "Unable to determine recovery partition."
409 return 1
410 fi
411 fi
Luca Stefani3d548072020-03-11 12:24:26 +0100412 adb wait-for-device-recovery
Michael Bestas3952f6c2016-08-26 01:12:08 +0300413 adb root
Luca Stefani3d548072020-03-11 12:24:26 +0100414 adb wait-for-device-recovery
Jackeagled6811aa2019-09-24 08:26:40 +0200415 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300416 then
417 adb push $OUT/recovery.img /cache/
418 adb shell dd if=/cache/recovery.img of=$PARTITION
Michael W2e203942018-01-14 18:46:02 +0100419 adb shell rm -rf /cache/recovery.img
Michael Bestas3952f6c2016-08-26 01:12:08 +0300420 echo "Installation complete."
421 else
Jackeagled6811aa2019-09-24 08:26:40 +0200422 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300423 fi
424}
425
426function makerecipe() {
427 if [ -z "$1" ]
428 then
429 echo "No branch name provided."
430 return 1
431 fi
432 cd android
433 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
434 git commit -a -m "$1"
435 cd ..
436
437 repo forall -c '
438
439 if [ "$REPO_REMOTE" = "github" ]
440 then
441 pwd
Jackeagled6811aa2019-09-24 08:26:40 +0200442 blissremote
443 git push bliss HEAD:refs/heads/'$1'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300444 fi
445 '
446}
447
Jackeagled6811aa2019-09-24 08:26:40 +0200448function blissgerrit() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300449 if [ "$(__detect_shell)" = "zsh" ]; then
450 # zsh does not define FUNCNAME, derive from funcstack
451 local FUNCNAME=$funcstack[1]
452 fi
453
454 if [ $# -eq 0 ]; then
455 $FUNCNAME help
456 return 1
457 fi
Jackeagled6811aa2019-09-24 08:26:40 +0200458 local user=`git config --get review.review.blissroms.com.username`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300459 local review=`git config --get remote.github.review`
460 local project=`git config --get remote.github.projectname`
461 local command=$1
462 shift
463 case $command in
464 help)
465 if [ $# -eq 0 ]; then
466 cat <<EOF
467Usage:
468 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
469
470Commands:
471 fetch Just fetch the change as FETCH_HEAD
472 help Show this help, or for a specific command
473 pull Pull a change into current branch
474 push Push HEAD or a local branch to Gerrit for a specific branch
475
476Any other Git commands that support refname would work as:
477 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
478
479See '$FUNCNAME help COMMAND' for more information on a specific command.
480
481Example:
482 $FUNCNAME checkout -b topic 1234/5
483works as:
484 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
485 && git checkout -b topic FETCH_HEAD
486will checkout a new branch 'topic' base on patch-set 5 of change 1234.
487Patch-set 1 will be fetched if omitted.
488EOF
489 return
490 fi
491 case $1 in
492 __cmg_*) echo "For internal use only." ;;
493 changes|for)
Jackeagled6811aa2019-09-24 08:26:40 +0200494 if [ "$FUNCNAME" = "blissgerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300495 echo "'$FUNCNAME $1' is deprecated."
496 fi
497 ;;
498 help) $FUNCNAME help ;;
499 fetch|pull) cat <<EOF
500usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
501
502works as:
503 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
504 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
505
506Example:
507 $FUNCNAME $1 1234
508will $1 patch-set 1 of change 1234
509EOF
510 ;;
511 push) cat <<EOF
512usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
513
514works as:
515 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
516 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
517
518Example:
519 $FUNCNAME push fix6789:gingerbread
520will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
521HEAD will be pushed from local if omitted.
522EOF
523 ;;
524 *)
525 $FUNCNAME __cmg_err_not_supported $1 && return
526 cat <<EOF
527usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
528
529works as:
530 git fetch http://DOMAIN/p/PROJECT \\
531 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
532 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
533EOF
534 ;;
535 esac
536 ;;
537 __cmg_get_ref)
538 $FUNCNAME __cmg_err_no_arg $command $# && return 1
539 local change_id patchset_id hash
540 case $1 in
541 */*)
542 change_id=${1%%/*}
543 patchset_id=${1#*/}
544 ;;
545 *)
546 change_id=$1
547 patchset_id=1
548 ;;
549 esac
550 hash=$(($change_id % 100))
551 case $hash in
552 [0-9]) hash="0$hash" ;;
553 esac
554 echo "refs/changes/$hash/$change_id/$patchset_id"
555 ;;
556 fetch|pull)
557 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
558 $FUNCNAME __cmg_err_not_repo && return 1
559 local change=$1
560 shift
561 git $command $@ http://$review/p/$project \
562 $($FUNCNAME __cmg_get_ref $change) || return 1
563 ;;
564 push)
565 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
566 $FUNCNAME __cmg_err_not_repo && return 1
567 if [ -z "$user" ]; then
568 echo >&2 "Gerrit username not found."
569 return 1
570 fi
571 local local_branch remote_branch
572 case $1 in
573 *:*)
574 local_branch=${1%:*}
575 remote_branch=${1##*:}
576 ;;
577 *)
578 local_branch=HEAD
579 remote_branch=$1
580 ;;
581 esac
582 shift
583 git push $@ ssh://$user@$review:29418/$project \
584 $local_branch:refs/for/$remote_branch || return 1
585 ;;
586 changes|for)
Jackeagled6811aa2019-09-24 08:26:40 +0200587 if [ "$FUNCNAME" = "blissgerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300588 echo >&2 "'$FUNCNAME $command' is deprecated."
589 fi
590 ;;
591 __cmg_err_no_arg)
592 if [ $# -lt 2 ]; then
593 echo >&2 "'$FUNCNAME $command' missing argument."
594 elif [ $2 -eq 0 ]; then
595 if [ -n "$3" ]; then
596 $FUNCNAME help $1
597 else
598 echo >&2 "'$FUNCNAME $1' missing argument."
599 fi
600 else
601 return 1
602 fi
603 ;;
604 __cmg_err_not_repo)
605 if [ -z "$review" -o -z "$project" ]; then
606 echo >&2 "Not currently in any reviewable repository."
607 else
608 return 1
609 fi
610 ;;
611 __cmg_err_not_supported)
612 $FUNCNAME __cmg_err_no_arg $command $# && return
613 case $1 in
614 #TODO: filter more git commands that don't use refname
615 init|add|rm|mv|status|clone|remote|bisect|config|stash)
616 echo >&2 "'$FUNCNAME $1' is not supported."
617 ;;
618 *) return 1 ;;
619 esac
620 ;;
621 #TODO: other special cases?
622 *)
623 $FUNCNAME __cmg_err_not_supported $command && return 1
624 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
625 $FUNCNAME __cmg_err_not_repo && return 1
626 local args="$@"
627 local change pre_args refs_arg post_args
628 case "$args" in
629 *--\ *)
630 pre_args=${args%%-- *}
631 post_args="-- ${args#*-- }"
632 ;;
633 *) pre_args="$args" ;;
634 esac
635 args=($pre_args)
636 pre_args=
637 if [ ${#args[@]} -gt 0 ]; then
638 change=${args[${#args[@]}-1]}
639 fi
640 if [ ${#args[@]} -gt 1 ]; then
641 pre_args=${args[0]}
642 for ((i=1; i<${#args[@]}-1; i++)); do
643 pre_args="$pre_args ${args[$i]}"
644 done
645 fi
646 while ((1)); do
647 case $change in
648 ""|--)
649 $FUNCNAME help $command
650 return 1
651 ;;
652 *@*)
653 if [ -z "$refs_arg" ]; then
654 refs_arg="@${change#*@}"
655 change=${change%%@*}
656 fi
657 ;;
658 *~*)
659 if [ -z "$refs_arg" ]; then
660 refs_arg="~${change#*~}"
661 change=${change%%~*}
662 fi
663 ;;
664 *^*)
665 if [ -z "$refs_arg" ]; then
666 refs_arg="^${change#*^}"
667 change=${change%%^*}
668 fi
669 ;;
670 *:*)
671 if [ -z "$refs_arg" ]; then
672 refs_arg=":${change#*:}"
673 change=${change%%:*}
674 fi
675 ;;
676 *) break ;;
677 esac
678 done
679 $FUNCNAME fetch $change \
680 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
681 || return 1
682 ;;
683 esac
684}
685
Jackeagled6811aa2019-09-24 08:26:40 +0200686function blissrebase() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300687 local repo=$1
688 local refs=$2
689 local pwd="$(pwd)"
690 local dir="$(gettop)/$repo"
691
692 if [ -z $repo ] || [ -z $refs ]; then
Dan Pasanen03447712016-12-19 11:22:55 -0600693 echo "LineageOS Gerrit Rebase Usage: "
Jackeagled6811aa2019-09-24 08:26:40 +0200694 echo " blissrebase <path to project> <patch IDs on Gerrit>"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300695 echo " The patch IDs appear on the Gerrit commands that are offered."
696 echo " They consist on a series of numbers and slashes, after the text"
697 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
698 echo ""
699 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
700 echo ""
701 return
702 fi
703
704 if [ ! -d $dir ]; then
705 echo "Directory $dir doesn't exist in tree."
706 return
707 fi
708 cd $dir
709 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
710 echo "Starting branch..."
711 repo start tmprebase .
712 echo "Bringing it up to date..."
713 repo sync .
714 echo "Fetching change..."
Jackeagled6811aa2019-09-24 08:26:40 +0200715 git fetch "https://review.blissroms.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Michael Bestas3952f6c2016-08-26 01:12:08 +0300716 if [ "$?" != "0" ]; then
717 echo "Error cherry-picking. Not uploading!"
718 return
719 fi
720 echo "Uploading..."
721 repo upload .
722 echo "Cleaning up..."
723 repo abandon tmprebase .
724 cd $pwd
725}
726
727function mka() {
Luca Stefani085af722017-08-17 20:34:44 +0200728 m -j "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300729}
730
731function cmka() {
732 if [ ! -z "$1" ]; then
733 for i in "$@"; do
734 case $i in
735 bacon|otapackage|systemimage)
736 mka installclean
737 mka $i
738 ;;
739 *)
740 mka clean-$i
741 mka $i
742 ;;
743 esac
744 done
745 else
746 mka clean
747 mka
748 fi
749}
750
Michael Bestas3952f6c2016-08-26 01:12:08 +0300751function repolastsync() {
752 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
753 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
754 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
755 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
756}
757
758function reposync() {
Luca Stefani085af722017-08-17 20:34:44 +0200759 repo sync -j 4 "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300760}
761
762function repodiff() {
763 if [ -z "$*" ]; then
764 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
765 return
766 fi
767 diffopts=$* repo forall -c \
768 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
769}
770
771# Return success if adb is up and not in recovery
772function _adb_connected {
773 {
Alessandro Astonecdf9ae82019-09-28 16:53:08 +0200774 if [[ "$(adb get-state)" == device ]]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300775 then
776 return 0
777 fi
778 } 2>/dev/null
779
780 return 1
781};
782
783# Credit for color strip sed: http://goo.gl/BoIcm
784function dopush()
785{
786 local func=$1
787 shift
788
789 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
790 if ! _adb_connected; then
791 echo "No device is online. Waiting for one..."
792 echo "Please connect USB and/or enable USB debugging"
793 until _adb_connected; do
794 sleep 1
795 done
796 echo "Device Found."
797 fi
798
Jackeagled6811aa2019-09-24 08:26:40 +0200799 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD") || [ "$FORCE_PUSH" = "true" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300800 then
801 # retrieve IP and PORT info if we're using a TCP connection
Marc K2be9cac2016-10-20 10:27:35 +0200802 TCPIPPORT=$(adb devices \
803 | 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 +0300804 | head -1 | awk '{print $1}')
805 adb root &> /dev/null
806 sleep 0.3
807 if [ -n "$TCPIPPORT" ]
808 then
809 # adb root just killed our connection
810 # so reconnect...
811 adb connect "$TCPIPPORT"
812 fi
813 adb wait-for-device &> /dev/null
Michael Bestas3952f6c2016-08-26 01:12:08 +0300814 adb remount &> /dev/null
815
816 mkdir -p $OUT
817 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
818 ret=$?;
819 if [ $ret -ne 0 ]; then
820 rm -f $OUT/.log;return $ret
821 fi
822
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500823 is_gnu_sed=`sed --version | head -1 | grep -c GNU`
824
Michael Bestas3952f6c2016-08-26 01:12:08 +0300825 # Install: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500826 if [ $is_gnu_sed -gt 0 ]; then
Marc K97b035d2016-10-20 10:27:44 +0200827 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}\] +//' \
828 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300829 else
Marc K97b035d2016-10-20 10:27:44 +0200830 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}\] +//" \
831 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300832 fi
833
834 # Copy: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500835 if [ $is_gnu_sed -gt 0 ]; then
Marc K97b035d2016-10-20 10:27:44 +0200836 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}\] +//' \
837 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300838 else
Marc K97b035d2016-10-20 10:27:44 +0200839 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}\] +//' \
840 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300841 fi
842
843 # If any files are going to /data, push an octal file permissions reader to device
844 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
845 CHKPERM="/data/local/tmp/chkfileperm.sh"
846(
847cat <<'EOF'
Bruno Martins5bc28e22022-02-08 19:35:40 +0000848#!/system/bin/sh
Michael Bestas3952f6c2016-08-26 01:12:08 +0300849FILE=$@
850if [ -e $FILE ]; then
851 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
852fi
853EOF
854) > $OUT/.chkfileperm.sh
855 echo "Pushing file permissions checker to device"
856 adb push $OUT/.chkfileperm.sh $CHKPERM
857 adb shell chmod 755 $CHKPERM
858 rm -f $OUT/.chkfileperm.sh
859 fi
860
Sam Mortimerc3865952019-10-12 02:14:13 -0700861 RELOUT=$(echo $OUT | sed "s#^${ANDROID_BUILD_TOP}/##")
862
Michael Bestas3952f6c2016-08-26 01:12:08 +0300863 stop_n_start=false
Sam Mortimerc3865952019-10-12 02:14:13 -0700864 for TARGET in $(echo $LOC | tr " " "\n" | sed "s#.*${RELOUT}##" | sort | uniq); do
Roman Birgd51094c2018-03-28 09:47:30 -0700865 # 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 +0200866 case $TARGET in
Roman Birgd51094c2018-03-28 09:47:30 -0700867 /system/*|/data/*|/odm/*|/oem/*|/product/*|/product_services/*|/vendor/*)
Adrian DCa8e06d32018-06-17 00:15:00 +0200868 # Get out file from target (i.e. /system/bin/adb)
869 FILE=$OUT$TARGET
Michael Bestas3952f6c2016-08-26 01:12:08 +0300870 ;;
871 *) continue ;;
872 esac
873
874 case $TARGET in
875 /data/*)
876 # fs_config only sets permissions and se labels for files pushed to /system
877 if [ -n "$CHKPERM" ]; then
878 OLDPERM=$(adb shell $CHKPERM $TARGET)
879 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
880 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
881 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
882 fi
883 echo "Pushing: $TARGET"
884 adb push $FILE $TARGET
885 if [ -n "$OLDPERM" ]; then
886 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
887 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
888 adb shell chmod "$OLDPERM" $TARGET
889 else
890 echo "$TARGET did not exist previously, you should set file permissions manually"
891 fi
892 adb shell restorecon "$TARGET"
893 ;;
Michael Wec0363e2020-06-17 17:37:09 +0200894 */SystemUI.apk|*/framework/*)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300895 # Only need to stop services once
896 if ! $stop_n_start; then
897 adb shell stop
898 stop_n_start=true
899 fi
900 echo "Pushing: $TARGET"
901 adb push $FILE $TARGET
902 ;;
903 *)
904 echo "Pushing: $TARGET"
905 adb push $FILE $TARGET
906 ;;
907 esac
908 done
909 if [ -n "$CHKPERM" ]; then
910 adb shell rm $CHKPERM
911 fi
912 if $stop_n_start; then
913 adb shell start
914 fi
915 rm -f $OUT/.log
916 return 0
917 else
Jackeagled6811aa2019-09-24 08:26:40 +0200918 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300919 fi
920}
921
922alias mmp='dopush mm'
923alias mmmp='dopush mmm'
924alias mmap='dopush mma'
Zhao Wei Liew64fc5ae2016-12-10 16:48:27 +0800925alias mmmap='dopush mmma'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300926alias mkap='dopush mka'
927alias cmkap='dopush cmka'
928
929function repopick() {
930 T=$(gettop)
Jackeagled6811aa2019-09-24 08:26:40 +0200931 $T/vendor/bliss/build/tools/repopick.py $@
Michael Bestas3952f6c2016-08-26 01:12:08 +0300932}
933
934function fixup_common_out_dir() {
935 common_out_dir=$(get_build_var OUT_DIR)/target/common
936 target_device=$(get_build_var TARGET_DEVICE)
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700937 common_target_out=common-${target_device}
Jackeagle305db7c2020-01-23 10:35:22 +0100938 if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300939 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
940 mv ${common_out_dir} ${common_out_dir}-${target_device}
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700941 ln -s ${common_target_out} ${common_out_dir}
Michael Bestas3952f6c2016-08-26 01:12:08 +0300942 else
943 [ -L ${common_out_dir} ] && rm ${common_out_dir}
944 mkdir -p ${common_out_dir}-${target_device}
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700945 ln -s ${common_target_out} ${common_out_dir}
Michael Bestas3952f6c2016-08-26 01:12:08 +0300946 fi
947 else
948 [ -L ${common_out_dir} ] && rm ${common_out_dir}
949 mkdir -p ${common_out_dir}
950 fi
951}
Jackeagle305db7c2020-01-23 10:35:22 +0100952
953function blissify()
954{
Jon West6f429fa2021-04-24 18:09:38 -0400955 abt="$ANDROID_BUILD_TOP"
956 cd $abt
957 clean="n"
958 deviceclean="n"
959 export BLISS_BUILD_VARIANT=vanilla
960 while test $# -gt 0
961 do
962 case $1 in
963
964 # Normal option processing
965 -h | --help)
966 echo "Usage: $0 options deviceCodename "
967 echo "options: -h | --help: Shows this dialog"
968 echo " -c | --clean: Clean up before running the build"
969 echo " -d | --devclean: Clean up device tree before running the build"
970 echo " -v | --vanilla: Build with no added app store solution **default option** "
971 echo " -g | --gapps: Build with Google Play Services added"
972 echo " -f | --fossa: build with FOSS (arm64-v8a) app store solutions added"
973 echo " -F | --fossx: build with FOSS (x86_64) app store solutions added"
974 echo ""
975 echo "deviceCodename: "
976 echo "your device codename, without the 'bliss_' in front"
977 echo ""
978 ;;
979 -c | --clean)
980 clean="y";
981 echo "Cleaning build and device tree selected."
982 ;;
983 -d | --devclean)
984 deviceclean="y";
985 echo "Cleaning device tree selected."
986 ;;
987 -v | --vanilla)
988 echo "Building as stock (no gapps) **DEFAULT**"
989 export BLISS_BUILD_VARIANT=vanilla
990 ;;
991 -g | --gapps)
992 echo "Building with gapps"
993 export BLISS_BUILD_VARIANT=gapps
994 ;;
995 -f | --fossa)
996 echo "Building with FOSS apps for arm64-v8a support"
997 export BLISS_BUILD_VARIANT=foss
998 cd vendor/foss
999 bash update.sh 2
1000 cd $abt
1001 ;;
1002 -F | --fossx)
1003 echo "Building with FOSS apps for x86_64 support"
1004 export BLISS_BUILD_VARIANT=foss
1005 cd vendor/foss
1006 bash update.sh 1
1007 cd $abt
1008 ;;
Jon West68fe7e52021-06-02 15:24:20 -04001009 -u | --userdebug)
1010 echo "Building userdebug variant"
1011 TARGET_BUILD_VARIANT=userdebug
1012 ;;
1013 -U | --user)
1014 echo "Building user variant"
1015 TARGET_BUILD_VARIANT=user
1016 ;;
1017 -e | --eng)
1018 echo "Building eng variant"
1019 TARGET_BUILD_VARIANT=eng
1020 ;;
1021
Jon West6f429fa2021-04-24 18:09:38 -04001022
1023 # ...
1024
1025 # Special cases
1026 --)
1027 echo "Please use --help to verify correct usage"
1028 break
1029 ;;
1030 --*)
1031 # error unknown (long) option $1
1032 echo "Please use --help to verify correct usage"
1033 break
1034 ;;
1035 -?)
1036 echo "Please use --help to verify correct usage"
1037 # error unknown (short) option $1
1038 break
1039 ;;
1040
1041 # FUN STUFF HERE:
1042 # Split apart combined short options
1043 -*)
1044 split=$1
1045 shift
1046 set -- $(echo "$split" | cut -c 2- | sed 's/./-& /g') "$@"
1047 continue
1048 ;;
1049
1050 # Done with options
1051 *)
1052 break
1053 ;;
1054 esac
1055
1056 # for testing purposes:
1057 shift
1058 done
Jon West6f429fa2021-04-24 18:09:38 -04001059 if [ "$1" == "" ]; then
1060 echo "No device name specified. Please use --help to verify correct usage"
1061 return 0
1062 fi
Jackeagle911602f2021-12-06 05:17:55 +01001063
1064 checkofficial $1
1065
Jon West68fe7e52021-06-02 15:24:20 -04001066 # Breakfast extension
1067 if [ $TARGET_BUILD_VARIANT == "user" ];then
1068 breakfast $* user
1069 elif [ $TARGET_BUILD_VARIANT == "eng" ];then
1070 breakfast $* eng
1071 else
1072 breakfast $*
1073 fi
Jackeagled52fd812021-09-10 23:21:00 -04001074
1075 if [ $clean == "y" ];then
1076 echo "Cleaning up a bit"
1077 make clean && make clobber
1078 fi
1079
1080 if [ $deviceclean == "y" ];then
1081 echo "Doing some device cleanup"
1082 make deviceclean
1083 fi
1084
Jackeagle305db7c2020-01-23 10:35:22 +01001085 if [ $? -eq 0 ]; then
1086 mka blissify
1087 else
Jon West6f429fa2021-04-24 18:09:38 -04001088 echo "No such item in brunch menu. Try 'breakfast' or verify your product is added to AndroidProducts.mk"
Jackeagle305db7c2020-01-23 10:35:22 +01001089 return 1
1090 fi
1091 return $?
1092}
Danny Line0ece602021-11-12 11:25:02 +00001093
1094# Override host metadata to make builds more reproducible and avoid leaking info
1095export BUILD_USERNAME=nobody
1096export BUILD_HOSTNAME=android-build