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