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