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: |
Greg Kaiser | 5e2d339 | 2023-10-27 14:15:48 -0600 | [diff] [blame] | 59 | - lunch: lunch <product_name>-<release_type>-<build_variant> |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 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). |
Martin Stjernholm | a73fe8d | 2023-12-22 13:32:42 +0000 | [diff] [blame] | 65 | - banchan: banchan <module1> [<module2> ...] \\ |
Ulya Trafimovich | 08c381b | 2023-06-12 15:33:09 +0100 | [diff] [blame] | 66 | [arm|x86|arm64|riscv64|x86_64|arm64_only|x86_64only] [eng|userdebug|user] |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 67 | Sets up the build environment for building unbundled modules (APEXes). |
Anton Hansson | ece9c48 | 2019-02-04 18:15:39 +0000 | [diff] [blame] | 68 | - croot: Changes directory to the top of the tree, or a subdirectory thereof. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 69 | - m: Makes from the top of the tree. |
Dan Willemsen | 67074fe | 2019-10-30 12:35:34 -0700 | [diff] [blame] | 70 | - mm: Builds and installs all of the modules in the current directory, and their |
| 71 | dependencies. |
| 72 | - mmm: Builds and installs all of the modules in the supplied directories, and their |
| 73 | dependencies. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 74 | To limit the modules being built use the syntax: mmm dir/:target1,target2. |
Dan Willemsen | 67074fe | 2019-10-30 12:35:34 -0700 | [diff] [blame] | 75 | - mma: Same as 'mm' |
| 76 | - mmma: Same as 'mmm' |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 77 | - provision: Flash device with all required partitions. Options will be passed on to fastboot. |
| 78 | - cgrep: Greps on all local C/C++ files. |
| 79 | - ggrep: Greps on all local Gradle files. |
Orion Hodson | 831472d | 2019-10-25 11:35:15 +0100 | [diff] [blame] | 80 | - gogrep: Greps on all local Go files. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 81 | - jgrep: Greps on all local Java files. |
Jeff Vander Stoep | f5f5146 | 2023-01-10 14:09:45 +0100 | [diff] [blame] | 82 | - jsongrep: Greps on all local Json files. |
Taesu Lee | ea0cecd | 2020-10-28 11:05:18 +0900 | [diff] [blame] | 83 | - ktgrep: Greps on all local Kotlin files. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 84 | - resgrep: Greps on all local res/*.xml files. |
| 85 | - mangrep: Greps on all local AndroidManifest.xml files. |
Jaewoong Jung | 892d0fe | 2019-05-04 10:06:28 -0700 | [diff] [blame] | 86 | - mgrep: Greps on all local Makefiles and *.bp files. |
Jeff Sharkey | f17cddf | 2019-08-21 12:51:26 -0600 | [diff] [blame] | 87 | - owngrep: Greps on all local OWNERS files. |
Alistair Delva | 176e534 | 2021-02-22 13:31:26 -0800 | [diff] [blame] | 88 | - rsgrep: Greps on all local Rust files. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 89 | - sepgrep: Greps on all local sepolicy files. |
| 90 | - sgrep: Greps on all local source files. |
Jeff Vander Stoep | f5f5146 | 2023-01-10 14:09:45 +0100 | [diff] [blame] | 91 | - tomlgrep: Greps on all local Toml files. |
DroidFreak32 | a278198 | 2020-11-26 11:30:19 -0500 | [diff] [blame] | 92 | - pygrep: Greps on all local Python files. |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 93 | - godir: Go to the directory containing a file. |
| 94 | - allmod: List all modules. |
| 95 | - gomod: Go to the directory containing a module. |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 96 | - pathmod: Get the directory containing a module. |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 97 | - 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] | 98 | - dirmods: Gets the modules defined in a given directory. |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 99 | - installmod: Adb installs a module's built APK. |
| 100 | - refreshmod: Refresh list of modules for allmod/gomod/pathmod/outmod/installmod. |
Steven Moreland | 74114f1 | 2020-09-10 01:23:32 +0000 | [diff] [blame] | 101 | - 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] | 102 | |
Roland Levillain | 3934192 | 2015-10-20 12:48:19 +0100 | [diff] [blame] | 103 | Environment options: |
Steven Moreland | 115d1f5 | 2019-09-26 16:30:28 -0700 | [diff] [blame] | 104 | - SANITIZE_HOST: Set to 'address' to use ASAN for all host modules. |
Sasha Smundak | 9f27cc0 | 2019-01-31 13:25:31 -0800 | [diff] [blame] | 105 | - ANDROID_QUIET_BUILD: set to 'true' to display only the essential messages. |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 106 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 107 | Look at the source to view more functions. The complete list is: |
| 108 | EOF |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 109 | local T=$(gettop) |
| 110 | local A="" |
| 111 | local i |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 112 | 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] | 113 | A="$A $i" |
| 114 | done |
| 115 | echo $A |
| 116 | } |
| 117 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 118 | # 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] | 119 | function build_build_var_cache() |
| 120 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 121 | local T=$(gettop) |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 122 | # Grep out the variable names from the script. |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 123 | 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' ' '`) |
| 124 | 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] | 125 | # 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] | 126 | 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] | 127 | --vars="${cached_vars[*]}" \ |
| 128 | --abs-vars="${cached_abs_vars[*]}" \ |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 129 | --var-prefix=var_cache_ \ |
| 130 | --abs-var-prefix=abs_var_cache_` |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 131 | local ret=$? |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 132 | if [ $ret -ne 0 ] |
| 133 | then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 134 | unset build_dicts_script |
| 135 | return $ret |
| 136 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 137 | # Execute the script to store the "<val>=<value>" pairs as shell variables. |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 138 | eval "$build_dicts_script" |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 139 | ret=$? |
Ying Wang | f0cb397 | 2016-03-04 13:56:23 -0800 | [diff] [blame] | 140 | unset build_dicts_script |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 141 | if [ $ret -ne 0 ] |
| 142 | then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 143 | return $ret |
| 144 | fi |
| 145 | BUILD_VAR_CACHE_READY="true" |
| 146 | } |
| 147 | |
Ying Wang | f0cb397 | 2016-03-04 13:56:23 -0800 | [diff] [blame] | 148 | # 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] | 149 | # to get build variables not listed in this script. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 150 | function destroy_build_var_cache() |
| 151 | { |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 152 | unset BUILD_VAR_CACHE_READY |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 153 | local v |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 154 | for v in $cached_vars; do |
| 155 | unset var_cache_$v |
| 156 | done |
| 157 | unset cached_vars |
| 158 | for v in $cached_abs_vars; do |
| 159 | unset abs_var_cache_$v |
| 160 | done |
| 161 | unset cached_abs_vars |
| 162 | } |
| 163 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 164 | # Get the value of a build variable as an absolute path. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 165 | function get_abs_build_var() |
| 166 | { |
| 167 | if [ "$BUILD_VAR_CACHE_READY" = "true" ] |
| 168 | then |
Vishwath Mohan | 7d35f00 | 2016-03-11 10:00:40 -0800 | [diff] [blame] | 169 | eval "echo \"\${abs_var_cache_$1}\"" |
Timi | 0469c3f | 2021-04-15 16:41:18 +0200 | [diff] [blame] | 170 | return |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 171 | fi |
| 172 | |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 173 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 174 | if [ ! "$T" ]; then |
| 175 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 176 | return |
| 177 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 178 | (\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] | 179 | } |
| 180 | |
| 181 | # Get the exact value of a build variable. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 182 | function get_build_var() |
| 183 | { |
| 184 | if [ "$BUILD_VAR_CACHE_READY" = "true" ] |
| 185 | then |
Vishwath Mohan | 7d35f00 | 2016-03-11 10:00:40 -0800 | [diff] [blame] | 186 | eval "echo \"\${var_cache_$1}\"" |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 187 | return 0 |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 188 | fi |
| 189 | |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 190 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 191 | if [ ! "$T" ]; then |
| 192 | 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] | 193 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 194 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 195 | (\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] | 196 | } |
| 197 | |
Joe Onorato | 32b2aa3 | 2024-05-14 13:54:13 -0700 | [diff] [blame] | 198 | # This logic matches envsetup.mk |
| 199 | function get_host_prebuilt_prefix |
| 200 | { |
| 201 | local un=$(uname) |
| 202 | if [[ $un == "Linux" ]] ; then |
| 203 | echo linux-x86 |
| 204 | elif [[ $un == "Darwin" ]] ; then |
| 205 | echo darwin-x86 |
| 206 | else |
| 207 | echo "Error: Invalid host operating system: $un" 1>&2 |
| 208 | fi |
| 209 | } |
| 210 | |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 211 | # Add directories to PATH that are dependent on the lunch target. |
| 212 | # For directories that are not lunch-specific, add them in set_global_paths |
| 213 | function set_lunch_paths() |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 214 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 215 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 216 | if [ ! "$T" ]; then |
| 217 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 218 | return |
| 219 | fi |
| 220 | |
| 221 | ################################################################## |
| 222 | # # |
| 223 | # Read me before you modify this code # |
| 224 | # # |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 225 | # This function sets ANDROID_LUNCH_BUILD_PATHS to what it is # |
| 226 | # adding to PATH, and the next time it is run, it removes that # |
| 227 | # from PATH. This is required so lunch can be run more than # |
| 228 | # once and still have working paths. # |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 229 | # # |
| 230 | ################################################################## |
| 231 | |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 232 | # Note: on windows/cygwin, ANDROID_LUNCH_BUILD_PATHS will contain spaces |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 233 | # due to "C:\Program Files" being in the path. |
| 234 | |
Kevin Dagostino | 185109b | 2024-01-11 17:39:02 +0000 | [diff] [blame] | 235 | # Handle compat with the old ANDROID_BUILD_PATHS variable. |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 236 | # TODO: Remove this after we think everyone has lunched again. |
| 237 | if [ -z "$ANDROID_LUNCH_BUILD_PATHS" -a -n "$ANDROID_BUILD_PATHS" ] ; then |
| 238 | ANDROID_LUNCH_BUILD_PATHS="$ANDROID_BUILD_PATHS" |
| 239 | ANDROID_BUILD_PATHS= |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 240 | fi |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 241 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 242 | export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} |
Ying Wang | aa1c9b5 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 243 | # strip leading ':', if any |
| 244 | export PATH=${PATH/:%/} |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 245 | ANDROID_PRE_BUILD_PATHS= |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 246 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 247 | |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 248 | # Out with the old... |
| 249 | if [ -n "$ANDROID_LUNCH_BUILD_PATHS" ] ; then |
| 250 | export PATH=${PATH/$ANDROID_LUNCH_BUILD_PATHS/} |
| 251 | fi |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 252 | |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 253 | # And in with the new... |
| 254 | ANDROID_LUNCH_BUILD_PATHS=$(get_abs_build_var SOONG_HOST_OUT_EXECUTABLES) |
| 255 | ANDROID_LUNCH_BUILD_PATHS+=:$(get_abs_build_var HOST_OUT_EXECUTABLES) |
Yueyao Zhu | efc786a | 2017-04-07 14:11:54 -0700 | [diff] [blame] | 256 | |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 257 | # Append llvm binutils prebuilts path to ANDROID_LUNCH_BUILD_PATHS. |
Yi Kong | dfd00b1 | 2019-05-21 16:00:04 -0700 | [diff] [blame] | 258 | 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] | 259 | ANDROID_LUNCH_BUILD_PATHS+=:$ANDROID_LLVM_BINUTILS |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 260 | |
Stephen Hines | aa8d72c | 2020-02-04 09:15:18 -0800 | [diff] [blame] | 261 | # Set up ASAN_SYMBOLIZER_PATH for SANITIZE_HOST=address builds. |
| 262 | export ASAN_SYMBOLIZER_PATH=$ANDROID_LLVM_BINUTILS/llvm-symbolizer |
| 263 | |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 264 | # Append asuite prebuilts path to ANDROID_LUNCH_BUILD_PATHS. |
Jim Tang | b3fda30 | 2018-12-22 10:24:55 +0800 | [diff] [blame] | 265 | local os_arch=$(get_build_var HOST_PREBUILT_TAG) |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 266 | ANDROID_LUNCH_BUILD_PATHS+=:$T/prebuilts/asuite/acloud/$os_arch |
| 267 | ANDROID_LUNCH_BUILD_PATHS+=:$T/prebuilts/asuite/aidegen/$os_arch |
| 268 | 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] | 269 | |
Colin Cross | e97e693 | 2017-06-30 16:01:45 -0700 | [diff] [blame] | 270 | export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME) |
| 271 | export JAVA_HOME=$ANDROID_JAVA_HOME |
| 272 | export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN) |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 273 | ANDROID_LUNCH_BUILD_PATHS+=:$ANDROID_JAVA_TOOLCHAIN |
| 274 | |
| 275 | # Fix up PYTHONPATH |
| 276 | if [ -n $ANDROID_PYTHONPATH ]; then |
| 277 | export PYTHONPATH=${PYTHONPATH//$ANDROID_PYTHONPATH/} |
| 278 | fi |
Dan Albert | 0d6d359 | 2023-01-26 00:07:03 +0000 | [diff] [blame] | 279 | # //development/python-packages contains both a pseudo-PYTHONPATH which |
| 280 | # mimics an already assembled venv, but also contains real Python packages |
| 281 | # that are not in that layout until they are installed. We can fake it for |
| 282 | # the latter type by adding the package source directories to the PYTHONPATH |
| 283 | # directly. For the former group, we only need to add the python-packages |
| 284 | # directory itself. |
| 285 | # |
| 286 | # This could be cleaned up by converting the remaining packages that are in |
| 287 | # the first category into a typical python source layout (that is, another |
| 288 | # layer of directory nesting) and automatically adding all subdirectories of |
| 289 | # python-packages to the PYTHONPATH instead of manually curating this. We |
| 290 | # can't convert the packages like adb to the other style because doing so |
| 291 | # would prevent exporting type info from those packages. |
| 292 | # |
| 293 | # http://b/266688086 |
Dan Albert | 426ac69 | 2023-05-16 22:59:55 +0000 | [diff] [blame] | 294 | export ANDROID_PYTHONPATH=$T/development/python-packages/adb:$T/development/python-packages/gdbrunner:$T/development/python-packages: |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 295 | if [ -n $VENDOR_PYTHONPATH ]; then |
| 296 | ANDROID_PYTHONPATH=$ANDROID_PYTHONPATH$VENDOR_PYTHONPATH |
| 297 | fi |
| 298 | export PYTHONPATH=$ANDROID_PYTHONPATH$PYTHONPATH |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 299 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 300 | unset ANDROID_PRODUCT_OUT |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 301 | export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) |
| 302 | export OUT=$ANDROID_PRODUCT_OUT |
| 303 | |
Jeff Brown | 8fd5cce | 2011-03-24 17:03:06 -0700 | [diff] [blame] | 304 | unset ANDROID_HOST_OUT |
| 305 | export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) |
| 306 | |
Jiyong Park | c02b1c4 | 2020-11-03 11:06:39 +0900 | [diff] [blame] | 307 | unset ANDROID_SOONG_HOST_OUT |
| 308 | export ANDROID_SOONG_HOST_OUT=$(get_abs_build_var SOONG_HOST_OUT) |
| 309 | |
Simran Basi | dd050ed | 2017-02-13 13:46:48 -0800 | [diff] [blame] | 310 | unset ANDROID_HOST_OUT_TESTCASES |
| 311 | export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES) |
| 312 | |
| 313 | unset ANDROID_TARGET_OUT_TESTCASES |
| 314 | export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES) |
| 315 | |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 316 | # Finally, set PATH |
Joe Onorato | 1cb9e15 | 2022-12-05 16:56:15 -0800 | [diff] [blame] | 317 | export PATH=$ANDROID_LUNCH_BUILD_PATHS:$PATH |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | # Add directories to PATH that are NOT dependent on the lunch target. |
| 321 | # For directories that are lunch-specific, add them in set_lunch_paths |
| 322 | function set_global_paths() |
| 323 | { |
| 324 | local T=$(gettop) |
| 325 | if [ ! "$T" ]; then |
| 326 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 327 | return |
| 328 | fi |
| 329 | |
| 330 | ################################################################## |
| 331 | # # |
| 332 | # Read me before you modify this code # |
| 333 | # # |
| 334 | # This function sets ANDROID_GLOBAL_BUILD_PATHS to what it is # |
| 335 | # adding to PATH, and the next time it is run, it removes that # |
| 336 | # from PATH. This is required so envsetup.sh can be sourced # |
| 337 | # more than once and still have working paths. # |
| 338 | # # |
| 339 | ################################################################## |
| 340 | |
| 341 | # Out with the old... |
| 342 | if [ -n "$ANDROID_GLOBAL_BUILD_PATHS" ] ; then |
| 343 | export PATH=${PATH/$ANDROID_GLOBAL_BUILD_PATHS/} |
| 344 | fi |
| 345 | |
| 346 | # And in with the new... |
Joe Onorato | 84e61d0 | 2024-02-02 22:53:39 -0800 | [diff] [blame] | 347 | ANDROID_GLOBAL_BUILD_PATHS=$T/build/soong/bin |
LaMont Jones | e8a3be2 | 2024-02-12 09:55:41 -0800 | [diff] [blame] | 348 | ANDROID_GLOBAL_BUILD_PATHS+=:$T/build/bazel/bin |
Joe Onorato | 1cb9e15 | 2022-12-05 16:56:15 -0800 | [diff] [blame] | 349 | ANDROID_GLOBAL_BUILD_PATHS+=:$T/development/scripts |
| 350 | ANDROID_GLOBAL_BUILD_PATHS+=:$T/prebuilts/devtools/tools |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 351 | |
| 352 | # add kernel specific binaries |
| 353 | if [ $(uname -s) = Linux ] ; then |
| 354 | ANDROID_GLOBAL_BUILD_PATHS+=:$T/prebuilts/misc/linux-x86/dtc |
| 355 | ANDROID_GLOBAL_BUILD_PATHS+=:$T/prebuilts/misc/linux-x86/libufdt |
| 356 | fi |
| 357 | |
| 358 | # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH |
| 359 | # to ensure that the corresponding 'emulator' binaries are used. |
| 360 | case $(uname -s) in |
| 361 | Darwin) |
| 362 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64 |
| 363 | ;; |
| 364 | Linux) |
| 365 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64 |
| 366 | ;; |
| 367 | *) |
| 368 | ANDROID_EMULATOR_PREBUILTS= |
| 369 | ;; |
| 370 | esac |
| 371 | if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then |
| 372 | ANDROID_GLOBAL_BUILD_PATHS+=:$ANDROID_EMULATOR_PREBUILTS |
| 373 | export ANDROID_EMULATOR_PREBUILTS |
| 374 | fi |
| 375 | |
| 376 | # Finally, set PATH |
Joe Onorato | 1cb9e15 | 2022-12-05 16:56:15 -0800 | [diff] [blame] | 377 | export PATH=$ANDROID_GLOBAL_BUILD_PATHS:$PATH |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 380 | function printconfig() |
| 381 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 382 | local T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 383 | if [ ! "$T" ]; then |
| 384 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 385 | return |
| 386 | fi |
| 387 | get_build_var report_config |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 390 | function set_stuff_for_environment() |
| 391 | { |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 392 | set_lunch_paths |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 393 | set_sequence_number |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 394 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 395 | export ANDROID_BUILD_TOP=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 398 | function set_sequence_number() |
| 399 | { |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 400 | export BUILD_ENV_SEQUENCE_NUMBER=13 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 403 | # Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not. |
| 404 | function should_add_completion() { |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 405 | local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')" |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 406 | case :"$ENVSETUP_NO_COMPLETION": in |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 407 | *:"$cmd":*) |
| 408 | return 1 |
| 409 | ;; |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 410 | esac |
| 411 | return 0 |
| 412 | } |
| 413 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 414 | function addcompletions() |
| 415 | { |
Ben Taitelbaum | 8c2c9cf | 2020-09-22 16:45:05 -0700 | [diff] [blame] | 416 | local f= |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 417 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 418 | # Keep us from trying to run in something that's neither bash nor zsh. |
| 419 | if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 420 | return |
| 421 | fi |
| 422 | |
| 423 | # Keep us from trying to run in bash that's too old. |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 424 | if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 425 | return |
| 426 | fi |
| 427 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 428 | local completion_files=( |
MÃ¥rten Kongstad | cb5c73f | 2022-05-04 14:08:12 +0000 | [diff] [blame] | 429 | packages/modules/adb/adb.bash |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 430 | system/core/fastboot/fastboot.bash |
Jim Tang | b3fda30 | 2018-12-22 10:24:55 +0800 | [diff] [blame] | 431 | tools/asuite/asuite.sh |
Chris Parsons | a297297 | 2022-08-31 15:04:38 -0400 | [diff] [blame] | 432 | prebuilts/bazel/common/bazel-complete.bash |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 433 | ) |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 434 | # Completion can be disabled selectively to allow users to use non-standard completion. |
| 435 | # e.g. |
| 436 | # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion |
| 437 | # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion |
Usta Shrestha | 1433fb3 | 2022-05-13 14:49:40 -0400 | [diff] [blame] | 438 | local T=$(gettop) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 439 | for f in ${completion_files[*]}; do |
Usta Shrestha | 1433fb3 | 2022-05-13 14:49:40 -0400 | [diff] [blame] | 440 | f="$T/$f" |
MÃ¥rten Kongstad | cb5c73f | 2022-05-04 14:08:12 +0000 | [diff] [blame] | 441 | if [ ! -f "$f" ]; then |
| 442 | echo "Warning: completion file $f not found" |
| 443 | elif should_add_completion "$f"; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 444 | . $f |
Elliott Hughes | ce18dd4 | 2018-04-03 13:49:48 -0700 | [diff] [blame] | 445 | fi |
| 446 | done |
Joe Onorato | 002a6c7 | 2016-10-20 16:39:49 -0700 | [diff] [blame] | 447 | |
Anton Hansson | ece9c48 | 2019-02-04 18:15:39 +0000 | [diff] [blame] | 448 | if [ -z "$ZSH_VERSION" ]; then |
| 449 | # Doesn't work in zsh. |
| 450 | complete -o nospace -F _croot croot |
Chris Parsons | a297297 | 2022-08-31 15:04:38 -0400 | [diff] [blame] | 451 | # TODO(b/244559459): Support b autocompletion for zsh |
| 452 | complete -F _bazel__complete -o nospace b |
Anton Hansson | ece9c48 | 2019-02-04 18:15:39 +0000 | [diff] [blame] | 453 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 454 | complete -F _lunch lunch |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 455 | |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 456 | complete -F _complete_android_module_names pathmod |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame] | 457 | complete -F _complete_android_module_names gomod |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 458 | complete -F _complete_android_module_names outmod |
| 459 | complete -F _complete_android_module_names installmod |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame] | 460 | complete -F _complete_android_module_names m |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 463 | function add_lunch_combo() |
| 464 | { |
Dan Willemsen | 5436c7e | 2019-02-11 21:31:47 -0800 | [diff] [blame] | 465 | if [ -n "$ZSH_VERSION" ]; then |
| 466 | echo -n "${funcfiletrace[1]}: " |
| 467 | else |
| 468 | echo -n "${BASH_SOURCE[1]}:${BASH_LINENO[0]}: " |
| 469 | fi |
| 470 | 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] | 471 | } |
| 472 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 473 | function print_lunch_menu() |
| 474 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 475 | local uname=$(uname) |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 476 | local choices |
Greg Kaiser | b6a0d39 | 2023-10-27 15:56:32 -0600 | [diff] [blame] | 477 | choices=$(TARGET_BUILD_APPS= TARGET_PRODUCT= TARGET_RELEASE= TARGET_BUILD_VARIANT= get_build_var COMMON_LUNCH_CHOICES 2>/dev/null) |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 478 | local ret=$? |
| 479 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 480 | echo |
| 481 | echo "You're building on" $uname |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 482 | echo |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 483 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 484 | if [ $ret -ne 0 ] |
| 485 | then |
Roland Levillain | 23c46cf | 2020-03-31 16:11:05 +0100 | [diff] [blame] | 486 | echo "Warning: Cannot display lunch menu." |
| 487 | echo |
| 488 | echo "Note: You can invoke lunch with an explicit target:" |
| 489 | echo |
| 490 | echo " usage: lunch [target]" >&2 |
| 491 | echo |
| 492 | return |
| 493 | fi |
| 494 | |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 495 | echo "Lunch menu .. Here are the common combinations:" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 496 | |
| 497 | local i=1 |
| 498 | local choice |
Dan Willemsen | 91763e9 | 2019-10-03 15:13:12 -0700 | [diff] [blame] | 499 | for choice in $(echo $choices) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 500 | do |
| 501 | echo " $i. $choice" |
| 502 | i=$(($i+1)) |
| 503 | done |
| 504 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 505 | echo |
| 506 | } |
| 507 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 508 | function lunch() |
| 509 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 510 | local answer |
| 511 | |
Steven Moreland | 92793dc | 2020-02-25 18:30:18 -0800 | [diff] [blame] | 512 | if [[ $# -gt 1 ]]; then |
| 513 | echo "usage: lunch [target]" >&2 |
| 514 | return 1 |
| 515 | fi |
| 516 | |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 517 | local used_lunch_menu=0 |
| 518 | |
Steven Moreland | 92793dc | 2020-02-25 18:30:18 -0800 | [diff] [blame] | 519 | if [ "$1" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 520 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 521 | else |
| 522 | print_lunch_menu |
Greg Kaiser | bae4c57 | 2024-01-04 15:57:54 -0700 | [diff] [blame] | 523 | echo "Which would you like? [aosp_cf_x86_64_phone-trunk_staging-eng]" |
Greg Kaiser | 9a5a526 | 2023-11-02 16:54:27 +0000 | [diff] [blame] | 524 | echo -n "Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-trunk_staging-eng): " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 525 | read answer |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 526 | used_lunch_menu=1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 527 | fi |
| 528 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 529 | local selection= |
| 530 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 531 | if [ -z "$answer" ] |
| 532 | then |
Greg Kaiser | bae4c57 | 2024-01-04 15:57:54 -0700 | [diff] [blame] | 533 | selection=aosp_cf_x86_64_phone-trunk_staging-eng |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 534 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 535 | then |
Fabián Cañas | 03dd028 | 2024-01-05 16:57:39 -0500 | [diff] [blame] | 536 | local choices=($(TARGET_BUILD_APPS= TARGET_PRODUCT= TARGET_RELEASE= TARGET_BUILD_VARIANT= get_build_var COMMON_LUNCH_CHOICES 2>/dev/null)) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 537 | if [ $answer -le ${#choices[@]} ] |
| 538 | then |
Jim Tang | 0e3397b | 2018-10-03 18:25:50 +0800 | [diff] [blame] | 539 | # array in zsh starts from 1 instead of 0. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 540 | if [ -n "$ZSH_VERSION" ] |
| 541 | then |
Jim Tang | 0e3397b | 2018-10-03 18:25:50 +0800 | [diff] [blame] | 542 | selection=${choices[$(($answer))]} |
| 543 | else |
| 544 | selection=${choices[$(($answer-1))]} |
| 545 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 546 | fi |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 547 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 548 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 549 | fi |
| 550 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 551 | export TARGET_BUILD_APPS= |
| 552 | |
Greg Kaiser | 5e2d339 | 2023-10-27 14:15:48 -0600 | [diff] [blame] | 553 | # This must be <product>-<release>-<variant> |
| 554 | local product release variant |
| 555 | # Split string on the '-' character. |
| 556 | IFS="-" read -r product release variant <<< "$selection" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 557 | |
Greg Kaiser | 5e2d339 | 2023-10-27 14:15:48 -0600 | [diff] [blame] | 558 | if [[ -z "$product" ]] || [[ -z "$release" ]] || [[ -z "$variant" ]] |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 559 | then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 560 | echo |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 561 | echo "Invalid lunch combo: $selection" |
Greg Kaiser | 5e2d339 | 2023-10-27 14:15:48 -0600 | [diff] [blame] | 562 | echo "Valid combos must be of the form <product>-<release>-<variant>" |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 563 | return 1 |
| 564 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 565 | |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 566 | TARGET_PRODUCT=$product \ |
| 567 | TARGET_BUILD_VARIANT=$variant \ |
Jeff Hamilton | a02c747 | 2023-05-08 03:13:29 +0000 | [diff] [blame] | 568 | TARGET_RELEASE=$release \ |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 569 | build_build_var_cache |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 570 | if [ $? -ne 0 ] |
| 571 | then |
Anton Hansson | 32fa7ee | 2021-06-14 17:09:58 +0100 | [diff] [blame] | 572 | if [[ "$product" =~ .*_(eng|user|userdebug) ]] |
| 573 | then |
| 574 | echo "Did you mean -${product/*_/}? (dash instead of underscore)" |
| 575 | fi |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 576 | return 1 |
| 577 | fi |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 578 | export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT) |
| 579 | export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT) |
Greg Kaiser | 5e2d339 | 2023-10-27 14:15:48 -0600 | [diff] [blame] | 580 | export TARGET_RELEASE=$release |
| 581 | # Note this is the string "release", not the value of the variable. |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 582 | export TARGET_BUILD_TYPE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 583 | |
Mark White | 2c80751 | 2023-10-25 17:27:07 +0000 | [diff] [blame] | 584 | [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || echo |
| 585 | |
| 586 | set_stuff_for_environment |
| 587 | [[ -n "${ANDROID_QUIET_BUILD:-}" ]] || printconfig |
| 588 | |
| 589 | if [ "${TARGET_BUILD_VARIANT}" = "userdebug" ] && [[ -z "${ANDROID_QUIET_BUILD}" ]]; then |
| 590 | echo |
| 591 | echo "Want FASTER LOCAL BUILDS? Use -eng instead of -userdebug (however for" \ |
| 592 | "performance benchmarking continue to use userdebug)" |
| 593 | fi |
Will Burr | 4040120 | 2022-02-07 12:12:01 +0000 | [diff] [blame] | 594 | if [ $used_lunch_menu -eq 1 ]; then |
| 595 | echo |
| 596 | echo "Hint: next time you can simply run 'lunch $selection'" |
| 597 | fi |
| 598 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 599 | destroy_build_var_cache |
Kousik Kumar | 41dacd1 | 2021-05-11 18:38:38 -0400 | [diff] [blame] | 600 | |
| 601 | if [[ -n "${CHECK_MU_CONFIG:-}" ]]; then |
| 602 | check_mu_config |
| 603 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 606 | unset COMMON_LUNCH_CHOICES_CACHE |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 607 | # Tab completion for lunch. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 608 | function _lunch() |
| 609 | { |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 610 | local cur prev opts |
| 611 | COMPREPLY=() |
| 612 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 613 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 614 | |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 615 | if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then |
Dan Willemsen | 5436c7e | 2019-02-11 21:31:47 -0800 | [diff] [blame] | 616 | 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] | 617 | fi |
| 618 | |
| 619 | COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) ) |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 620 | return 0 |
| 621 | } |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 622 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 623 | # Configures the build to build unbundled apps. |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 624 | # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 625 | function tapas() |
| 626 | { |
Jeff Gaston | 9fb05d8 | 2017-08-21 18:27:00 -0700 | [diff] [blame] | 627 | local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)" |
Elliott Hughes | f71c05a | 2020-03-06 16:46:59 -0800 | [diff] [blame] | 628 | local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|arm64|x86_64)$' | xargs)" |
Greg Kaiser | 83ed159 | 2023-10-26 18:37:40 +0000 | [diff] [blame] | 629 | # TODO(b/307975293): Expand tapas to take release arguments (and update hmm() usage). |
| 630 | local release="trunk_staging" |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 631 | 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] | 632 | 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] | 633 | local keys="$(echo $* | xargs -n 1 echo | \grep -E '^(devkeys)$' | xargs)" |
| 634 | 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)" |
| 635 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 636 | |
Jeff Gaston | 9fb05d8 | 2017-08-21 18:27:00 -0700 | [diff] [blame] | 637 | if [ "$showHelp" != "" ]; then |
| 638 | $(gettop)/build/make/tapasHelp.sh |
| 639 | return |
| 640 | fi |
| 641 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 642 | if [ $(echo $arch | wc -w) -gt 1 ]; then |
| 643 | echo "tapas: Error: Multiple build archs supplied: $arch" |
| 644 | return |
| 645 | fi |
Greg Kaiser | 83ed159 | 2023-10-26 18:37:40 +0000 | [diff] [blame] | 646 | if [ $(echo $release | wc -w) -gt 1 ]; then |
| 647 | echo "tapas: Error: Multiple build releases supplied: $release" |
| 648 | return |
| 649 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 650 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 651 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 652 | return |
| 653 | fi |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 654 | if [ $(echo $density | wc -w) -gt 1 ]; then |
| 655 | echo "tapas: Error: Multiple densities supplied: $density" |
| 656 | return |
| 657 | fi |
Colin Cross | 7f49a67 | 2022-01-27 18:15:53 -0800 | [diff] [blame] | 658 | if [ $(echo $keys | wc -w) -gt 1 ]; then |
| 659 | echo "tapas: Error: Multiple keys supplied: $keys" |
| 660 | return |
| 661 | fi |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 662 | |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 663 | local product=aosp_arm |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 664 | case $arch in |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 665 | x86) product=aosp_x86;; |
| 666 | arm64) product=aosp_arm64;; |
| 667 | x86_64) product=aosp_x86_64;; |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 668 | esac |
Colin Cross | 7f49a67 | 2022-01-27 18:15:53 -0800 | [diff] [blame] | 669 | if [ -n "$keys" ]; then |
| 670 | product=${product/aosp_/aosp_${keys}_} |
| 671 | fi; |
| 672 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 673 | if [ -z "$variant" ]; then |
| 674 | variant=eng |
| 675 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 676 | if [ -z "$apps" ]; then |
| 677 | apps=all |
| 678 | fi |
Justin Morey | 29d225c | 2014-11-04 13:35:51 -0600 | [diff] [blame] | 679 | if [ -z "$density" ]; then |
| 680 | density=alldpi |
| 681 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 682 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 683 | export TARGET_PRODUCT=$product |
Greg Kaiser | 83ed159 | 2023-10-26 18:37:40 +0000 | [diff] [blame] | 684 | export TARGET_RELEASE=$release |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 685 | export TARGET_BUILD_VARIANT=$variant |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 686 | export TARGET_BUILD_DENSITY=$density |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 687 | export TARGET_BUILD_TYPE=release |
| 688 | export TARGET_BUILD_APPS=$apps |
| 689 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 690 | build_build_var_cache |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 691 | set_stuff_for_environment |
| 692 | printconfig |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 693 | destroy_build_var_cache |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 696 | # Configures the build to build unbundled Android modules (APEXes). |
| 697 | # Run banchan with one or more module names (from apex{} modules). |
| 698 | function banchan() |
| 699 | { |
| 700 | local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)" |
Ulya Trafimovich | 08c381b | 2023-06-12 15:33:09 +0100 | [diff] [blame] | 701 | local product="$(echo $* | xargs -n 1 echo | \grep -E '^(.*_)?(arm|x86|arm64|riscv64|x86_64|arm64only|x86_64only)$' | xargs)" |
Greg Kaiser | d35095e | 2023-10-27 16:04:30 -0600 | [diff] [blame] | 702 | # TODO: Expand banchan to take release arguments (and update hmm() usage). |
| 703 | local release="trunk_staging" |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 704 | local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)" |
Ulya Trafimovich | 08c381b | 2023-06-12 15:33:09 +0100 | [diff] [blame] | 705 | local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|(.*_)?(arm|x86|arm64|riscv64|x86_64))$' | xargs)" |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 706 | |
| 707 | if [ "$showHelp" != "" ]; then |
| 708 | $(gettop)/build/make/banchanHelp.sh |
| 709 | return |
| 710 | fi |
| 711 | |
Martin Stjernholm | 2b8d923 | 2021-04-16 20:45:03 +0100 | [diff] [blame] | 712 | if [ -z "$product" ]; then |
Anton Hansson | 0328e32 | 2022-05-24 15:47:40 +0000 | [diff] [blame] | 713 | product=arm64 |
Martin Stjernholm | 2b8d923 | 2021-04-16 20:45:03 +0100 | [diff] [blame] | 714 | elif [ $(echo $product | wc -w) -gt 1 ]; then |
| 715 | echo "banchan: Error: Multiple build archs or products supplied: $products" |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 716 | return |
| 717 | fi |
Greg Kaiser | d35095e | 2023-10-27 16:04:30 -0600 | [diff] [blame] | 718 | if [ $(echo $release | wc -w) -gt 1 ]; then |
| 719 | echo "banchan: Error: Multiple build releases supplied: $release" |
| 720 | return |
| 721 | fi |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 722 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 723 | echo "banchan: Error: Multiple build variants supplied: $variant" |
| 724 | return |
| 725 | fi |
| 726 | if [ -z "$apps" ]; then |
| 727 | echo "banchan: Error: No modules supplied" |
| 728 | return |
| 729 | fi |
| 730 | |
Martin Stjernholm | 2b8d923 | 2021-04-16 20:45:03 +0100 | [diff] [blame] | 731 | case $product in |
| 732 | arm) product=module_arm;; |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 733 | x86) product=module_x86;; |
| 734 | arm64) product=module_arm64;; |
Ulya Trafimovich | 08c381b | 2023-06-12 15:33:09 +0100 | [diff] [blame] | 735 | riscv64) product=module_riscv64;; |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 736 | x86_64) product=module_x86_64;; |
Anton Hansson | 90ac61c | 2022-09-06 14:36:00 +0000 | [diff] [blame] | 737 | arm64only) product=module_arm64only;; |
| 738 | x86_64only) product=module_x86_64only;; |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 739 | esac |
| 740 | if [ -z "$variant" ]; then |
| 741 | variant=eng |
| 742 | fi |
| 743 | |
| 744 | export TARGET_PRODUCT=$product |
Greg Kaiser | d35095e | 2023-10-27 16:04:30 -0600 | [diff] [blame] | 745 | export TARGET_RELEASE=$release |
Martin Stjernholm | f692c75 | 2021-04-12 00:01:10 +0100 | [diff] [blame] | 746 | export TARGET_BUILD_VARIANT=$variant |
| 747 | export TARGET_BUILD_DENSITY=alldpi |
| 748 | export TARGET_BUILD_TYPE=release |
| 749 | |
| 750 | # This setup currently uses TARGET_BUILD_APPS just like tapas, but the use |
| 751 | # case is different and it may diverge in the future. |
| 752 | export TARGET_BUILD_APPS=$apps |
| 753 | |
| 754 | build_build_var_cache |
| 755 | set_stuff_for_environment |
| 756 | printconfig |
| 757 | destroy_build_var_cache |
| 758 | } |
| 759 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 760 | function croot() |
| 761 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 762 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 763 | if [ "$T" ]; then |
Marie Janssen | 32ec50a | 2016-04-21 16:53:39 -0700 | [diff] [blame] | 764 | if [ "$1" ]; then |
| 765 | \cd $(gettop)/$1 |
| 766 | else |
| 767 | \cd $(gettop) |
| 768 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 769 | else |
| 770 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 771 | fi |
| 772 | } |
| 773 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 774 | function _croot() |
| 775 | { |
Anton Hansson | ece9c48 | 2019-02-04 18:15:39 +0000 | [diff] [blame] | 776 | local T=$(gettop) |
| 777 | if [ "$T" ]; then |
| 778 | local cur="${COMP_WORDS[COMP_CWORD]}" |
| 779 | k=0 |
| 780 | for c in $(compgen -d ${T}/${cur}); do |
| 781 | COMPREPLY[k++]=${c#${T}/}/ |
| 782 | done |
| 783 | fi |
| 784 | } |
| 785 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 786 | function cproj() |
| 787 | { |
Colin Cross | 6cdc5d2 | 2017-10-20 11:37:33 -0700 | [diff] [blame] | 788 | local TOPFILE=build/make/core/envsetup.mk |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 789 | local HERE=$PWD |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 790 | local T= |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 791 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 792 | T=$PWD |
| 793 | if [ -f "$T/Android.mk" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 794 | \cd $T |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 795 | return |
| 796 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 797 | \cd .. |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 798 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 799 | \cd $HERE |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 800 | echo "can't find Android.mk" |
| 801 | } |
| 802 | |
Elliott Hughes | 86e9917 | 2024-03-21 16:55:08 +0000 | [diff] [blame] | 803 | # Ensure that we're always using the adb in the tree. This works around the fact |
| 804 | # that bash caches $PATH lookups, so if you use adb before lunching/building the |
| 805 | # one in your tree, you'll continue to get /usr/bin/adb or whatever even after |
| 806 | # you have the one from your current tree on your path. Historically this would |
| 807 | # cause confusion because glinux had adb in /usr/bin/ by default, though that |
| 808 | # doesn't appear to be the case on my rodete hosts; it is however still the case |
| 809 | # that my Mac has /usr/local/bin/adb installed by default and on the default |
| 810 | # path. |
Shaju Mathew | 2143900 | 2023-07-10 00:53:22 +0000 | [diff] [blame] | 811 | function adb() { |
Elliott Hughes | 57c47b7 | 2024-03-22 15:46:59 +0000 | [diff] [blame] | 812 | # We need `command which` because zsh has a built-in `which` that's more |
| 813 | # like `type`. |
| 814 | local ADB=$(command which adb) |
Elliott Hughes | 7e7ff75 | 2024-03-20 17:23:40 -0700 | [diff] [blame] | 815 | if [ -z "$ADB" ]; then |
| 816 | echo "Command adb not found; try lunch (and building) first?" |
| 817 | return 1 |
| 818 | fi |
Zhuoyao Zhang | 60dd9dd | 2024-04-19 00:07:59 +0000 | [diff] [blame] | 819 | run_tool_with_logging "ADB" $ADB "${@}" |
Shaju Mathew | 2143900 | 2023-07-10 00:53:22 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Zhuoyao Zhang | cc44d2e | 2024-03-26 22:50:12 +0000 | [diff] [blame] | 822 | function run_tool_with_logging() { |
| 823 | # Run commands in a subshell for us to handle forced terminations with a trap |
| 824 | # handler. |
| 825 | ( |
| 826 | local tool_tag="$1" |
| 827 | shift |
| 828 | local tool_binary="$1" |
| 829 | shift |
| 830 | |
Zhuoyao Zhang | ef1c03f | 2024-05-07 22:18:37 +0000 | [diff] [blame] | 831 | # If the logger is not configured, run the original command and return. |
| 832 | if [[ -z "${ANDROID_TOOL_LOGGER}" ]]; then |
Zhuoyao Zhang | cc44d2e | 2024-03-26 22:50:12 +0000 | [diff] [blame] | 833 | "${tool_binary}" "${@}" |
| 834 | return $? |
| 835 | fi |
| 836 | |
| 837 | # Otherwise, run the original command and call the logger when done. |
| 838 | local start_time |
| 839 | start_time=$(date +%s.%N) |
| 840 | local logger=${ANDROID_TOOL_LOGGER} |
| 841 | |
| 842 | # Install a trap to call the logger even when the process terminates abnormally. |
| 843 | # The logger is run in the background and its output suppressed to avoid |
| 844 | # interference with the user flow. |
| 845 | trap ' |
| 846 | exit_code=$?; |
| 847 | # Remove the trap to prevent duplicate log. |
| 848 | trap - EXIT; |
| 849 | "${logger}" \ |
Zhuoyao Zhang | dfdf19f | 2024-05-20 18:31:12 +0000 | [diff] [blame] | 850 | --tool_tag="${tool_tag}" \ |
| 851 | --start_timestamp="${start_time}" \ |
| 852 | --end_timestamp="$(date +%s.%N)" \ |
| 853 | --tool_args="$*" \ |
| 854 | --exit_code="${exit_code}" \ |
Zhuoyao Zhang | db666bc | 2024-04-30 00:28:34 +0000 | [diff] [blame] | 855 | ${ANDROID_TOOL_LOGGER_EXTRA_ARGS} \ |
Zhuoyao Zhang | cc44d2e | 2024-03-26 22:50:12 +0000 | [diff] [blame] | 856 | > /dev/null 2>&1 & |
| 857 | exit ${exit_code} |
| 858 | ' SIGINT SIGTERM SIGQUIT EXIT |
| 859 | |
| 860 | # Run the original command. |
| 861 | "${tool_binary}" "${@}" |
| 862 | ) |
| 863 | } |
| 864 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 865 | # coredump_setup - enable core dumps globally for any process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 866 | # that has the core-file-size limit set correctly |
| 867 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 868 | # NOTE: You must call also coredump_enable for a specific process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 869 | # if its core-file-size limit is not set already. |
| 870 | # NOTE: Core dumps are written to ramdisk; they will not survive a reboot! |
| 871 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 872 | function coredump_setup() |
| 873 | { |
| 874 | echo "Getting root..."; |
| 875 | adb root; |
| 876 | adb wait-for-device; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 877 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 878 | echo "Remounting root partition read-write..."; |
| 879 | adb shell mount -w -o remount -t rootfs rootfs; |
| 880 | sleep 1; |
| 881 | adb wait-for-device; |
| 882 | adb shell mkdir -p /cores; |
| 883 | adb shell mount -t tmpfs tmpfs /cores; |
| 884 | adb shell chmod 0777 /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 885 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 886 | echo "Granting SELinux permission to dump in /cores..."; |
| 887 | adb shell restorecon -R /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 888 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 889 | echo "Set core pattern."; |
| 890 | adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern'; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 891 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 892 | echo "Done." |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 895 | # coredump_enable - enable core dumps for the specified process |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 896 | # $1 = PID of process (e.g., $(pid mediaserver)) |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 897 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 898 | # NOTE: coredump_setup must have been called as well for a core |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 899 | # dump to actually be generated. |
| 900 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 901 | function coredump_enable() |
| 902 | { |
| 903 | local PID=$1; |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 904 | if [ -z "$PID" ]; then |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 905 | printf "Expecting a PID!\n"; |
| 906 | return; |
| 907 | fi; |
| 908 | echo "Setting core limit for $PID to infinite..."; |
xi yu | addf483 | 2022-05-26 12:41:21 +0000 | [diff] [blame] | 909 | adb shell /system/bin/ulimit -P $PID -c unlimited |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | # core - send SIGV and pull the core for process |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 913 | # $1 = PID of process (e.g., $(pid mediaserver)) |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 914 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 915 | # 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] | 916 | # enabled globally. |
| 917 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 918 | function core() |
| 919 | { |
| 920 | local PID=$1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 921 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 922 | if [ -z "$PID" ]; then |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 923 | printf "Expecting a PID!\n"; |
| 924 | return; |
| 925 | fi; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 926 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 927 | local CORENAME=core.$PID; |
| 928 | local COREPATH=/cores/$CORENAME; |
| 929 | local SIG=SEGV; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 930 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 931 | coredump_enable $1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 932 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 933 | local done=0; |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 934 | while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 935 | printf "\tSending SIG%s to %d...\n" $SIG $PID; |
| 936 | adb shell kill -$SIG $PID; |
| 937 | sleep 1; |
| 938 | done; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 939 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 940 | adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done" |
| 941 | echo "Done: core is under $COREPATH on device."; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 944 | # systemstack - dump the current stack trace of all threads in the system process |
| 945 | # to the usual ANR traces file |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 946 | function systemstack() |
| 947 | { |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 948 | stacks system_server |
| 949 | } |
| 950 | |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 951 | # Read the ELF header from /proc/$PID/exe to determine if the process is |
| 952 | # 64-bit. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 953 | function is64bit() |
| 954 | { |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 955 | local PID="$1" |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 956 | if [ "$PID" ] ; then |
| 957 | 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] | 958 | echo "64" |
| 959 | else |
| 960 | echo "" |
| 961 | fi |
| 962 | else |
| 963 | echo "" |
| 964 | fi |
| 965 | } |
| 966 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 967 | function gettargetarch |
| 968 | { |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 969 | get_build_var TARGET_ARCH |
| 970 | } |
| 971 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 972 | function getprebuilt |
| 973 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 974 | get_abs_build_var ANDROID_PREBUILTS |
| 975 | } |
| 976 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 977 | # communicate with a running device or emulator, set up necessary state, |
| 978 | # and run the hat command. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 979 | function runhat() |
| 980 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 981 | # process standard adb options |
| 982 | local adbTarget="" |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 983 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 984 | adbTarget=$1 |
| 985 | shift 1 |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 986 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 987 | adbTarget="$1 $2" |
| 988 | shift 2 |
| 989 | fi |
| 990 | local adbOptions=${adbTarget} |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 991 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 992 | |
| 993 | # runhat options |
| 994 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 995 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 996 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 997 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 998 | return |
| 999 | fi |
| 1000 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1001 | # confirm hat is available |
| 1002 | if [ -z $(which hat) ]; then |
| 1003 | echo "hat is not available in this configuration." |
| 1004 | return |
| 1005 | fi |
| 1006 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1007 | # issue "am" command to cause the hprof dump |
Nick Kralevich | 9948b1e | 2014-07-18 15:45:38 -0700 | [diff] [blame] | 1008 | local devFile=/data/local/tmp/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1009 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1010 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1011 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1012 | 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] | 1013 | echo -n "> " |
| 1014 | read |
| 1015 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1016 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1017 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1018 | echo "Retrieving file $devFile..." |
| 1019 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1020 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1021 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1022 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1023 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1024 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1025 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1026 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1029 | function getbugreports() |
| 1030 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1031 | 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] | 1032 | |
| 1033 | if [ ! "$reports" ]; then |
| 1034 | echo "Could not locate any bugreports." |
| 1035 | return |
| 1036 | fi |
| 1037 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1038 | local report |
| 1039 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1040 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1041 | echo "/sdcard/bugreports/${report}" |
| 1042 | adb pull /sdcard/bugreports/${report} ${report} |
| 1043 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1044 | done |
| 1045 | } |
| 1046 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1047 | function getsdcardpath() |
| 1048 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1049 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1050 | } |
| 1051 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1052 | function getscreenshotpath() |
| 1053 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1054 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1055 | } |
| 1056 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1057 | function getlastscreenshot() |
| 1058 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1059 | local screenshot_path=$(getscreenshotpath) |
| 1060 | 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] | 1061 | if [ "$screenshot" = "" ]; then |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1062 | echo "No screenshots found." |
| 1063 | return |
| 1064 | fi |
| 1065 | echo "${screenshot}" |
| 1066 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1067 | } |
| 1068 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1069 | function startviewserver() |
| 1070 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1071 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1072 | if [ $# -gt 0 ]; then |
| 1073 | port=$1 |
| 1074 | fi |
| 1075 | adb shell service call window 1 i32 $port |
| 1076 | } |
| 1077 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1078 | function stopviewserver() |
| 1079 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1080 | adb shell service call window 2 |
| 1081 | } |
| 1082 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1083 | function isviewserverstarted() |
| 1084 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1085 | adb shell service call window 3 |
| 1086 | } |
| 1087 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1088 | function key_home() |
| 1089 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1090 | adb shell input keyevent 3 |
| 1091 | } |
| 1092 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1093 | function key_back() |
| 1094 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1095 | adb shell input keyevent 4 |
| 1096 | } |
| 1097 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1098 | function key_menu() |
| 1099 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1100 | adb shell input keyevent 82 |
| 1101 | } |
| 1102 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1103 | function smoketest() |
| 1104 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1105 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1106 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1107 | return |
| 1108 | fi |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1109 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1110 | if [ ! "$T" ]; then |
| 1111 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1112 | return |
| 1113 | fi |
| 1114 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1115 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1116 | adb uninstall com.android.smoketest > /dev/null && |
| 1117 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1118 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1119 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1120 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1121 | } |
| 1122 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1123 | function godir () { |
| 1124 | if [[ -z "$1" ]]; then |
| 1125 | echo "Usage: godir <regex>" |
| 1126 | return |
| 1127 | fi |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1128 | local T=$(gettop) |
| 1129 | local FILELIST |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1130 | if [ ! "$OUT_DIR" = "" ]; then |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1131 | mkdir -p $OUT_DIR |
| 1132 | FILELIST=$OUT_DIR/filelist |
| 1133 | else |
| 1134 | FILELIST=$T/filelist |
| 1135 | fi |
| 1136 | if [[ ! -f $FILELIST ]]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1137 | echo -n "Creating index..." |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1138 | (\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] | 1139 | echo " Done" |
| 1140 | echo "" |
| 1141 | fi |
| 1142 | local lines |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1143 | lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq)) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1144 | if [[ ${#lines[@]} = 0 ]]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1145 | echo "Not found" |
| 1146 | return |
| 1147 | fi |
| 1148 | local pathname |
| 1149 | local choice |
| 1150 | if [[ ${#lines[@]} > 1 ]]; then |
| 1151 | while [[ -z "$pathname" ]]; do |
| 1152 | local index=1 |
| 1153 | local line |
| 1154 | for line in ${lines[@]}; do |
| 1155 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1156 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1157 | done |
| 1158 | echo |
| 1159 | echo -n "Select one: " |
| 1160 | unset choice |
| 1161 | read choice |
| 1162 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1163 | echo "Invalid choice" |
| 1164 | continue |
| 1165 | fi |
Guillaume Chelfi | ce000fd | 2019-10-03 12:02:46 +0200 | [diff] [blame] | 1166 | pathname=${lines[@]:$(($choice-1)):1} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1167 | done |
| 1168 | else |
Guillaume Chelfi | ce000fd | 2019-10-03 12:02:46 +0200 | [diff] [blame] | 1169 | pathname=${lines[@]:0:1} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1170 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1171 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1172 | } |
| 1173 | |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1174 | # Go to a specific module in the android tree, as cached in module-info.json. If any build change |
| 1175 | # is made, and it should be reflected in the output, you should run 'refreshmod' first. |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1176 | # Note: This function is in envsetup because changing the directory needs to happen in the current |
| 1177 | # shell. All other functions that use module-info.json should be in build/soong/bin. |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1178 | function gomod() { |
| 1179 | if [[ $# -ne 1 ]]; then |
| 1180 | echo "usage: gomod <module>" >&2 |
| 1181 | return 1 |
| 1182 | fi |
| 1183 | |
| 1184 | local path="$(pathmod $@)" |
| 1185 | if [ -z "$path" ]; then |
| 1186 | return 1 |
| 1187 | fi |
| 1188 | cd $path |
| 1189 | } |
| 1190 | |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame] | 1191 | function _complete_android_module_names() { |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1192 | local word=${COMP_WORDS[COMP_CWORD]} |
Cole Faust | 5d825b7 | 2022-10-26 18:16:44 -0700 | [diff] [blame] | 1193 | COMPREPLY=( $(allmod | grep -E "^$word") ) |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1196 | # Print colored exit condition |
| 1197 | function pez { |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1198 | "$@" |
| 1199 | local retval=$? |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1200 | if [ $retval -ne 0 ] |
| 1201 | then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1202 | echo $'\E'"[0;31mFAILURE\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1203 | else |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1204 | echo $'\E'"[0;32mSUCCESS\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1205 | fi |
| 1206 | return $retval |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1207 | } |
| 1208 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1209 | function get_make_command() |
| 1210 | { |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1211 | # If we're in the top of an Android tree, use soong_ui.bash instead of make |
| 1212 | if [ -f build/soong/soong_ui.bash ]; then |
Dan Willemsen | e984224 | 2017-07-28 13:00:13 -0700 | [diff] [blame] | 1213 | # Always use the real make if -C is passed in |
| 1214 | for arg in "$@"; do |
| 1215 | if [[ $arg == -C* ]]; then |
| 1216 | echo command make |
| 1217 | return |
| 1218 | fi |
| 1219 | done |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1220 | echo build/soong/soong_ui.bash --make-mode |
| 1221 | else |
| 1222 | echo command make |
| 1223 | fi |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1226 | function make() |
| 1227 | { |
Dan Willemsen | e984224 | 2017-07-28 13:00:13 -0700 | [diff] [blame] | 1228 | _wrap_build $(get_make_command "$@") "$@" |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1231 | # Zsh needs bashcompinit called to support bash-style completion. |
Patrik Fimml | df248e6 | 2018-10-15 18:15:12 +0200 | [diff] [blame] | 1232 | function enable_zsh_completion() { |
| 1233 | # Don't override user's options if bash-style completion is already enabled. |
| 1234 | if ! declare -f complete >/dev/null; then |
| 1235 | autoload -U compinit && compinit |
| 1236 | autoload -U bashcompinit && bashcompinit |
| 1237 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | function validate_current_shell() { |
| 1241 | local current_sh="$(ps -o command -p $$)" |
| 1242 | case "$current_sh" in |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1243 | *bash*) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1244 | function check_type() { type -t "$1"; } |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1245 | ;; |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1246 | *zsh*) |
| 1247 | function check_type() { type "$1"; } |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1248 | enable_zsh_completion ;; |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1249 | *) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1250 | 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] | 1251 | ;; |
| 1252 | esac |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1253 | } |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1254 | |
| 1255 | # Execute the contents of any vendorsetup.sh files we can find. |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1256 | # Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only |
| 1257 | # load those. |
| 1258 | # |
| 1259 | # This allows loading only approved vendorsetup.sh files |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1260 | function source_vendorsetup() { |
Jim Tang | c4dba1d | 2019-07-25 16:54:27 +0800 | [diff] [blame] | 1261 | unset VENDOR_PYTHONPATH |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1262 | local T="$(gettop)" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1263 | allowed= |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1264 | 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] | 1265 | if [ -n "$allowed" ]; then |
| 1266 | echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:" |
| 1267 | echo " $allowed" |
| 1268 | echo " $f" |
| 1269 | return |
| 1270 | fi |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1271 | allowed="$T/$f" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1272 | done |
| 1273 | |
| 1274 | allowed_files= |
| 1275 | [ -n "$allowed" ] && allowed_files=$(cat "$allowed") |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1276 | for dir in device vendor product; do |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1277 | for f in $(cd "$T" && test -d $dir && \ |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1278 | 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] | 1279 | |
| 1280 | if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1281 | echo "including $f"; . "$T/$f" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1282 | else |
| 1283 | echo "ignoring $f, not in $allowed" |
| 1284 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1285 | done |
| 1286 | done |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 1287 | |
| 1288 | if [[ "${PWD}" == /google/cog/* ]]; then |
| 1289 | f="build/make/cogsetup.sh" |
| 1290 | echo "including $f"; . "$T/$f" |
| 1291 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1292 | } |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1293 | |
Dan Albert | bab814f | 2020-08-26 15:34:53 -0700 | [diff] [blame] | 1294 | function showcommands() { |
| 1295 | local T=$(gettop) |
| 1296 | if [[ -z "$TARGET_PRODUCT" ]]; then |
| 1297 | >&2 echo "TARGET_PRODUCT not set. Run lunch." |
| 1298 | return |
| 1299 | fi |
| 1300 | case $(uname -s) in |
| 1301 | Darwin) |
| 1302 | PREBUILT_NAME=darwin-x86 |
| 1303 | ;; |
| 1304 | Linux) |
| 1305 | PREBUILT_NAME=linux-x86 |
| 1306 | ;; |
| 1307 | *) |
| 1308 | >&2 echo Unknown host $(uname -s) |
| 1309 | return |
| 1310 | ;; |
| 1311 | esac |
Jingwen Chen | acdcaa0 | 2022-10-13 07:24:24 +0000 | [diff] [blame] | 1312 | OUT_DIR="$(get_abs_build_var OUT_DIR)" |
Dan Albert | bab814f | 2020-08-26 15:34:53 -0700 | [diff] [blame] | 1313 | if [[ "$1" == "--regenerate" ]]; then |
| 1314 | shift 1 |
| 1315 | NINJA_ARGS="-t commands $@" m |
| 1316 | else |
| 1317 | (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \ |
| 1318 | -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \ |
| 1319 | -t commands "$@") |
| 1320 | fi |
| 1321 | } |
| 1322 | |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1323 | # These functions used to be here but are now standalone scripts |
| 1324 | # in build/soong/bin. Unset these for the time being so the real |
| 1325 | # script is picked up. |
Joe Onorato | 2312475 | 2024-05-14 15:06:48 -0700 | [diff] [blame] | 1326 | # TODO: Remove this some time after a suitable delay (maybe 2025?) |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1327 | unset allmod |
Joe Onorato | 2312475 | 2024-05-14 15:06:48 -0700 | [diff] [blame] | 1328 | unset aninja |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1329 | unset cgrep |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1330 | unset dirmods |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1331 | unset ggrep |
| 1332 | unset gogrep |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1333 | unset installmod |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1334 | unset jgrep |
| 1335 | unset jsongrep |
| 1336 | unset ktgrep |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1337 | unset m |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1338 | unset mangrep |
| 1339 | unset mgrep |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1340 | unset mm |
| 1341 | unset mma |
| 1342 | unset mmm |
| 1343 | unset mmma |
| 1344 | unset outmod |
| 1345 | unset overrideflags |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1346 | unset owngrep |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1347 | unset pathmod |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1348 | unset pygrep |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1349 | unset qpid |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1350 | unset rcgrep |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1351 | unset refreshmod |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1352 | unset resgrep |
| 1353 | unset rsgrep |
| 1354 | unset sepgrep |
| 1355 | unset sgrep |
Joe Onorato | 6b54383 | 2024-05-23 12:26:50 -0700 | [diff] [blame^] | 1356 | unset syswrite |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame] | 1357 | unset tomlgrep |
| 1358 | unset treegrep |
Cole Faust | 45844ab | 2022-08-30 13:59:07 -0700 | [diff] [blame] | 1359 | |
Colin Cross | 7131972 | 2023-10-24 10:58:46 -0700 | [diff] [blame] | 1360 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1361 | validate_current_shell |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 1362 | set_global_paths |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1363 | source_vendorsetup |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1364 | addcompletions |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 1365 | |
Joe Onorato | 2312475 | 2024-05-14 15:06:48 -0700 | [diff] [blame] | 1366 | |
| 1367 | |