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