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