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