Scott Anderson | 1a5fc95 | 2012-03-07 17:15:06 -0800 | [diff] [blame] | 1 | function hmm() { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 2 | cat <<EOF |
Jeff Gaston | c6dfc4e | 2017-05-30 17:12:37 -0700 | [diff] [blame] | 3 | |
| 4 | Run "m help" for help with the build system itself. |
| 5 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 6 | Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment: |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 7 | - lunch: lunch <product_name>-<build_variant> |
| 8 | Selects <product_name> as the product to build, and <build_variant> as the variant to |
| 9 | build, and stores those selections in the environment to be read by subsequent |
| 10 | invocations of 'm' etc. |
Elliott Hughes | f71c05a | 2020-03-06 16:46:59 -0800 | [diff] [blame] | 11 | - tapas: tapas [<App1> <App2> ...] [arm|x86|arm64|x86_64] [eng|userdebug|user] |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 12 | Sets up the build environment for building unbundled apps (APKs). |
Anton Hansson | 90ac61c | 2022-09-06 14:36:00 +0000 | [diff] [blame] | 13 | - banchan: banchan <module1> [<module2> ...] [arm|x86|arm64|x86_64|arm64_only|x86_64only] \ |
| 14 | [eng|userdebug|user] |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 15 | Sets up the build environment for building unbundled modules (APEXes). |
Anton Hansson | ece9c48 | 2019-02-04 18:15:39 +0000 | [diff] [blame] | 16 | - croot: Changes directory to the top of the tree, or a subdirectory thereof. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 17 | - m: Makes from the top of the tree. |
Dan Willemsen | 67074fe | 2019-10-30 12:35:34 -0700 | [diff] [blame] | 18 | - mm: Builds and installs all of the modules in the current directory, and their |
| 19 | dependencies. |
| 20 | - mmm: Builds and installs all of the modules in the supplied directories, and their |
| 21 | dependencies. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 22 | To limit the modules being built use the syntax: mmm dir/:target1,target2. |
Dan Willemsen | 67074fe | 2019-10-30 12:35:34 -0700 | [diff] [blame] | 23 | - mma: Same as 'mm' |
| 24 | - mmma: Same as 'mmm' |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 25 | - provision: Flash device with all required partitions. Options will be passed on to fastboot. |
| 26 | - cgrep: Greps on all local C/C++ files. |
| 27 | - ggrep: Greps on all local Gradle files. |
Orion Hodson | 831472d | 2019-10-25 11:35:15 +0100 | [diff] [blame] | 28 | - gogrep: Greps on all local Go files. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 29 | - jgrep: Greps on all local Java files. |
Taesu Lee | ea0cecd | 2020-10-28 11:05:18 +0900 | [diff] [blame] | 30 | - ktgrep: Greps on all local Kotlin files. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 31 | - resgrep: Greps on all local res/*.xml files. |
| 32 | - mangrep: Greps on all local AndroidManifest.xml files. |
Jaewoong Jung | 892d0fe | 2019-05-04 10:06:28 -0700 | [diff] [blame] | 33 | - mgrep: Greps on all local Makefiles and *.bp files. |
Jeff Sharkey | f17cddf | 2019-08-21 12:51:26 -0600 | [diff] [blame] | 34 | - owngrep: Greps on all local OWNERS files. |
Alistair Delva | 176e534 | 2021-02-22 13:31:26 -0800 | [diff] [blame] | 35 | - rsgrep: Greps on all local Rust files. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 36 | - sepgrep: Greps on all local sepolicy files. |
| 37 | - sgrep: Greps on all local source files. |
DroidFreak32 | a278198 | 2020-11-26 11:30:19 -0500 | [diff] [blame] | 38 | - pygrep: Greps on all local Python files. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 39 | - godir: Go to the directory containing a file. |
| 40 | - allmod: List all modules. |
| 41 | - gomod: Go to the directory containing a module. |
Jingwen Chen | 83eeebb | 2022-10-05 02:27:07 +0000 | [diff] [blame] | 42 | - bmod: Get the Bazel label of a Soong module if it is converted with bp2build. |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 43 | - pathmod: Get the directory containing a module. |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 44 | - outmod: Gets the location of a module's installed outputs with a certain extension. |
Joe Onorato | 2c1aa47 | 2021-02-25 16:42:39 -0800 | [diff] [blame] | 45 | - dirmods: Gets the modules defined in a given directory. |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 46 | - installmod: Adb installs a module's built APK. |
| 47 | - refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod. |
Steven Moreland | 74114f1 | 2020-09-10 01:23:32 +0000 | [diff] [blame] | 48 | - syswrite: Remount partitions (e.g. system.img) as writable, rebooting if necessary. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | |
Roland Levillain | 3934192 | 2015-10-20 12:48:19 +0100 | [diff] [blame] | 50 | Environment options: |
Steven Moreland | 115d1f5 | 2019-09-26 16:30:28 -0700 | [diff] [blame] | 51 | - SANITIZE_HOST: Set to 'address' to use ASAN for all host modules. |
Sasha Smundak | 9f27cc0 | 2019-01-31 13:25:31 -0800 | [diff] [blame] | 52 | - ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages. |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 53 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 54 | Look at the source to view more functions. The complete list is: |
| 55 | EOF |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 56 | local T=$(gettop) |
| 57 | local A="" |
| 58 | local i |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 59 | for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 60 | A="$A $i" |
| 61 | done |
| 62 | echo $A |
| 63 | } |
| 64 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 65 | # Get all the build variables needed by this script in a single call to the build system. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 66 | function build_build_var_cache() |
| 67 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 68 | local T=$(gettop) |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 69 | # Grep out the variable names from the script. |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 70 | cached_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`) |
| 71 | cached_abs_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`) |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 72 | # Call the build system to dump the "<val>=<value>" pairs as a shell script. |
Steven Moreland | 0540296 | 2018-01-05 12:13:11 -0800 | [diff] [blame] | 73 | build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \ |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 74 | --vars="${cached_vars[*]}" \ |
| 75 | --abs-vars="${cached_abs_vars[*]}" \ |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 76 | --var-prefix=var_cache_ \ |
| 77 | --abs-var-prefix=abs_var_cache_` |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 78 | local ret=$? |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 79 | if [ $ret -ne 0 ] |
| 80 | then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 81 | unset build_dicts_script |
| 82 | return $ret |
| 83 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 84 | # Execute the script to store the "<val>=<value>" pairs as shell variables. |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 85 | eval "$build_dicts_script" |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 86 | ret=$? |
Ying Wang | f0cb397 | 2016-03-04 13:56:23 -0800 | [diff] [blame] | 87 | unset build_dicts_script |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 88 | if [ $ret -ne 0 ] |
| 89 | then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 90 | return $ret |
| 91 | fi |
| 92 | BUILD_VAR_CACHE_READY="true" |
| 93 | } |
| 94 | |
Ying Wang | f0cb397 | 2016-03-04 13:56:23 -0800 | [diff] [blame] | 95 | # Delete the build var cache, so that we can still call into the build system |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 96 | # to get build variables not listed in this script. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 97 | function destroy_build_var_cache() |
| 98 | { |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 99 | unset BUILD_VAR_CACHE_READY |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 100 | local v |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 101 | for v in $cached_vars; do |
| 102 | unset var_cache_$v |
| 103 | done |
| 104 | unset cached_vars |
| 105 | for v in $cached_abs_vars; do |
| 106 | unset abs_var_cache_$v |
| 107 | done |
| 108 | unset cached_abs_vars |
| 109 | } |
| 110 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 111 | # Get the value of a build variable as an absolute path. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 112 | function get_abs_build_var() |
| 113 | { |
| 114 | if [ "$BUILD_VAR_CACHE_READY" = "true" ] |
| 115 | then |
Vishwath Mohan | 7d35f00 | 2016-03-11 10:00:40 -0800 | [diff] [blame] | 116 | eval "echo \"\${abs_var_cache_$1}\"" |
Timi | 0469c3f | 2021-04-15 16:41:18 +0200 | [diff] [blame] | 117 | return |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 118 | fi |
| 119 | |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 120 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 121 | if [ ! "$T" ]; then |
| 122 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 123 | return |
| 124 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 125 | (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | # Get the exact value of a build variable. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 129 | function get_build_var() |
| 130 | { |
| 131 | if [ "$BUILD_VAR_CACHE_READY" = "true" ] |
| 132 | then |
Vishwath Mohan | 7d35f00 | 2016-03-11 10:00:40 -0800 | [diff] [blame] | 133 | eval "echo \"\${var_cache_$1}\"" |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 134 | return 0 |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 135 | fi |
| 136 | |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 137 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 138 | if [ ! "$T" ]; then |
| 139 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 140 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 141 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 142 | (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | # check to see if the supplied product is one we can build |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 146 | function check_product() |
| 147 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 148 | local T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 149 | if [ ! "$T" ]; then |
| 150 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 151 | return |
| 152 | fi |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 153 | TARGET_PRODUCT=$1 \ |
| 154 | TARGET_BUILD_VARIANT= \ |
| 155 | TARGET_BUILD_TYPE= \ |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 156 | TARGET_BUILD_APPS= \ |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 157 | get_build_var TARGET_DEVICE > /dev/null |
| 158 | # hide successful answers, but allow the errors to show |
| 159 | } |
| 160 | |
| 161 | VARIANT_CHOICES=(user userdebug eng) |
| 162 | |
| 163 | # check to see if the supplied variant is valid |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 164 | function check_variant() |
| 165 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 166 | local v |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 167 | for v in ${VARIANT_CHOICES[@]} |
| 168 | do |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 169 | if [ "$v" = "$1" ] |
| 170 | then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 171 | return 0 |
| 172 | fi |
| 173 | done |
| 174 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 177 | function setpaths() |
| 178 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 179 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 180 | if [ ! "$T" ]; then |
| 181 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 182 | return |
| 183 | fi |
| 184 | |
| 185 | ################################################################## |
| 186 | # # |
| 187 | # Read me before you modify this code # |
| 188 | # # |
| 189 | # This function sets ANDROID_BUILD_PATHS to what it is adding # |
| 190 | # to PATH, and the next time it is run, it removes that from # |
| 191 | # PATH. This is required so lunch can be run more than once # |
| 192 | # and still have working paths. # |
| 193 | # # |
| 194 | ################################################################## |
| 195 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 196 | # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces |
| 197 | # due to "C:\Program Files" being in the path. |
| 198 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 199 | # out with the old |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 200 | if [ -n "$ANDROID_BUILD_PATHS" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 201 | export PATH=${PATH/$ANDROID_BUILD_PATHS/} |
| 202 | fi |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 203 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 204 | export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} |
Ying Wang | aa1c9b5 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 205 | # strip leading ':', if any |
| 206 | export PATH=${PATH/:%/} |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 207 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 208 | |
| 209 | # and in with the new |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 210 | |
Dan Willemsen | 838dcec | 2021-09-30 22:40:34 +0000 | [diff] [blame] | 211 | export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools |
Yueyao Zhu | efc786a | 2017-04-07 14:11:54 -0700 | [diff] [blame] | 212 | |
| 213 | # add kernel specific binaries |
| 214 | case $(uname -s) in |
| 215 | Linux) |
| 216 | export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt |
| 217 | ;; |
| 218 | *) |
| 219 | ;; |
| 220 | esac |
| 221 | |
Colin Cross | c0b0104 | 2022-10-05 12:03:03 -0700 | [diff] [blame] | 222 | ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS) |
Yi Kong | dfd00b1 | 2019-05-21 16:00:04 -0700 | [diff] [blame] | 223 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS |
| 224 | |
| 225 | # Append llvm binutils prebuilts path to ANDROID_BUILD_PATHS. |
| 226 | local ANDROID_LLVM_BINUTILS=$(get_abs_build_var ANDROID_CLANG_PREBUILTS)/llvm-binutils-stable |
| 227 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_LLVM_BINUTILS |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 228 | |
Stephen Hines | aa8d72c | 2020-02-04 09:15:18 -0800 | [diff] [blame] | 229 | # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds. |
| 230 | export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer |
| 231 | |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 232 | # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH |
| 233 | # to ensure that the corresponding 'emulator' binaries are used. |
| 234 | case $(uname -s) in |
| 235 | Darwin) |
| 236 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64 |
| 237 | ;; |
| 238 | Linux) |
| 239 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64 |
| 240 | ;; |
| 241 | *) |
| 242 | ANDROID_EMULATOR_PREBUILTS= |
| 243 | ;; |
| 244 | esac |
| 245 | if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then |
Yi Kong | dfd00b1 | 2019-05-21 16:00:04 -0700 | [diff] [blame] | 246 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_EMULATOR_PREBUILTS |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 247 | export ANDROID_EMULATOR_PREBUILTS |
| 248 | fi |
| 249 | |
Jim Tang | b3fda30 | 2018-12-22 10:24:55 +0800 | [diff] [blame] | 250 | # Append asuite prebuilts path to ANDROID_BUILD_PATHS. |
| 251 | local os_arch=$(get_build_var HOST_PREBUILT_TAG) |
Ryan Prichard | 8426a19 | 2019-07-15 18:05:29 -0700 | [diff] [blame] | 252 | local ACLOUD_PATH="$T/prebuilts/asuite/acloud/$os_arch" |
| 253 | local AIDEGEN_PATH="$T/prebuilts/asuite/aidegen/$os_arch" |
| 254 | local ATEST_PATH="$T/prebuilts/asuite/atest/$os_arch" |
Martin Stjernholm | 6a01226 | 2021-11-24 14:56:15 +0000 | [diff] [blame] | 255 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ACLOUD_PATH:$AIDEGEN_PATH:$ATEST_PATH |
Jim Tang | b3fda30 | 2018-12-22 10:24:55 +0800 | [diff] [blame] | 256 | |
Joe Onorato | 404fde5 | 2022-10-24 04:35:48 -0700 | [diff] [blame] | 257 | # Build system |
| 258 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$T/build/bazel/bin |
| 259 | |
Martin Stjernholm | 6a01226 | 2021-11-24 14:56:15 +0000 | [diff] [blame] | 260 | export ANDROID_BUILD_PATHS=$(tr -s : <<<"${ANDROID_BUILD_PATHS}:") |
Ryan Prichard | 8426a19 | 2019-07-15 18:05:29 -0700 | [diff] [blame] | 261 | export PATH=$ANDROID_BUILD_PATHS$PATH |
Jim Tang | 22f4c32 | 2018-12-17 15:21:53 +0800 | [diff] [blame] | 262 | |
| 263 | # out with the duplicate old |
| 264 | if [ -n $ANDROID_PYTHONPATH ]; then |
| 265 | export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/} |
| 266 | fi |
| 267 | # and in with the new |
| 268 | export ANDROID_PYTHONPATH=$T/development/python-packages: |
Jim Tang | c4dba1d | 2019-07-25 16:54:27 +0800 | [diff] [blame] | 269 | if [ -n $VENDOR_PYTHONPATH ]; then |
| 270 | ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH |
| 271 | fi |
Jim Tang | 22f4c32 | 2018-12-17 15:21:53 +0800 | [diff] [blame] | 272 | export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 273 | |
Colin Cross | e97e693 | 2017-06-30 16:01:45 -0700 | [diff] [blame] | 274 | export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME) |
| 275 | export JAVA_HOME=$ANDROID_JAVA_HOME |
| 276 | export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN) |
| 277 | export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN: |
| 278 | export PATH=$ANDROID_PRE_BUILD_PATHS$PATH |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 279 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 280 | unset ANDROID_PRODUCT_OUT |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 281 | export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) |
| 282 | export OUT=$ANDROID_PRODUCT_OUT |
| 283 | |
Jeff Brown | 8fd5cce | 2011-03-24 17:03:06 -0700 | [diff] [blame] | 284 | unset ANDROID_HOST_OUT |
| 285 | export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) |
| 286 | |
Jiyong Park | c02b1c4 | 2020-11-03 11:06:39 +0900 | [diff] [blame] | 287 | unset ANDROID_SOONG_HOST_OUT |
| 288 | export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT) |
| 289 | |
Simran Basi | dd050ed | 2017-02-13 13:46:48 -0800 | [diff] [blame] | 290 | unset ANDROID_HOST_OUT_TESTCASES |
| 291 | export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES) |
| 292 | |
| 293 | unset ANDROID_TARGET_OUT_TESTCASES |
| 294 | export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES) |
| 295 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 296 | # needed for building linux on MacOS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 297 | # TODO: fix the path |
| 298 | #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include |
| 299 | } |
| 300 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 301 | function printconfig() |
| 302 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 303 | local T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 304 | if [ ! "$T" ]; then |
| 305 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 306 | return |
| 307 | fi |
| 308 | get_build_var report_config |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 311 | function set_stuff_for_environment() |
| 312 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 313 | setpaths |
| 314 | set_sequence_number |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 315 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 316 | export ANDROID_BUILD_TOP=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 319 | function set_sequence_number() |
| 320 | { |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 321 | export BUILD_ENV_SEQUENCE_NUMBER=13 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 324 | # Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not. |
| 325 | function should_add_completion() { |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 326 | local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')" |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 327 | case :"$ENVSETUP_NO_COMPLETION": in |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 328 | *:"$cmd":*) |
| 329 | return 1 |
| 330 | ;; |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 331 | esac |
| 332 | return 0 |
| 333 | } |
| 334 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 335 | function addcompletions() |
| 336 | { |
Ben Taitelbaum | 8c2c9cf | 2020-09-22 16:45:05 -0700 | [diff] [blame] | 337 | local f= |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 338 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 339 | # Keep us from trying to run in something that's neither bash nor zsh. |
| 340 | if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 341 | return |
| 342 | fi |
| 343 | |
| 344 | # Keep us from trying to run in bash that's too old. |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 345 | if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 346 | return |
| 347 | fi |
| 348 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 349 | local completion_files=( |
MÃ¥rten Kongstad | cb5c73f | 2022-05-04 14:08:12 +0000 | [diff] [blame] | 350 | packages/modules/adb/adb.bash |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 351 | system/core/fastboot/fastboot.bash |
Jim Tang | b3fda30 | 2018-12-22 10:24:55 +0800 | [diff] [blame] | 352 | tools/asuite/asuite.sh |
Chris Parsons | a297297 | 2022-08-31 15:04:38 -0400 | [diff] [blame] | 353 | prebuilts/bazel/common/bazel-complete.bash |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 354 | ) |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 355 | # Completion can be disabled selectively to allow users to use non-standard completion. |
| 356 | # e.g. |
| 357 | # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion |
| 358 | # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion |
Usta Shrestha | 1433fb3 | 2022-05-13 14:49:40 -0400 | [diff] [blame] | 359 | local T=$(gettop) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 360 | for f in ${completion_files[*]}; do |
Usta Shrestha | 1433fb3 | 2022-05-13 14:49:40 -0400 | [diff] [blame] | 361 | f="$T/$f" |
MÃ¥rten Kongstad | cb5c73f | 2022-05-04 14:08:12 +0000 | [diff] [blame] | 362 | if [ ! -f "$f" ]; then |
| 363 | echo "Warning: completion file $f not found" |
| 364 | elif should_add_completion "$f"; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 365 | . $f |
Elliott Hughes | ce18dd4 | 2018-04-03 13:49:48 -0700 | [diff] [blame] | 366 | fi |
| 367 | done |
Joe Onorato | 002a6c7 | 2016-10-20 16:39:49 -0700 | [diff] [blame] | 368 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 369 | if should_add_completion bit ; then |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 370 | complete -C "bit --tab" bit |
| 371 | fi |
Anton Hansson | ece9c48 | 2019-02-04 18:15:39 +0000 | [diff] [blame] | 372 | if [ -z "$ZSH_VERSION" ]; then |
| 373 | # Doesn't work in zsh. |
| 374 | complete -o nospace -F _croot croot |
Chris Parsons | a297297 | 2022-08-31 15:04:38 -0400 | [diff] [blame] | 375 | # TODO(b/244559459): Support b autocompletion for zsh |
| 376 | complete -F _bazel__complete -o nospace b |
Anton Hansson | ece9c48 | 2019-02-04 18:15:39 +0000 | [diff] [blame] | 377 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 378 | complete -F _lunch lunch |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 379 | |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 380 | complete -F _complete_android_module_names pathmod |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame] | 381 | complete -F _complete_android_module_names gomod |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 382 | complete -F _complete_android_module_names outmod |
| 383 | complete -F _complete_android_module_names installmod |
Jingwen Chen | 83eeebb | 2022-10-05 02:27:07 +0000 | [diff] [blame] | 384 | complete -F _complete_android_module_names bmod |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame] | 385 | complete -F _complete_android_module_names m |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Joe Onorato | 824608c | 2022-04-08 11:06:16 -0700 | [diff] [blame] | 388 | function multitree_lunch_help() |
| 389 | { |
| 390 | echo "usage: lunch PRODUCT-VARIANT" 1>&2 |
| 391 | echo " Set up android build environment based on a product short name and variant" 1>&2 |
| 392 | echo 1>&2 |
| 393 | echo "lunch COMBO_FILE VARIANT" 1>&2 |
| 394 | echo " Set up android build environment based on a specific lunch combo file" 1>&2 |
| 395 | echo " and variant." 1>&2 |
| 396 | echo 1>&2 |
| 397 | echo "lunch --print [CONFIG]" 1>&2 |
| 398 | echo " Print the contents of a configuration. If CONFIG is supplied, that config" 1>&2 |
| 399 | echo " will be flattened and printed. If CONFIG is not supplied, the currently" 1>&2 |
| 400 | echo " selected config will be printed. Returns 0 on success or nonzero on error." 1>&2 |
| 401 | echo 1>&2 |
| 402 | echo "lunch --list" 1>&2 |
| 403 | echo " List all possible combo files available in the current tree" 1>&2 |
| 404 | echo 1>&2 |
| 405 | echo "lunch --help" 1>&2 |
| 406 | echo "lunch -h" 1>&2 |
| 407 | echo " Prints this message." 1>&2 |
| 408 | } |
| 409 | |
| 410 | function multitree_lunch() |
| 411 | { |
| 412 | local code |
| 413 | local results |
LaMont Jones | c39e502 | 2022-06-23 19:09:06 +0000 | [diff] [blame] | 414 | # Lunch must be run in the topdir, but this way we get a clear error |
| 415 | # message, instead of FileNotFound. |
| 416 | local T=$(multitree_gettop) |
| 417 | if [ -n "$T" ]; then |
LaMont Jones | 5151ddc | 2022-10-13 23:05:15 +0000 | [diff] [blame] | 418 | "$T/orchestrator/build/orchestrator/core/lunch.py" "$@" |
LaMont Jones | c39e502 | 2022-06-23 19:09:06 +0000 | [diff] [blame] | 419 | else |
| 420 | _multitree_lunch_error |
| 421 | return 1 |
| 422 | fi |
Joe Onorato | 824608c | 2022-04-08 11:06:16 -0700 | [diff] [blame] | 423 | if $(echo "$1" | grep -q '^-') ; then |
| 424 | # Calls starting with a -- argument are passed directly and the function |
| 425 | # returns with the lunch.py exit code. |
Spandan Das | ca76205 | 2022-09-21 00:08:34 +0000 | [diff] [blame] | 426 | "${T}/orchestrator/build/orchestrator/core/lunch.py" "$@" |
Joe Onorato | 824608c | 2022-04-08 11:06:16 -0700 | [diff] [blame] | 427 | code=$? |
| 428 | if [[ $code -eq 2 ]] ; then |
| 429 | echo 1>&2 |
| 430 | multitree_lunch_help |
| 431 | return $code |
| 432 | elif [[ $code -ne 0 ]] ; then |
| 433 | return $code |
| 434 | fi |
| 435 | else |
| 436 | # All other calls go through the --lunch variant of lunch.py |
Spandan Das | ca76205 | 2022-09-21 00:08:34 +0000 | [diff] [blame] | 437 | results=($(${T}/orchestrator/build/orchestrator/core/lunch.py --lunch "$@")) |
Joe Onorato | 824608c | 2022-04-08 11:06:16 -0700 | [diff] [blame] | 438 | code=$? |
| 439 | if [[ $code -eq 2 ]] ; then |
| 440 | echo 1>&2 |
| 441 | multitree_lunch_help |
| 442 | return $code |
| 443 | elif [[ $code -ne 0 ]] ; then |
| 444 | return $code |
| 445 | fi |
| 446 | |
| 447 | export TARGET_BUILD_COMBO=${results[0]} |
| 448 | export TARGET_BUILD_VARIANT=${results[1]} |
| 449 | fi |
| 450 | } |
| 451 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 452 | function choosetype() |
| 453 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 454 | echo "Build type choices are:" |
| 455 | echo " 1. release" |
| 456 | echo " 2. debug" |
| 457 | echo |
| 458 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 459 | local DEFAULT_NUM DEFAULT_VALUE |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 460 | DEFAULT_NUM=1 |
| 461 | DEFAULT_VALUE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 462 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 463 | export TARGET_BUILD_TYPE= |
| 464 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 465 | while [ -z $TARGET_BUILD_TYPE ] |
| 466 | do |
| 467 | echo -n "Which would you like? ["$DEFAULT_NUM"] " |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 468 | if [ -z "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 469 | read ANSWER |
| 470 | else |
| 471 | echo $1 |
| 472 | ANSWER=$1 |
| 473 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 474 | case $ANSWER in |
| 475 | "") |
| 476 | export TARGET_BUILD_TYPE=$DEFAULT_VALUE |
| 477 | ;; |
| 478 | 1) |
| 479 | export TARGET_BUILD_TYPE=release |
| 480 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 481 | release) |
| 482 | export TARGET_BUILD_TYPE=release |
| 483 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 484 | 2) |
| 485 | export TARGET_BUILD_TYPE=debug |
| 486 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 487 | debug) |
| 488 | export TARGET_BUILD_TYPE=debug |
| 489 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 490 | *) |
| 491 | echo |
| 492 | echo "I didn't understand your response. Please try again." |
| 493 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 494 | ;; |
| 495 | esac |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 496 | if [ -n "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 497 | break |
| 498 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 499 | done |
| 500 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 501 | build_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 502 | set_stuff_for_environment |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 503 | destroy_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 504 | } |
| 505 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 506 | # |
| 507 | # This function isn't really right: It chooses a TARGET_PRODUCT |
| 508 | # based on the list of boards. Usually, that gets you something |
| 509 | # that kinda works with a generic product, but really, you should |
| 510 | # pick a product by name. |
| 511 | # |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 512 | function chooseproduct() |
| 513 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 514 | local default_value |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 515 | if [ "x$TARGET_PRODUCT" != x ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 516 | default_value=$TARGET_PRODUCT |
| 517 | else |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 518 | default_value=aosp_arm |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 519 | fi |
| 520 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 521 | export TARGET_BUILD_APPS= |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 522 | export TARGET_PRODUCT= |
| 523 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 524 | while [ -z "$TARGET_PRODUCT" ] |
| 525 | do |
Joe Onorato | 8849aed | 2009-04-29 15:56:47 -0700 | [diff] [blame] | 526 | echo -n "Which product would you like? [$default_value] " |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 527 | if [ -z "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 528 | read ANSWER |
| 529 | else |
| 530 | echo $1 |
| 531 | ANSWER=$1 |
| 532 | fi |
| 533 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 534 | if [ -z "$ANSWER" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 535 | export TARGET_PRODUCT=$default_value |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 536 | else |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 537 | if check_product $ANSWER |
| 538 | then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 539 | export TARGET_PRODUCT=$ANSWER |
| 540 | else |
| 541 | echo "** Not a valid product: $ANSWER" |
| 542 | fi |
| 543 | fi |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 544 | if [ -n "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 545 | break |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 546 | fi |
| 547 | done |
| 548 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 549 | build_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 550 | set_stuff_for_environment |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 551 | destroy_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 554 | function choosevariant() |
| 555 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 556 | echo "Variant choices are:" |
| 557 | local index=1 |
| 558 | local v |
| 559 | for v in ${VARIANT_CHOICES[@]} |
| 560 | do |
| 561 | # The product name is the name of the directory containing |
| 562 | # the makefile we found, above. |
| 563 | echo " $index. $v" |
| 564 | index=$(($index+1)) |
| 565 | done |
| 566 | |
| 567 | local default_value=eng |
| 568 | local ANSWER |
| 569 | |
| 570 | export TARGET_BUILD_VARIANT= |
| 571 | while [ -z "$TARGET_BUILD_VARIANT" ] |
| 572 | do |
| 573 | echo -n "Which would you like? [$default_value] " |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 574 | if [ -z "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 575 | read ANSWER |
| 576 | else |
| 577 | echo $1 |
| 578 | ANSWER=$1 |
| 579 | fi |
| 580 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 581 | if [ -z "$ANSWER" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 582 | export TARGET_BUILD_VARIANT=$default_value |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 583 | elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then |
| 584 | if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then |
Guillaume Chelfi | ce000fd | 2019-10-03 12:02:46 +0200 | [diff] [blame] | 585 | export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[@]:$(($ANSWER-1)):1} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 586 | fi |
| 587 | else |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 588 | if check_variant $ANSWER |
| 589 | then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 590 | export TARGET_BUILD_VARIANT=$ANSWER |
| 591 | else |
| 592 | echo "** Not a valid variant: $ANSWER" |
| 593 | fi |
| 594 | fi |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 595 | if [ -n "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 596 | break |
| 597 | fi |
| 598 | done |
| 599 | } |
| 600 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 601 | function choosecombo() |
| 602 | { |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 603 | choosetype $1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 604 | |
| 605 | echo |
| 606 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 607 | chooseproduct $2 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 608 | |
| 609 | echo |
| 610 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 611 | choosevariant $3 |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 612 | |
| 613 | echo |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 614 | build_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 615 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 616 | printconfig |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 617 | destroy_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 620 | function add_lunch_combo() |
| 621 | { |
Dan Willemsen | 5436c7e | 2019-02-11 21:31:47 -0800 | [diff] [blame] | 622 | if [ -n "$ZSH_VERSION" ]; then |
| 623 | echo -n "${funcfiletrace[1]}: " |
| 624 | else |
| 625 | echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: " |
| 626 | fi |
| 627 | echo "add_lunch_combo is obsolete. Use COMMON_LUNCH_CHOICES in your AndroidProducts.mk instead." |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 630 | function print_lunch_menu() |
| 631 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 632 | local uname=$(uname) |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 633 | local choices |
Colin Cross | fa50d40 | 2021-04-22 13:05:41 -0700 | [diff] [blame] | 634 | choices=$(TARGET_BUILD_APPS= TARGET_PRODUCT= TARGET_BUILD_VARIANT= get_build_var COMMON_LUNCH_CHOICES 2>/dev/null) |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 635 | local ret=$? |
| 636 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 637 | echo |
| 638 | echo "You're building on" $uname |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 639 | echo |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 640 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 641 | if [ $ret -ne 0 ] |
| 642 | then |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 643 | echo "Warning: Cannot display lunch menu." |
| 644 | echo |
| 645 | echo "Note: You can invoke lunch with an explicit target:" |
| 646 | echo |
| 647 | echo " usage: lunch [target]" >&2 |
| 648 | echo |
| 649 | return |
| 650 | fi |
| 651 | |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 652 | echo "Lunch menu .. Here are the common combinations:" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 653 | |
| 654 | local i=1 |
| 655 | local choice |
Dan Willemsen | 91763e9 | 2019-10-03 15:13:12 -0700 | [diff] [blame] | 656 | for choice in $(echo $choices) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 657 | do |
| 658 | echo " $i. $choice" |
| 659 | i=$(($i+1)) |
| 660 | done |
| 661 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 662 | echo |
| 663 | } |
| 664 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 665 | function lunch() |
| 666 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 667 | local answer |
| 668 | |
Steven Moreland | 92793dc | 2020-02-25 18:30:18 -0800 | [diff] [blame] | 669 | if [[ $# -gt 1 ]]; then |
| 670 | echo "usage: lunch [target]" >&2 |
| 671 | return 1 |
| 672 | fi |
| 673 | |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 674 | local used_lunch_menu=0 |
| 675 | |
Steven Moreland | 92793dc | 2020-02-25 18:30:18 -0800 | [diff] [blame] | 676 | if [ "$1" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 677 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 678 | else |
| 679 | print_lunch_menu |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 680 | echo "Which would you like? [aosp_arm-eng]" |
| 681 | echo -n "Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-eng): " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 682 | read answer |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 683 | used_lunch_menu=1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 684 | fi |
| 685 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 686 | local selection= |
| 687 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 688 | if [ -z "$answer" ] |
| 689 | then |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 690 | selection=aosp_arm-eng |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 691 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 692 | then |
Dan Willemsen | 5436c7e | 2019-02-11 21:31:47 -0800 | [diff] [blame] | 693 | local choices=($(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES)) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 694 | if [ $answer -le ${#choices[@]} ] |
| 695 | then |
Jim Tang | 0e3397b | 2018-10-03 18:25:50 +0800 | [diff] [blame] | 696 | # array in zsh starts from 1 instead of 0. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 697 | if [ -n "$ZSH_VERSION" ] |
| 698 | then |
Jim Tang | 0e3397b | 2018-10-03 18:25:50 +0800 | [diff] [blame] | 699 | selection=${choices[$(($answer))]} |
| 700 | else |
| 701 | selection=${choices[$(($answer-1))]} |
| 702 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 703 | fi |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 704 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 705 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 706 | fi |
| 707 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 708 | export TARGET_BUILD_APPS= |
| 709 | |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 710 | local product variant_and_version variant version |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 711 | product=${selection%%-*} # Trim everything after first dash |
| 712 | variant_and_version=${selection#*-} # Trim everything up to first dash |
| 713 | if [ "$variant_and_version" != "$selection" ]; then |
| 714 | variant=${variant_and_version%%-*} |
| 715 | if [ "$variant" != "$variant_and_version" ]; then |
| 716 | version=${variant_and_version#*-} |
| 717 | fi |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 718 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 719 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 720 | if [ -z "$product" ] |
| 721 | then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 722 | echo |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 723 | echo "Invalid lunch combo: $selection" |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 724 | return 1 |
| 725 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 726 | |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 727 | TARGET_PRODUCT=$product \ |
| 728 | TARGET_BUILD_VARIANT=$variant \ |
| 729 | TARGET_PLATFORM_VERSION=$version \ |
| 730 | build_build_var_cache |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 731 | if [ $? -ne 0 ] |
| 732 | then |
Anton Hansson | 32fa7ee | 2021-06-14 17:09:58 +0100 | [diff] [blame] | 733 | if [[ "$product" =~ .*_(eng|user|userdebug) ]] |
| 734 | then |
| 735 | echo "Did you mean -${product/*_/}? (dash instead of underscore)" |
| 736 | fi |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 737 | return 1 |
| 738 | fi |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 739 | export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT) |
| 740 | export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT) |
Colin Cross | b105e36 | 2017-05-01 14:21:28 -0700 | [diff] [blame] | 741 | if [ -n "$version" ]; then |
| 742 | export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION) |
| 743 | else |
| 744 | unset TARGET_PLATFORM_VERSION |
| 745 | fi |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 746 | export TARGET_BUILD_TYPE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 747 | |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 748 | if [ $used_lunch_menu -eq 1 ]; then |
| 749 | echo |
| 750 | echo "Hint: next time you can simply run 'lunch $selection'" |
| 751 | fi |
| 752 | |
Sasha Smundak | 90d07bc | 2020-06-04 10:48:15 -0700 | [diff] [blame] | 753 | [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 754 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 755 | set_stuff_for_environment |
Sasha Smundak | 90d07bc | 2020-06-04 10:48:15 -0700 | [diff] [blame] | 756 | [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 757 | destroy_build_var_cache |
Kousik Kumar | 41dacd1 | 2021-05-11 18:38:38 -0400 | [diff] [blame] | 758 | |
| 759 | if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then |
| 760 | check_mu_config |
| 761 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 764 | unset COMMON_LUNCH_CHOICES_CACHE |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 765 | # Tab completion for lunch. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 766 | function _lunch() |
| 767 | { |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 768 | local cur prev opts |
| 769 | COMPREPLY=() |
| 770 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 771 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 772 | |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 773 | if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then |
Dan Willemsen | 5436c7e | 2019-02-11 21:31:47 -0800 | [diff] [blame] | 774 | COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= get_build_var COMMON_LUNCH_CHOICES) |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 775 | fi |
| 776 | |
| 777 | COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) ) |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 778 | return 0 |
| 779 | } |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 780 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 781 | # Configures the build to build unbundled apps. |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 782 | # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 783 | function tapas() |
| 784 | { |
Jeff Gaston | 9fb05d8 | 2017-08-21 18:27:00 -0700 | [diff] [blame] | 785 | local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)" |
Elliott Hughes | f71c05a | 2020-03-06 16:46:59 -0800 | [diff] [blame] | 786 | local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)" |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 787 | local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)" |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 788 | local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)" |
Colin Cross | 7f49a67 | 2022-01-27 18:15:53 -0800 | [diff] [blame] | 789 | local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)" |
| 790 | local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|arm64|x86_64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi|devkeys)$' | xargs)" |
| 791 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 792 | |
Jeff Gaston | 9fb05d8 | 2017-08-21 18:27:00 -0700 | [diff] [blame] | 793 | if [ "$showHelp" != "" ]; then |
| 794 | $(gettop)/build/make/tapasHelp.sh |
| 795 | return |
| 796 | fi |
| 797 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 798 | if [ $(echo $arch | wc -w) -gt 1 ]; then |
| 799 | echo "tapas: Error: Multiple build archs supplied: $arch" |
| 800 | return |
| 801 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 802 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 803 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 804 | return |
| 805 | fi |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 806 | if [ $(echo $density | wc -w) -gt 1 ]; then |
| 807 | echo "tapas: Error: Multiple densities supplied: $density" |
| 808 | return |
| 809 | fi |
Colin Cross | 7f49a67 | 2022-01-27 18:15:53 -0800 | [diff] [blame] | 810 | if [ $(echo $keys | wc -w) -gt 1 ]; then |
| 811 | echo "tapas: Error: Multiple keys supplied: $keys" |
| 812 | return |
| 813 | fi |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 814 | |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 815 | local product=aosp_arm |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 816 | case $arch in |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 817 | x86) product=aosp_x86;; |
| 818 | arm64) product=aosp_arm64;; |
| 819 | x86_64) product=aosp_x86_64;; |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 820 | esac |
Colin Cross | 7f49a67 | 2022-01-27 18:15:53 -0800 | [diff] [blame] | 821 | if [ -n "$keys" ]; then |
| 822 | product=${product/aosp_/aosp_${keys}_} |
| 823 | fi; |
| 824 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 825 | if [ -z "$variant" ]; then |
| 826 | variant=eng |
| 827 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 828 | if [ -z "$apps" ]; then |
| 829 | apps=all |
| 830 | fi |
Justin Morey | 29d225c | 2014-11-04 13:35:51 -0600 | [diff] [blame] | 831 | if [ -z "$density" ]; then |
| 832 | density=alldpi |
| 833 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 834 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 835 | export TARGET_PRODUCT=$product |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 836 | export TARGET_BUILD_VARIANT=$variant |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 837 | export TARGET_BUILD_DENSITY=$density |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 838 | export TARGET_BUILD_TYPE=release |
| 839 | export TARGET_BUILD_APPS=$apps |
| 840 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 841 | build_build_var_cache |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 842 | set_stuff_for_environment |
| 843 | printconfig |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 844 | destroy_build_var_cache |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 847 | # Configures the build to build unbundled Android modules (APEXes). |
| 848 | # Run banchan with one or more module names (from apex{} modules). |
| 849 | function banchan() |
| 850 | { |
| 851 | local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)" |
Anton Hansson | 90ac61c | 2022-09-06 14:36:00 +0000 | [diff] [blame] | 852 | local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|x86_64|arm64only|x86_64only)$' | xargs)" |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 853 | local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)" |
Martin Stjernholm | 2b8d923 | 2021-04-16 20:45:03 +0100 | [diff] [blame] | 854 | local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|(.*_)?(arm|x86|arm64|x86_64))$' | xargs)" |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 855 | |
| 856 | if [ "$showHelp" != "" ]; then |
| 857 | $(gettop)/build/make/banchanHelp.sh |
| 858 | return |
| 859 | fi |
| 860 | |
Martin Stjernholm | 2b8d923 | 2021-04-16 20:45:03 +0100 | [diff] [blame] | 861 | if [ -z "$product" ]; then |
Anton Hansson | 0328e32 | 2022-05-24 15:47:40 +0000 | [diff] [blame] | 862 | product=arm64 |
Martin Stjernholm | 2b8d923 | 2021-04-16 20:45:03 +0100 | [diff] [blame] | 863 | elif [ $(echo $product | wc -w) -gt 1 ]; then |
| 864 | echo "banchan: Error: Multiple build archs or products supplied: $products" |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 865 | return |
| 866 | fi |
| 867 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 868 | echo "banchan: Error: Multiple build variants supplied: $variant" |
| 869 | return |
| 870 | fi |
| 871 | if [ -z "$apps" ]; then |
| 872 | echo "banchan: Error: No modules supplied" |
| 873 | return |
| 874 | fi |
| 875 | |
Martin Stjernholm | 2b8d923 | 2021-04-16 20:45:03 +0100 | [diff] [blame] | 876 | case $product in |
| 877 | arm) product=module_arm;; |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 878 | x86) product=module_x86;; |
| 879 | arm64) product=module_arm64;; |
| 880 | x86_64) product=module_x86_64;; |
Anton Hansson | 90ac61c | 2022-09-06 14:36:00 +0000 | [diff] [blame] | 881 | arm64only) product=module_arm64only;; |
| 882 | x86_64only) product=module_x86_64only;; |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 883 | esac |
| 884 | if [ -z "$variant" ]; then |
| 885 | variant=eng |
| 886 | fi |
| 887 | |
| 888 | export TARGET_PRODUCT=$product |
| 889 | export TARGET_BUILD_VARIANT=$variant |
| 890 | export TARGET_BUILD_DENSITY=alldpi |
| 891 | export TARGET_BUILD_TYPE=release |
| 892 | |
| 893 | # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use |
| 894 | # case is different and it may diverge in the future. |
| 895 | export TARGET_BUILD_APPS=$apps |
| 896 | |
| 897 | build_build_var_cache |
| 898 | set_stuff_for_environment |
| 899 | printconfig |
| 900 | destroy_build_var_cache |
| 901 | } |
| 902 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 903 | function gettop |
| 904 | { |
Colin Cross | 6cdc5d2 | 2017-10-20 11:37:33 -0700 | [diff] [blame] | 905 | local TOPFILE=build/make/core/envsetup.mk |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 906 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
Brian Carlstrom | a5c4f17 | 2014-09-12 00:33:25 -0700 | [diff] [blame] | 907 | # The following circumlocution ensures we remove symlinks from TOP. |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 908 | (cd "$TOP"; PWD= /bin/pwd) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 909 | else |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 910 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 911 | # The following circumlocution (repeated below as well) ensures |
| 912 | # that we record the true directory name and not one that is |
| 913 | # faked up with symlink names. |
| 914 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 915 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 916 | local HERE=$PWD |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 917 | local T= |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 918 | while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 919 | \cd .. |
synergy | b112a40 | 2013-07-05 19:47:47 -0700 | [diff] [blame] | 920 | T=`PWD= /bin/pwd -P` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 921 | done |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 922 | \cd "$HERE" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 923 | if [ -f "$T/$TOPFILE" ]; then |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 924 | echo "$T" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 925 | fi |
| 926 | fi |
| 927 | fi |
| 928 | } |
| 929 | |
Joe Onorato | 7cf6f97 | 2022-05-11 21:39:57 -0700 | [diff] [blame] | 930 | # TODO: Merge into gettop as part of launching multitree |
| 931 | function multitree_gettop |
| 932 | { |
Spandan Das | ca76205 | 2022-09-21 00:08:34 +0000 | [diff] [blame] | 933 | local TOPFILE=orchestrator/build/make/core/envsetup.mk |
Joe Onorato | 7cf6f97 | 2022-05-11 21:39:57 -0700 | [diff] [blame] | 934 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
| 935 | # The following circumlocution ensures we remove symlinks from TOP. |
| 936 | (cd "$TOP"; PWD= /bin/pwd) |
| 937 | else |
| 938 | if [ -f $TOPFILE ] ; then |
| 939 | # The following circumlocution (repeated below as well) ensures |
| 940 | # that we record the true directory name and not one that is |
| 941 | # faked up with symlink names. |
| 942 | PWD= /bin/pwd |
| 943 | else |
| 944 | local HERE=$PWD |
| 945 | local T= |
| 946 | while [ \( ! \( -f $TOPFILE \) \) -a \( "$PWD" != "/" \) ]; do |
| 947 | \cd .. |
| 948 | T=`PWD= /bin/pwd -P` |
| 949 | done |
| 950 | \cd "$HERE" |
| 951 | if [ -f "$T/$TOPFILE" ]; then |
| 952 | echo "$T" |
| 953 | fi |
| 954 | fi |
| 955 | fi |
| 956 | } |
| 957 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 958 | function croot() |
| 959 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 960 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 961 | if [ "$T" ]; then |
Marie Janssen | 32ec50a | 2016-04-21 16:53:39 -0700 | [diff] [blame] | 962 | if [ "$1" ]; then |
| 963 | \cd $(gettop)/$1 |
| 964 | else |
| 965 | \cd $(gettop) |
| 966 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 967 | else |
| 968 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 969 | fi |
| 970 | } |
| 971 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 972 | function _croot() |
| 973 | { |
Anton Hansson | ece9c48 | 2019-02-04 18:15:39 +0000 | [diff] [blame] | 974 | local T=$(gettop) |
| 975 | if [ "$T" ]; then |
| 976 | local cur="${COMP_WORDS[COMP_CWORD]}" |
| 977 | k=0 |
| 978 | for c in $(compgen -d ${T}/${cur}); do |
| 979 | COMPREPLY[k++]=${c#${T}/}/ |
| 980 | done |
| 981 | fi |
| 982 | } |
| 983 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 984 | function cproj() |
| 985 | { |
Colin Cross | 6cdc5d2 | 2017-10-20 11:37:33 -0700 | [diff] [blame] | 986 | local TOPFILE=build/make/core/envsetup.mk |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 987 | local HERE=$PWD |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 988 | local T= |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 989 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 990 | T=$PWD |
| 991 | if [ -f "$T/Android.mk" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 992 | \cd $T |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 993 | return |
| 994 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 995 | \cd .. |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 996 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 997 | \cd $HERE |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 998 | echo "can't find Android.mk" |
| 999 | } |
| 1000 | |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1001 | # simplified version of ps; output in the form |
| 1002 | # <pid> <procname> |
| 1003 | function qpid() { |
| 1004 | local prepend='' |
| 1005 | local append='' |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1006 | if [ "$1" = "--exact" ]; then |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1007 | prepend=' ' |
| 1008 | append='$' |
| 1009 | shift |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1010 | elif [ "$1" = "--help" -o "$1" = "-h" ]; then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1011 | echo "usage: qpid [[--exact] <process name|pid>" |
| 1012 | return 255 |
| 1013 | fi |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1014 | |
| 1015 | local EXE="$1" |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1016 | if [ "$EXE" ] ; then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1017 | qpid | \grep "$prepend$EXE$append" |
| 1018 | else |
| 1019 | adb shell ps \ |
| 1020 | | tr -d '\r' \ |
| 1021 | | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/' |
| 1022 | fi |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1023 | } |
| 1024 | |
Steven Moreland | 74114f1 | 2020-09-10 01:23:32 +0000 | [diff] [blame] | 1025 | # syswrite - disable verity, reboot if needed, and remount image |
| 1026 | # |
| 1027 | # Easy way to make system.img/etc writable |
| 1028 | function syswrite() { |
| 1029 | adb wait-for-device && adb root || return 1 |
Frederick Mayle | e59a879 | 2022-08-22 22:40:23 +0000 | [diff] [blame] | 1030 | if [[ $(adb disable-verity | grep -i "reboot") ]]; then |
Steven Moreland | 74114f1 | 2020-09-10 01:23:32 +0000 | [diff] [blame] | 1031 | echo "rebooting" |
| 1032 | adb reboot && adb wait-for-device && adb root || return 1 |
| 1033 | fi |
| 1034 | adb wait-for-device && adb remount || return 1 |
| 1035 | } |
| 1036 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 1037 | # coredump_setup - enable core dumps globally for any process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1038 | # that has the core-file-size limit set correctly |
| 1039 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1040 | # NOTE: You must call also coredump_enable for a specific process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1041 | # if its core-file-size limit is not set already. |
| 1042 | # NOTE: Core dumps are written to ramdisk; they will not survive a reboot! |
| 1043 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1044 | function coredump_setup() |
| 1045 | { |
| 1046 | echo "Getting root..."; |
| 1047 | adb root; |
| 1048 | adb wait-for-device; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1049 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1050 | echo "Remounting root partition read-write..."; |
| 1051 | adb shell mount -w -o remount -t rootfs rootfs; |
| 1052 | sleep 1; |
| 1053 | adb wait-for-device; |
| 1054 | adb shell mkdir -p /cores; |
| 1055 | adb shell mount -t tmpfs tmpfs /cores; |
| 1056 | adb shell chmod 0777 /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1057 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1058 | echo "Granting SELinux permission to dump in /cores..."; |
| 1059 | adb shell restorecon -R /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1060 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1061 | echo "Set core pattern."; |
| 1062 | adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern'; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1063 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1064 | echo "Done." |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1067 | # coredump_enable - enable core dumps for the specified process |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1068 | # $1 = PID of process (e.g., $(pid mediaserver)) |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1069 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1070 | # NOTE: coredump_setup must have been called as well for a core |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1071 | # dump to actually be generated. |
| 1072 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1073 | function coredump_enable() |
| 1074 | { |
| 1075 | local PID=$1; |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1076 | if [ -z "$PID" ]; then |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1077 | printf "Expecting a PID!\n"; |
| 1078 | return; |
| 1079 | fi; |
| 1080 | echo "Setting core limit for $PID to infinite..."; |
xi yu | addf483 | 2022-05-26 12:41:21 +0000 | [diff] [blame] | 1081 | adb shell /system/bin/ulimit -P $PID -c unlimited |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | # core - send SIGV and pull the core for process |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1085 | # $1 = PID of process (e.g., $(pid mediaserver)) |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1086 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1087 | # NOTE: coredump_setup must be called once per boot for core dumps to be |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1088 | # enabled globally. |
| 1089 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1090 | function core() |
| 1091 | { |
| 1092 | local PID=$1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1093 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1094 | if [ -z "$PID" ]; then |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1095 | printf "Expecting a PID!\n"; |
| 1096 | return; |
| 1097 | fi; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1098 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1099 | local CORENAME=core.$PID; |
| 1100 | local COREPATH=/cores/$CORENAME; |
| 1101 | local SIG=SEGV; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1102 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1103 | coredump_enable $1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1104 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1105 | local done=0; |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1106 | while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1107 | printf "\tSending SIG%s to %d...\n" $SIG $PID; |
| 1108 | adb shell kill -$SIG $PID; |
| 1109 | sleep 1; |
| 1110 | done; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1111 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1112 | adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done" |
| 1113 | echo "Done: core is under $COREPATH on device."; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 1116 | # systemstack - dump the current stack trace of all threads in the system process |
| 1117 | # to the usual ANR traces file |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1118 | function systemstack() |
| 1119 | { |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1120 | stacks system_server |
| 1121 | } |
| 1122 | |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1123 | # Read the ELF header from /proc/$PID/exe to determine if the process is |
| 1124 | # 64-bit. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1125 | function is64bit() |
| 1126 | { |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1127 | local PID="$1" |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1128 | if [ "$PID" ] ; then |
| 1129 | if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1130 | echo "64" |
| 1131 | else |
| 1132 | echo "" |
| 1133 | fi |
| 1134 | else |
| 1135 | echo "" |
| 1136 | fi |
| 1137 | } |
| 1138 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1139 | case `uname -s` in |
| 1140 | Darwin) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1141 | function sgrep() |
| 1142 | { |
Taesu Lee | ea0cecd | 2020-10-28 11:05:18 +0900 | [diff] [blame] | 1143 | find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|hpp|S|java|kt|xml|sh|mk|aidl|vts|proto)' \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1144 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1145 | } |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1146 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1147 | ;; |
| 1148 | *) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1149 | function sgrep() |
| 1150 | { |
Taesu Lee | ea0cecd | 2020-10-28 11:05:18 +0900 | [diff] [blame] | 1151 | find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|kt\|xml\|sh\|mk\|aidl\|vts\|proto\)' \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1152 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1153 | } |
| 1154 | ;; |
| 1155 | esac |
| 1156 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1157 | function gettargetarch |
| 1158 | { |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1159 | get_build_var TARGET_ARCH |
| 1160 | } |
| 1161 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1162 | function ggrep() |
| 1163 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1164 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \ |
| 1165 | -exec grep --color -n "$@" {} + |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1168 | function gogrep() |
| 1169 | { |
Orion Hodson | 831472d | 2019-10-25 11:35:15 +0100 | [diff] [blame] | 1170 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.go" \ |
| 1171 | -exec grep --color -n "$@" {} + |
| 1172 | } |
| 1173 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1174 | function jgrep() |
| 1175 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1176 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \ |
| 1177 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Alistair Delva | 176e534 | 2021-02-22 13:31:26 -0800 | [diff] [blame] | 1180 | function rsgrep() |
Jeff Vander Stoep | 1431ab8 | 2021-02-02 19:18:26 +0100 | [diff] [blame] | 1181 | { |
| 1182 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rs" \ |
| 1183 | -exec grep --color -n "$@" {} + |
| 1184 | } |
| 1185 | |
Taesu Lee | ea0cecd | 2020-10-28 11:05:18 +0900 | [diff] [blame] | 1186 | function ktgrep() |
| 1187 | { |
| 1188 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.kt" \ |
| 1189 | -exec grep --color -n "$@" {} + |
| 1190 | } |
| 1191 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1192 | function cgrep() |
| 1193 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1194 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \ |
| 1195 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1198 | function resgrep() |
| 1199 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1200 | local dir |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1201 | for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do |
| 1202 | find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} + |
| 1203 | done |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1206 | function mangrep() |
| 1207 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1208 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \ |
| 1209 | -exec grep --color -n "$@" {} + |
Jeff Sharkey | 50b61e9 | 2013-03-08 10:20:47 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1212 | function owngrep() |
| 1213 | { |
Jeff Sharkey | f17cddf | 2019-08-21 12:51:26 -0600 | [diff] [blame] | 1214 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'OWNERS' \ |
| 1215 | -exec grep --color -n "$@" {} + |
| 1216 | } |
| 1217 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1218 | function sepgrep() |
| 1219 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1220 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \ |
| 1221 | -exec grep --color -n -r --exclude-dir=\.git "$@" {} + |
Alex Klyubin | ba5fc8e | 2013-05-06 14:11:48 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1224 | function rcgrep() |
| 1225 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1226 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \ |
| 1227 | -exec grep --color -n "$@" {} + |
Jeff Sharkey | ea0068a | 2015-02-26 14:13:46 -0800 | [diff] [blame] | 1228 | } |
| 1229 | |
DroidFreak32 | a278198 | 2020-11-26 11:30:19 -0500 | [diff] [blame] | 1230 | function pygrep() |
| 1231 | { |
| 1232 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.py" \ |
| 1233 | -exec grep --color -n "$@" {} + |
| 1234 | } |
| 1235 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1236 | case `uname -s` in |
| 1237 | Darwin) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1238 | function mgrep() |
| 1239 | { |
Orion Hodson | 831472d | 2019-10-25 11:35:15 +0100 | [diff] [blame] | 1240 | find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1241 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1244 | function treegrep() |
| 1245 | { |
Taesu Lee | ea0cecd | 2020-10-28 11:05:18 +0900 | [diff] [blame] | 1246 | find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|hpp|S|java|kt|xml)' \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1247 | -exec grep --color -n -i "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | ;; |
| 1251 | *) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1252 | function mgrep() |
| 1253 | { |
Orion Hodson | 831472d | 2019-10-25 11:35:15 +0100 | [diff] [blame] | 1254 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regextype posix-extended -regex '(.*/)?(build|soong)/.*[^/]*\.go' \) -type f \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1255 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1258 | function treegrep() |
| 1259 | { |
Taesu Lee | ea0cecd | 2020-10-28 11:05:18 +0900 | [diff] [blame] | 1260 | find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|kt|xml)' -type f \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1261 | -exec grep --color -n -i "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | ;; |
| 1265 | esac |
| 1266 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1267 | function getprebuilt |
| 1268 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1269 | get_abs_build_var ANDROID_PREBUILTS |
| 1270 | } |
| 1271 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1272 | function tracedmdump() |
| 1273 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1274 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1275 | if [ ! "$T" ]; then |
| 1276 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 1277 | return |
| 1278 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1279 | local prebuiltdir=$(getprebuilt) |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1280 | local arch=$(gettargetarch) |
| 1281 | local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1282 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1283 | local TRACE=$1 |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1284 | if [ ! "$TRACE" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1285 | echo "usage: tracedmdump tracename" |
| 1286 | return |
| 1287 | fi |
| 1288 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1289 | if [ ! -r "$KERNEL" ] ; then |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 1290 | echo "Error: cannot find kernel: '$KERNEL'" |
| 1291 | return |
| 1292 | fi |
| 1293 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1294 | local BASETRACE=$(basename $TRACE) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1295 | if [ "$BASETRACE" = "$TRACE" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1296 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 1297 | fi |
| 1298 | |
| 1299 | echo "post-processing traces..." |
| 1300 | rm -f $TRACE/qtrace.dexlist |
| 1301 | post_trace $TRACE |
| 1302 | if [ $? -ne 0 ]; then |
| 1303 | echo "***" |
| 1304 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 1305 | echo "***" |
| 1306 | return |
| 1307 | fi |
| 1308 | echo "generating dexlist output..." |
| 1309 | /bin/ls $ANDROID_PRODUCT_OUT/system/framework/*.jar $ANDROID_PRODUCT_OUT/system/app/*.apk $ANDROID_PRODUCT_OUT/data/app/*.apk 2>/dev/null | xargs dexlist > $TRACE/qtrace.dexlist |
| 1310 | echo "generating dmtrace data..." |
| 1311 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 1312 | echo "generating html file..." |
| 1313 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 1314 | echo "done, see $TRACE/dmtrace.html for details" |
| 1315 | echo "or run:" |
| 1316 | echo " traceview $TRACE/dmtrace" |
| 1317 | } |
| 1318 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1319 | # communicate with a running device or emulator, set up necessary state, |
| 1320 | # and run the hat command. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1321 | function runhat() |
| 1322 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1323 | # process standard adb options |
| 1324 | local adbTarget="" |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1325 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1326 | adbTarget=$1 |
| 1327 | shift 1 |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1328 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1329 | adbTarget="$1 $2" |
| 1330 | shift 2 |
| 1331 | fi |
| 1332 | local adbOptions=${adbTarget} |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1333 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1334 | |
| 1335 | # runhat options |
| 1336 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1337 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1338 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1339 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1340 | return |
| 1341 | fi |
| 1342 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1343 | # confirm hat is available |
| 1344 | if [ -z $(which hat) ]; then |
| 1345 | echo "hat is not available in this configuration." |
| 1346 | return |
| 1347 | fi |
| 1348 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1349 | # issue "am" command to cause the hprof dump |
Nick Kralevich | 9948b1e | 2014-07-18 15:45:38 -0700 | [diff] [blame] | 1350 | local devFile=/data/local/tmp/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1351 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1352 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1353 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1354 | echo "Press enter when logcat shows \"hprof: heap dump completed\"" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1355 | echo -n "> " |
| 1356 | read |
| 1357 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1358 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1359 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1360 | echo "Retrieving file $devFile..." |
| 1361 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1362 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1363 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1364 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1365 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1366 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1367 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1368 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1371 | function getbugreports() |
| 1372 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1373 | local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1374 | |
| 1375 | if [ ! "$reports" ]; then |
| 1376 | echo "Could not locate any bugreports." |
| 1377 | return |
| 1378 | fi |
| 1379 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1380 | local report |
| 1381 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1382 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1383 | echo "/sdcard/bugreports/${report}" |
| 1384 | adb pull /sdcard/bugreports/${report} ${report} |
| 1385 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1386 | done |
| 1387 | } |
| 1388 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1389 | function getsdcardpath() |
| 1390 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1391 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1392 | } |
| 1393 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1394 | function getscreenshotpath() |
| 1395 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1396 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1397 | } |
| 1398 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1399 | function getlastscreenshot() |
| 1400 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1401 | local screenshot_path=$(getscreenshotpath) |
| 1402 | local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1403 | if [ "$screenshot" = "" ]; then |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1404 | echo "No screenshots found." |
| 1405 | return |
| 1406 | fi |
| 1407 | echo "${screenshot}" |
| 1408 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1409 | } |
| 1410 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1411 | function startviewserver() |
| 1412 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1413 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1414 | if [ $# -gt 0 ]; then |
| 1415 | port=$1 |
| 1416 | fi |
| 1417 | adb shell service call window 1 i32 $port |
| 1418 | } |
| 1419 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1420 | function stopviewserver() |
| 1421 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1422 | adb shell service call window 2 |
| 1423 | } |
| 1424 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1425 | function isviewserverstarted() |
| 1426 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1427 | adb shell service call window 3 |
| 1428 | } |
| 1429 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1430 | function key_home() |
| 1431 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1432 | adb shell input keyevent 3 |
| 1433 | } |
| 1434 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1435 | function key_back() |
| 1436 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1437 | adb shell input keyevent 4 |
| 1438 | } |
| 1439 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1440 | function key_menu() |
| 1441 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1442 | adb shell input keyevent 82 |
| 1443 | } |
| 1444 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1445 | function smoketest() |
| 1446 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1447 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1448 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1449 | return |
| 1450 | fi |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1451 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1452 | if [ ! "$T" ]; then |
| 1453 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1454 | return |
| 1455 | fi |
| 1456 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1457 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1458 | adb uninstall com.android.smoketest > /dev/null && |
| 1459 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1460 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1461 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1462 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1463 | } |
| 1464 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1465 | # simple shortcut to the runtest command |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1466 | function runtest() |
| 1467 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1468 | local T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1469 | if [ ! "$T" ]; then |
| 1470 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1471 | return |
| 1472 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1473 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1476 | function godir () { |
| 1477 | if [[ -z "$1" ]]; then |
| 1478 | echo "Usage: godir <regex>" |
| 1479 | return |
| 1480 | fi |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1481 | local T=$(gettop) |
| 1482 | local FILELIST |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1483 | if [ ! "$OUT_DIR" = "" ]; then |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1484 | mkdir -p $OUT_DIR |
| 1485 | FILELIST=$OUT_DIR/filelist |
| 1486 | else |
| 1487 | FILELIST=$T/filelist |
| 1488 | fi |
| 1489 | if [[ ! -f $FILELIST ]]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1490 | echo -n "Creating index..." |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1491 | (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1492 | echo " Done" |
| 1493 | echo "" |
| 1494 | fi |
| 1495 | local lines |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1496 | lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq)) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1497 | if [[ ${#lines[@]} = 0 ]]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1498 | echo "Not found" |
| 1499 | return |
| 1500 | fi |
| 1501 | local pathname |
| 1502 | local choice |
| 1503 | if [[ ${#lines[@]} > 1 ]]; then |
| 1504 | while [[ -z "$pathname" ]]; do |
| 1505 | local index=1 |
| 1506 | local line |
| 1507 | for line in ${lines[@]}; do |
| 1508 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1509 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1510 | done |
| 1511 | echo |
| 1512 | echo -n "Select one: " |
| 1513 | unset choice |
| 1514 | read choice |
| 1515 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1516 | echo "Invalid choice" |
| 1517 | continue |
| 1518 | fi |
Guillaume Chelfi | ce000fd | 2019-10-03 12:02:46 +0200 | [diff] [blame] | 1519 | pathname=${lines[@]:$(($choice-1)):1} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1520 | done |
| 1521 | else |
Guillaume Chelfi | ce000fd | 2019-10-03 12:02:46 +0200 | [diff] [blame] | 1522 | pathname=${lines[@]:0:1} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1523 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1524 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1525 | } |
| 1526 | |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1527 | # Update module-info.json in out. |
| 1528 | function refreshmod() { |
| 1529 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1530 | echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 |
| 1531 | return 1 |
| 1532 | fi |
| 1533 | |
| 1534 | echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2 |
| 1535 | |
| 1536 | # for the output of the next command |
| 1537 | mkdir -p $ANDROID_PRODUCT_OUT || return 1 |
| 1538 | |
| 1539 | # Note, can't use absolute path because of the way make works. |
Alessandro Astone | c8771be | 2020-05-10 11:27:57 +0200 | [diff] [blame] | 1540 | m $(get_build_var PRODUCT_OUT)/module-info.json \ |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1541 | > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1 |
| 1542 | } |
| 1543 | |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1544 | # Verifies that module-info.txt exists, returning nonzero if it doesn't. |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1545 | function verifymodinfo() { |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1546 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
Joe Onorato | 0bac4fe | 2021-04-07 08:51:28 -0700 | [diff] [blame] | 1547 | if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then |
| 1548 | echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 |
| 1549 | fi |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1550 | return 1 |
| 1551 | fi |
| 1552 | |
| 1553 | if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then |
Joe Onorato | 0bac4fe | 2021-04-07 08:51:28 -0700 | [diff] [blame] | 1554 | if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1555 | echo "Could not find module-info.json. Please run 'refreshmod' first." >&2 |
Joe Onorato | 0bac4fe | 2021-04-07 08:51:28 -0700 | [diff] [blame] | 1556 | fi |
| 1557 | return 1 |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1558 | fi |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
Cole Faust | 5d825b7 | 2022-10-26 18:16:44 -0700 | [diff] [blame] | 1561 | # List all modules for the current device, as cached in all_modules.txt. If any build change is |
| 1562 | # made and it should be reflected in the output, you should run `m nothing` first. |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1563 | function allmod() { |
Cole Faust | 5d825b7 | 2022-10-26 18:16:44 -0700 | [diff] [blame] | 1564 | cat $ANDROID_PRODUCT_OUT/all_modules.txt 2>/dev/null |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1565 | } |
| 1566 | |
Jingwen Chen | 83eeebb | 2022-10-05 02:27:07 +0000 | [diff] [blame] | 1567 | # Return the Bazel label of a Soong module if it is converted with bp2build. |
| 1568 | function bmod() |
| 1569 | ( |
| 1570 | if [ $# -ne 1 ]; then |
| 1571 | echo "usage: bmod <module>" >&2 |
| 1572 | return 1 |
| 1573 | fi |
| 1574 | |
| 1575 | # We could run bp2build here, but it might trigger bp2build invalidation |
| 1576 | # when used with `b` (e.g. --run_soong_tests) and/or add unnecessary waiting |
| 1577 | # time overhead. |
| 1578 | # |
| 1579 | # For a snappy result, use the latest generated version in soong_injection, |
| 1580 | # and ask users to run m bp2build if it doesn't exist. |
Jingwen Chen | acdcaa0 | 2022-10-13 07:24:24 +0000 | [diff] [blame] | 1581 | converted_json="$(get_abs_build_var OUT_DIR)/soong/soong_injection/metrics/converted_modules_path_map.json" |
Jingwen Chen | 83eeebb | 2022-10-05 02:27:07 +0000 | [diff] [blame] | 1582 | |
Jingwen Chen | acdcaa0 | 2022-10-13 07:24:24 +0000 | [diff] [blame] | 1583 | if [ ! -f ${converted_json} ]; then |
Jingwen Chen | 83eeebb | 2022-10-05 02:27:07 +0000 | [diff] [blame] | 1584 | echo "bp2build files not found. Have you ran 'm bp2build'?" >&2 |
| 1585 | return 1 |
| 1586 | fi |
| 1587 | |
| 1588 | local target_label=$(python3 -c "import json |
| 1589 | module = '$1' |
| 1590 | converted_json='$converted_json' |
| 1591 | bp2build_converted_map = json.load(open(converted_json)) |
| 1592 | if module not in bp2build_converted_map: |
| 1593 | exit(1) |
| 1594 | print(bp2build_converted_map[module] + ':' + module)") |
| 1595 | |
| 1596 | if [ -z "${target_label}" ]; then |
| 1597 | echo "$1 is not converted to Bazel." >&2 |
| 1598 | return 1 |
| 1599 | else |
| 1600 | echo "${target_label}" |
| 1601 | fi |
| 1602 | ) |
| 1603 | |
Joe Onorato | 2c1aa47 | 2021-02-25 16:42:39 -0800 | [diff] [blame] | 1604 | # Get the path of a specific module in the android tree, as cached in module-info.json. |
| 1605 | # If any build change is made, and it should be reflected in the output, you should run |
| 1606 | # 'refreshmod' first. Note: This is the inverse of dirmods. |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1607 | function pathmod() { |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1608 | if [[ $# -ne 1 ]]; then |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1609 | echo "usage: pathmod <module>" >&2 |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1610 | return 1 |
| 1611 | fi |
| 1612 | |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1613 | verifymodinfo || return 1 |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1614 | |
Joe Onorato | 4acbe3b | 2021-04-29 15:31:42 -0700 | [diff] [blame] | 1615 | local relpath=$(python3 -c "import json, os |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1616 | module = '$1' |
| 1617 | module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')) |
| 1618 | if module not in module_info: |
| 1619 | exit(1) |
LuK1337 | b6a7819 | 2020-01-12 03:12:17 +0100 | [diff] [blame] | 1620 | print(module_info[module]['path'][0])" 2>/dev/null) |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1621 | |
| 1622 | if [ -z "$relpath" ]; then |
| 1623 | echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2 |
| 1624 | return 1 |
| 1625 | else |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1626 | echo "$ANDROID_BUILD_TOP/$relpath" |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1627 | fi |
| 1628 | } |
| 1629 | |
Joe Onorato | 2c1aa47 | 2021-02-25 16:42:39 -0800 | [diff] [blame] | 1630 | # Get the path of a specific module in the android tree, as cached in module-info.json. |
| 1631 | # If any build change is made, and it should be reflected in the output, you should run |
| 1632 | # 'refreshmod' first. Note: This is the inverse of pathmod. |
| 1633 | function dirmods() { |
| 1634 | if [[ $# -ne 1 ]]; then |
| 1635 | echo "usage: dirmods <path>" >&2 |
| 1636 | return 1 |
| 1637 | fi |
| 1638 | |
| 1639 | verifymodinfo || return 1 |
| 1640 | |
Joe Onorato | 4acbe3b | 2021-04-29 15:31:42 -0700 | [diff] [blame] | 1641 | python3 -c "import json, os |
Joe Onorato | 2c1aa47 | 2021-02-25 16:42:39 -0800 | [diff] [blame] | 1642 | dir = '$1' |
| 1643 | while dir.endswith('/'): |
| 1644 | dir = dir[:-1] |
| 1645 | prefix = dir + '/' |
| 1646 | module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')) |
| 1647 | results = set() |
| 1648 | for m in module_info.values(): |
| 1649 | for path in m.get(u'path', []): |
| 1650 | if path == dir or path.startswith(prefix): |
| 1651 | name = m.get(u'module_name') |
| 1652 | if name: |
| 1653 | results.add(name) |
| 1654 | for name in sorted(results): |
| 1655 | print(name) |
| 1656 | " |
| 1657 | } |
| 1658 | |
| 1659 | |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1660 | # Go to a specific module in the android tree, as cached in module-info.json. If any build change |
| 1661 | # is made, and it should be reflected in the output, you should run 'refreshmod' first. |
| 1662 | function gomod() { |
| 1663 | if [[ $# -ne 1 ]]; then |
| 1664 | echo "usage: gomod <module>" >&2 |
| 1665 | return 1 |
| 1666 | fi |
| 1667 | |
| 1668 | local path="$(pathmod $@)" |
| 1669 | if [ -z "$path" ]; then |
| 1670 | return 1 |
| 1671 | fi |
| 1672 | cd $path |
| 1673 | } |
| 1674 | |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1675 | # Gets the list of a module's installed outputs, as cached in module-info.json. |
| 1676 | # If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first. |
| 1677 | function outmod() { |
| 1678 | if [[ $# -ne 1 ]]; then |
| 1679 | echo "usage: outmod <module>" >&2 |
| 1680 | return 1 |
| 1681 | fi |
| 1682 | |
| 1683 | verifymodinfo || return 1 |
| 1684 | |
| 1685 | local relpath |
Joe Onorato | 4acbe3b | 2021-04-29 15:31:42 -0700 | [diff] [blame] | 1686 | relpath=$(python3 -c "import json, os |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1687 | module = '$1' |
| 1688 | module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')) |
| 1689 | if module not in module_info: |
| 1690 | exit(1) |
| 1691 | for output in module_info[module]['installed']: |
| 1692 | print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null) |
| 1693 | |
| 1694 | if [ $? -ne 0 ]; then |
| 1695 | echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2 |
| 1696 | return 1 |
| 1697 | elif [ ! -z "$relpath" ]; then |
| 1698 | echo "$relpath" |
| 1699 | fi |
| 1700 | } |
| 1701 | |
| 1702 | # adb install a module's apk, as cached in module-info.json. If any build change |
| 1703 | # is made, and it should be reflected in the output, you should run 'refreshmod' first. |
| 1704 | # Usage: installmod [adb install arguments] <module> |
| 1705 | # For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk |
| 1706 | function installmod() { |
| 1707 | if [[ $# -eq 0 ]]; then |
| 1708 | echo "usage: installmod [adb install arguments] <module>" >&2 |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1709 | echo "" >&2 |
| 1710 | echo "Only flags to be passed after the \"install\" in adb install are supported," >&2 |
| 1711 | echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2 |
| 1712 | echo "-s must be the first flag passed if it exists." >&2 |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1713 | return 1 |
| 1714 | fi |
| 1715 | |
| 1716 | local _path |
| 1717 | _path=$(outmod ${@:$#:1}) |
| 1718 | if [ $? -ne 0 ]; then |
| 1719 | return 1 |
| 1720 | fi |
| 1721 | |
| 1722 | _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1) |
| 1723 | if [ -z "$_path" ]; then |
| 1724 | echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2 |
| 1725 | return 1 |
| 1726 | fi |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1727 | local serial_device="" |
| 1728 | if [[ "$1" == "-s" ]]; then |
| 1729 | if [[ $# -le 2 ]]; then |
| 1730 | echo "-s requires an argument" >&2 |
| 1731 | return 1 |
| 1732 | fi |
| 1733 | serial_device="-s $2" |
| 1734 | shift 2 |
| 1735 | fi |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1736 | local length=$(( $# - 1 )) |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1737 | echo adb $serial_device install ${@:1:$length} $_path |
| 1738 | adb $serial_device install ${@:1:$length} $_path |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame] | 1741 | function _complete_android_module_names() { |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1742 | local word=${COMP_WORDS[COMP_CWORD]} |
Cole Faust | 5d825b7 | 2022-10-26 18:16:44 -0700 | [diff] [blame] | 1743 | COMPREPLY=( $(allmod | grep -E "^$word") ) |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1746 | # Print colored exit condition |
| 1747 | function pez { |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1748 | "$@" |
| 1749 | local retval=$? |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1750 | if [ $retval -ne 0 ] |
| 1751 | then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1752 | echo $'\E'"[0;31mFAILURE\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1753 | else |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1754 | echo $'\E'"[0;32mSUCCESS\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1755 | fi |
| 1756 | return $retval |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1757 | } |
| 1758 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1759 | function get_make_command() |
| 1760 | { |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1761 | # If we're in the top of an Android tree, use soong_ui.bash instead of make |
| 1762 | if [ -f build/soong/soong_ui.bash ]; then |
Dan Willemsen | e984224 | 2017-07-28 13:00:13 -0700 | [diff] [blame] | 1763 | # Always use the real make if -C is passed in |
| 1764 | for arg in "$@"; do |
| 1765 | if [[ $arg == -C* ]]; then |
| 1766 | echo command make |
| 1767 | return |
| 1768 | fi |
| 1769 | done |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1770 | echo build/soong/soong_ui.bash --make-mode |
| 1771 | else |
| 1772 | echo command make |
| 1773 | fi |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1776 | function _wrap_build() |
| 1777 | { |
Sasha Smundak | 9f27cc0 | 2019-01-31 13:25:31 -0800 | [diff] [blame] | 1778 | if [[ "${ANDROID_QUIET_BUILD:-}" == true ]]; then |
| 1779 | "$@" |
| 1780 | return $? |
| 1781 | fi |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1782 | local start_time=$(date +"%s") |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1783 | "$@" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1784 | local ret=$? |
| 1785 | local end_time=$(date +"%s") |
| 1786 | local tdiff=$(($end_time-$start_time)) |
| 1787 | local hours=$(($tdiff / 3600 )) |
| 1788 | local mins=$((($tdiff % 3600) / 60)) |
| 1789 | local secs=$(($tdiff % 60)) |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1790 | local ncolors=$(tput colors 2>/dev/null) |
| 1791 | if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1792 | color_failed=$'\E'"[0;31m" |
| 1793 | color_success=$'\E'"[0;32m" |
Kousik Kumar | 09af254 | 2021-08-19 16:13:32 -0400 | [diff] [blame] | 1794 | color_warning=$'\E'"[0;33m" |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1795 | color_reset=$'\E'"[00m" |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1796 | else |
| 1797 | color_failed="" |
| 1798 | color_success="" |
| 1799 | color_reset="" |
| 1800 | fi |
Kousik Kumar | 09af254 | 2021-08-19 16:13:32 -0400 | [diff] [blame] | 1801 | |
| 1802 | if [[ "x${USE_RBE}" == "x" && $mins -gt 15 && "${ANDROID_BUILD_ENVIRONMENT_CONFIG}" == "googler" ]]; then |
| 1803 | echo |
| 1804 | echo "${color_warning}Start using RBE (http://go/build-fast) to get faster builds!${color_reset}" |
| 1805 | fi |
| 1806 | |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1807 | echo |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1808 | if [ $ret -eq 0 ] ; then |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1809 | echo -n "${color_success}#### build completed successfully " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1810 | else |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1811 | echo -n "${color_failed}#### failed to build some targets " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1812 | fi |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1813 | if [ $hours -gt 0 ] ; then |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1814 | printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1815 | elif [ $mins -gt 0 ] ; then |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1816 | printf "(%02g:%02g (mm:ss))" $mins $secs |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1817 | elif [ $secs -gt 0 ] ; then |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1818 | printf "(%s seconds)" $secs |
| 1819 | fi |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1820 | echo " ####${color_reset}" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1821 | echo |
| 1822 | return $ret |
| 1823 | } |
| 1824 | |
Patrice Arruda | fa7204b | 2019-06-20 23:40:33 +0000 | [diff] [blame] | 1825 | function _trigger_build() |
| 1826 | ( |
| 1827 | local -r bc="$1"; shift |
LaMont Jones | c39e502 | 2022-06-23 19:09:06 +0000 | [diff] [blame] | 1828 | local T=$(gettop) |
| 1829 | if [ -n "$T" ]; then |
Patrice Arruda | fa7204b | 2019-06-20 23:40:33 +0000 | [diff] [blame] | 1830 | _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@" |
| 1831 | else |
Jingwen Chen | d728ee1 | 2021-05-18 06:02:53 +0000 | [diff] [blame] | 1832 | >&2 echo "Couldn't locate the top of the tree. Try setting TOP." |
| 1833 | return 1 |
Patrice Arruda | fa7204b | 2019-06-20 23:40:33 +0000 | [diff] [blame] | 1834 | fi |
| 1835 | ) |
| 1836 | |
| 1837 | function m() |
| 1838 | ( |
| 1839 | _trigger_build "all-modules" "$@" |
| 1840 | ) |
| 1841 | |
| 1842 | function mm() |
| 1843 | ( |
| 1844 | _trigger_build "modules-in-a-dir-no-deps" "$@" |
| 1845 | ) |
| 1846 | |
| 1847 | function mmm() |
| 1848 | ( |
| 1849 | _trigger_build "modules-in-dirs-no-deps" "$@" |
| 1850 | ) |
| 1851 | |
| 1852 | function mma() |
| 1853 | ( |
| 1854 | _trigger_build "modules-in-a-dir" "$@" |
| 1855 | ) |
| 1856 | |
| 1857 | function mmma() |
| 1858 | ( |
| 1859 | _trigger_build "modules-in-dirs" "$@" |
| 1860 | ) |
| 1861 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1862 | function make() |
| 1863 | { |
Dan Willemsen | e984224 | 2017-07-28 13:00:13 -0700 | [diff] [blame] | 1864 | _wrap_build $(get_make_command "$@") "$@" |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1865 | } |
| 1866 | |
Joe Onorato | 7cf6f97 | 2022-05-11 21:39:57 -0700 | [diff] [blame] | 1867 | function _multitree_lunch_error() |
| 1868 | { |
| 1869 | >&2 echo "Couldn't locate the top of the tree. Please run \'source build/envsetup.sh\' and multitree_lunch from the root of your workspace." |
| 1870 | } |
| 1871 | |
| 1872 | function multitree_build() |
| 1873 | { |
LaMont Jones | c39e502 | 2022-06-23 19:09:06 +0000 | [diff] [blame] | 1874 | local T=$(multitree_gettop) |
| 1875 | if [ -n "$T" ]; then |
Spandan Das | ca76205 | 2022-09-21 00:08:34 +0000 | [diff] [blame] | 1876 | "$T/orchestrator/build/orchestrator/core/orchestrator.py" "$@" |
Joe Onorato | 7cf6f97 | 2022-05-11 21:39:57 -0700 | [diff] [blame] | 1877 | else |
| 1878 | _multitree_lunch_error |
| 1879 | return 1 |
| 1880 | fi |
| 1881 | } |
| 1882 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1883 | function provision() |
| 1884 | { |
David Zeuthen | 1b126ff | 2015-09-30 17:10:48 -0400 | [diff] [blame] | 1885 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1886 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1887 | return 1 |
| 1888 | fi |
| 1889 | if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then |
| 1890 | echo "There is no provisioning script for the device." >&2 |
| 1891 | return 1 |
| 1892 | fi |
| 1893 | |
| 1894 | # Check if user really wants to do this. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1895 | if [ "$1" = "--no-confirmation" ]; then |
David Zeuthen | 1b126ff | 2015-09-30 17:10:48 -0400 | [diff] [blame] | 1896 | shift 1 |
| 1897 | else |
| 1898 | echo "This action will reflash your device." |
| 1899 | echo "" |
| 1900 | echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED." |
| 1901 | echo "" |
Marie Janssen | 4afc2c0 | 2015-11-10 10:41:15 -0800 | [diff] [blame] | 1902 | echo -n "Are you sure you want to do this (yes/no)? " |
| 1903 | read |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1904 | if [[ "${REPLY}" != "yes" ]] ; then |
David Zeuthen | 1b126ff | 2015-09-30 17:10:48 -0400 | [diff] [blame] | 1905 | echo "Not taking any action. Exiting." >&2 |
| 1906 | return 1 |
| 1907 | fi |
| 1908 | fi |
| 1909 | "$ANDROID_PRODUCT_OUT/provision-device" "$@" |
| 1910 | } |
| 1911 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1912 | # Zsh needs bashcompinit called to support bash-style completion. |
Patrik Fimml | df248e6 | 2018-10-15 18:15:12 +0200 | [diff] [blame] | 1913 | function enable_zsh_completion() { |
| 1914 | # Don't override user's options if bash-style completion is already enabled. |
| 1915 | if ! declare -f complete >/dev/null; then |
| 1916 | autoload -U compinit && compinit |
| 1917 | autoload -U bashcompinit && bashcompinit |
| 1918 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | function validate_current_shell() { |
| 1922 | local current_sh="$(ps -o command -p $$)" |
| 1923 | case "$current_sh" in |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1924 | *bash*) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1925 | function check_type() { type -t "$1"; } |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1926 | ;; |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1927 | *zsh*) |
| 1928 | function check_type() { type "$1"; } |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1929 | enable_zsh_completion ;; |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1930 | *) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1931 | echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results." |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1932 | ;; |
| 1933 | esac |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1934 | } |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1935 | |
| 1936 | # Execute the contents of any vendorsetup.sh files we can find. |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1937 | # Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only |
| 1938 | # load those. |
| 1939 | # |
| 1940 | # This allows loading only approved vendorsetup.sh files |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1941 | function source_vendorsetup() { |
Jim Tang | c4dba1d | 2019-07-25 16:54:27 +0800 | [diff] [blame] | 1942 | unset VENDOR_PYTHONPATH |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1943 | local T="$(gettop)" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1944 | allowed= |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1945 | for f in $(cd "$T" && find -L device vendor product -maxdepth 4 -name 'allowed-vendorsetup_sh-files' 2>/dev/null | sort); do |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1946 | if [ -n "$allowed" ]; then |
| 1947 | echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:" |
| 1948 | echo " $allowed" |
| 1949 | echo " $f" |
| 1950 | return |
| 1951 | fi |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1952 | allowed="$T/$f" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1953 | done |
| 1954 | |
| 1955 | allowed_files= |
| 1956 | [ -n "$allowed" ] && allowed_files=$(cat "$allowed") |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1957 | for dir in device vendor product; do |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1958 | for f in $(cd "$T" && test -d $dir && \ |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1959 | find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1960 | |
| 1961 | if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1962 | echo "including $f"; . "$T/$f" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1963 | else |
| 1964 | echo "ignoring $f, not in $allowed" |
| 1965 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1966 | done |
| 1967 | done |
| 1968 | } |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1969 | |
Dan Albert | bab814f | 2020-08-26 15:34:53 -0700 | [diff] [blame] | 1970 | function showcommands() { |
| 1971 | local T=$(gettop) |
| 1972 | if [[ -z "$TARGET_PRODUCT" ]]; then |
| 1973 | >&2 echo "TARGET_PRODUCT not set. Run lunch." |
| 1974 | return |
| 1975 | fi |
| 1976 | case $(uname -s) in |
| 1977 | Darwin) |
| 1978 | PREBUILT_NAME=darwin-x86 |
| 1979 | ;; |
| 1980 | Linux) |
| 1981 | PREBUILT_NAME=linux-x86 |
| 1982 | ;; |
| 1983 | *) |
| 1984 | >&2 echo Unknown host $(uname -s) |
| 1985 | return |
| 1986 | ;; |
| 1987 | esac |
Jingwen Chen | acdcaa0 | 2022-10-13 07:24:24 +0000 | [diff] [blame] | 1988 | OUT_DIR="$(get_abs_build_var OUT_DIR)" |
Dan Albert | bab814f | 2020-08-26 15:34:53 -0700 | [diff] [blame] | 1989 | if [[ "$1" == "--regenerate" ]]; then |
| 1990 | shift 1 |
| 1991 | NINJA_ARGS="-t commands $@" m |
| 1992 | else |
| 1993 | (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \ |
| 1994 | -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \ |
| 1995 | -t commands "$@") |
| 1996 | fi |
| 1997 | } |
| 1998 | |
Cole Faust | 45844ab | 2022-08-30 13:59:07 -0700 | [diff] [blame] | 1999 | function avbtool() { |
| 2000 | if [[ ! -f "$ANDROID_SOONG_HOST_OUT"/bin/avbtool ]]; then |
| 2001 | m avbtool |
| 2002 | fi |
| 2003 | "$ANDROID_SOONG_HOST_OUT"/bin/avbtool $@ |
| 2004 | } |
| 2005 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 2006 | validate_current_shell |
| 2007 | source_vendorsetup |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 2008 | addcompletions |