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