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