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