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