blob: 3adae2e4f1a88256938584eefbfe7799ac27953a [file] [log] [blame]
Michael Bestas3952f6c2016-08-26 01:12:08 +03001function __print_cm_functions_help() {
2cat <<EOF
Dan Pasanen03447712016-12-19 11:22:55 -06003Additional LineageOS 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.
8- mms: Short circuit builder. Quickly re-build the kernel, rootfs, boot and system images
9 without deep dependencies. Requires the full build to have run before.
Dan Pasanen03447712016-12-19 11:22:55 -060010- cmgerrit: A Git wrapper that fetches/pushes patch from/to LineageOS Gerrit Review.
Michael Bestas3952f6c2016-08-26 01:12:08 +030011- cmrebase: Rebase a Gerrit change and push it again.
Dan Pasanen03447712016-12-19 11:22:55 -060012- cmremote: Add git remote for LineageOS Gerrit Review.
Michael Bestas3952f6c2016-08-26 01:12:08 +030013- aospremote: Add git remote for matching AOSP repository.
14- cafremote: Add git remote for matching CodeAurora repository.
15- mka: Builds using SCHED_BATCH on all processors.
16- mkap: Builds the module(s) using mka and pushes them to the device.
17- cmka: Cleans and builds using mka.
18- repodiff: Diff 2 different branches or tags within the same repo
19- repolastsync: Prints date and time of last repo sync.
20- reposync: Parallel repo sync using ionice and SCHED_BATCH.
21- repopick: Utility to fetch changes from Gerrit.
22- installboot: Installs a boot.img to the connected device.
23- installrecovery: Installs a recovery.img to the connected device.
24EOF
25}
26
27function brunch()
28{
29 breakfast $*
30 if [ $? -eq 0 ]; then
31 mka bacon
32 else
33 echo "No such item in brunch menu. Try 'breakfast'"
34 return 1
35 fi
36 return $?
37}
38
39function breakfast()
40{
41 target=$1
42 local variant=$2
43 CM_DEVICES_ONLY="true"
44 unset LUNCH_MENU_CHOICES
45 add_lunch_combo full-eng
46 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
47 do
48 echo "including $f"
49 . $f
50 done
51 unset f
52
53 if [ $# -eq 0 ]; then
54 # No arguments, so let's have the full menu
55 lunch
56 else
57 echo "z$target" | grep -q "-"
58 if [ $? -eq 0 ]; then
59 # A buildtype was specified, assume a full device name
60 lunch $target
61 else
Simon Shields63ce74b2016-12-28 11:33:29 +110062 # This is probably just the Lineage model name
Michael Bestas3952f6c2016-08-26 01:12:08 +030063 if [ -z "$variant" ]; then
64 variant="userdebug"
65 fi
Matt Mowered8c2482017-01-02 02:26:01 -060066
67 if ! check_product lineage_$target && check_product cm_$target; then
Simon Shields63ce74b2016-12-28 11:33:29 +110068 echo "** Warning: '$target' is using CM-based makefiles. This will be deprecated in the next major release."
69 lunch cm_$target-$variant
Matt Mowered8c2482017-01-02 02:26:01 -060070 else
71 lunch lineage_$target-$variant
Simon Shields63ce74b2016-12-28 11:33:29 +110072 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +030073 fi
74 fi
75 return $?
76}
77
78alias bib=breakfast
79
80function eat()
81{
82 if [ "$OUT" ] ; then
Zhao Wei Liew321dde52017-01-01 15:24:38 +080083 MODVERSION=$(get_build_var LINEAGE_VERSION)
Dan Pasanen03447712016-12-19 11:22:55 -060084 ZIPFILE=lineage-$MODVERSION.zip
Michael Bestas3952f6c2016-08-26 01:12:08 +030085 ZIPPATH=$OUT/$ZIPFILE
86 if [ ! -f $ZIPPATH ] ; then
87 echo "Nothing to eat"
88 return 1
89 fi
90 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
91 if [ $(adb get-state) != device -a $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
92 echo "No device is online. Waiting for one..."
93 echo "Please connect USB and/or enable USB debugging"
94 until [ $(adb get-state) = device -o $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
95 sleep 1
96 done
97 echo "Device Found.."
98 fi
99 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
100 then
101 # if adbd isn't root we can't write to /cache/recovery/
102 adb root
103 sleep 1
104 adb wait-for-device
105 cat << EOF > /tmp/command
106--sideload_auto_reboot
107EOF
108 if adb push /tmp/command /cache/recovery/ ; then
109 echo "Rebooting into recovery for sideload installation"
110 adb reboot recovery
111 adb wait-for-sideload
112 adb sideload $ZIPPATH
113 fi
114 rm /tmp/command
115 else
116 echo "Nothing to eat"
117 return 1
118 fi
119 return $?
120 else
121 echo "The connected device does not appear to be $CM_BUILD, run away!"
122 fi
123}
124
125function omnom()
126{
127 brunch $*
128 eat
129}
130
131function cout()
132{
133 if [ "$OUT" ]; then
134 cd $OUT
135 else
136 echo "Couldn't locate out directory. Try setting OUT."
137 fi
138}
139
140function dddclient()
141{
142 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
143 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
144 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
145 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
146 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
147 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
148 local ARCH=$(get_build_var TARGET_ARCH)
149 local GDB
150 case "$ARCH" in
151 arm) GDB=arm-linux-androideabi-gdb;;
152 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
153 mips|mips64) GDB=mips64el-linux-android-gdb;;
154 x86) GDB=x86_64-linux-android-gdb;;
155 x86_64) GDB=x86_64-linux-android-gdb;;
156 *) echo "Unknown arch $ARCH"; return 1;;
157 esac
158
159 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
160 local EXE="$1"
161 if [ "$EXE" ] ; then
162 EXE=$1
163 if [[ $EXE =~ ^[^/].* ]] ; then
164 EXE="system/bin/"$EXE
165 fi
166 else
167 EXE="app_process"
168 fi
169
170 local PORT="$2"
171 if [ "$PORT" ] ; then
172 PORT=$2
173 else
174 PORT=":5039"
175 fi
176
177 local PID="$3"
178 if [ "$PID" ] ; then
179 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
180 PID=`pid $3`
181 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
182 # that likely didn't work because of returning multiple processes
183 # try again, filtering by root processes (don't contain colon)
184 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
185 if [[ ! "$PID" =~ ^[0-9]+$ ]]
186 then
187 echo "Couldn't resolve '$3' to single PID"
188 return 1
189 else
190 echo ""
191 echo "WARNING: multiple processes matching '$3' observed, using root process"
192 echo ""
193 fi
194 fi
195 fi
196 adb forward "tcp$PORT" "tcp$PORT"
197 local USE64BIT="$(is64bit $PID)"
198 adb shell gdbserver$USE64BIT $PORT --attach $PID &
199 sleep 2
200 else
201 echo ""
202 echo "If you haven't done so already, do this first on the device:"
203 echo " gdbserver $PORT /system/bin/$EXE"
204 echo " or"
205 echo " gdbserver $PORT --attach <PID>"
206 echo ""
207 fi
208
209 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
210 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
211
212 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
213 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"
214 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
215 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
216 # Enable special debugging for ART processes.
217 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
218 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
219 fi
220 echo >>"$OUT_ROOT/gdbclient.cmds" ""
221
222 local WHICH_GDB=
223 # 64-bit exe found
224 if [ "$USE64BIT" != "" ] ; then
225 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
226 # 32-bit exe / 32-bit platform
227 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
228 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
229 # 32-bit exe / 64-bit platform
230 else
231 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
232 fi
233
234 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
235 else
236 echo "Unable to determine build system output dir."
237 fi
238}
239
240function cmremote()
241{
242 if ! git rev-parse --git-dir &> /dev/null
243 then
244 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
245 return 1
246 fi
247 git remote rm cmremote 2> /dev/null
248 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Dan Pasanen03447712016-12-19 11:22:55 -0600249 CMUSER=$(git config --get review.review.lineageos.org.username)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300250 if [ -z "$CMUSER" ]
251 then
Dan Pasanen03447712016-12-19 11:22:55 -0600252 git remote add cmremote ssh://review.lineageos.org:29418/$GERRIT_REMOTE
Michael Bestas3952f6c2016-08-26 01:12:08 +0300253 else
Dan Pasanen03447712016-12-19 11:22:55 -0600254 git remote add cmremote ssh://$CMUSER@review.lineageos.org:29418/$GERRIT_REMOTE
Michael Bestas3952f6c2016-08-26 01:12:08 +0300255 fi
256 echo "Remote 'cmremote' created"
257}
258
259function aospremote()
260{
261 if ! git rev-parse --git-dir &> /dev/null
262 then
263 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
264 return 1
265 fi
266 git remote rm aosp 2> /dev/null
Michael Bestase724a1c2016-10-20 23:25:40 +0300267 PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Michael Bestas3952f6c2016-08-26 01:12:08 +0300268 if (echo $PROJECT | grep -qv "^device")
269 then
270 PFX="platform/"
271 fi
272 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
273 echo "Remote 'aosp' created"
274}
275
276function cafremote()
277{
278 if ! git rev-parse --git-dir &> /dev/null
279 then
280 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
281 return 1
282 fi
283 git remote rm caf 2> /dev/null
Michael Bestase724a1c2016-10-20 23:25:40 +0300284 PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Michael Bestas3952f6c2016-08-26 01:12:08 +0300285 if (echo $PROJECT | grep -qv "^device")
286 then
287 PFX="platform/"
288 fi
289 git remote add caf git://codeaurora.org/$PFX$PROJECT
290 echo "Remote 'caf' created"
291}
292
293function installboot()
294{
295 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
296 then
297 echo "No recovery.fstab found. Build recovery first."
298 return 1
299 fi
300 if [ ! -e "$OUT/boot.img" ];
301 then
302 echo "No boot.img found. Run make bootimage first."
303 return 1
304 fi
305 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
306 if [ -z "$PARTITION" ];
307 then
308 # Try for RECOVERY_FSTAB_VERSION = 2
309 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
310 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
311 if [ -z "$PARTITION" ];
312 then
313 echo "Unable to determine boot partition."
314 return 1
315 fi
316 fi
317 adb start-server
318 adb wait-for-online
319 adb root
320 sleep 1
321 adb wait-for-online shell mount /system 2>&1 > /dev/null
322 adb wait-for-online remount
323 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
324 then
325 adb push $OUT/boot.img /cache/
326 for i in $OUT/system/lib/modules/*;
327 do
328 adb push $i /system/lib/modules/
329 done
330 adb shell dd if=/cache/boot.img of=$PARTITION
331 adb shell chmod 644 /system/lib/modules/*
332 echo "Installation complete."
333 else
334 echo "The connected device does not appear to be $CM_BUILD, run away!"
335 fi
336}
337
338function installrecovery()
339{
340 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
341 then
342 echo "No recovery.fstab found. Build recovery first."
343 return 1
344 fi
345 if [ ! -e "$OUT/recovery.img" ];
346 then
347 echo "No recovery.img found. Run make recoveryimage first."
348 return 1
349 fi
350 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
351 if [ -z "$PARTITION" ];
352 then
353 # Try for RECOVERY_FSTAB_VERSION = 2
354 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
355 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
356 if [ -z "$PARTITION" ];
357 then
358 echo "Unable to determine recovery partition."
359 return 1
360 fi
361 fi
362 adb start-server
363 adb wait-for-online
364 adb root
365 sleep 1
366 adb wait-for-online shell mount /system 2>&1 >> /dev/null
367 adb wait-for-online remount
368 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
369 then
370 adb push $OUT/recovery.img /cache/
371 adb shell dd if=/cache/recovery.img of=$PARTITION
372 echo "Installation complete."
373 else
374 echo "The connected device does not appear to be $CM_BUILD, run away!"
375 fi
376}
377
378function makerecipe() {
379 if [ -z "$1" ]
380 then
381 echo "No branch name provided."
382 return 1
383 fi
384 cd android
385 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
386 git commit -a -m "$1"
387 cd ..
388
389 repo forall -c '
390
391 if [ "$REPO_REMOTE" = "github" ]
392 then
393 pwd
394 cmremote
395 git push cmremote HEAD:refs/heads/'$1'
396 fi
397 '
398}
399
400function cmgerrit() {
401 if [ "$(__detect_shell)" = "zsh" ]; then
402 # zsh does not define FUNCNAME, derive from funcstack
403 local FUNCNAME=$funcstack[1]
404 fi
405
406 if [ $# -eq 0 ]; then
407 $FUNCNAME help
408 return 1
409 fi
Dan Pasanen03447712016-12-19 11:22:55 -0600410 local user=`git config --get review.review.lineageos.org.username`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300411 local review=`git config --get remote.github.review`
412 local project=`git config --get remote.github.projectname`
413 local command=$1
414 shift
415 case $command in
416 help)
417 if [ $# -eq 0 ]; then
418 cat <<EOF
419Usage:
420 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
421
422Commands:
423 fetch Just fetch the change as FETCH_HEAD
424 help Show this help, or for a specific command
425 pull Pull a change into current branch
426 push Push HEAD or a local branch to Gerrit for a specific branch
427
428Any other Git commands that support refname would work as:
429 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
430
431See '$FUNCNAME help COMMAND' for more information on a specific command.
432
433Example:
434 $FUNCNAME checkout -b topic 1234/5
435works as:
436 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
437 && git checkout -b topic FETCH_HEAD
438will checkout a new branch 'topic' base on patch-set 5 of change 1234.
439Patch-set 1 will be fetched if omitted.
440EOF
441 return
442 fi
443 case $1 in
444 __cmg_*) echo "For internal use only." ;;
445 changes|for)
446 if [ "$FUNCNAME" = "cmgerrit" ]; then
447 echo "'$FUNCNAME $1' is deprecated."
448 fi
449 ;;
450 help) $FUNCNAME help ;;
451 fetch|pull) cat <<EOF
452usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
453
454works as:
455 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
456 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
457
458Example:
459 $FUNCNAME $1 1234
460will $1 patch-set 1 of change 1234
461EOF
462 ;;
463 push) cat <<EOF
464usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
465
466works as:
467 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
468 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
469
470Example:
471 $FUNCNAME push fix6789:gingerbread
472will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
473HEAD will be pushed from local if omitted.
474EOF
475 ;;
476 *)
477 $FUNCNAME __cmg_err_not_supported $1 && return
478 cat <<EOF
479usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
480
481works as:
482 git fetch http://DOMAIN/p/PROJECT \\
483 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
484 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
485EOF
486 ;;
487 esac
488 ;;
489 __cmg_get_ref)
490 $FUNCNAME __cmg_err_no_arg $command $# && return 1
491 local change_id patchset_id hash
492 case $1 in
493 */*)
494 change_id=${1%%/*}
495 patchset_id=${1#*/}
496 ;;
497 *)
498 change_id=$1
499 patchset_id=1
500 ;;
501 esac
502 hash=$(($change_id % 100))
503 case $hash in
504 [0-9]) hash="0$hash" ;;
505 esac
506 echo "refs/changes/$hash/$change_id/$patchset_id"
507 ;;
508 fetch|pull)
509 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
510 $FUNCNAME __cmg_err_not_repo && return 1
511 local change=$1
512 shift
513 git $command $@ http://$review/p/$project \
514 $($FUNCNAME __cmg_get_ref $change) || return 1
515 ;;
516 push)
517 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
518 $FUNCNAME __cmg_err_not_repo && return 1
519 if [ -z "$user" ]; then
520 echo >&2 "Gerrit username not found."
521 return 1
522 fi
523 local local_branch remote_branch
524 case $1 in
525 *:*)
526 local_branch=${1%:*}
527 remote_branch=${1##*:}
528 ;;
529 *)
530 local_branch=HEAD
531 remote_branch=$1
532 ;;
533 esac
534 shift
535 git push $@ ssh://$user@$review:29418/$project \
536 $local_branch:refs/for/$remote_branch || return 1
537 ;;
538 changes|for)
539 if [ "$FUNCNAME" = "cmgerrit" ]; then
540 echo >&2 "'$FUNCNAME $command' is deprecated."
541 fi
542 ;;
543 __cmg_err_no_arg)
544 if [ $# -lt 2 ]; then
545 echo >&2 "'$FUNCNAME $command' missing argument."
546 elif [ $2 -eq 0 ]; then
547 if [ -n "$3" ]; then
548 $FUNCNAME help $1
549 else
550 echo >&2 "'$FUNCNAME $1' missing argument."
551 fi
552 else
553 return 1
554 fi
555 ;;
556 __cmg_err_not_repo)
557 if [ -z "$review" -o -z "$project" ]; then
558 echo >&2 "Not currently in any reviewable repository."
559 else
560 return 1
561 fi
562 ;;
563 __cmg_err_not_supported)
564 $FUNCNAME __cmg_err_no_arg $command $# && return
565 case $1 in
566 #TODO: filter more git commands that don't use refname
567 init|add|rm|mv|status|clone|remote|bisect|config|stash)
568 echo >&2 "'$FUNCNAME $1' is not supported."
569 ;;
570 *) return 1 ;;
571 esac
572 ;;
573 #TODO: other special cases?
574 *)
575 $FUNCNAME __cmg_err_not_supported $command && return 1
576 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
577 $FUNCNAME __cmg_err_not_repo && return 1
578 local args="$@"
579 local change pre_args refs_arg post_args
580 case "$args" in
581 *--\ *)
582 pre_args=${args%%-- *}
583 post_args="-- ${args#*-- }"
584 ;;
585 *) pre_args="$args" ;;
586 esac
587 args=($pre_args)
588 pre_args=
589 if [ ${#args[@]} -gt 0 ]; then
590 change=${args[${#args[@]}-1]}
591 fi
592 if [ ${#args[@]} -gt 1 ]; then
593 pre_args=${args[0]}
594 for ((i=1; i<${#args[@]}-1; i++)); do
595 pre_args="$pre_args ${args[$i]}"
596 done
597 fi
598 while ((1)); do
599 case $change in
600 ""|--)
601 $FUNCNAME help $command
602 return 1
603 ;;
604 *@*)
605 if [ -z "$refs_arg" ]; then
606 refs_arg="@${change#*@}"
607 change=${change%%@*}
608 fi
609 ;;
610 *~*)
611 if [ -z "$refs_arg" ]; then
612 refs_arg="~${change#*~}"
613 change=${change%%~*}
614 fi
615 ;;
616 *^*)
617 if [ -z "$refs_arg" ]; then
618 refs_arg="^${change#*^}"
619 change=${change%%^*}
620 fi
621 ;;
622 *:*)
623 if [ -z "$refs_arg" ]; then
624 refs_arg=":${change#*:}"
625 change=${change%%:*}
626 fi
627 ;;
628 *) break ;;
629 esac
630 done
631 $FUNCNAME fetch $change \
632 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
633 || return 1
634 ;;
635 esac
636}
637
638function cmrebase() {
639 local repo=$1
640 local refs=$2
641 local pwd="$(pwd)"
642 local dir="$(gettop)/$repo"
643
644 if [ -z $repo ] || [ -z $refs ]; then
Dan Pasanen03447712016-12-19 11:22:55 -0600645 echo "LineageOS Gerrit Rebase Usage: "
Michael Bestas3952f6c2016-08-26 01:12:08 +0300646 echo " cmrebase <path to project> <patch IDs on Gerrit>"
647 echo " The patch IDs appear on the Gerrit commands that are offered."
648 echo " They consist on a series of numbers and slashes, after the text"
649 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
650 echo ""
651 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
652 echo ""
653 return
654 fi
655
656 if [ ! -d $dir ]; then
657 echo "Directory $dir doesn't exist in tree."
658 return
659 fi
660 cd $dir
661 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
662 echo "Starting branch..."
663 repo start tmprebase .
664 echo "Bringing it up to date..."
665 repo sync .
666 echo "Fetching change..."
Dan Pasanen03447712016-12-19 11:22:55 -0600667 git fetch "http://review.lineageos.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Michael Bestas3952f6c2016-08-26 01:12:08 +0300668 if [ "$?" != "0" ]; then
669 echo "Error cherry-picking. Not uploading!"
670 return
671 fi
672 echo "Uploading..."
673 repo upload .
674 echo "Cleaning up..."
675 repo abandon tmprebase .
676 cd $pwd
677}
678
679function mka() {
680 local T=$(gettop)
681 if [ "$T" ]; then
682 case `uname -s` in
683 Darwin)
684 make -C $T -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
685 ;;
686 *)
Steve Kondik36ae30b2016-10-26 17:37:40 -0700687 mk_timer schedtool -B -n 10 -e ionice -n 7 make -C $T -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300688 ;;
689 esac
690
691 else
692 echo "Couldn't locate the top of the tree. Try setting TOP."
693 fi
694}
695
696function cmka() {
697 if [ ! -z "$1" ]; then
698 for i in "$@"; do
699 case $i in
700 bacon|otapackage|systemimage)
701 mka installclean
702 mka $i
703 ;;
704 *)
705 mka clean-$i
706 mka $i
707 ;;
708 esac
709 done
710 else
711 mka clean
712 mka
713 fi
714}
715
716function mms() {
717 local T=$(gettop)
718 if [ -z "$T" ]
719 then
720 echo "Couldn't locate the top of the tree. Try setting TOP."
721 return 1
722 fi
723
724 case `uname -s` in
725 Darwin)
726 local NUM_CPUS=$(sysctl hw.ncpu|cut -d" " -f2)
727 ONE_SHOT_MAKEFILE="__none__" \
728 make -C $T -j $NUM_CPUS "$@"
729 ;;
730 *)
731 local NUM_CPUS=$(cat /proc/cpuinfo | grep "^processor" | wc -l)
732 ONE_SHOT_MAKEFILE="__none__" \
733 mk_timer schedtool -B -n 1 -e ionice -n 1 \
734 make -C $T -j $NUM_CPUS "$@"
735 ;;
736 esac
737}
738
739function repolastsync() {
740 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
741 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
742 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
743 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
744}
745
746function reposync() {
747 case `uname -s` in
748 Darwin)
749 repo sync -j 4 "$@"
750 ;;
751 *)
752 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
753 ;;
754 esac
755}
756
757function repodiff() {
758 if [ -z "$*" ]; then
759 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
760 return
761 fi
762 diffopts=$* repo forall -c \
763 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
764}
765
766# Return success if adb is up and not in recovery
767function _adb_connected {
768 {
769 if [[ "$(adb get-state)" == device &&
Marc K299137f2016-10-20 10:27:10 +0200770 "$(adb shell test -e /sbin/recovery; echo $?)" != 0 ]]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300771 then
772 return 0
773 fi
774 } 2>/dev/null
775
776 return 1
777};
778
779# Credit for color strip sed: http://goo.gl/BoIcm
780function dopush()
781{
782 local func=$1
783 shift
784
785 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
786 if ! _adb_connected; then
787 echo "No device is online. Waiting for one..."
788 echo "Please connect USB and/or enable USB debugging"
789 until _adb_connected; do
790 sleep 1
791 done
792 echo "Device Found."
793 fi
794
795 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD") || [ "$FORCE_PUSH" = "true" ];
796 then
797 # retrieve IP and PORT info if we're using a TCP connection
Marc K2be9cac2016-10-20 10:27:35 +0200798 TCPIPPORT=$(adb devices \
799 | 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 +0300800 | head -1 | awk '{print $1}')
801 adb root &> /dev/null
802 sleep 0.3
803 if [ -n "$TCPIPPORT" ]
804 then
805 # adb root just killed our connection
806 # so reconnect...
807 adb connect "$TCPIPPORT"
808 fi
809 adb wait-for-device &> /dev/null
810 sleep 0.3
811 adb remount &> /dev/null
812
813 mkdir -p $OUT
814 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
815 ret=$?;
816 if [ $ret -ne 0 ]; then
817 rm -f $OUT/.log;return $ret
818 fi
819
820 # Install: <file>
821 if [ `uname` = "Linux" ]; then
Marc K97b035d2016-10-20 10:27:44 +0200822 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}\] +//' \
823 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300824 else
Marc K97b035d2016-10-20 10:27:44 +0200825 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}\] +//" \
826 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300827 fi
828
829 # Copy: <file>
830 if [ `uname` = "Linux" ]; then
Marc K97b035d2016-10-20 10:27:44 +0200831 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}\] +//' \
832 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300833 else
Marc K97b035d2016-10-20 10:27:44 +0200834 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}\] +//' \
835 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300836 fi
837
838 # If any files are going to /data, push an octal file permissions reader to device
839 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
840 CHKPERM="/data/local/tmp/chkfileperm.sh"
841(
842cat <<'EOF'
843#!/system/xbin/sh
844FILE=$@
845if [ -e $FILE ]; then
846 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
847fi
848EOF
849) > $OUT/.chkfileperm.sh
850 echo "Pushing file permissions checker to device"
851 adb push $OUT/.chkfileperm.sh $CHKPERM
852 adb shell chmod 755 $CHKPERM
853 rm -f $OUT/.chkfileperm.sh
854 fi
855
856 stop_n_start=false
857 for FILE in $(echo $LOC | tr " " "\n"); do
858 # Make sure file is in $OUT/system or $OUT/data
859 case $FILE in
860 $OUT/system/*|$OUT/data/*)
861 # Get target file name (i.e. /system/bin/adb)
862 TARGET=$(echo $FILE | sed "s#$OUT##")
863 ;;
864 *) continue ;;
865 esac
866
867 case $TARGET in
868 /data/*)
869 # fs_config only sets permissions and se labels for files pushed to /system
870 if [ -n "$CHKPERM" ]; then
871 OLDPERM=$(adb shell $CHKPERM $TARGET)
872 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
873 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
874 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
875 fi
876 echo "Pushing: $TARGET"
877 adb push $FILE $TARGET
878 if [ -n "$OLDPERM" ]; then
879 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
880 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
881 adb shell chmod "$OLDPERM" $TARGET
882 else
883 echo "$TARGET did not exist previously, you should set file permissions manually"
884 fi
885 adb shell restorecon "$TARGET"
886 ;;
887 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
888 # Only need to stop services once
889 if ! $stop_n_start; then
890 adb shell stop
891 stop_n_start=true
892 fi
893 echo "Pushing: $TARGET"
894 adb push $FILE $TARGET
895 ;;
896 *)
897 echo "Pushing: $TARGET"
898 adb push $FILE $TARGET
899 ;;
900 esac
901 done
902 if [ -n "$CHKPERM" ]; then
903 adb shell rm $CHKPERM
904 fi
905 if $stop_n_start; then
906 adb shell start
907 fi
908 rm -f $OUT/.log
909 return 0
910 else
911 echo "The connected device does not appear to be $CM_BUILD, run away!"
912 fi
913}
914
915alias mmp='dopush mm'
916alias mmmp='dopush mmm'
917alias mmap='dopush mma'
Zhao Wei Liew64fc5ae2016-12-10 16:48:27 +0800918alias mmmap='dopush mmma'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300919alias mkap='dopush mka'
920alias cmkap='dopush cmka'
921
922function repopick() {
923 T=$(gettop)
924 $T/vendor/cm/build/tools/repopick.py $@
925}
926
927function fixup_common_out_dir() {
928 common_out_dir=$(get_build_var OUT_DIR)/target/common
929 target_device=$(get_build_var TARGET_DEVICE)
930 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
931 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
932 mv ${common_out_dir} ${common_out_dir}-${target_device}
933 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
934 else
935 [ -L ${common_out_dir} ] && rm ${common_out_dir}
936 mkdir -p ${common_out_dir}-${target_device}
937 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
938 fi
939 else
940 [ -L ${common_out_dir} ] && rm ${common_out_dir}
941 mkdir -p ${common_out_dir}
942 fi
943}
Steve Kondik26e669b2016-11-04 12:05:19 -0700944
945# Enable SD-LLVM if available
946if [ -d $(gettop)/prebuilts/snapdragon-llvm/toolchains ]; then
Alexander Martinz1bbf3e92016-11-05 15:27:43 +0100947 case `uname -s` in
948 Darwin)
949 # Darwin is not supported yet
950 ;;
951 *)
952 export SDCLANG=true
953 export SDCLANG_PATH=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_3.8/prebuilt/linux-x86_64/bin
954 export SDCLANG_LTO_DEFS=$(gettop)/device/qcom/common/sdllvm-lto-defs.mk
955 ;;
956 esac
Steve Kondik26e669b2016-11-04 12:05:19 -0700957fi
Luca Stefani84fda602016-11-24 14:16:33 +0100958
959# Android specific JACK args
960if [ -n "$JACK_SERVER_VM_ARGUMENTS" ] && [ -z "$ANDROID_JACK_VM_ARGS" ]; then
961 export ANDROID_JACK_VM_ARGS=$JACK_SERVER_VM_ARGUMENTS
962fi