Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 1 | function __print_lineage_functions_help() { |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 2 | cat <<EOF |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 3 | Additional LineageOS functions: |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 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. |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 8 | - 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 11 | - 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. |
| 22 | EOF |
| 23 | } |
| 24 | |
Luca Stefani | 076c27b | 2017-08-17 20:30:00 +0200 | [diff] [blame] | 25 | function 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 54 | function 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 | |
| 66 | function breakfast() |
| 67 | { |
| 68 | target=$1 |
| 69 | local variant=$2 |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 70 | LINEAGE_DEVICES_ONLY="true" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 71 | unset LUNCH_MENU_CHOICES |
| 72 | add_lunch_combo full-eng |
Dan Pasanen | 91f7620 | 2017-07-06 08:21:30 -0500 | [diff] [blame] | 73 | for f in `/bin/ls vendor/lineage/vendorsetup.sh 2> /dev/null` |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 74 | 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 Shields | 63ce74b | 2016-12-28 11:33:29 +1100 | [diff] [blame] | 89 | # This is probably just the Lineage model name |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 90 | if [ -z "$variant" ]; then |
| 91 | variant="userdebug" |
| 92 | fi |
Matt Mower | ed8c248 | 2017-01-02 02:26:01 -0600 | [diff] [blame] | 93 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 94 | lunch lineage_$target-$variant |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 95 | fi |
| 96 | fi |
| 97 | return $? |
| 98 | } |
| 99 | |
| 100 | alias bib=breakfast |
| 101 | |
| 102 | function eat() |
| 103 | { |
| 104 | if [ "$OUT" ] ; then |
Zhao Wei Liew | 321dde5 | 2017-01-01 15:24:38 +0800 | [diff] [blame] | 105 | MODVERSION=$(get_build_var LINEAGE_VERSION) |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 106 | ZIPFILE=lineage-$MODVERSION.zip |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 107 | 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 Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 121 | if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD"); then |
Ethan Chen | b69c2ff | 2016-12-31 13:23:56 -0800 | [diff] [blame] | 122 | # 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 127 | --sideload_auto_reboot |
| 128 | EOF |
Ethan Chen | b69c2ff | 2016-12-31 13:23:56 -0800 | [diff] [blame] | 129 | 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 Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 137 | echo "The connected device does not appear to be $LINEAGE_BUILD, run away!" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 138 | fi |
Ethan Chen | b69c2ff | 2016-12-31 13:23:56 -0800 | [diff] [blame] | 139 | return $? |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 140 | else |
| 141 | echo "Nothing to eat" |
| 142 | return 1 |
| 143 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | function omnom() |
| 147 | { |
| 148 | brunch $* |
| 149 | eat |
| 150 | } |
| 151 | |
| 152 | function 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 | |
| 161 | function 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 Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 261 | function lineageremote() |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 262 | { |
| 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 Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 268 | git remote rm lineage 2> /dev/null |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 269 | local GERRIT_REMOTE=$(git config --get remote.github.projectname) |
Michael Bestas | af3532b | 2017-08-23 17:40:40 +0300 | [diff] [blame] | 270 | if [ -z "$GERRIT_REMOTE" ] |
| 271 | then |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 272 | local GERRIT_REMOTE=$(git config --get remote.aosp.projectname | sed s#platform/#android/#g | sed s#/#_#g) |
| 273 | local PFX="LineageOS/" |
Michael Bestas | af3532b | 2017-08-23 17:40:40 +0300 | [diff] [blame] | 274 | fi |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 275 | local LINEAGE_USER=$(git config --get review.review.lineageos.org.username) |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 276 | if [ -z "$LINEAGE_USER" ] |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 277 | then |
Michael Bestas | af3532b | 2017-08-23 17:40:40 +0300 | [diff] [blame] | 278 | git remote add lineage ssh://review.lineageos.org:29418/$PFX$GERRIT_REMOTE |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 279 | else |
Michael Bestas | af3532b | 2017-08-23 17:40:40 +0300 | [diff] [blame] | 280 | git remote add lineage ssh://$LINEAGE_USER@review.lineageos.org:29418/$PFX$GERRIT_REMOTE |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 281 | fi |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 282 | echo "Remote 'lineage' created" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | function 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 Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 293 | local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##") |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 294 | if (echo $PROJECT | grep -qv "^device") |
| 295 | then |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 296 | local PFX="platform/" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 297 | fi |
| 298 | git remote add aosp https://android.googlesource.com/$PFX$PROJECT |
| 299 | echo "Remote 'aosp' created" |
| 300 | } |
| 301 | |
| 302 | function cafremote() |
| 303 | { |
| 304 | if ! git rev-parse --git-dir &> /dev/null |
| 305 | then |
| 306 | echo ".git directory not found. Please run this from the root directory of the Android repository you wish to set up." |
| 307 | return 1 |
| 308 | fi |
| 309 | git remote rm caf 2> /dev/null |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 310 | local PROJECT=$(pwd -P | sed -e "s#$ANDROID_BUILD_TOP\/##; s#-caf.*##; s#\/default##") |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 311 | if (echo $PROJECT | grep -qv "^device") |
| 312 | then |
Michael Bestas | ad3a570 | 2017-08-24 00:00:48 +0300 | [diff] [blame] | 313 | local PFX="platform/" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 314 | fi |
Zhao Wei Liew | fb4b8c5 | 2017-01-08 09:03:01 +0800 | [diff] [blame] | 315 | git remote add caf https://source.codeaurora.org/quic/la/$PFX$PROJECT |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 316 | echo "Remote 'caf' created" |
| 317 | } |
| 318 | |
| 319 | function installboot() |
| 320 | { |
| 321 | if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ]; |
| 322 | then |
| 323 | echo "No recovery.fstab found. Build recovery first." |
| 324 | return 1 |
| 325 | fi |
| 326 | if [ ! -e "$OUT/boot.img" ]; |
| 327 | then |
| 328 | echo "No boot.img found. Run make bootimage first." |
| 329 | return 1 |
| 330 | fi |
| 331 | PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 332 | if [ -z "$PARTITION" ]; |
| 333 | then |
| 334 | # Try for RECOVERY_FSTAB_VERSION = 2 |
| 335 | PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}` |
| 336 | PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 337 | if [ -z "$PARTITION" ]; |
| 338 | then |
| 339 | echo "Unable to determine boot partition." |
| 340 | return 1 |
| 341 | fi |
| 342 | fi |
| 343 | adb start-server |
| 344 | adb wait-for-online |
| 345 | adb root |
| 346 | sleep 1 |
| 347 | adb wait-for-online shell mount /system 2>&1 > /dev/null |
| 348 | adb wait-for-online remount |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 349 | if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD"); |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 350 | then |
| 351 | adb push $OUT/boot.img /cache/ |
Ashwin Ramesh | b0ea62a | 2017-08-13 12:00:15 +0530 | [diff] [blame] | 352 | if [ -e "$OUT/system/lib/modules/*" ]; |
| 353 | then |
| 354 | for i in $OUT/system/lib/modules/*; |
| 355 | do |
| 356 | adb push $i /system/lib/modules/ |
| 357 | done |
| 358 | adb shell chmod 644 /system/lib/modules/* |
| 359 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 360 | adb shell dd if=/cache/boot.img of=$PARTITION |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 361 | echo "Installation complete." |
| 362 | else |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 363 | echo "The connected device does not appear to be $LINEAGE_BUILD, run away!" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 364 | fi |
| 365 | } |
| 366 | |
| 367 | function installrecovery() |
| 368 | { |
| 369 | if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ]; |
| 370 | then |
| 371 | echo "No recovery.fstab found. Build recovery first." |
| 372 | return 1 |
| 373 | fi |
| 374 | if [ ! -e "$OUT/recovery.img" ]; |
| 375 | then |
| 376 | echo "No recovery.img found. Run make recoveryimage first." |
| 377 | return 1 |
| 378 | fi |
| 379 | PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 380 | if [ -z "$PARTITION" ]; |
| 381 | then |
| 382 | # Try for RECOVERY_FSTAB_VERSION = 2 |
| 383 | PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}` |
| 384 | PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}` |
| 385 | if [ -z "$PARTITION" ]; |
| 386 | then |
| 387 | echo "Unable to determine recovery partition." |
| 388 | return 1 |
| 389 | fi |
| 390 | fi |
| 391 | adb start-server |
| 392 | adb wait-for-online |
| 393 | adb root |
| 394 | sleep 1 |
| 395 | adb wait-for-online shell mount /system 2>&1 >> /dev/null |
| 396 | adb wait-for-online remount |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 397 | if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD"); |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 398 | then |
| 399 | adb push $OUT/recovery.img /cache/ |
| 400 | adb shell dd if=/cache/recovery.img of=$PARTITION |
| 401 | echo "Installation complete." |
| 402 | else |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 403 | echo "The connected device does not appear to be $LINEAGE_BUILD, run away!" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 404 | fi |
| 405 | } |
| 406 | |
| 407 | function makerecipe() { |
| 408 | if [ -z "$1" ] |
| 409 | then |
| 410 | echo "No branch name provided." |
| 411 | return 1 |
| 412 | fi |
| 413 | cd android |
| 414 | sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml |
| 415 | git commit -a -m "$1" |
| 416 | cd .. |
| 417 | |
| 418 | repo forall -c ' |
| 419 | |
| 420 | if [ "$REPO_REMOTE" = "github" ] |
| 421 | then |
| 422 | pwd |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 423 | lineageremote |
| 424 | git push lineage HEAD:refs/heads/'$1' |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 425 | fi |
| 426 | ' |
| 427 | } |
| 428 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 429 | function lineagegerrit() { |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 430 | if [ "$(__detect_shell)" = "zsh" ]; then |
| 431 | # zsh does not define FUNCNAME, derive from funcstack |
| 432 | local FUNCNAME=$funcstack[1] |
| 433 | fi |
| 434 | |
| 435 | if [ $# -eq 0 ]; then |
| 436 | $FUNCNAME help |
| 437 | return 1 |
| 438 | fi |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 439 | local user=`git config --get review.review.lineageos.org.username` |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 440 | local review=`git config --get remote.github.review` |
| 441 | local project=`git config --get remote.github.projectname` |
| 442 | local command=$1 |
| 443 | shift |
| 444 | case $command in |
| 445 | help) |
| 446 | if [ $# -eq 0 ]; then |
| 447 | cat <<EOF |
| 448 | Usage: |
| 449 | $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS] |
| 450 | |
| 451 | Commands: |
| 452 | fetch Just fetch the change as FETCH_HEAD |
| 453 | help Show this help, or for a specific command |
| 454 | pull Pull a change into current branch |
| 455 | push Push HEAD or a local branch to Gerrit for a specific branch |
| 456 | |
| 457 | Any other Git commands that support refname would work as: |
| 458 | git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS |
| 459 | |
| 460 | See '$FUNCNAME help COMMAND' for more information on a specific command. |
| 461 | |
| 462 | Example: |
| 463 | $FUNCNAME checkout -b topic 1234/5 |
| 464 | works as: |
| 465 | git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\ |
| 466 | && git checkout -b topic FETCH_HEAD |
| 467 | will checkout a new branch 'topic' base on patch-set 5 of change 1234. |
| 468 | Patch-set 1 will be fetched if omitted. |
| 469 | EOF |
| 470 | return |
| 471 | fi |
| 472 | case $1 in |
| 473 | __cmg_*) echo "For internal use only." ;; |
| 474 | changes|for) |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 475 | if [ "$FUNCNAME" = "lineagegerrit" ]; then |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 476 | echo "'$FUNCNAME $1' is deprecated." |
| 477 | fi |
| 478 | ;; |
| 479 | help) $FUNCNAME help ;; |
| 480 | fetch|pull) cat <<EOF |
| 481 | usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET] |
| 482 | |
| 483 | works as: |
| 484 | git $1 OPTIONS http://DOMAIN/p/PROJECT \\ |
| 485 | refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} |
| 486 | |
| 487 | Example: |
| 488 | $FUNCNAME $1 1234 |
| 489 | will $1 patch-set 1 of change 1234 |
| 490 | EOF |
| 491 | ;; |
| 492 | push) cat <<EOF |
| 493 | usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH |
| 494 | |
| 495 | works as: |
| 496 | git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\ |
| 497 | {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH |
| 498 | |
| 499 | Example: |
| 500 | $FUNCNAME push fix6789:gingerbread |
| 501 | will push local branch 'fix6789' to Gerrit for branch 'gingerbread'. |
| 502 | HEAD will be pushed from local if omitted. |
| 503 | EOF |
| 504 | ;; |
| 505 | *) |
| 506 | $FUNCNAME __cmg_err_not_supported $1 && return |
| 507 | cat <<EOF |
| 508 | usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS] |
| 509 | |
| 510 | works as: |
| 511 | git fetch http://DOMAIN/p/PROJECT \\ |
| 512 | refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\ |
| 513 | && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS |
| 514 | EOF |
| 515 | ;; |
| 516 | esac |
| 517 | ;; |
| 518 | __cmg_get_ref) |
| 519 | $FUNCNAME __cmg_err_no_arg $command $# && return 1 |
| 520 | local change_id patchset_id hash |
| 521 | case $1 in |
| 522 | */*) |
| 523 | change_id=${1%%/*} |
| 524 | patchset_id=${1#*/} |
| 525 | ;; |
| 526 | *) |
| 527 | change_id=$1 |
| 528 | patchset_id=1 |
| 529 | ;; |
| 530 | esac |
| 531 | hash=$(($change_id % 100)) |
| 532 | case $hash in |
| 533 | [0-9]) hash="0$hash" ;; |
| 534 | esac |
| 535 | echo "refs/changes/$hash/$change_id/$patchset_id" |
| 536 | ;; |
| 537 | fetch|pull) |
| 538 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 539 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 540 | local change=$1 |
| 541 | shift |
| 542 | git $command $@ http://$review/p/$project \ |
| 543 | $($FUNCNAME __cmg_get_ref $change) || return 1 |
| 544 | ;; |
| 545 | push) |
| 546 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 547 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 548 | if [ -z "$user" ]; then |
| 549 | echo >&2 "Gerrit username not found." |
| 550 | return 1 |
| 551 | fi |
| 552 | local local_branch remote_branch |
| 553 | case $1 in |
| 554 | *:*) |
| 555 | local_branch=${1%:*} |
| 556 | remote_branch=${1##*:} |
| 557 | ;; |
| 558 | *) |
| 559 | local_branch=HEAD |
| 560 | remote_branch=$1 |
| 561 | ;; |
| 562 | esac |
| 563 | shift |
| 564 | git push $@ ssh://$user@$review:29418/$project \ |
| 565 | $local_branch:refs/for/$remote_branch || return 1 |
| 566 | ;; |
| 567 | changes|for) |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 568 | if [ "$FUNCNAME" = "lineagegerrit" ]; then |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 569 | echo >&2 "'$FUNCNAME $command' is deprecated." |
| 570 | fi |
| 571 | ;; |
| 572 | __cmg_err_no_arg) |
| 573 | if [ $# -lt 2 ]; then |
| 574 | echo >&2 "'$FUNCNAME $command' missing argument." |
| 575 | elif [ $2 -eq 0 ]; then |
| 576 | if [ -n "$3" ]; then |
| 577 | $FUNCNAME help $1 |
| 578 | else |
| 579 | echo >&2 "'$FUNCNAME $1' missing argument." |
| 580 | fi |
| 581 | else |
| 582 | return 1 |
| 583 | fi |
| 584 | ;; |
| 585 | __cmg_err_not_repo) |
| 586 | if [ -z "$review" -o -z "$project" ]; then |
| 587 | echo >&2 "Not currently in any reviewable repository." |
| 588 | else |
| 589 | return 1 |
| 590 | fi |
| 591 | ;; |
| 592 | __cmg_err_not_supported) |
| 593 | $FUNCNAME __cmg_err_no_arg $command $# && return |
| 594 | case $1 in |
| 595 | #TODO: filter more git commands that don't use refname |
| 596 | init|add|rm|mv|status|clone|remote|bisect|config|stash) |
| 597 | echo >&2 "'$FUNCNAME $1' is not supported." |
| 598 | ;; |
| 599 | *) return 1 ;; |
| 600 | esac |
| 601 | ;; |
| 602 | #TODO: other special cases? |
| 603 | *) |
| 604 | $FUNCNAME __cmg_err_not_supported $command && return 1 |
| 605 | $FUNCNAME __cmg_err_no_arg $command $# help && return 1 |
| 606 | $FUNCNAME __cmg_err_not_repo && return 1 |
| 607 | local args="$@" |
| 608 | local change pre_args refs_arg post_args |
| 609 | case "$args" in |
| 610 | *--\ *) |
| 611 | pre_args=${args%%-- *} |
| 612 | post_args="-- ${args#*-- }" |
| 613 | ;; |
| 614 | *) pre_args="$args" ;; |
| 615 | esac |
| 616 | args=($pre_args) |
| 617 | pre_args= |
| 618 | if [ ${#args[@]} -gt 0 ]; then |
| 619 | change=${args[${#args[@]}-1]} |
| 620 | fi |
| 621 | if [ ${#args[@]} -gt 1 ]; then |
| 622 | pre_args=${args[0]} |
| 623 | for ((i=1; i<${#args[@]}-1; i++)); do |
| 624 | pre_args="$pre_args ${args[$i]}" |
| 625 | done |
| 626 | fi |
| 627 | while ((1)); do |
| 628 | case $change in |
| 629 | ""|--) |
| 630 | $FUNCNAME help $command |
| 631 | return 1 |
| 632 | ;; |
| 633 | *@*) |
| 634 | if [ -z "$refs_arg" ]; then |
| 635 | refs_arg="@${change#*@}" |
| 636 | change=${change%%@*} |
| 637 | fi |
| 638 | ;; |
| 639 | *~*) |
| 640 | if [ -z "$refs_arg" ]; then |
| 641 | refs_arg="~${change#*~}" |
| 642 | change=${change%%~*} |
| 643 | fi |
| 644 | ;; |
| 645 | *^*) |
| 646 | if [ -z "$refs_arg" ]; then |
| 647 | refs_arg="^${change#*^}" |
| 648 | change=${change%%^*} |
| 649 | fi |
| 650 | ;; |
| 651 | *:*) |
| 652 | if [ -z "$refs_arg" ]; then |
| 653 | refs_arg=":${change#*:}" |
| 654 | change=${change%%:*} |
| 655 | fi |
| 656 | ;; |
| 657 | *) break ;; |
| 658 | esac |
| 659 | done |
| 660 | $FUNCNAME fetch $change \ |
| 661 | && git $command $pre_args FETCH_HEAD$refs_arg $post_args \ |
| 662 | || return 1 |
| 663 | ;; |
| 664 | esac |
| 665 | } |
| 666 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 667 | function lineagerebase() { |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 668 | local repo=$1 |
| 669 | local refs=$2 |
| 670 | local pwd="$(pwd)" |
| 671 | local dir="$(gettop)/$repo" |
| 672 | |
| 673 | if [ -z $repo ] || [ -z $refs ]; then |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 674 | echo "LineageOS Gerrit Rebase Usage: " |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 675 | echo " lineagerebase <path to project> <patch IDs on Gerrit>" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 676 | echo " The patch IDs appear on the Gerrit commands that are offered." |
| 677 | echo " They consist on a series of numbers and slashes, after the text" |
| 678 | echo " refs/changes. For example, the ID in the following command is 26/8126/2" |
| 679 | echo "" |
| 680 | echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD" |
| 681 | echo "" |
| 682 | return |
| 683 | fi |
| 684 | |
| 685 | if [ ! -d $dir ]; then |
| 686 | echo "Directory $dir doesn't exist in tree." |
| 687 | return |
| 688 | fi |
| 689 | cd $dir |
| 690 | repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g) |
| 691 | echo "Starting branch..." |
| 692 | repo start tmprebase . |
| 693 | echo "Bringing it up to date..." |
| 694 | repo sync . |
| 695 | echo "Fetching change..." |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 696 | git fetch "http://review.lineageos.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 697 | if [ "$?" != "0" ]; then |
| 698 | echo "Error cherry-picking. Not uploading!" |
| 699 | return |
| 700 | fi |
| 701 | echo "Uploading..." |
| 702 | repo upload . |
| 703 | echo "Cleaning up..." |
| 704 | repo abandon tmprebase . |
| 705 | cd $pwd |
| 706 | } |
| 707 | |
| 708 | function mka() { |
Luca Stefani | 085af72 | 2017-08-17 20:34:44 +0200 | [diff] [blame] | 709 | m -j "$@" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | function cmka() { |
| 713 | if [ ! -z "$1" ]; then |
| 714 | for i in "$@"; do |
| 715 | case $i in |
| 716 | bacon|otapackage|systemimage) |
| 717 | mka installclean |
| 718 | mka $i |
| 719 | ;; |
| 720 | *) |
| 721 | mka clean-$i |
| 722 | mka $i |
| 723 | ;; |
| 724 | esac |
| 725 | done |
| 726 | else |
| 727 | mka clean |
| 728 | mka |
| 729 | fi |
| 730 | } |
| 731 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 732 | function repolastsync() { |
| 733 | RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json" |
| 734 | RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z") |
| 735 | RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z") |
| 736 | echo "Last repo sync: $RLSLOCAL / $RLSUTC" |
| 737 | } |
| 738 | |
| 739 | function reposync() { |
Luca Stefani | 085af72 | 2017-08-17 20:34:44 +0200 | [diff] [blame] | 740 | repo sync -j 4 "$@" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | function repodiff() { |
| 744 | if [ -z "$*" ]; then |
| 745 | echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]" |
| 746 | return |
| 747 | fi |
| 748 | diffopts=$* repo forall -c \ |
| 749 | 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;' |
| 750 | } |
| 751 | |
| 752 | # Return success if adb is up and not in recovery |
| 753 | function _adb_connected { |
| 754 | { |
| 755 | if [[ "$(adb get-state)" == device && |
Marc K | 299137f | 2016-10-20 10:27:10 +0200 | [diff] [blame] | 756 | "$(adb shell test -e /sbin/recovery; echo $?)" != 0 ]] |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 757 | then |
| 758 | return 0 |
| 759 | fi |
| 760 | } 2>/dev/null |
| 761 | |
| 762 | return 1 |
| 763 | }; |
| 764 | |
| 765 | # Credit for color strip sed: http://goo.gl/BoIcm |
| 766 | function dopush() |
| 767 | { |
| 768 | local func=$1 |
| 769 | shift |
| 770 | |
| 771 | adb start-server # Prevent unexpected starting server message from adb get-state in the next line |
| 772 | if ! _adb_connected; then |
| 773 | echo "No device is online. Waiting for one..." |
| 774 | echo "Please connect USB and/or enable USB debugging" |
| 775 | until _adb_connected; do |
| 776 | sleep 1 |
| 777 | done |
| 778 | echo "Device Found." |
| 779 | fi |
| 780 | |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 781 | if (adb shell getprop ro.lineage.device | grep -q "$LINEAGE_BUILD") || [ "$FORCE_PUSH" = "true" ]; |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 782 | then |
| 783 | # retrieve IP and PORT info if we're using a TCP connection |
Marc K | 2be9cac | 2016-10-20 10:27:35 +0200 | [diff] [blame] | 784 | TCPIPPORT=$(adb devices \ |
| 785 | | 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 786 | | head -1 | awk '{print $1}') |
| 787 | adb root &> /dev/null |
| 788 | sleep 0.3 |
| 789 | if [ -n "$TCPIPPORT" ] |
| 790 | then |
| 791 | # adb root just killed our connection |
| 792 | # so reconnect... |
| 793 | adb connect "$TCPIPPORT" |
| 794 | fi |
| 795 | adb wait-for-device &> /dev/null |
| 796 | sleep 0.3 |
| 797 | adb remount &> /dev/null |
| 798 | |
| 799 | mkdir -p $OUT |
| 800 | ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]}) |
| 801 | ret=$?; |
| 802 | if [ $ret -ne 0 ]; then |
| 803 | rm -f $OUT/.log;return $ret |
| 804 | fi |
| 805 | |
Rashed Abdel-Tawab | 0180664 | 2017-01-19 15:52:13 -0500 | [diff] [blame] | 806 | is_gnu_sed=`sed --version | head -1 | grep -c GNU` |
| 807 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 808 | # Install: <file> |
Rashed Abdel-Tawab | 0180664 | 2017-01-19 15:52:13 -0500 | [diff] [blame] | 809 | if [ $is_gnu_sed -gt 0 ]; then |
Marc K | 97b035d | 2016-10-20 10:27:44 +0200 | [diff] [blame] | 810 | 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}\] +//' \ |
| 811 | | grep '^Install: ' | cut -d ':' -f 2)" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 812 | else |
Marc K | 97b035d | 2016-10-20 10:27:44 +0200 | [diff] [blame] | 813 | 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}\] +//" \ |
| 814 | | grep '^Install: ' | cut -d ':' -f 2)" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 815 | fi |
| 816 | |
| 817 | # Copy: <file> |
Rashed Abdel-Tawab | 0180664 | 2017-01-19 15:52:13 -0500 | [diff] [blame] | 818 | if [ $is_gnu_sed -gt 0 ]; then |
Marc K | 97b035d | 2016-10-20 10:27:44 +0200 | [diff] [blame] | 819 | 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}\] +//' \ |
| 820 | | grep '^Copy: ' | cut -d ':' -f 2)" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 821 | else |
Marc K | 97b035d | 2016-10-20 10:27:44 +0200 | [diff] [blame] | 822 | 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}\] +//' \ |
| 823 | | grep '^Copy: ' | cut -d ':' -f 2)" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 824 | fi |
| 825 | |
| 826 | # If any files are going to /data, push an octal file permissions reader to device |
| 827 | if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then |
| 828 | CHKPERM="/data/local/tmp/chkfileperm.sh" |
| 829 | ( |
| 830 | cat <<'EOF' |
| 831 | #!/system/xbin/sh |
| 832 | FILE=$@ |
| 833 | if [ -e $FILE ]; then |
| 834 | 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 |
| 835 | fi |
| 836 | EOF |
| 837 | ) > $OUT/.chkfileperm.sh |
| 838 | echo "Pushing file permissions checker to device" |
| 839 | adb push $OUT/.chkfileperm.sh $CHKPERM |
| 840 | adb shell chmod 755 $CHKPERM |
| 841 | rm -f $OUT/.chkfileperm.sh |
| 842 | fi |
| 843 | |
| 844 | stop_n_start=false |
| 845 | for FILE in $(echo $LOC | tr " " "\n"); do |
| 846 | # Make sure file is in $OUT/system or $OUT/data |
| 847 | case $FILE in |
| 848 | $OUT/system/*|$OUT/data/*) |
| 849 | # Get target file name (i.e. /system/bin/adb) |
| 850 | TARGET=$(echo $FILE | sed "s#$OUT##") |
| 851 | ;; |
| 852 | *) continue ;; |
| 853 | esac |
| 854 | |
| 855 | case $TARGET in |
| 856 | /data/*) |
| 857 | # fs_config only sets permissions and se labels for files pushed to /system |
| 858 | if [ -n "$CHKPERM" ]; then |
| 859 | OLDPERM=$(adb shell $CHKPERM $TARGET) |
| 860 | OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n') |
| 861 | OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}') |
| 862 | OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}') |
| 863 | fi |
| 864 | echo "Pushing: $TARGET" |
| 865 | adb push $FILE $TARGET |
| 866 | if [ -n "$OLDPERM" ]; then |
| 867 | echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP" |
| 868 | adb shell chown "$OLDOWN":"$OLDGRP" $TARGET |
| 869 | adb shell chmod "$OLDPERM" $TARGET |
| 870 | else |
| 871 | echo "$TARGET did not exist previously, you should set file permissions manually" |
| 872 | fi |
| 873 | adb shell restorecon "$TARGET" |
| 874 | ;; |
| 875 | /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*) |
| 876 | # Only need to stop services once |
| 877 | if ! $stop_n_start; then |
| 878 | adb shell stop |
| 879 | stop_n_start=true |
| 880 | fi |
| 881 | echo "Pushing: $TARGET" |
| 882 | adb push $FILE $TARGET |
| 883 | ;; |
| 884 | *) |
| 885 | echo "Pushing: $TARGET" |
| 886 | adb push $FILE $TARGET |
| 887 | ;; |
| 888 | esac |
| 889 | done |
| 890 | if [ -n "$CHKPERM" ]; then |
| 891 | adb shell rm $CHKPERM |
| 892 | fi |
| 893 | if $stop_n_start; then |
| 894 | adb shell start |
| 895 | fi |
| 896 | rm -f $OUT/.log |
| 897 | return 0 |
| 898 | else |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 899 | echo "The connected device does not appear to be $LINEAGE_BUILD, run away!" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 900 | fi |
| 901 | } |
| 902 | |
| 903 | alias mmp='dopush mm' |
| 904 | alias mmmp='dopush mmm' |
| 905 | alias mmap='dopush mma' |
Zhao Wei Liew | 64fc5ae | 2016-12-10 16:48:27 +0800 | [diff] [blame] | 906 | alias mmmap='dopush mmma' |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 907 | alias mkap='dopush mka' |
| 908 | alias cmkap='dopush cmka' |
| 909 | |
| 910 | function repopick() { |
| 911 | T=$(gettop) |
Dan Pasanen | 91f7620 | 2017-07-06 08:21:30 -0500 | [diff] [blame] | 912 | $T/vendor/lineage/build/tools/repopick.py $@ |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | function fixup_common_out_dir() { |
| 916 | common_out_dir=$(get_build_var OUT_DIR)/target/common |
| 917 | target_device=$(get_build_var TARGET_DEVICE) |
Luca Stefani | 5c60e4f | 2017-08-17 19:28:48 +0200 | [diff] [blame] | 918 | if [ ! -z $LINEAGE_FIXUP_COMMON_OUT ]; then |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 919 | if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then |
| 920 | mv ${common_out_dir} ${common_out_dir}-${target_device} |
| 921 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 922 | else |
| 923 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 924 | mkdir -p ${common_out_dir}-${target_device} |
| 925 | ln -s ${common_out_dir}-${target_device} ${common_out_dir} |
| 926 | fi |
| 927 | else |
| 928 | [ -L ${common_out_dir} ] && rm ${common_out_dir} |
| 929 | mkdir -p ${common_out_dir} |
| 930 | fi |
| 931 | } |
Steve Kondik | 26e669b | 2016-11-04 12:05:19 -0700 | [diff] [blame] | 932 | |
| 933 | # Enable SD-LLVM if available |
| 934 | if [ -d $(gettop)/prebuilts/snapdragon-llvm/toolchains ]; then |
Alexander Martinz | 1bbf3e9 | 2016-11-05 15:27:43 +0100 | [diff] [blame] | 935 | case `uname -s` in |
| 936 | Darwin) |
| 937 | # Darwin is not supported yet |
| 938 | ;; |
| 939 | *) |
| 940 | export SDCLANG=true |
| 941 | export SDCLANG_PATH=$(gettop)/prebuilts/snapdragon-llvm/toolchains/llvm-Snapdragon_LLVM_for_Android_3.8/prebuilt/linux-x86_64/bin |
| 942 | export SDCLANG_LTO_DEFS=$(gettop)/device/qcom/common/sdllvm-lto-defs.mk |
| 943 | ;; |
| 944 | esac |
Steve Kondik | 26e669b | 2016-11-04 12:05:19 -0700 | [diff] [blame] | 945 | fi |
Luca Stefani | 84fda60 | 2016-11-24 14:16:33 +0100 | [diff] [blame] | 946 | |
| 947 | # Android specific JACK args |
| 948 | if [ -n "$JACK_SERVER_VM_ARGUMENTS" ] && [ -z "$ANDROID_JACK_VM_ARGS" ]; then |
| 949 | export ANDROID_JACK_VM_ARGS=$JACK_SERVER_VM_ARGUMENTS |
| 950 | fi |