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