blob: 973f530319293af3860a9d28e03f2964bf965bc5 [file] [log] [blame]
Jackeaglecf6f4de2019-09-24 04:07:22 -04001function __print_bliss_functions_help() {
Michael Bestas3952f6c2016-08-26 01:12:08 +03002cat <<EOF
Jackeaglecf6f4de2019-09-24 04:07:22 -04003Additional Bliss 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.
Jackeaglecf6f4de2019-09-24 04:07:22 -04008- 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.
Jackeaglecf6f4de2019-09-24 04:07:22 -040013- 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.
Jackeagle739e9ab2020-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
Luca Stefani076c27b2017-08-17 20:30:00 +020028function mk_timer()
29{
30 local start_time=$(date +"%s")
31 $@
32 local ret=$?
33 local end_time=$(date +"%s")
34 local tdiff=$(($end_time-$start_time))
35 local hours=$(($tdiff / 3600 ))
36 local mins=$((($tdiff % 3600) / 60))
37 local secs=$(($tdiff % 60))
38 local ncolors=$(tput colors 2>/dev/null)
39 echo
40 if [ $ret -eq 0 ] ; then
41 echo -n "#### make completed successfully "
42 else
43 echo -n "#### make failed to build some targets "
44 fi
45 if [ $hours -gt 0 ] ; then
46 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
47 elif [ $mins -gt 0 ] ; then
48 printf "(%02g:%02g (mm:ss))" $mins $secs
49 elif [ $secs -gt 0 ] ; then
50 printf "(%s seconds)" $secs
51 fi
52 echo " ####"
53 echo
54 return $ret
55}
56
Michael Bestas3952f6c2016-08-26 01:12:08 +030057function breakfast()
58{
59 target=$1
60 local variant=$2
Michael Bestas3952f6c2016-08-26 01:12:08 +030061
62 if [ $# -eq 0 ]; then
63 # No arguments, so let's have the full menu
64 lunch
65 else
66 echo "z$target" | grep -q "-"
67 if [ $? -eq 0 ]; then
68 # A buildtype was specified, assume a full device name
69 lunch $target
70 else
Jackeaglecf6f4de2019-09-24 04:07:22 -040071 # This is probably just the Bliss model name
Michael Bestas3952f6c2016-08-26 01:12:08 +030072 if [ -z "$variant" ]; then
73 variant="userdebug"
74 fi
Matt Mowered8c2482017-01-02 02:26:01 -060075
Jackeaglecf6f4de2019-09-24 04:07:22 -040076 lunch bliss_$target-$variant
Michael Bestas3952f6c2016-08-26 01:12:08 +030077 fi
78 fi
79 return $?
80}
81
82alias bib=breakfast
83
84function eat()
85{
86 if [ "$OUT" ] ; then
Jackeaglecf6f4de2019-09-24 04:07:22 -040087 ZIPPATH=`ls -tr "$OUT"/Bliss-*.zip | tail -1`
Michael Bestas3952f6c2016-08-26 01:12:08 +030088 if [ ! -f $ZIPPATH ] ; then
89 echo "Nothing to eat"
90 return 1
91 fi
92 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
Adrian DC6393a3f2018-06-16 19:56:43 +020093 if [ $(adb get-state) != device -a $(adb shell 'test -e /sbin/recovery 2> /dev/null; echo $?') != 0 ] ; then
Michael Bestas3952f6c2016-08-26 01:12:08 +030094 echo "No device is online. Waiting for one..."
95 echo "Please connect USB and/or enable USB debugging"
Adrian DC6393a3f2018-06-16 19:56:43 +020096 until [ $(adb get-state) = device -o $(adb shell 'test -e /sbin/recovery 2> /dev/null; echo $?') = 0 ];do
Michael Bestas3952f6c2016-08-26 01:12:08 +030097 sleep 1
98 done
99 echo "Device Found.."
100 fi
Jackeaglecf6f4de2019-09-24 04:07:22 -0400101 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD"); then
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800102 # if adbd isn't root we can't write to /cache/recovery/
103 adb root
104 sleep 1
105 adb wait-for-device
106 cat << EOF > /tmp/command
Michael Bestas3952f6c2016-08-26 01:12:08 +0300107--sideload_auto_reboot
108EOF
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800109 if adb push /tmp/command /cache/recovery/ ; then
110 echo "Rebooting into recovery for sideload installation"
111 adb reboot recovery
112 adb wait-for-sideload
113 adb sideload $ZIPPATH
114 fi
115 rm /tmp/command
116 else
Jackeaglecf6f4de2019-09-24 04:07:22 -0400117 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300118 fi
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800119 return $?
Michael Bestas3952f6c2016-08-26 01:12:08 +0300120 else
121 echo "Nothing to eat"
122 return 1
123 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300124}
125
126function omnom()
127{
128 brunch $*
129 eat
130}
131
132function cout()
133{
134 if [ "$OUT" ]; then
135 cd $OUT
136 else
137 echo "Couldn't locate out directory. Try setting OUT."
138 fi
139}
140
141function dddclient()
142{
143 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
144 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
145 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
146 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
147 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
148 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
149 local ARCH=$(get_build_var TARGET_ARCH)
150 local GDB
151 case "$ARCH" in
152 arm) GDB=arm-linux-androideabi-gdb;;
153 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
154 mips|mips64) GDB=mips64el-linux-android-gdb;;
155 x86) GDB=x86_64-linux-android-gdb;;
156 x86_64) GDB=x86_64-linux-android-gdb;;
157 *) echo "Unknown arch $ARCH"; return 1;;
158 esac
159
160 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
161 local EXE="$1"
162 if [ "$EXE" ] ; then
163 EXE=$1
164 if [[ $EXE =~ ^[^/].* ]] ; then
165 EXE="system/bin/"$EXE
166 fi
167 else
168 EXE="app_process"
169 fi
170
171 local PORT="$2"
172 if [ "$PORT" ] ; then
173 PORT=$2
174 else
175 PORT=":5039"
176 fi
177
178 local PID="$3"
179 if [ "$PID" ] ; then
180 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
181 PID=`pid $3`
182 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
183 # that likely didn't work because of returning multiple processes
184 # try again, filtering by root processes (don't contain colon)
185 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
186 if [[ ! "$PID" =~ ^[0-9]+$ ]]
187 then
188 echo "Couldn't resolve '$3' to single PID"
189 return 1
190 else
191 echo ""
192 echo "WARNING: multiple processes matching '$3' observed, using root process"
193 echo ""
194 fi
195 fi
196 fi
197 adb forward "tcp$PORT" "tcp$PORT"
198 local USE64BIT="$(is64bit $PID)"
199 adb shell gdbserver$USE64BIT $PORT --attach $PID &
200 sleep 2
201 else
202 echo ""
203 echo "If you haven't done so already, do this first on the device:"
204 echo " gdbserver $PORT /system/bin/$EXE"
205 echo " or"
206 echo " gdbserver $PORT --attach <PID>"
207 echo ""
208 fi
209
210 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
211 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
212
213 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
214 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"
215 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
216 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
217 # Enable special debugging for ART processes.
218 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
219 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
220 fi
221 echo >>"$OUT_ROOT/gdbclient.cmds" ""
222
223 local WHICH_GDB=
224 # 64-bit exe found
225 if [ "$USE64BIT" != "" ] ; then
226 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
227 # 32-bit exe / 32-bit platform
228 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
229 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
230 # 32-bit exe / 64-bit platform
231 else
232 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
233 fi
234
235 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
236 else
237 echo "Unable to determine build system output dir."
238 fi
239}
240
Jackeaglecf6f4de2019-09-24 04:07:22 -0400241function blissremote()
Michael Bestas3952f6c2016-08-26 01:12:08 +0300242{
243 if ! git rev-parse --git-dir &> /dev/null
244 then
245 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
246 return 1
247 fi
Jackeaglecf6f4de2019-09-24 04:07:22 -0400248 git remote rm bliss 2> /dev/null
Michael Bestas9e6bde52018-04-02 19:54:45 +0300249 local REMOTE=$(git config --get remote.github.projectname)
Jackeaglecf6f4de2019-09-24 04:07:22 -0400250 local BLISS="true"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300251 if [ -z "$REMOTE" ]
Michael Bestasaf3532b2017-08-23 17:40:40 +0300252 then
Michael Bestas9e6bde52018-04-02 19:54:45 +0300253 REMOTE=$(git config --get remote.aosp.projectname)
Jackeaglecf6f4de2019-09-24 04:07:22 -0400254 BLISS="false"
Michael Bestasaf3532b2017-08-23 17:40:40 +0300255 fi
Michael Bestas9e6bde52018-04-02 19:54:45 +0300256 if [ -z "$REMOTE" ]
257 then
258 REMOTE=$(git config --get remote.caf.projectname)
Jackeaglecf6f4de2019-09-24 04:07:22 -0400259 BLISS="false"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300260 fi
261
Jackeaglecf6f4de2019-09-24 04:07:22 -0400262 if [ $BLISS = "false" ]
Michael Bestas9e6bde52018-04-02 19:54:45 +0300263 then
264 local PROJECT=$(echo $REMOTE | sed -e "s#platform/#android/#g; s#/#_#g")
Jackeaglecf6f4de2019-09-24 04:07:22 -0400265 local PFX="BlissRoms/"
Michael Bestas9e6bde52018-04-02 19:54:45 +0300266 else
267 local PROJECT=$REMOTE
268 fi
269
Jackeaglecf6f4de2019-09-24 04:07:22 -0400270 local BLISS_USER=$(git config --get review.review.lineageos.org.username)
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200271 if [ -z "$LINEAGE_USER" ]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300272 then
Michael Bestas9e6bde52018-04-02 19:54:45 +0300273 git remote add lineage ssh://review.lineageos.org:29418/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300274 else
Michael Bestas9e6bde52018-04-02 19:54:45 +0300275 git remote add lineage ssh://$LINEAGE_USER@review.lineageos.org:29418/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300276 fi
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200277 echo "Remote 'lineage' created"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300278}
279
280function aospremote()
281{
282 if ! git rev-parse --git-dir &> /dev/null
283 then
284 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
285 return 1
286 fi
287 git remote rm aosp 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300288 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400289 # Google moved the repo location in Oreo
290 if [ $PROJECT = "build/make" ]
291 then
292 PROJECT="build"
293 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300294 if (echo $PROJECT | grep -qv "^device")
295 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300296 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300297 fi
298 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
299 echo "Remote 'aosp' created"
300}
301
302function cafremote()
303{
304 if ! git rev-parse --git-dir &> /dev/null
305 then
306 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
307 return 1
308 fi
309 git remote rm caf 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300310 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400311 # Google moved the repo location in Oreo
312 if [ $PROJECT = "build/make" ]
313 then
314 PROJECT="build"
315 fi
Rashed Abdel-Tawabb52c7082017-12-24 22:40:31 +0200316 if [[ $PROJECT =~ "qcom/opensource" ]];
317 then
318 PROJECT=$(echo $PROJECT | sed -e "s#qcom\/opensource#qcom-opensource#")
319 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300320 if (echo $PROJECT | grep -qv "^device")
321 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300322 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300323 fi
Zhao Wei Liewfb4b8c52017-01-08 09:03:01 +0800324 git remote add caf https://source.codeaurora.org/quic/la/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300325 echo "Remote 'caf' created"
326}
327
Michael Bestasa504aa42018-08-10 22:51:37 +0300328function githubremote()
329{
330 if ! git rev-parse --git-dir &> /dev/null
331 then
332 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
333 return 1
334 fi
335 git remote rm github 2> /dev/null
336 local REMOTE=$(git config --get remote.aosp.projectname)
337
338 if [ -z "$REMOTE" ]
339 then
340 REMOTE=$(git config --get remote.caf.projectname)
341 fi
342
343 local PROJECT=$(echo $REMOTE | sed -e "s#platform/#android/#g; s#/#_#g")
344
Jackeaglecf6f4de2019-09-24 04:07:22 -0400345 git remote add github https://github.com/BlissRoms/$PROJECT
Michael Bestasa504aa42018-08-10 22:51:37 +0300346 echo "Remote 'github' created"
347}
348
Michael Bestas3952f6c2016-08-26 01:12:08 +0300349function installboot()
350{
Alessandro Astone582cc922019-09-06 13:07:03 +0200351 if [ ! -e "$OUT/recovery/root/system/etc/recovery.fstab" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300352 then
353 echo "No recovery.fstab found. Build recovery first."
354 return 1
355 fi
356 if [ ! -e "$OUT/boot.img" ];
357 then
358 echo "No boot.img found. Run make bootimage first."
359 return 1
360 fi
Alessandro Astone582cc922019-09-06 13:07:03 +0200361 PARTITION=`grep "^\/boot" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300362 if [ -z "$PARTITION" ];
363 then
364 # Try for RECOVERY_FSTAB_VERSION = 2
Alessandro Astone582cc922019-09-06 13:07:03 +0200365 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $1'}`
366 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300367 if [ -z "$PARTITION" ];
368 then
369 echo "Unable to determine boot partition."
370 return 1
371 fi
372 fi
373 adb start-server
374 adb wait-for-online
375 adb root
376 sleep 1
377 adb wait-for-online shell mount /system 2>&1 > /dev/null
378 adb wait-for-online remount
Jackeaglecf6f4de2019-09-24 04:07:22 -0400379 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300380 then
381 adb push $OUT/boot.img /cache/
Ashwin Rameshb0ea62a2017-08-13 12:00:15 +0530382 if [ -e "$OUT/system/lib/modules/*" ];
383 then
384 for i in $OUT/system/lib/modules/*;
385 do
386 adb push $i /system/lib/modules/
387 done
388 adb shell chmod 644 /system/lib/modules/*
389 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300390 adb shell dd if=/cache/boot.img of=$PARTITION
Michael W2e203942018-01-14 18:46:02 +0100391 adb shell rm -rf /cache/boot.img
Michael Bestas3952f6c2016-08-26 01:12:08 +0300392 echo "Installation complete."
393 else
Jackeaglecf6f4de2019-09-24 04:07:22 -0400394 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300395 fi
396}
397
398function installrecovery()
399{
Alessandro Astone582cc922019-09-06 13:07:03 +0200400 if [ ! -e "$OUT/recovery/root/system/etc/recovery.fstab" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300401 then
402 echo "No recovery.fstab found. Build recovery first."
403 return 1
404 fi
405 if [ ! -e "$OUT/recovery.img" ];
406 then
407 echo "No recovery.img found. Run make recoveryimage first."
408 return 1
409 fi
Alessandro Astone582cc922019-09-06 13:07:03 +0200410 PARTITION=`grep "^\/recovery" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300411 if [ -z "$PARTITION" ];
412 then
413 # Try for RECOVERY_FSTAB_VERSION = 2
Alessandro Astone582cc922019-09-06 13:07:03 +0200414 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $1'}`
415 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/system/etc/recovery.fstab | awk {'print $3'}`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300416 if [ -z "$PARTITION" ];
417 then
418 echo "Unable to determine recovery partition."
419 return 1
420 fi
421 fi
422 adb start-server
423 adb wait-for-online
424 adb root
425 sleep 1
426 adb wait-for-online shell mount /system 2>&1 >> /dev/null
427 adb wait-for-online remount
Jackeaglecf6f4de2019-09-24 04:07:22 -0400428 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300429 then
430 adb push $OUT/recovery.img /cache/
431 adb shell dd if=/cache/recovery.img of=$PARTITION
Michael W2e203942018-01-14 18:46:02 +0100432 adb shell rm -rf /cache/recovery.img
Michael Bestas3952f6c2016-08-26 01:12:08 +0300433 echo "Installation complete."
434 else
Jackeaglecf6f4de2019-09-24 04:07:22 -0400435 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300436 fi
437}
438
439function makerecipe() {
440 if [ -z "$1" ]
441 then
442 echo "No branch name provided."
443 return 1
444 fi
445 cd android
446 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
447 git commit -a -m "$1"
448 cd ..
449
450 repo forall -c '
451
452 if [ "$REPO_REMOTE" = "github" ]
453 then
454 pwd
Jackeaglecf6f4de2019-09-24 04:07:22 -0400455 blissremote
456 git push bliss HEAD:refs/heads/'$1'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300457 fi
458 '
459}
460
Jackeaglecf6f4de2019-09-24 04:07:22 -0400461function blissgerrit() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300462 if [ "$(__detect_shell)" = "zsh" ]; then
463 # zsh does not define FUNCNAME, derive from funcstack
464 local FUNCNAME=$funcstack[1]
465 fi
466
467 if [ $# -eq 0 ]; then
468 $FUNCNAME help
469 return 1
470 fi
Dan Pasanen03447712016-12-19 11:22:55 -0600471 local user=`git config --get review.review.lineageos.org.username`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300472 local review=`git config --get remote.github.review`
473 local project=`git config --get remote.github.projectname`
474 local command=$1
475 shift
476 case $command in
477 help)
478 if [ $# -eq 0 ]; then
479 cat <<EOF
480Usage:
481 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
482
483Commands:
484 fetch Just fetch the change as FETCH_HEAD
485 help Show this help, or for a specific command
486 pull Pull a change into current branch
487 push Push HEAD or a local branch to Gerrit for a specific branch
488
489Any other Git commands that support refname would work as:
490 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
491
492See '$FUNCNAME help COMMAND' for more information on a specific command.
493
494Example:
495 $FUNCNAME checkout -b topic 1234/5
496works as:
497 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
498 && git checkout -b topic FETCH_HEAD
499will checkout a new branch 'topic' base on patch-set 5 of change 1234.
500Patch-set 1 will be fetched if omitted.
501EOF
502 return
503 fi
504 case $1 in
505 __cmg_*) echo "For internal use only." ;;
506 changes|for)
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200507 if [ "$FUNCNAME" = "lineagegerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300508 echo "'$FUNCNAME $1' is deprecated."
509 fi
510 ;;
511 help) $FUNCNAME help ;;
512 fetch|pull) cat <<EOF
513usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
514
515works as:
516 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
517 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
518
519Example:
520 $FUNCNAME $1 1234
521will $1 patch-set 1 of change 1234
522EOF
523 ;;
524 push) cat <<EOF
525usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
526
527works as:
528 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
529 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
530
531Example:
532 $FUNCNAME push fix6789:gingerbread
533will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
534HEAD will be pushed from local if omitted.
535EOF
536 ;;
537 *)
538 $FUNCNAME __cmg_err_not_supported $1 && return
539 cat <<EOF
540usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
541
542works as:
543 git fetch http://DOMAIN/p/PROJECT \\
544 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
545 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
546EOF
547 ;;
548 esac
549 ;;
550 __cmg_get_ref)
551 $FUNCNAME __cmg_err_no_arg $command $# && return 1
552 local change_id patchset_id hash
553 case $1 in
554 */*)
555 change_id=${1%%/*}
556 patchset_id=${1#*/}
557 ;;
558 *)
559 change_id=$1
560 patchset_id=1
561 ;;
562 esac
563 hash=$(($change_id % 100))
564 case $hash in
565 [0-9]) hash="0$hash" ;;
566 esac
567 echo "refs/changes/$hash/$change_id/$patchset_id"
568 ;;
569 fetch|pull)
570 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
571 $FUNCNAME __cmg_err_not_repo && return 1
572 local change=$1
573 shift
574 git $command $@ http://$review/p/$project \
575 $($FUNCNAME __cmg_get_ref $change) || return 1
576 ;;
577 push)
578 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
579 $FUNCNAME __cmg_err_not_repo && return 1
580 if [ -z "$user" ]; then
581 echo >&2 "Gerrit username not found."
582 return 1
583 fi
584 local local_branch remote_branch
585 case $1 in
586 *:*)
587 local_branch=${1%:*}
588 remote_branch=${1##*:}
589 ;;
590 *)
591 local_branch=HEAD
592 remote_branch=$1
593 ;;
594 esac
595 shift
596 git push $@ ssh://$user@$review:29418/$project \
597 $local_branch:refs/for/$remote_branch || return 1
598 ;;
599 changes|for)
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200600 if [ "$FUNCNAME" = "lineagegerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300601 echo >&2 "'$FUNCNAME $command' is deprecated."
602 fi
603 ;;
604 __cmg_err_no_arg)
605 if [ $# -lt 2 ]; then
606 echo >&2 "'$FUNCNAME $command' missing argument."
607 elif [ $2 -eq 0 ]; then
608 if [ -n "$3" ]; then
609 $FUNCNAME help $1
610 else
611 echo >&2 "'$FUNCNAME $1' missing argument."
612 fi
613 else
614 return 1
615 fi
616 ;;
617 __cmg_err_not_repo)
618 if [ -z "$review" -o -z "$project" ]; then
619 echo >&2 "Not currently in any reviewable repository."
620 else
621 return 1
622 fi
623 ;;
624 __cmg_err_not_supported)
625 $FUNCNAME __cmg_err_no_arg $command $# && return
626 case $1 in
627 #TODO: filter more git commands that don't use refname
628 init|add|rm|mv|status|clone|remote|bisect|config|stash)
629 echo >&2 "'$FUNCNAME $1' is not supported."
630 ;;
631 *) return 1 ;;
632 esac
633 ;;
634 #TODO: other special cases?
635 *)
636 $FUNCNAME __cmg_err_not_supported $command && return 1
637 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
638 $FUNCNAME __cmg_err_not_repo && return 1
639 local args="$@"
640 local change pre_args refs_arg post_args
641 case "$args" in
642 *--\ *)
643 pre_args=${args%%-- *}
644 post_args="-- ${args#*-- }"
645 ;;
646 *) pre_args="$args" ;;
647 esac
648 args=($pre_args)
649 pre_args=
650 if [ ${#args[@]} -gt 0 ]; then
651 change=${args[${#args[@]}-1]}
652 fi
653 if [ ${#args[@]} -gt 1 ]; then
654 pre_args=${args[0]}
655 for ((i=1; i<${#args[@]}-1; i++)); do
656 pre_args="$pre_args ${args[$i]}"
657 done
658 fi
659 while ((1)); do
660 case $change in
661 ""|--)
662 $FUNCNAME help $command
663 return 1
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 *^*)
678 if [ -z "$refs_arg" ]; then
679 refs_arg="^${change#*^}"
680 change=${change%%^*}
681 fi
682 ;;
683 *:*)
684 if [ -z "$refs_arg" ]; then
685 refs_arg=":${change#*:}"
686 change=${change%%:*}
687 fi
688 ;;
689 *) break ;;
690 esac
691 done
692 $FUNCNAME fetch $change \
693 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
694 || return 1
695 ;;
696 esac
697}
698
Jackeaglecf6f4de2019-09-24 04:07:22 -0400699function blissrebase() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300700 local repo=$1
701 local refs=$2
702 local pwd="$(pwd)"
703 local dir="$(gettop)/$repo"
704
705 if [ -z $repo ] || [ -z $refs ]; then
Dan Pasanen03447712016-12-19 11:22:55 -0600706 echo "LineageOS Gerrit Rebase Usage: "
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200707 echo " lineagerebase <path to project> <patch IDs on Gerrit>"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300708 echo " The patch IDs appear on the Gerrit commands that are offered."
709 echo " They consist on a series of numbers and slashes, after the text"
710 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
711 echo ""
712 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
713 echo ""
714 return
715 fi
716
717 if [ ! -d $dir ]; then
718 echo "Directory $dir doesn't exist in tree."
719 return
720 fi
721 cd $dir
722 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
723 echo "Starting branch..."
724 repo start tmprebase .
725 echo "Bringing it up to date..."
726 repo sync .
727 echo "Fetching change..."
Dan Pasanen03447712016-12-19 11:22:55 -0600728 git fetch "http://review.lineageos.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Michael Bestas3952f6c2016-08-26 01:12:08 +0300729 if [ "$?" != "0" ]; then
730 echo "Error cherry-picking. Not uploading!"
731 return
732 fi
733 echo "Uploading..."
734 repo upload .
735 echo "Cleaning up..."
736 repo abandon tmprebase .
737 cd $pwd
738}
739
740function mka() {
Luca Stefani085af722017-08-17 20:34:44 +0200741 m -j "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300742}
743
744function cmka() {
745 if [ ! -z "$1" ]; then
746 for i in "$@"; do
747 case $i in
748 bacon|otapackage|systemimage)
749 mka installclean
750 mka $i
751 ;;
752 *)
753 mka clean-$i
754 mka $i
755 ;;
756 esac
757 done
758 else
759 mka clean
760 mka
761 fi
762}
763
Michael Bestas3952f6c2016-08-26 01:12:08 +0300764function repolastsync() {
765 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
766 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
767 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
768 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
769}
770
771function reposync() {
Luca Stefani085af722017-08-17 20:34:44 +0200772 repo sync -j 4 "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300773}
774
775function repodiff() {
776 if [ -z "$*" ]; then
777 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
778 return
779 fi
780 diffopts=$* repo forall -c \
781 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
782}
783
784# Return success if adb is up and not in recovery
785function _adb_connected {
786 {
787 if [[ "$(adb get-state)" == device &&
Adrian DC6393a3f2018-06-16 19:56:43 +0200788 "$(adb shell 'test -e /sbin/recovery; echo $?')" != 0 ]]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300789 then
790 return 0
791 fi
792 } 2>/dev/null
793
794 return 1
795};
796
797# Credit for color strip sed: http://goo.gl/BoIcm
798function dopush()
799{
800 local func=$1
801 shift
802
803 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
804 if ! _adb_connected; then
805 echo "No device is online. Waiting for one..."
806 echo "Please connect USB and/or enable USB debugging"
807 until _adb_connected; do
808 sleep 1
809 done
810 echo "Device Found."
811 fi
812
Jackeaglecf6f4de2019-09-24 04:07:22 -0400813 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD") || [ "$FORCE_PUSH" = "true" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300814 then
815 # retrieve IP and PORT info if we're using a TCP connection
Marc K2be9cac2016-10-20 10:27:35 +0200816 TCPIPPORT=$(adb devices \
817 | 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 +0300818 | head -1 | awk '{print $1}')
819 adb root &> /dev/null
820 sleep 0.3
821 if [ -n "$TCPIPPORT" ]
822 then
823 # adb root just killed our connection
824 # so reconnect...
825 adb connect "$TCPIPPORT"
826 fi
827 adb wait-for-device &> /dev/null
828 sleep 0.3
829 adb remount &> /dev/null
830
831 mkdir -p $OUT
832 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
833 ret=$?;
834 if [ $ret -ne 0 ]; then
835 rm -f $OUT/.log;return $ret
836 fi
837
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500838 is_gnu_sed=`sed --version | head -1 | grep -c GNU`
839
Michael Bestas3952f6c2016-08-26 01:12:08 +0300840 # Install: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500841 if [ $is_gnu_sed -gt 0 ]; then
Marc K97b035d2016-10-20 10:27:44 +0200842 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}\] +//' \
843 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300844 else
Marc K97b035d2016-10-20 10:27:44 +0200845 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}\] +//" \
846 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300847 fi
848
849 # Copy: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500850 if [ $is_gnu_sed -gt 0 ]; then
Marc K97b035d2016-10-20 10:27:44 +0200851 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}\] +//' \
852 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300853 else
Marc K97b035d2016-10-20 10:27:44 +0200854 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}\] +//' \
855 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300856 fi
857
858 # If any files are going to /data, push an octal file permissions reader to device
859 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
860 CHKPERM="/data/local/tmp/chkfileperm.sh"
861(
862cat <<'EOF'
863#!/system/xbin/sh
864FILE=$@
865if [ -e $FILE ]; then
866 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
867fi
868EOF
869) > $OUT/.chkfileperm.sh
870 echo "Pushing file permissions checker to device"
871 adb push $OUT/.chkfileperm.sh $CHKPERM
872 adb shell chmod 755 $CHKPERM
873 rm -f $OUT/.chkfileperm.sh
874 fi
875
876 stop_n_start=false
Adrian DCa8e06d32018-06-17 00:15:00 +0200877 for TARGET in $(echo $LOC | tr " " "\n" | sed "s#.*$OUT##" | sort | uniq); do
Michael Bestas3952f6c2016-08-26 01:12:08 +0300878 # Make sure file is in $OUT/system or $OUT/data
Adrian DCa8e06d32018-06-17 00:15:00 +0200879 case $TARGET in
880 /system/*|/data/*)
881 # Get out file from target (i.e. /system/bin/adb)
882 FILE=$OUT$TARGET
Michael Bestas3952f6c2016-08-26 01:12:08 +0300883 ;;
884 *) continue ;;
885 esac
886
887 case $TARGET in
888 /data/*)
889 # fs_config only sets permissions and se labels for files pushed to /system
890 if [ -n "$CHKPERM" ]; then
891 OLDPERM=$(adb shell $CHKPERM $TARGET)
892 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
893 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
894 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
895 fi
896 echo "Pushing: $TARGET"
897 adb push $FILE $TARGET
898 if [ -n "$OLDPERM" ]; then
899 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
900 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
901 adb shell chmod "$OLDPERM" $TARGET
902 else
903 echo "$TARGET did not exist previously, you should set file permissions manually"
904 fi
905 adb shell restorecon "$TARGET"
906 ;;
907 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
908 # Only need to stop services once
909 if ! $stop_n_start; then
910 adb shell stop
911 stop_n_start=true
912 fi
913 echo "Pushing: $TARGET"
914 adb push $FILE $TARGET
915 ;;
916 *)
917 echo "Pushing: $TARGET"
918 adb push $FILE $TARGET
919 ;;
920 esac
921 done
922 if [ -n "$CHKPERM" ]; then
923 adb shell rm $CHKPERM
924 fi
925 if $stop_n_start; then
926 adb shell start
927 fi
928 rm -f $OUT/.log
929 return 0
930 else
Jackeaglecf6f4de2019-09-24 04:07:22 -0400931 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300932 fi
933}
934
935alias mmp='dopush mm'
936alias mmmp='dopush mmm'
937alias mmap='dopush mma'
Zhao Wei Liew64fc5ae2016-12-10 16:48:27 +0800938alias mmmap='dopush mmma'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300939alias mkap='dopush mka'
940alias cmkap='dopush cmka'
941
942function repopick() {
943 T=$(gettop)
Jackeaglecf6f4de2019-09-24 04:07:22 -0400944 $T/vendor/bliss/build/tools/repopick.py $@
Michael Bestas3952f6c2016-08-26 01:12:08 +0300945}
946
947function fixup_common_out_dir() {
948 common_out_dir=$(get_build_var OUT_DIR)/target/common
949 target_device=$(get_build_var TARGET_DEVICE)
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700950 common_target_out=common-${target_device}
Jackeaglecf6f4de2019-09-24 04:07:22 -0400951 if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300952 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
953 mv ${common_out_dir} ${common_out_dir}-${target_device}
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700954 ln -s ${common_target_out} ${common_out_dir}
Michael Bestas3952f6c2016-08-26 01:12:08 +0300955 else
956 [ -L ${common_out_dir} ] && rm ${common_out_dir}
957 mkdir -p ${common_out_dir}-${target_device}
Sam Mortimer55d6ec52019-09-10 11:40:34 -0700958 ln -s ${common_target_out} ${common_out_dir}
Michael Bestas3952f6c2016-08-26 01:12:08 +0300959 fi
960 else
961 [ -L ${common_out_dir} ] && rm ${common_out_dir}
962 mkdir -p ${common_out_dir}
963 fi
964}
Jackeaglecf6f4de2019-09-24 04:07:22 -0400965
966# Android specific JACK args
967if [ -n "$JACK_SERVER_VM_ARGUMENTS" ] && [ -z "$ANDROID_JACK_VM_ARGS" ]; then
968 export ANDROID_JACK_VM_ARGS=$JACK_SERVER_VM_ARGUMENTS
969fi
Jackeagle739e9ab2020-01-23 10:35:22 +0100970
971function blissify()
972{
973 breakfast $*
974 if [ $? -eq 0 ]; then
975 mka blissify
976 else
977 echo "No such item in brunch menu. Try 'breakfast'"
978 return 1
979 fi
980 return $?
981}