blob: 24ae320be52caddd2203a86e6f38811efd8c5ea2 [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
Luca Stefani076c27b2017-08-17 20:30:00 +020025function mk_timer()
26{
27 local start_time=$(date +"%s")
28 $@
29 local ret=$?
30 local end_time=$(date +"%s")
31 local tdiff=$(($end_time-$start_time))
32 local hours=$(($tdiff / 3600 ))
33 local mins=$((($tdiff % 3600) / 60))
34 local secs=$(($tdiff % 60))
35 local ncolors=$(tput colors 2>/dev/null)
36 echo
37 if [ $ret -eq 0 ] ; then
38 echo -n "#### make completed successfully "
39 else
40 echo -n "#### make failed to build some targets "
41 fi
42 if [ $hours -gt 0 ] ; then
43 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
44 elif [ $mins -gt 0 ] ; then
45 printf "(%02g:%02g (mm:ss))" $mins $secs
46 elif [ $secs -gt 0 ] ; then
47 printf "(%s seconds)" $secs
48 fi
49 echo " ####"
50 echo
51 return $ret
52}
53
Michael Bestas3952f6c2016-08-26 01:12:08 +030054function brunch()
55{
56 breakfast $*
57 if [ $? -eq 0 ]; then
58 mka bacon
59 else
60 echo "No such item in brunch menu. Try 'breakfast'"
61 return 1
62 fi
63 return $?
64}
65
66function breakfast()
67{
68 target=$1
69 local variant=$2
Luca Stefani5c60e4f2017-08-17 19:28:48 +020070 LINEAGE_DEVICES_ONLY="true"
Michael Bestas3952f6c2016-08-26 01:12:08 +030071 unset LUNCH_MENU_CHOICES
72 add_lunch_combo full-eng
Dan Pasanen91f76202017-07-06 08:21:30 -050073 for f in `/bin/ls vendor/lineage/vendorsetup.sh 2> /dev/null`
Michael Bestas3952f6c2016-08-26 01:12:08 +030074 do
75 echo "including $f"
76 . $f
77 done
78 unset f
79
80 if [ $# -eq 0 ]; then
81 # No arguments, so let's have the full menu
82 lunch
83 else
84 echo "z$target" | grep -q "-"
85 if [ $? -eq 0 ]; then
86 # A buildtype was specified, assume a full device name
87 lunch $target
88 else
Simon Shields63ce74b2016-12-28 11:33:29 +110089 # This is probably just the Lineage model name
Michael Bestas3952f6c2016-08-26 01:12:08 +030090 if [ -z "$variant" ]; then
91 variant="userdebug"
92 fi
Matt Mowered8c2482017-01-02 02:26:01 -060093
Luca Stefani5c60e4f2017-08-17 19:28:48 +020094 lunch lineage_$target-$variant
Michael Bestas3952f6c2016-08-26 01:12:08 +030095 fi
96 fi
97 return $?
98}
99
100alias bib=breakfast
101
102function eat()
103{
104 if [ "$OUT" ] ; then
Zhao Wei Liew321dde52017-01-01 15:24:38 +0800105 MODVERSION=$(get_build_var LINEAGE_VERSION)
Dan Pasanen03447712016-12-19 11:22:55 -0600106 ZIPFILE=lineage-$MODVERSION.zip
Michael Bestas3952f6c2016-08-26 01:12:08 +0300107 ZIPPATH=$OUT/$ZIPFILE
108 if [ ! -f $ZIPPATH ] ; then
109 echo "Nothing to eat"
110 return 1
111 fi
112 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
113 if [ $(adb get-state) != device -a $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
114 echo "No device is online. Waiting for one..."
115 echo "Please connect USB and/or enable USB debugging"
116 until [ $(adb get-state) = device -o $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
117 sleep 1
118 done
119 echo "Device Found.."
120 fi
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200121 if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD"); then
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800122 # if adbd isn't root we can't write to /cache/recovery/
123 adb root
124 sleep 1
125 adb wait-for-device
126 cat << EOF > /tmp/command
Michael Bestas3952f6c2016-08-26 01:12:08 +0300127--sideload_auto_reboot
128EOF
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800129 if adb push /tmp/command /cache/recovery/ ; then
130 echo "Rebooting into recovery for sideload installation"
131 adb reboot recovery
132 adb wait-for-sideload
133 adb sideload $ZIPPATH
134 fi
135 rm /tmp/command
136 else
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200137 echo "The connected device does not appear to be $LINEAGE_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300138 fi
Ethan Chenb69c2ff2016-12-31 13:23:56 -0800139 return $?
Michael Bestas3952f6c2016-08-26 01:12:08 +0300140 else
141 echo "Nothing to eat"
142 return 1
143 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300144}
145
146function omnom()
147{
148 brunch $*
149 eat
150}
151
152function cout()
153{
154 if [ "$OUT" ]; then
155 cd $OUT
156 else
157 echo "Couldn't locate out directory. Try setting OUT."
158 fi
159}
160
161function dddclient()
162{
163 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
164 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
165 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
166 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
167 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
168 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
169 local ARCH=$(get_build_var TARGET_ARCH)
170 local GDB
171 case "$ARCH" in
172 arm) GDB=arm-linux-androideabi-gdb;;
173 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
174 mips|mips64) GDB=mips64el-linux-android-gdb;;
175 x86) GDB=x86_64-linux-android-gdb;;
176 x86_64) GDB=x86_64-linux-android-gdb;;
177 *) echo "Unknown arch $ARCH"; return 1;;
178 esac
179
180 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
181 local EXE="$1"
182 if [ "$EXE" ] ; then
183 EXE=$1
184 if [[ $EXE =~ ^[^/].* ]] ; then
185 EXE="system/bin/"$EXE
186 fi
187 else
188 EXE="app_process"
189 fi
190
191 local PORT="$2"
192 if [ "$PORT" ] ; then
193 PORT=$2
194 else
195 PORT=":5039"
196 fi
197
198 local PID="$3"
199 if [ "$PID" ] ; then
200 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
201 PID=`pid $3`
202 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
203 # that likely didn't work because of returning multiple processes
204 # try again, filtering by root processes (don't contain colon)
205 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
206 if [[ ! "$PID" =~ ^[0-9]+$ ]]
207 then
208 echo "Couldn't resolve '$3' to single PID"
209 return 1
210 else
211 echo ""
212 echo "WARNING: multiple processes matching '$3' observed, using root process"
213 echo ""
214 fi
215 fi
216 fi
217 adb forward "tcp$PORT" "tcp$PORT"
218 local USE64BIT="$(is64bit $PID)"
219 adb shell gdbserver$USE64BIT $PORT --attach $PID &
220 sleep 2
221 else
222 echo ""
223 echo "If you haven't done so already, do this first on the device:"
224 echo " gdbserver $PORT /system/bin/$EXE"
225 echo " or"
226 echo " gdbserver $PORT --attach <PID>"
227 echo ""
228 fi
229
230 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
231 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
232
233 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
234 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"
235 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
236 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
237 # Enable special debugging for ART processes.
238 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
239 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
240 fi
241 echo >>"$OUT_ROOT/gdbclient.cmds" ""
242
243 local WHICH_GDB=
244 # 64-bit exe found
245 if [ "$USE64BIT" != "" ] ; then
246 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
247 # 32-bit exe / 32-bit platform
248 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
249 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
250 # 32-bit exe / 64-bit platform
251 else
252 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
253 fi
254
255 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
256 else
257 echo "Unable to determine build system output dir."
258 fi
259}
260
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200261function lineageremote()
Michael Bestas3952f6c2016-08-26 01:12:08 +0300262{
263 if ! git rev-parse --git-dir &> /dev/null
264 then
265 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
266 return 1
267 fi
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200268 git remote rm lineage 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300269 local GERRIT_REMOTE=$(git config --get remote.github.projectname)
Michael Bestasaf3532b2017-08-23 17:40:40 +0300270 if [ -z "$GERRIT_REMOTE" ]
271 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300272 local GERRIT_REMOTE=$(git config --get remote.aosp.projectname | sed s#platform/#android/#g | sed s#/#_#g)
273 local PFX="LineageOS/"
Michael Bestasaf3532b2017-08-23 17:40:40 +0300274 fi
Michael Bestasad3a5702017-08-24 00:00:48 +0300275 local LINEAGE_USER=$(git config --get review.review.lineageos.org.username)
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200276 if [ -z "$LINEAGE_USER" ]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300277 then
Michael Bestasaf3532b2017-08-23 17:40:40 +0300278 git remote add lineage ssh://review.lineageos.org:29418/$PFX$GERRIT_REMOTE
Michael Bestas3952f6c2016-08-26 01:12:08 +0300279 else
Michael Bestasaf3532b2017-08-23 17:40:40 +0300280 git remote add lineage ssh://$LINEAGE_USER@review.lineageos.org:29418/$PFX$GERRIT_REMOTE
Michael Bestas3952f6c2016-08-26 01:12:08 +0300281 fi
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200282 echo "Remote 'lineage' created"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300283}
284
285function aospremote()
286{
287 if ! git rev-parse --git-dir &> /dev/null
288 then
289 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
290 return 1
291 fi
292 git remote rm aosp 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300293 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400294 # Google moved the repo location in Oreo
295 if [ $PROJECT = "build/make" ]
296 then
297 PROJECT="build"
298 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300299 if (echo $PROJECT | grep -qv "^device")
300 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300301 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300302 fi
303 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
304 echo "Remote 'aosp' created"
305}
306
307function cafremote()
308{
309 if ! git rev-parse --git-dir &> /dev/null
310 then
311 echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up."
312 return 1
313 fi
314 git remote rm caf 2> /dev/null
Michael Bestasad3a5702017-08-24 00:00:48 +0300315 local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##")
Rashed Abdel-Tawabfd8b8292017-10-24 21:55:52 -0400316 # Google moved the repo location in Oreo
317 if [ $PROJECT = "build/make" ]
318 then
319 PROJECT="build"
320 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300321 if (echo $PROJECT | grep -qv "^device")
322 then
Michael Bestasad3a5702017-08-24 00:00:48 +0300323 local PFX="platform/"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300324 fi
Zhao Wei Liewfb4b8c52017-01-08 09:03:01 +0800325 git remote add caf https://source.codeaurora.org/quic/la/$PFX$PROJECT
Michael Bestas3952f6c2016-08-26 01:12:08 +0300326 echo "Remote 'caf' created"
327}
328
329function installboot()
330{
331 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
332 then
333 echo "No recovery.fstab found. Build recovery first."
334 return 1
335 fi
336 if [ ! -e "$OUT/boot.img" ];
337 then
338 echo "No boot.img found. Run make bootimage first."
339 return 1
340 fi
341 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
342 if [ -z "$PARTITION" ];
343 then
344 # Try for RECOVERY_FSTAB_VERSION = 2
345 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
346 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
347 if [ -z "$PARTITION" ];
348 then
349 echo "Unable to determine boot partition."
350 return 1
351 fi
352 fi
353 adb start-server
354 adb wait-for-online
355 adb root
356 sleep 1
357 adb wait-for-online shell mount /system 2>&1 > /dev/null
358 adb wait-for-online remount
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200359 if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300360 then
361 adb push $OUT/boot.img /cache/
Ashwin Rameshb0ea62a2017-08-13 12:00:15 +0530362 if [ -e "$OUT/system/lib/modules/*" ];
363 then
364 for i in $OUT/system/lib/modules/*;
365 do
366 adb push $i /system/lib/modules/
367 done
368 adb shell chmod 644 /system/lib/modules/*
369 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300370 adb shell dd if=/cache/boot.img of=$PARTITION
Michael Bestas3952f6c2016-08-26 01:12:08 +0300371 echo "Installation complete."
372 else
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200373 echo "The connected device does not appear to be $LINEAGE_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300374 fi
375}
376
377function installrecovery()
378{
379 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
380 then
381 echo "No recovery.fstab found. Build recovery first."
382 return 1
383 fi
384 if [ ! -e "$OUT/recovery.img" ];
385 then
386 echo "No recovery.img found. Run make recoveryimage first."
387 return 1
388 fi
389 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
390 if [ -z "$PARTITION" ];
391 then
392 # Try for RECOVERY_FSTAB_VERSION = 2
393 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
394 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
395 if [ -z "$PARTITION" ];
396 then
397 echo "Unable to determine recovery partition."
398 return 1
399 fi
400 fi
401 adb start-server
402 adb wait-for-online
403 adb root
404 sleep 1
405 adb wait-for-online shell mount /system 2>&1 >> /dev/null
406 adb wait-for-online remount
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200407 if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD");
Michael Bestas3952f6c2016-08-26 01:12:08 +0300408 then
409 adb push $OUT/recovery.img /cache/
410 adb shell dd if=/cache/recovery.img of=$PARTITION
411 echo "Installation complete."
412 else
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200413 echo "The connected device does not appear to be $LINEAGE_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300414 fi
415}
416
417function makerecipe() {
418 if [ -z "$1" ]
419 then
420 echo "No branch name provided."
421 return 1
422 fi
423 cd android
424 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
425 git commit -a -m "$1"
426 cd ..
427
428 repo forall -c '
429
430 if [ "$REPO_REMOTE" = "github" ]
431 then
432 pwd
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200433 lineageremote
434 git push lineage HEAD:refs/heads/'$1'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300435 fi
436 '
437}
438
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200439function lineagegerrit() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300440 if [ "$(__detect_shell)" = "zsh" ]; then
441 # zsh does not define FUNCNAME, derive from funcstack
442 local FUNCNAME=$funcstack[1]
443 fi
444
445 if [ $# -eq 0 ]; then
446 $FUNCNAME help
447 return 1
448 fi
Dan Pasanen03447712016-12-19 11:22:55 -0600449 local user=`git config --get review.review.lineageos.org.username`
Michael Bestas3952f6c2016-08-26 01:12:08 +0300450 local review=`git config --get remote.github.review`
451 local project=`git config --get remote.github.projectname`
452 local command=$1
453 shift
454 case $command in
455 help)
456 if [ $# -eq 0 ]; then
457 cat <<EOF
458Usage:
459 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
460
461Commands:
462 fetch Just fetch the change as FETCH_HEAD
463 help Show this help, or for a specific command
464 pull Pull a change into current branch
465 push Push HEAD or a local branch to Gerrit for a specific branch
466
467Any other Git commands that support refname would work as:
468 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
469
470See '$FUNCNAME help COMMAND' for more information on a specific command.
471
472Example:
473 $FUNCNAME checkout -b topic 1234/5
474works as:
475 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
476 && git checkout -b topic FETCH_HEAD
477will checkout a new branch 'topic' base on patch-set 5 of change 1234.
478Patch-set 1 will be fetched if omitted.
479EOF
480 return
481 fi
482 case $1 in
483 __cmg_*) echo "For internal use only." ;;
484 changes|for)
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200485 if [ "$FUNCNAME" = "lineagegerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300486 echo "'$FUNCNAME $1' is deprecated."
487 fi
488 ;;
489 help) $FUNCNAME help ;;
490 fetch|pull) cat <<EOF
491usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
492
493works as:
494 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
495 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
496
497Example:
498 $FUNCNAME $1 1234
499will $1 patch-set 1 of change 1234
500EOF
501 ;;
502 push) cat <<EOF
503usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
504
505works as:
506 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
507 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
508
509Example:
510 $FUNCNAME push fix6789:gingerbread
511will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
512HEAD will be pushed from local if omitted.
513EOF
514 ;;
515 *)
516 $FUNCNAME __cmg_err_not_supported $1 && return
517 cat <<EOF
518usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
519
520works as:
521 git fetch http://DOMAIN/p/PROJECT \\
522 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
523 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
524EOF
525 ;;
526 esac
527 ;;
528 __cmg_get_ref)
529 $FUNCNAME __cmg_err_no_arg $command $# && return 1
530 local change_id patchset_id hash
531 case $1 in
532 */*)
533 change_id=${1%%/*}
534 patchset_id=${1#*/}
535 ;;
536 *)
537 change_id=$1
538 patchset_id=1
539 ;;
540 esac
541 hash=$(($change_id % 100))
542 case $hash in
543 [0-9]) hash="0$hash" ;;
544 esac
545 echo "refs/changes/$hash/$change_id/$patchset_id"
546 ;;
547 fetch|pull)
548 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
549 $FUNCNAME __cmg_err_not_repo && return 1
550 local change=$1
551 shift
552 git $command $@ http://$review/p/$project \
553 $($FUNCNAME __cmg_get_ref $change) || return 1
554 ;;
555 push)
556 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
557 $FUNCNAME __cmg_err_not_repo && return 1
558 if [ -z "$user" ]; then
559 echo >&2 "Gerrit username not found."
560 return 1
561 fi
562 local local_branch remote_branch
563 case $1 in
564 *:*)
565 local_branch=${1%:*}
566 remote_branch=${1##*:}
567 ;;
568 *)
569 local_branch=HEAD
570 remote_branch=$1
571 ;;
572 esac
573 shift
574 git push $@ ssh://$user@$review:29418/$project \
575 $local_branch:refs/for/$remote_branch || return 1
576 ;;
577 changes|for)
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200578 if [ "$FUNCNAME" = "lineagegerrit" ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300579 echo >&2 "'$FUNCNAME $command' is deprecated."
580 fi
581 ;;
582 __cmg_err_no_arg)
583 if [ $# -lt 2 ]; then
584 echo >&2 "'$FUNCNAME $command' missing argument."
585 elif [ $2 -eq 0 ]; then
586 if [ -n "$3" ]; then
587 $FUNCNAME help $1
588 else
589 echo >&2 "'$FUNCNAME $1' missing argument."
590 fi
591 else
592 return 1
593 fi
594 ;;
595 __cmg_err_not_repo)
596 if [ -z "$review" -o -z "$project" ]; then
597 echo >&2 "Not currently in any reviewable repository."
598 else
599 return 1
600 fi
601 ;;
602 __cmg_err_not_supported)
603 $FUNCNAME __cmg_err_no_arg $command $# && return
604 case $1 in
605 #TODO: filter more git commands that don't use refname
606 init|add|rm|mv|status|clone|remote|bisect|config|stash)
607 echo >&2 "'$FUNCNAME $1' is not supported."
608 ;;
609 *) return 1 ;;
610 esac
611 ;;
612 #TODO: other special cases?
613 *)
614 $FUNCNAME __cmg_err_not_supported $command && return 1
615 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
616 $FUNCNAME __cmg_err_not_repo && return 1
617 local args="$@"
618 local change pre_args refs_arg post_args
619 case "$args" in
620 *--\ *)
621 pre_args=${args%%-- *}
622 post_args="-- ${args#*-- }"
623 ;;
624 *) pre_args="$args" ;;
625 esac
626 args=($pre_args)
627 pre_args=
628 if [ ${#args[@]} -gt 0 ]; then
629 change=${args[${#args[@]}-1]}
630 fi
631 if [ ${#args[@]} -gt 1 ]; then
632 pre_args=${args[0]}
633 for ((i=1; i<${#args[@]}-1; i++)); do
634 pre_args="$pre_args ${args[$i]}"
635 done
636 fi
637 while ((1)); do
638 case $change in
639 ""|--)
640 $FUNCNAME help $command
641 return 1
642 ;;
643 *@*)
644 if [ -z "$refs_arg" ]; then
645 refs_arg="@${change#*@}"
646 change=${change%%@*}
647 fi
648 ;;
649 *~*)
650 if [ -z "$refs_arg" ]; then
651 refs_arg="~${change#*~}"
652 change=${change%%~*}
653 fi
654 ;;
655 *^*)
656 if [ -z "$refs_arg" ]; then
657 refs_arg="^${change#*^}"
658 change=${change%%^*}
659 fi
660 ;;
661 *:*)
662 if [ -z "$refs_arg" ]; then
663 refs_arg=":${change#*:}"
664 change=${change%%:*}
665 fi
666 ;;
667 *) break ;;
668 esac
669 done
670 $FUNCNAME fetch $change \
671 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
672 || return 1
673 ;;
674 esac
675}
676
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200677function lineagerebase() {
Michael Bestas3952f6c2016-08-26 01:12:08 +0300678 local repo=$1
679 local refs=$2
680 local pwd="$(pwd)"
681 local dir="$(gettop)/$repo"
682
683 if [ -z $repo ] || [ -z $refs ]; then
Dan Pasanen03447712016-12-19 11:22:55 -0600684 echo "LineageOS Gerrit Rebase Usage: "
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200685 echo " lineagerebase <path to project> <patch IDs on Gerrit>"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300686 echo " The patch IDs appear on the Gerrit commands that are offered."
687 echo " They consist on a series of numbers and slashes, after the text"
688 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
689 echo ""
690 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
691 echo ""
692 return
693 fi
694
695 if [ ! -d $dir ]; then
696 echo "Directory $dir doesn't exist in tree."
697 return
698 fi
699 cd $dir
700 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
701 echo "Starting branch..."
702 repo start tmprebase .
703 echo "Bringing it up to date..."
704 repo sync .
705 echo "Fetching change..."
Dan Pasanen03447712016-12-19 11:22:55 -0600706 git fetch "http://review.lineageos.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Michael Bestas3952f6c2016-08-26 01:12:08 +0300707 if [ "$?" != "0" ]; then
708 echo "Error cherry-picking. Not uploading!"
709 return
710 fi
711 echo "Uploading..."
712 repo upload .
713 echo "Cleaning up..."
714 repo abandon tmprebase .
715 cd $pwd
716}
717
718function mka() {
Luca Stefani085af722017-08-17 20:34:44 +0200719 m -j "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300720}
721
722function cmka() {
723 if [ ! -z "$1" ]; then
724 for i in "$@"; do
725 case $i in
726 bacon|otapackage|systemimage)
727 mka installclean
728 mka $i
729 ;;
730 *)
731 mka clean-$i
732 mka $i
733 ;;
734 esac
735 done
736 else
737 mka clean
738 mka
739 fi
740}
741
Michael Bestas3952f6c2016-08-26 01:12:08 +0300742function repolastsync() {
743 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
744 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
745 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
746 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
747}
748
749function reposync() {
Luca Stefani085af722017-08-17 20:34:44 +0200750 repo sync -j 4 "$@"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300751}
752
753function repodiff() {
754 if [ -z "$*" ]; then
755 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
756 return
757 fi
758 diffopts=$* repo forall -c \
759 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
760}
761
762# Return success if adb is up and not in recovery
763function _adb_connected {
764 {
765 if [[ "$(adb get-state)" == device &&
Marc K299137f2016-10-20 10:27:10 +0200766 "$(adb shell test -e /sbin/recovery; echo $?)" != 0 ]]
Michael Bestas3952f6c2016-08-26 01:12:08 +0300767 then
768 return 0
769 fi
770 } 2>/dev/null
771
772 return 1
773};
774
775# Credit for color strip sed: http://goo.gl/BoIcm
776function dopush()
777{
778 local func=$1
779 shift
780
781 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
782 if ! _adb_connected; then
783 echo "No device is online. Waiting for one..."
784 echo "Please connect USB and/or enable USB debugging"
785 until _adb_connected; do
786 sleep 1
787 done
788 echo "Device Found."
789 fi
790
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200791 if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD") || [ "$FORCE_PUSH" = "true" ];
Michael Bestas3952f6c2016-08-26 01:12:08 +0300792 then
793 # retrieve IP and PORT info if we're using a TCP connection
Marc K2be9cac2016-10-20 10:27:35 +0200794 TCPIPPORT=$(adb devices \
795 | 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 +0300796 | head -1 | awk '{print $1}')
797 adb root &> /dev/null
798 sleep 0.3
799 if [ -n "$TCPIPPORT" ]
800 then
801 # adb root just killed our connection
802 # so reconnect...
803 adb connect "$TCPIPPORT"
804 fi
805 adb wait-for-device &> /dev/null
806 sleep 0.3
807 adb remount &> /dev/null
808
809 mkdir -p $OUT
810 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
811 ret=$?;
812 if [ $ret -ne 0 ]; then
813 rm -f $OUT/.log;return $ret
814 fi
815
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500816 is_gnu_sed=`sed --version | head -1 | grep -c GNU`
817
Michael Bestas3952f6c2016-08-26 01:12:08 +0300818 # Install: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500819 if [ $is_gnu_sed -gt 0 ]; then
Marc K97b035d2016-10-20 10:27:44 +0200820 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}\] +//' \
821 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300822 else
Marc K97b035d2016-10-20 10:27:44 +0200823 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}\] +//" \
824 | grep '^Install: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300825 fi
826
827 # Copy: <file>
Rashed Abdel-Tawab01806642017-01-19 15:52:13 -0500828 if [ $is_gnu_sed -gt 0 ]; then
Marc K97b035d2016-10-20 10:27:44 +0200829 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}\] +//' \
830 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300831 else
Marc K97b035d2016-10-20 10:27:44 +0200832 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}\] +//' \
833 | grep '^Copy: ' | cut -d ':' -f 2)"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300834 fi
835
836 # If any files are going to /data, push an octal file permissions reader to device
837 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
838 CHKPERM="/data/local/tmp/chkfileperm.sh"
839(
840cat <<'EOF'
841#!/system/xbin/sh
842FILE=$@
843if [ -e $FILE ]; then
844 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
845fi
846EOF
847) > $OUT/.chkfileperm.sh
848 echo "Pushing file permissions checker to device"
849 adb push $OUT/.chkfileperm.sh $CHKPERM
850 adb shell chmod 755 $CHKPERM
851 rm -f $OUT/.chkfileperm.sh
852 fi
853
854 stop_n_start=false
855 for FILE in $(echo $LOC | tr " " "\n"); do
856 # Make sure file is in $OUT/system or $OUT/data
857 case $FILE in
858 $OUT/system/*|$OUT/data/*)
859 # Get target file name (i.e. /system/bin/adb)
860 TARGET=$(echo $FILE | sed "s#$OUT##")
861 ;;
862 *) continue ;;
863 esac
864
865 case $TARGET in
866 /data/*)
867 # fs_config only sets permissions and se labels for files pushed to /system
868 if [ -n "$CHKPERM" ]; then
869 OLDPERM=$(adb shell $CHKPERM $TARGET)
870 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
871 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
872 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
873 fi
874 echo "Pushing: $TARGET"
875 adb push $FILE $TARGET
876 if [ -n "$OLDPERM" ]; then
877 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
878 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
879 adb shell chmod "$OLDPERM" $TARGET
880 else
881 echo "$TARGET did not exist previously, you should set file permissions manually"
882 fi
883 adb shell restorecon "$TARGET"
884 ;;
885 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
886 # Only need to stop services once
887 if ! $stop_n_start; then
888 adb shell stop
889 stop_n_start=true
890 fi
891 echo "Pushing: $TARGET"
892 adb push $FILE $TARGET
893 ;;
894 *)
895 echo "Pushing: $TARGET"
896 adb push $FILE $TARGET
897 ;;
898 esac
899 done
900 if [ -n "$CHKPERM" ]; then
901 adb shell rm $CHKPERM
902 fi
903 if $stop_n_start; then
904 adb shell start
905 fi
906 rm -f $OUT/.log
907 return 0
908 else
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200909 echo "The connected device does not appear to be $LINEAGE_BUILD, run away!"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300910 fi
911}
912
913alias mmp='dopush mm'
914alias mmmp='dopush mmm'
915alias mmap='dopush mma'
Zhao Wei Liew64fc5ae2016-12-10 16:48:27 +0800916alias mmmap='dopush mmma'
Michael Bestas3952f6c2016-08-26 01:12:08 +0300917alias mkap='dopush mka'
918alias cmkap='dopush cmka'
919
920function repopick() {
921 T=$(gettop)
Dan Pasanen91f76202017-07-06 08:21:30 -0500922 $T/vendor/lineage/build/tools/repopick.py $@
Michael Bestas3952f6c2016-08-26 01:12:08 +0300923}
924
925function fixup_common_out_dir() {
926 common_out_dir=$(get_build_var OUT_DIR)/target/common
927 target_device=$(get_build_var TARGET_DEVICE)
Luca Stefani5c60e4f2017-08-17 19:28:48 +0200928 if [ ! -z $LINEAGE_FIXUP_COMMON_OUT ]; then
Michael Bestas3952f6c2016-08-26 01:12:08 +0300929 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
930 mv ${common_out_dir} ${common_out_dir}-${target_device}
931 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
932 else
933 [ -L ${common_out_dir} ] && rm ${common_out_dir}
934 mkdir -p ${common_out_dir}-${target_device}
935 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
936 fi
937 else
938 [ -L ${common_out_dir} ] && rm ${common_out_dir}
939 mkdir -p ${common_out_dir}
940 fi
941}
Steve Kondik26e669b2016-11-04 12:05:19 -0700942
943# Enable SD-LLVM if available
944if [ -d $(gettop)/prebuilts/snapdragon-llvm/toolchains ]; then
Alexander Martinz1bbf3e92016-11-05 15:27:43 +0100945 case `uname -s` in
946 Darwin)
947 # Darwin is not supported yet
948 ;;
949 *)
950 export SDCLANG=true
951 export SDCLANG_PATH=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_3.8/prebuilt/linux-x86_64/bin
952 export SDCLANG_LTO_DEFS=$(gettop)/device/qcom/common/sdllvm-lto-defs.mk
953 ;;
954 esac
Steve Kondik26e669b2016-11-04 12:05:19 -0700955fi
Luca Stefani84fda602016-11-24 14:16:33 +0100956
957# Android specific JACK args
958if [ -n "$JACK_SERVER_VM_ARGUMENTS" ] && [ -z "$ANDROID_JACK_VM_ARGS" ]; then
959 export ANDROID_JACK_VM_ARGS=$JACK_SERVER_VM_ARGUMENTS
960fi