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