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