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}" \ |
| 850 | --tool_tag "${tool_tag}" \ |
| 851 | --start_timestamp "${start_time}" \ |
| 852 | --end_timestamp "$(date +%s.%N)" \ |
Zhuoyao Zhang | db666bc | 2024-04-30 00:28:34 +0000 | [diff] [blame] | 853 | --tool_args "$*" \ |
Zhuoyao Zhang | cc44d2e | 2024-03-26 22:50:12 +0000 | [diff] [blame] | 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 | |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 865 | # simplified version of ps; output in the form |
| 866 | # <pid> <procname> |
| 867 | function qpid() { |
| 868 | local prepend='' |
| 869 | local append='' |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 870 | if [ "$1" = "--exact" ]; then |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 871 | prepend=' ' |
| 872 | append='$' |
| 873 | shift |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 874 | elif [ "$1" = "--help" -o "$1" = "-h" ]; then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 875 | echo "usage: qpid [[--exact] <process name|pid>" |
| 876 | return 255 |
| 877 | fi |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 878 | |
| 879 | local EXE="$1" |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 880 | if [ "$EXE" ] ; then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 881 | qpid | \grep "$prepend$EXE$append" |
| 882 | else |
| 883 | adb shell ps \ |
| 884 | | tr -d '\r' \ |
| 885 | | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/' |
| 886 | fi |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 887 | } |
| 888 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 889 | # coredump_setup - enable core dumps globally for any process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 890 | # that has the core-file-size limit set correctly |
| 891 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 892 | # NOTE: You must call also coredump_enable for a specific process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 893 | # if its core-file-size limit is not set already. |
| 894 | # NOTE: Core dumps are written to ramdisk; they will not survive a reboot! |
| 895 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 896 | function coredump_setup() |
| 897 | { |
| 898 | echo "Getting root..."; |
| 899 | adb root; |
| 900 | adb wait-for-device; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 901 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 902 | echo "Remounting root partition read-write..."; |
| 903 | adb shell mount -w -o remount -t rootfs rootfs; |
| 904 | sleep 1; |
| 905 | adb wait-for-device; |
| 906 | adb shell mkdir -p /cores; |
| 907 | adb shell mount -t tmpfs tmpfs /cores; |
| 908 | adb shell chmod 0777 /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 909 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 910 | echo "Granting SELinux permission to dump in /cores..."; |
| 911 | adb shell restorecon -R /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 912 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 913 | echo "Set core pattern."; |
| 914 | adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern'; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 915 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 916 | echo "Done." |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 919 | # coredump_enable - enable core dumps for the specified process |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 920 | # $1 = PID of process (e.g., $(pid mediaserver)) |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 921 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 922 | # NOTE: coredump_setup must have been called as well for a core |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 923 | # dump to actually be generated. |
| 924 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 925 | function coredump_enable() |
| 926 | { |
| 927 | local PID=$1; |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 928 | if [ -z "$PID" ]; then |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 929 | printf "Expecting a PID!\n"; |
| 930 | return; |
| 931 | fi; |
| 932 | echo "Setting core limit for $PID to infinite..."; |
xi yu | addf483 | 2022-05-26 12:41:21 +0000 | [diff] [blame] | 933 | adb shell /system/bin/ulimit -P $PID -c unlimited |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | # core - send SIGV and pull the core for process |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 937 | # $1 = PID of process (e.g., $(pid mediaserver)) |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 938 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 939 | # 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] | 940 | # enabled globally. |
| 941 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 942 | function core() |
| 943 | { |
| 944 | local PID=$1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 945 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 946 | if [ -z "$PID" ]; then |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 947 | printf "Expecting a PID!\n"; |
| 948 | return; |
| 949 | fi; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 950 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 951 | local CORENAME=core.$PID; |
| 952 | local COREPATH=/cores/$CORENAME; |
| 953 | local SIG=SEGV; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 954 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 955 | coredump_enable $1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 956 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 957 | local done=0; |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 958 | while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 959 | printf "\tSending SIG%s to %d...\n" $SIG $PID; |
| 960 | adb shell kill -$SIG $PID; |
| 961 | sleep 1; |
| 962 | done; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 963 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 964 | adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done" |
| 965 | echo "Done: core is under $COREPATH on device."; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 968 | # systemstack - dump the current stack trace of all threads in the system process |
| 969 | # to the usual ANR traces file |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 970 | function systemstack() |
| 971 | { |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 972 | stacks system_server |
| 973 | } |
| 974 | |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 975 | # Read the ELF header from /proc/$PID/exe to determine if the process is |
| 976 | # 64-bit. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 977 | function is64bit() |
| 978 | { |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 979 | local PID="$1" |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 980 | if [ "$PID" ] ; then |
| 981 | 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] | 982 | echo "64" |
| 983 | else |
| 984 | echo "" |
| 985 | fi |
| 986 | else |
| 987 | echo "" |
| 988 | fi |
| 989 | } |
| 990 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 991 | function gettargetarch |
| 992 | { |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 993 | get_build_var TARGET_ARCH |
| 994 | } |
| 995 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 996 | function getprebuilt |
| 997 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 998 | get_abs_build_var ANDROID_PREBUILTS |
| 999 | } |
| 1000 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1001 | # communicate with a running device or emulator, set up necessary state, |
| 1002 | # and run the hat command. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1003 | function runhat() |
| 1004 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1005 | # process standard adb options |
| 1006 | local adbTarget="" |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1007 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1008 | adbTarget=$1 |
| 1009 | shift 1 |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1010 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1011 | adbTarget="$1 $2" |
| 1012 | shift 2 |
| 1013 | fi |
| 1014 | local adbOptions=${adbTarget} |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1015 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1016 | |
| 1017 | # runhat options |
| 1018 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1019 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1020 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1021 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1022 | return |
| 1023 | fi |
| 1024 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1025 | # confirm hat is available |
| 1026 | if [ -z $(which hat) ]; then |
| 1027 | echo "hat is not available in this configuration." |
| 1028 | return |
| 1029 | fi |
| 1030 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1031 | # issue "am" command to cause the hprof dump |
Nick Kralevich | 9948b1e | 2014-07-18 15:45:38 -0700 | [diff] [blame] | 1032 | local devFile=/data/local/tmp/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1033 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1034 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1035 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1036 | 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] | 1037 | echo -n "> " |
| 1038 | read |
| 1039 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1040 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1041 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1042 | echo "Retrieving file $devFile..." |
| 1043 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1044 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1045 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1046 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1047 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1048 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1049 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1050 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1053 | function getbugreports() |
| 1054 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1055 | 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] | 1056 | |
| 1057 | if [ ! "$reports" ]; then |
| 1058 | echo "Could not locate any bugreports." |
| 1059 | return |
| 1060 | fi |
| 1061 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1062 | local report |
| 1063 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1064 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1065 | echo "/sdcard/bugreports/${report}" |
| 1066 | adb pull /sdcard/bugreports/${report} ${report} |
| 1067 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1068 | done |
| 1069 | } |
| 1070 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1071 | function getsdcardpath() |
| 1072 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1073 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1074 | } |
| 1075 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1076 | function getscreenshotpath() |
| 1077 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1078 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1079 | } |
| 1080 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1081 | function getlastscreenshot() |
| 1082 | { |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1083 | local screenshot_path=$(getscreenshotpath) |
| 1084 | 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] | 1085 | if [ "$screenshot" = "" ]; then |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1086 | echo "No screenshots found." |
| 1087 | return |
| 1088 | fi |
| 1089 | echo "${screenshot}" |
| 1090 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1091 | } |
| 1092 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1093 | function startviewserver() |
| 1094 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1095 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1096 | if [ $# -gt 0 ]; then |
| 1097 | port=$1 |
| 1098 | fi |
| 1099 | adb shell service call window 1 i32 $port |
| 1100 | } |
| 1101 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1102 | function stopviewserver() |
| 1103 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1104 | adb shell service call window 2 |
| 1105 | } |
| 1106 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1107 | function isviewserverstarted() |
| 1108 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1109 | adb shell service call window 3 |
| 1110 | } |
| 1111 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1112 | function key_home() |
| 1113 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1114 | adb shell input keyevent 3 |
| 1115 | } |
| 1116 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1117 | function key_back() |
| 1118 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1119 | adb shell input keyevent 4 |
| 1120 | } |
| 1121 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1122 | function key_menu() |
| 1123 | { |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1124 | adb shell input keyevent 82 |
| 1125 | } |
| 1126 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1127 | function smoketest() |
| 1128 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1129 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1130 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1131 | return |
| 1132 | fi |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1133 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1134 | if [ ! "$T" ]; then |
| 1135 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1136 | return |
| 1137 | fi |
| 1138 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1139 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1140 | adb uninstall com.android.smoketest > /dev/null && |
| 1141 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1142 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1143 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1144 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1145 | } |
| 1146 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1147 | function godir () { |
| 1148 | if [[ -z "$1" ]]; then |
| 1149 | echo "Usage: godir <regex>" |
| 1150 | return |
| 1151 | fi |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1152 | local T=$(gettop) |
| 1153 | local FILELIST |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1154 | if [ ! "$OUT_DIR" = "" ]; then |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1155 | mkdir -p $OUT_DIR |
| 1156 | FILELIST=$OUT_DIR/filelist |
| 1157 | else |
| 1158 | FILELIST=$T/filelist |
| 1159 | fi |
| 1160 | if [[ ! -f $FILELIST ]]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1161 | echo -n "Creating index..." |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1162 | (\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] | 1163 | echo " Done" |
| 1164 | echo "" |
| 1165 | fi |
| 1166 | local lines |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1167 | lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq)) |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1168 | if [[ ${#lines[@]} = 0 ]]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1169 | echo "Not found" |
| 1170 | return |
| 1171 | fi |
| 1172 | local pathname |
| 1173 | local choice |
| 1174 | if [[ ${#lines[@]} > 1 ]]; then |
| 1175 | while [[ -z "$pathname" ]]; do |
| 1176 | local index=1 |
| 1177 | local line |
| 1178 | for line in ${lines[@]}; do |
| 1179 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1180 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1181 | done |
| 1182 | echo |
| 1183 | echo -n "Select one: " |
| 1184 | unset choice |
| 1185 | read choice |
| 1186 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1187 | echo "Invalid choice" |
| 1188 | continue |
| 1189 | fi |
Guillaume Chelfi | ce000fd | 2019-10-03 12:02:46 +0200 | [diff] [blame] | 1190 | pathname=${lines[@]:$(($choice-1)):1} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1191 | done |
| 1192 | else |
Guillaume Chelfi | ce000fd | 2019-10-03 12:02:46 +0200 | [diff] [blame] | 1193 | pathname=${lines[@]:0:1} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1194 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1195 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1196 | } |
| 1197 | |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1198 | function refreshmod() { |
| 1199 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1200 | echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 |
| 1201 | return 1 |
| 1202 | fi |
| 1203 | |
| 1204 | echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2 |
| 1205 | |
| 1206 | # for the output of the next command |
| 1207 | mkdir -p $ANDROID_PRODUCT_OUT || return 1 |
| 1208 | |
| 1209 | # Note, can't use absolute path because of the way make works. |
Alessandro Astone | c8771be | 2020-05-10 11:27:57 +0200 | [diff] [blame] | 1210 | m $(get_build_var PRODUCT_OUT)/module-info.json \ |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1211 | > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1 |
| 1212 | } |
| 1213 | |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1214 | # Verifies that module-info.txt exists, returning nonzero if it doesn't. |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1215 | function verifymodinfo() { |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1216 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
Joe Onorato | 0bac4fe | 2021-04-07 08:51:28 -0700 | [diff] [blame] | 1217 | if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then |
| 1218 | echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 |
| 1219 | fi |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1220 | return 1 |
| 1221 | fi |
| 1222 | |
| 1223 | if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then |
Joe Onorato | 0bac4fe | 2021-04-07 08:51:28 -0700 | [diff] [blame] | 1224 | if [ "$QUIET_VERIFYMODINFO" != "true" ] ; then |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1225 | echo "Could not find module-info.json. Please run 'refreshmod' first." >&2 |
Joe Onorato | 0bac4fe | 2021-04-07 08:51:28 -0700 | [diff] [blame] | 1226 | fi |
| 1227 | return 1 |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1228 | fi |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Cole Faust | 5d825b7 | 2022-10-26 18:16:44 -0700 | [diff] [blame] | 1231 | # List all modules for the current device, as cached in all_modules.txt. If any build change is |
| 1232 | # 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] | 1233 | function allmod() { |
Cole Faust | 5d825b7 | 2022-10-26 18:16:44 -0700 | [diff] [blame] | 1234 | cat $ANDROID_PRODUCT_OUT/all_modules.txt 2>/dev/null |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1235 | } |
| 1236 | |
Joe Onorato | 2c1aa47 | 2021-02-25 16:42:39 -0800 | [diff] [blame] | 1237 | # Get the path of a specific module in the android tree, as cached in module-info.json. |
| 1238 | # If any build change is made, and it should be reflected in the output, you should run |
| 1239 | # 'refreshmod' first. Note: This is the inverse of dirmods. |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1240 | function pathmod() { |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1241 | if [[ $# -ne 1 ]]; then |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1242 | echo "usage: pathmod <module>" >&2 |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1243 | return 1 |
| 1244 | fi |
| 1245 | |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1246 | verifymodinfo || return 1 |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1247 | |
Joe Onorato | 4acbe3b | 2021-04-29 15:31:42 -0700 | [diff] [blame] | 1248 | local relpath=$(python3 -c "import json, os |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1249 | module = '$1' |
| 1250 | module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')) |
| 1251 | if module not in module_info: |
| 1252 | exit(1) |
LuK1337 | b6a7819 | 2020-01-12 03:12:17 +0100 | [diff] [blame] | 1253 | print(module_info[module]['path'][0])" 2>/dev/null) |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1254 | |
| 1255 | if [ -z "$relpath" ]; then |
| 1256 | echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2 |
| 1257 | return 1 |
| 1258 | else |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1259 | echo "$ANDROID_BUILD_TOP/$relpath" |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1260 | fi |
| 1261 | } |
| 1262 | |
Joe Onorato | 2c1aa47 | 2021-02-25 16:42:39 -0800 | [diff] [blame] | 1263 | # Get the path of a specific module in the android tree, as cached in module-info.json. |
| 1264 | # If any build change is made, and it should be reflected in the output, you should run |
| 1265 | # 'refreshmod' first. Note: This is the inverse of pathmod. |
| 1266 | function dirmods() { |
| 1267 | if [[ $# -ne 1 ]]; then |
| 1268 | echo "usage: dirmods <path>" >&2 |
| 1269 | return 1 |
| 1270 | fi |
| 1271 | |
| 1272 | verifymodinfo || return 1 |
| 1273 | |
Joe Onorato | 4acbe3b | 2021-04-29 15:31:42 -0700 | [diff] [blame] | 1274 | python3 -c "import json, os |
Joe Onorato | 2c1aa47 | 2021-02-25 16:42:39 -0800 | [diff] [blame] | 1275 | dir = '$1' |
| 1276 | while dir.endswith('/'): |
| 1277 | dir = dir[:-1] |
| 1278 | prefix = dir + '/' |
| 1279 | module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')) |
| 1280 | results = set() |
| 1281 | for m in module_info.values(): |
| 1282 | for path in m.get(u'path', []): |
| 1283 | if path == dir or path.startswith(prefix): |
| 1284 | name = m.get(u'module_name') |
| 1285 | if name: |
| 1286 | results.add(name) |
| 1287 | for name in sorted(results): |
| 1288 | print(name) |
| 1289 | " |
| 1290 | } |
| 1291 | |
| 1292 | |
Rett Berg | 78d1c93 | 2019-01-24 14:34:23 -0800 | [diff] [blame] | 1293 | # Go to a specific module in the android tree, as cached in module-info.json. If any build change |
| 1294 | # is made, and it should be reflected in the output, you should run 'refreshmod' first. |
| 1295 | function gomod() { |
| 1296 | if [[ $# -ne 1 ]]; then |
| 1297 | echo "usage: gomod <module>" >&2 |
| 1298 | return 1 |
| 1299 | fi |
| 1300 | |
| 1301 | local path="$(pathmod $@)" |
| 1302 | if [ -z "$path" ]; then |
| 1303 | return 1 |
| 1304 | fi |
| 1305 | cd $path |
| 1306 | } |
| 1307 | |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1308 | # Gets the list of a module's installed outputs, as cached in module-info.json. |
| 1309 | # If any build change is made, and it should be reflected in the output, you should run 'refreshmod' first. |
| 1310 | function outmod() { |
| 1311 | if [[ $# -ne 1 ]]; then |
| 1312 | echo "usage: outmod <module>" >&2 |
| 1313 | return 1 |
| 1314 | fi |
| 1315 | |
| 1316 | verifymodinfo || return 1 |
| 1317 | |
| 1318 | local relpath |
Joe Onorato | 4acbe3b | 2021-04-29 15:31:42 -0700 | [diff] [blame] | 1319 | relpath=$(python3 -c "import json, os |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1320 | module = '$1' |
| 1321 | module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')) |
| 1322 | if module not in module_info: |
| 1323 | exit(1) |
| 1324 | for output in module_info[module]['installed']: |
| 1325 | print(os.path.join('$ANDROID_BUILD_TOP', output))" 2>/dev/null) |
| 1326 | |
| 1327 | if [ $? -ne 0 ]; then |
| 1328 | echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)" >&2 |
| 1329 | return 1 |
| 1330 | elif [ ! -z "$relpath" ]; then |
| 1331 | echo "$relpath" |
| 1332 | fi |
| 1333 | } |
| 1334 | |
| 1335 | # adb install a module's apk, as cached in module-info.json. If any build change |
| 1336 | # is made, and it should be reflected in the output, you should run 'refreshmod' first. |
| 1337 | # Usage: installmod [adb install arguments] <module> |
| 1338 | # For example: installmod -r Dialer -> adb install -r /path/to/Dialer.apk |
| 1339 | function installmod() { |
| 1340 | if [[ $# -eq 0 ]]; then |
| 1341 | echo "usage: installmod [adb install arguments] <module>" >&2 |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1342 | echo "" >&2 |
| 1343 | echo "Only flags to be passed after the \"install\" in adb install are supported," >&2 |
| 1344 | echo "with the exception of -s. If -s is passed it will be placed before the \"install\"." >&2 |
| 1345 | echo "-s must be the first flag passed if it exists." >&2 |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1346 | return 1 |
| 1347 | fi |
| 1348 | |
| 1349 | local _path |
| 1350 | _path=$(outmod ${@:$#:1}) |
| 1351 | if [ $? -ne 0 ]; then |
| 1352 | return 1 |
| 1353 | fi |
| 1354 | |
| 1355 | _path=$(echo "$_path" | grep -E \\.apk$ | head -n 1) |
| 1356 | if [ -z "$_path" ]; then |
| 1357 | echo "Module '$1' does not produce a file ending with .apk (try 'refreshmod' if there have been build changes?)" >&2 |
| 1358 | return 1 |
| 1359 | fi |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1360 | local serial_device="" |
| 1361 | if [[ "$1" == "-s" ]]; then |
| 1362 | if [[ $# -le 2 ]]; then |
| 1363 | echo "-s requires an argument" >&2 |
| 1364 | return 1 |
| 1365 | fi |
| 1366 | serial_device="-s $2" |
| 1367 | shift 2 |
| 1368 | fi |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1369 | local length=$(( $# - 1 )) |
Cole Faust | 3e19238 | 2021-10-25 13:29:15 -0700 | [diff] [blame] | 1370 | echo adb $serial_device install ${@:1:$length} $_path |
| 1371 | adb $serial_device install ${@:1:$length} $_path |
Cole Faust | 24c36db | 2021-01-23 02:39:37 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame] | 1374 | function _complete_android_module_names() { |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1375 | local word=${COMP_WORDS[COMP_CWORD]} |
Cole Faust | 5d825b7 | 2022-10-26 18:16:44 -0700 | [diff] [blame] | 1376 | COMPREPLY=( $(allmod | grep -E "^$word") ) |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1377 | } |
| 1378 | |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1379 | # Print colored exit condition |
| 1380 | function pez { |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1381 | "$@" |
| 1382 | local retval=$? |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1383 | if [ $retval -ne 0 ] |
| 1384 | then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1385 | echo $'\E'"[0;31mFAILURE\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1386 | else |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1387 | echo $'\E'"[0;32mSUCCESS\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1388 | fi |
| 1389 | return $retval |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1390 | } |
| 1391 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1392 | function get_make_command() |
| 1393 | { |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1394 | # If we're in the top of an Android tree, use soong_ui.bash instead of make |
| 1395 | if [ -f build/soong/soong_ui.bash ]; then |
Dan Willemsen | e984224 | 2017-07-28 13:00:13 -0700 | [diff] [blame] | 1396 | # Always use the real make if -C is passed in |
| 1397 | for arg in "$@"; do |
| 1398 | if [[ $arg == -C* ]]; then |
| 1399 | echo command make |
| 1400 | return |
| 1401 | fi |
| 1402 | done |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1403 | echo build/soong/soong_ui.bash --make-mode |
| 1404 | else |
| 1405 | echo command make |
| 1406 | fi |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Patrice Arruda | fa7204b | 2019-06-20 23:40:33 +0000 | [diff] [blame] | 1409 | function _trigger_build() |
| 1410 | ( |
| 1411 | local -r bc="$1"; shift |
LaMont Jones | c39e502 | 2022-06-23 19:09:06 +0000 | [diff] [blame] | 1412 | local T=$(gettop) |
| 1413 | if [ -n "$T" ]; then |
Patrice Arruda | fa7204b | 2019-06-20 23:40:33 +0000 | [diff] [blame] | 1414 | _wrap_build "$T/build/soong/soong_ui.bash" --build-mode --${bc} --dir="$(pwd)" "$@" |
| 1415 | else |
Jingwen Chen | d728ee1 | 2021-05-18 06:02:53 +0000 | [diff] [blame] | 1416 | >&2 echo "Couldn't locate the top of the tree. Try setting TOP." |
| 1417 | return 1 |
Patrice Arruda | fa7204b | 2019-06-20 23:40:33 +0000 | [diff] [blame] | 1418 | fi |
Kevin Dagostino | 185109b | 2024-01-11 17:39:02 +0000 | [diff] [blame] | 1419 | local ret=$? |
| 1420 | if [[ ret -eq 0 && -z "${ANDROID_QUIET_BUILD:-}" && -n "${ANDROID_BUILD_BANNER}" ]]; then |
| 1421 | echo "${ANDROID_BUILD_BANNER}" |
| 1422 | fi |
| 1423 | return $ret |
Patrice Arruda | fa7204b | 2019-06-20 23:40:33 +0000 | [diff] [blame] | 1424 | ) |
| 1425 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1426 | function make() |
| 1427 | { |
Dan Willemsen | e984224 | 2017-07-28 13:00:13 -0700 | [diff] [blame] | 1428 | _wrap_build $(get_make_command "$@") "$@" |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1431 | function provision() |
| 1432 | { |
David Zeuthen | 1b126ff | 2015-09-30 17:10:48 -0400 | [diff] [blame] | 1433 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1434 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1435 | return 1 |
| 1436 | fi |
| 1437 | if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then |
| 1438 | echo "There is no provisioning script for the device." >&2 |
| 1439 | return 1 |
| 1440 | fi |
| 1441 | |
| 1442 | # Check if user really wants to do this. |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1443 | if [ "$1" = "--no-confirmation" ]; then |
David Zeuthen | 1b126ff | 2015-09-30 17:10:48 -0400 | [diff] [blame] | 1444 | shift 1 |
| 1445 | else |
| 1446 | echo "This action will reflash your device." |
| 1447 | echo "" |
| 1448 | echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED." |
| 1449 | echo "" |
Marie Janssen | 4afc2c0 | 2015-11-10 10:41:15 -0800 | [diff] [blame] | 1450 | echo -n "Are you sure you want to do this (yes/no)? " |
| 1451 | read |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1452 | if [[ "${REPLY}" != "yes" ]] ; then |
David Zeuthen | 1b126ff | 2015-09-30 17:10:48 -0400 | [diff] [blame] | 1453 | echo "Not taking any action. Exiting." >&2 |
| 1454 | return 1 |
| 1455 | fi |
| 1456 | fi |
| 1457 | "$ANDROID_PRODUCT_OUT/provision-device" "$@" |
| 1458 | } |
| 1459 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1460 | # Zsh needs bashcompinit called to support bash-style completion. |
Patrik Fimml | df248e6 | 2018-10-15 18:15:12 +0200 | [diff] [blame] | 1461 | function enable_zsh_completion() { |
| 1462 | # Don't override user's options if bash-style completion is already enabled. |
| 1463 | if ! declare -f complete >/dev/null; then |
| 1464 | autoload -U compinit && compinit |
| 1465 | autoload -U bashcompinit && bashcompinit |
| 1466 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | function validate_current_shell() { |
| 1470 | local current_sh="$(ps -o command -p $$)" |
| 1471 | case "$current_sh" in |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1472 | *bash*) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1473 | function check_type() { type -t "$1"; } |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1474 | ;; |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1475 | *zsh*) |
| 1476 | function check_type() { type "$1"; } |
Matt Alexander | d9c5656 | 2020-05-21 10:49:17 +0000 | [diff] [blame] | 1477 | enable_zsh_completion ;; |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1478 | *) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1479 | 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] | 1480 | ;; |
| 1481 | esac |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1482 | } |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1483 | |
| 1484 | # Execute the contents of any vendorsetup.sh files we can find. |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1485 | # Unless we find an allowed-vendorsetup_sh-files file, in which case we'll only |
| 1486 | # load those. |
| 1487 | # |
| 1488 | # This allows loading only approved vendorsetup.sh files |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1489 | function source_vendorsetup() { |
Jim Tang | c4dba1d | 2019-07-25 16:54:27 +0800 | [diff] [blame] | 1490 | unset VENDOR_PYTHONPATH |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1491 | local T="$(gettop)" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1492 | allowed= |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1493 | 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] | 1494 | if [ -n "$allowed" ]; then |
| 1495 | echo "More than one 'allowed_vendorsetup_sh-files' file found, not including any vendorsetup.sh files:" |
| 1496 | echo " $allowed" |
| 1497 | echo " $f" |
| 1498 | return |
| 1499 | fi |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1500 | allowed="$T/$f" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1501 | done |
| 1502 | |
| 1503 | allowed_files= |
| 1504 | [ -n "$allowed" ] && allowed_files=$(cat "$allowed") |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1505 | for dir in device vendor product; do |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1506 | for f in $(cd "$T" && test -d $dir && \ |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1507 | 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] | 1508 | |
| 1509 | if [[ -z "$allowed" || "$allowed_files" =~ $f ]]; then |
Patrice Arruda | aa4b824 | 2020-10-12 21:29:14 +0000 | [diff] [blame] | 1510 | echo "including $f"; . "$T/$f" |
Dan Willemsen | d855a72 | 2019-02-12 15:52:36 -0800 | [diff] [blame] | 1511 | else |
| 1512 | echo "ignoring $f, not in $allowed" |
| 1513 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1514 | done |
| 1515 | done |
Kousik Kumar | ec5416c | 2023-09-14 17:11:45 +0000 | [diff] [blame] | 1516 | |
| 1517 | if [[ "${PWD}" == /google/cog/* ]]; then |
| 1518 | f="build/make/cogsetup.sh" |
| 1519 | echo "including $f"; . "$T/$f" |
| 1520 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1521 | } |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1522 | |
Dan Albert | bab814f | 2020-08-26 15:34:53 -0700 | [diff] [blame] | 1523 | function showcommands() { |
| 1524 | local T=$(gettop) |
| 1525 | if [[ -z "$TARGET_PRODUCT" ]]; then |
| 1526 | >&2 echo "TARGET_PRODUCT not set. Run lunch." |
| 1527 | return |
| 1528 | fi |
| 1529 | case $(uname -s) in |
| 1530 | Darwin) |
| 1531 | PREBUILT_NAME=darwin-x86 |
| 1532 | ;; |
| 1533 | Linux) |
| 1534 | PREBUILT_NAME=linux-x86 |
| 1535 | ;; |
| 1536 | *) |
| 1537 | >&2 echo Unknown host $(uname -s) |
| 1538 | return |
| 1539 | ;; |
| 1540 | esac |
Jingwen Chen | acdcaa0 | 2022-10-13 07:24:24 +0000 | [diff] [blame] | 1541 | OUT_DIR="$(get_abs_build_var OUT_DIR)" |
Dan Albert | bab814f | 2020-08-26 15:34:53 -0700 | [diff] [blame] | 1542 | if [[ "$1" == "--regenerate" ]]; then |
| 1543 | shift 1 |
| 1544 | NINJA_ARGS="-t commands $@" m |
| 1545 | else |
| 1546 | (cd $T && prebuilts/build-tools/$PREBUILT_NAME/bin/ninja \ |
| 1547 | -f $OUT_DIR/combined-${TARGET_PRODUCT}.ninja \ |
| 1548 | -t commands "$@") |
| 1549 | fi |
| 1550 | } |
| 1551 | |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame^] | 1552 | # These functions used to be here but are now standalone scripts |
| 1553 | # in build/soong/bin. Unset these for the time being so the real |
| 1554 | # script is picked up. |
Joe Onorato | 2312475 | 2024-05-14 15:06:48 -0700 | [diff] [blame] | 1555 | # TODO: Remove this some time after a suitable delay (maybe 2025?) |
| 1556 | unset aninja |
| 1557 | unset overrideflags |
Joe Onorato | 1b9ab29 | 2024-05-17 12:16:43 -0700 | [diff] [blame^] | 1558 | unset m |
| 1559 | unset mm |
| 1560 | unset mmm |
| 1561 | unset mma |
| 1562 | unset mmma |
| 1563 | unset cgrep |
| 1564 | unset ggrep |
| 1565 | unset gogrep |
| 1566 | unset jgrep |
| 1567 | unset jsongrep |
| 1568 | unset ktgrep |
| 1569 | unset mangrep |
| 1570 | unset mgrep |
| 1571 | unset owngrep |
| 1572 | unset pygrep |
| 1573 | unset rcgrep |
| 1574 | unset resgrep |
| 1575 | unset rsgrep |
| 1576 | unset sepgrep |
| 1577 | unset sgrep |
| 1578 | unset tomlgrep |
| 1579 | unset treegrep |
| 1580 | unset syswrite |
Cole Faust | 45844ab | 2022-08-30 13:59:07 -0700 | [diff] [blame] | 1581 | |
Colin Cross | 7131972 | 2023-10-24 10:58:46 -0700 | [diff] [blame] | 1582 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1583 | validate_current_shell |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 1584 | set_global_paths |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1585 | source_vendorsetup |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1586 | addcompletions |
Joe Onorato | 7c3a77f | 2022-12-05 13:05:14 -0800 | [diff] [blame] | 1587 | |
Joe Onorato | 2312475 | 2024-05-14 15:06:48 -0700 | [diff] [blame] | 1588 | |
| 1589 | |