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