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