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