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