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 |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 3 | Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment: |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 4 | - lunch: lunch <product_name>-<build_variant> |
Ying Wang | b541ab6 | 2014-05-29 17:57:40 -0700 | [diff] [blame] | 5 | - tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 6 | - croot: Changes directory to the top of the tree. |
| 7 | - m: Makes from the top of the tree. |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 8 | - mm: Builds all of the modules in the current directory, but not their dependencies. |
| 9 | - mmm: Builds all of the modules in the supplied directories, but not their dependencies. |
Primiano Tucci | 6a8069d | 2014-02-26 11:09:19 +0000 | [diff] [blame] | 10 | To limit the modules being built use the syntax: mmm dir/:target1,target2. |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 11 | - mma: Builds all of the modules in the current directory, and their dependencies. |
| 12 | - mmma: Builds all of the modules in the supplied directories, and their dependencies. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 13 | - cgrep: Greps on all local C/C++ files. |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 14 | - ggrep: Greps on all local Gradle files. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 15 | - jgrep: Greps on all local Java files. |
| 16 | - resgrep: Greps on all local res/*.xml files. |
Trevor Drake | 9c88976 | 2015-01-30 04:42:21 +0000 | [diff] [blame] | 17 | - mangrep: Greps on all local AndroidManifest.xml files. |
William Roberts | 23a298b | 2015-07-12 17:06:38 -0700 | [diff] [blame] | 18 | - mgrep: Greps on all local Makefiles files. |
Trevor Drake | 9c88976 | 2015-01-30 04:42:21 +0000 | [diff] [blame] | 19 | - sepgrep: Greps on all local sepolicy files. |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 20 | - sgrep: Greps on all local source files. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 21 | - godir: Go to the directory containing a file. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 22 | |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 23 | Environemnt options: |
| 24 | - SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that |
| 25 | ASAN_OPTIONS=detect_leaks=0 will be set by default until the |
| 26 | build is leak-check clean. |
| 27 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 28 | Look at the source to view more functions. The complete list is: |
| 29 | EOF |
| 30 | T=$(gettop) |
| 31 | local A |
| 32 | A="" |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 33 | 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] | 34 | A="$A $i" |
| 35 | done |
| 36 | echo $A |
| 37 | } |
| 38 | |
| 39 | # Get the value of a build variable as an absolute path. |
| 40 | function get_abs_build_var() |
| 41 | { |
| 42 | T=$(gettop) |
| 43 | if [ ! "$T" ]; then |
| 44 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 45 | return |
| 46 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 47 | (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
Ed Heyl | c6d11f8 | 2014-06-27 13:32:39 -0700 | [diff] [blame] | 48 | command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | # Get the exact value of a build variable. |
| 52 | function get_build_var() |
| 53 | { |
| 54 | T=$(gettop) |
| 55 | if [ ! "$T" ]; then |
| 56 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 57 | return |
| 58 | fi |
Andrew Boie | 6905e21 | 2013-12-19 13:21:46 -0800 | [diff] [blame] | 59 | (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
Ed Heyl | c6d11f8 | 2014-06-27 13:32:39 -0700 | [diff] [blame] | 60 | command make --no-print-directory -f build/core/config.mk dumpvar-$1) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | # check to see if the supplied product is one we can build |
| 64 | function check_product() |
| 65 | { |
| 66 | T=$(gettop) |
| 67 | if [ ! "$T" ]; then |
| 68 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 69 | return |
| 70 | fi |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 71 | TARGET_PRODUCT=$1 \ |
| 72 | TARGET_BUILD_VARIANT= \ |
| 73 | TARGET_BUILD_TYPE= \ |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 74 | TARGET_BUILD_APPS= \ |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 75 | get_build_var TARGET_DEVICE > /dev/null |
| 76 | # hide successful answers, but allow the errors to show |
| 77 | } |
| 78 | |
| 79 | VARIANT_CHOICES=(user userdebug eng) |
| 80 | |
| 81 | # check to see if the supplied variant is valid |
| 82 | function check_variant() |
| 83 | { |
| 84 | for v in ${VARIANT_CHOICES[@]} |
| 85 | do |
| 86 | if [ "$v" = "$1" ] |
| 87 | then |
| 88 | return 0 |
| 89 | fi |
| 90 | done |
| 91 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | function setpaths() |
| 95 | { |
| 96 | T=$(gettop) |
| 97 | if [ ! "$T" ]; then |
| 98 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 99 | return |
| 100 | fi |
| 101 | |
| 102 | ################################################################## |
| 103 | # # |
| 104 | # Read me before you modify this code # |
| 105 | # # |
| 106 | # This function sets ANDROID_BUILD_PATHS to what it is adding # |
| 107 | # to PATH, and the next time it is run, it removes that from # |
| 108 | # PATH. This is required so lunch can be run more than once # |
| 109 | # and still have working paths. # |
| 110 | # # |
| 111 | ################################################################## |
| 112 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 113 | # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces |
| 114 | # due to "C:\Program Files" being in the path. |
| 115 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 116 | # out with the old |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 117 | if [ -n "$ANDROID_BUILD_PATHS" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | export PATH=${PATH/$ANDROID_BUILD_PATHS/} |
| 119 | fi |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 120 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 121 | export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} |
Ying Wang | aa1c9b5 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 122 | # strip leading ':', if any |
| 123 | export PATH=${PATH/:%/} |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 124 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 125 | |
| 126 | # and in with the new |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 127 | prebuiltdir=$(getprebuilt) |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 128 | gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS) |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 129 | |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 130 | # defined in core/config.mk |
| 131 | targetgccversion=$(get_build_var TARGET_GCC_VERSION) |
Colin Cross | 03b424a | 2014-05-22 11:57:43 -0700 | [diff] [blame] | 132 | targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION) |
Ben Cheng | 1526670 | 2012-12-10 16:04:39 -0800 | [diff] [blame] | 133 | export TARGET_GCC_VERSION=$targetgccversion |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 134 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 135 | # 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] | 136 | export ANDROID_TOOLCHAIN= |
| 137 | export ANDROID_TOOLCHAIN_2ND_ARCH= |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 138 | local ARCH=$(get_build_var TARGET_ARCH) |
| 139 | case $ARCH in |
Pavel Chupin | c1a5664 | 2013-08-23 16:49:21 +0400 | [diff] [blame] | 140 | x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 141 | ;; |
Pavel Chupin | fd82a49 | 2012-11-26 09:50:07 +0400 | [diff] [blame] | 142 | x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin |
| 143 | ;; |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 144 | arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 145 | ;; |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 146 | arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin; |
Colin Cross | 03b424a | 2014-05-22 11:57:43 -0700 | [diff] [blame] | 147 | toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin |
Ben Cheng | db4fc20 | 2013-10-04 16:02:59 -0700 | [diff] [blame] | 148 | ;; |
Duane Sand | 3c4fcd8 | 2014-07-22 14:34:00 -0700 | [diff] [blame] | 149 | mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin |
Serban Constantinescu | 9b68fb2 | 2014-01-14 10:33:53 +0000 | [diff] [blame] | 150 | ;; |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 151 | *) |
| 152 | echo "Can't find toolchain for unknown architecture: $ARCH" |
| 153 | toolchaindir=xxxxxxxxx |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 154 | ;; |
| 155 | esac |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 156 | if [ -d "$gccprebuiltdir/$toolchaindir" ]; then |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 157 | export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 158 | fi |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 159 | |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 160 | if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then |
| 161 | export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2 |
| 162 | fi |
| 163 | |
Jeff Vander Stoep | 5f50f05 | 2015-06-12 09:56:39 -0700 | [diff] [blame] | 164 | export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin |
Ying Wang | 750396d | 2015-09-14 19:32:50 -0700 | [diff] [blame] | 165 | export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_DEV_SCRIPTS: |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 166 | |
| 167 | # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH |
| 168 | # to ensure that the corresponding 'emulator' binaries are used. |
| 169 | case $(uname -s) in |
| 170 | Darwin) |
| 171 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64 |
| 172 | ;; |
| 173 | Linux) |
| 174 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64 |
| 175 | ;; |
| 176 | *) |
| 177 | ANDROID_EMULATOR_PREBUILTS= |
| 178 | ;; |
| 179 | esac |
| 180 | if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then |
Christopher Ferris | 7110f24 | 2014-05-20 13:56:00 -0700 | [diff] [blame] | 181 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS: |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 182 | export ANDROID_EMULATOR_PREBUILTS |
| 183 | fi |
| 184 | |
Ying Wang | aa1c9b5 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 185 | export PATH=$ANDROID_BUILD_PATHS$PATH |
Dan Albert | f5caa3d | 2015-09-18 13:23:56 -0700 | [diff] [blame] | 186 | export PYTHONPATH=$T/development/python-packages:$PYTHONPATH |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 187 | |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 188 | unset ANDROID_JAVA_TOOLCHAIN |
Ji-Hwan Lee | 752ad06 | 2011-07-04 14:09:47 +0900 | [diff] [blame] | 189 | unset ANDROID_PRE_BUILD_PATHS |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 190 | if [ -n "$JAVA_HOME" ]; then |
| 191 | export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin |
Ji-Hwan Lee | 752ad06 | 2011-07-04 14:09:47 +0900 | [diff] [blame] | 192 | export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN: |
| 193 | export PATH=$ANDROID_PRE_BUILD_PATHS$PATH |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 194 | fi |
| 195 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 196 | unset ANDROID_PRODUCT_OUT |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 197 | export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) |
| 198 | export OUT=$ANDROID_PRODUCT_OUT |
| 199 | |
Jeff Brown | 8fd5cce | 2011-03-24 17:03:06 -0700 | [diff] [blame] | 200 | unset ANDROID_HOST_OUT |
| 201 | export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) |
| 202 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 203 | # needed for building linux on MacOS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 204 | # TODO: fix the path |
| 205 | #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include |
| 206 | } |
| 207 | |
| 208 | function printconfig() |
| 209 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 210 | T=$(gettop) |
| 211 | if [ ! "$T" ]; then |
| 212 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 213 | return |
| 214 | fi |
| 215 | get_build_var report_config |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | function set_stuff_for_environment() |
| 219 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 220 | settitle |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 221 | set_java_home |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 222 | setpaths |
| 223 | set_sequence_number |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 224 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 225 | export ANDROID_BUILD_TOP=$(gettop) |
Ben Cheng | aac3f81 | 2013-08-13 14:38:15 -0700 | [diff] [blame] | 226 | # With this environment variable new GCC can apply colors to warnings/errors |
| 227 | 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] | 228 | export ASAN_OPTIONS=detect_leaks=0 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | function set_sequence_number() |
| 232 | { |
Joe Onorato | aee4daa | 2010-06-23 14:03:13 -0700 | [diff] [blame] | 233 | export BUILD_ENV_SEQUENCE_NUMBER=10 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | function settitle() |
| 237 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 238 | if [ "$STAY_OFF_MY_LAWN" = "" ]; then |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 239 | local arch=$(gettargetarch) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 240 | local product=$TARGET_PRODUCT |
| 241 | local variant=$TARGET_BUILD_VARIANT |
| 242 | local apps=$TARGET_BUILD_APPS |
| 243 | if [ -z "$apps" ]; then |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 244 | export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\"" |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 245 | else |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 246 | export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\"" |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 247 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 248 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 251 | function addcompletions() |
| 252 | { |
| 253 | local T dir f |
| 254 | |
| 255 | # Keep us from trying to run in something that isn't bash. |
| 256 | if [ -z "${BASH_VERSION}" ]; then |
| 257 | return |
| 258 | fi |
| 259 | |
| 260 | # Keep us from trying to run in bash that's too old. |
| 261 | if [ ${BASH_VERSINFO[0]} -lt 3 ]; then |
| 262 | return |
| 263 | fi |
| 264 | |
| 265 | dir="sdk/bash_completion" |
| 266 | if [ -d ${dir} ]; then |
Kenny Root | 7546d61 | 2011-07-18 13:11:34 -0700 | [diff] [blame] | 267 | for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 268 | echo "including $f" |
| 269 | . $f |
| 270 | done |
| 271 | fi |
| 272 | } |
| 273 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 274 | function choosetype() |
| 275 | { |
| 276 | echo "Build type choices are:" |
| 277 | echo " 1. release" |
| 278 | echo " 2. debug" |
| 279 | echo |
| 280 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 281 | local DEFAULT_NUM DEFAULT_VALUE |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 282 | DEFAULT_NUM=1 |
| 283 | DEFAULT_VALUE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 284 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 285 | export TARGET_BUILD_TYPE= |
| 286 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 287 | while [ -z $TARGET_BUILD_TYPE ] |
| 288 | do |
| 289 | echo -n "Which would you like? ["$DEFAULT_NUM"] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 290 | if [ -z "$1" ] ; then |
| 291 | read ANSWER |
| 292 | else |
| 293 | echo $1 |
| 294 | ANSWER=$1 |
| 295 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 296 | case $ANSWER in |
| 297 | "") |
| 298 | export TARGET_BUILD_TYPE=$DEFAULT_VALUE |
| 299 | ;; |
| 300 | 1) |
| 301 | export TARGET_BUILD_TYPE=release |
| 302 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 303 | release) |
| 304 | export TARGET_BUILD_TYPE=release |
| 305 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 306 | 2) |
| 307 | export TARGET_BUILD_TYPE=debug |
| 308 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 309 | debug) |
| 310 | export TARGET_BUILD_TYPE=debug |
| 311 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 312 | *) |
| 313 | echo |
| 314 | echo "I didn't understand your response. Please try again." |
| 315 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 316 | ;; |
| 317 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 318 | if [ -n "$1" ] ; then |
| 319 | break |
| 320 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 321 | done |
| 322 | |
| 323 | set_stuff_for_environment |
| 324 | } |
| 325 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 326 | # |
| 327 | # This function isn't really right: It chooses a TARGET_PRODUCT |
| 328 | # based on the list of boards. Usually, that gets you something |
| 329 | # that kinda works with a generic product, but really, you should |
| 330 | # pick a product by name. |
| 331 | # |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 332 | function chooseproduct() |
| 333 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 334 | if [ "x$TARGET_PRODUCT" != x ] ; then |
| 335 | default_value=$TARGET_PRODUCT |
| 336 | else |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 337 | default_value=aosp_arm |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 338 | fi |
| 339 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 340 | export TARGET_PRODUCT= |
| 341 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 342 | while [ -z "$TARGET_PRODUCT" ] |
| 343 | do |
Joe Onorato | 8849aed | 2009-04-29 15:56:47 -0700 | [diff] [blame] | 344 | echo -n "Which product would you like? [$default_value] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 345 | if [ -z "$1" ] ; then |
| 346 | read ANSWER |
| 347 | else |
| 348 | echo $1 |
| 349 | ANSWER=$1 |
| 350 | fi |
| 351 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 352 | if [ -z "$ANSWER" ] ; then |
| 353 | export TARGET_PRODUCT=$default_value |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 354 | else |
| 355 | if check_product $ANSWER |
| 356 | then |
| 357 | export TARGET_PRODUCT=$ANSWER |
| 358 | else |
| 359 | echo "** Not a valid product: $ANSWER" |
| 360 | fi |
| 361 | fi |
| 362 | if [ -n "$1" ] ; then |
| 363 | break |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 364 | fi |
| 365 | done |
| 366 | |
| 367 | set_stuff_for_environment |
| 368 | } |
| 369 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 370 | function choosevariant() |
| 371 | { |
| 372 | echo "Variant choices are:" |
| 373 | local index=1 |
| 374 | local v |
| 375 | for v in ${VARIANT_CHOICES[@]} |
| 376 | do |
| 377 | # The product name is the name of the directory containing |
| 378 | # the makefile we found, above. |
| 379 | echo " $index. $v" |
| 380 | index=$(($index+1)) |
| 381 | done |
| 382 | |
| 383 | local default_value=eng |
| 384 | local ANSWER |
| 385 | |
| 386 | export TARGET_BUILD_VARIANT= |
| 387 | while [ -z "$TARGET_BUILD_VARIANT" ] |
| 388 | do |
| 389 | echo -n "Which would you like? [$default_value] " |
| 390 | if [ -z "$1" ] ; then |
| 391 | read ANSWER |
| 392 | else |
| 393 | echo $1 |
| 394 | ANSWER=$1 |
| 395 | fi |
| 396 | |
| 397 | if [ -z "$ANSWER" ] ; then |
| 398 | export TARGET_BUILD_VARIANT=$default_value |
| 399 | elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then |
| 400 | if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 401 | export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 402 | fi |
| 403 | else |
| 404 | if check_variant $ANSWER |
| 405 | then |
| 406 | export TARGET_BUILD_VARIANT=$ANSWER |
| 407 | else |
| 408 | echo "** Not a valid variant: $ANSWER" |
| 409 | fi |
| 410 | fi |
| 411 | if [ -n "$1" ] ; then |
| 412 | break |
| 413 | fi |
| 414 | done |
| 415 | } |
| 416 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 417 | function choosecombo() |
| 418 | { |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 419 | choosetype $1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 420 | |
| 421 | echo |
| 422 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 423 | chooseproduct $2 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 424 | |
| 425 | echo |
| 426 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 427 | choosevariant $3 |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 428 | |
| 429 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 430 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 431 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 432 | } |
| 433 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 434 | # Clear this variable. It will be built up again when the vendorsetup.sh |
| 435 | # files are included at the end of this file. |
| 436 | unset LUNCH_MENU_CHOICES |
| 437 | function add_lunch_combo() |
| 438 | { |
| 439 | local new_combo=$1 |
| 440 | local c |
| 441 | for c in ${LUNCH_MENU_CHOICES[@]} ; do |
| 442 | if [ "$new_combo" = "$c" ] ; then |
| 443 | return |
| 444 | fi |
| 445 | done |
| 446 | LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) |
| 447 | } |
| 448 | |
| 449 | # add the default one here |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 450 | add_lunch_combo aosp_arm-eng |
Colin Cross | 4f0eb7d | 2014-01-21 19:35:38 -0800 | [diff] [blame] | 451 | add_lunch_combo aosp_arm64-eng |
Serban Constantinescu | 9b68fb2 | 2014-01-14 10:33:53 +0000 | [diff] [blame] | 452 | add_lunch_combo aosp_mips-eng |
Chris Dearman | 1efd9e4 | 2014-02-03 15:01:24 -0800 | [diff] [blame] | 453 | add_lunch_combo aosp_mips64-eng |
Serban Constantinescu | 9b68fb2 | 2014-01-14 10:33:53 +0000 | [diff] [blame] | 454 | add_lunch_combo aosp_x86-eng |
| 455 | add_lunch_combo aosp_x86_64-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 456 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 457 | function print_lunch_menu() |
| 458 | { |
| 459 | local uname=$(uname) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 460 | echo |
| 461 | echo "You're building on" $uname |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 462 | echo |
| 463 | echo "Lunch menu... pick a combo:" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 464 | |
| 465 | local i=1 |
| 466 | local choice |
| 467 | for choice in ${LUNCH_MENU_CHOICES[@]} |
| 468 | do |
| 469 | echo " $i. $choice" |
| 470 | i=$(($i+1)) |
| 471 | done |
| 472 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 473 | echo |
| 474 | } |
| 475 | |
| 476 | function lunch() |
| 477 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 478 | local answer |
| 479 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 480 | if [ "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 481 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 482 | else |
| 483 | print_lunch_menu |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 484 | echo -n "Which would you like? [aosp_arm-eng] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 485 | read answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 486 | fi |
| 487 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 488 | local selection= |
| 489 | |
| 490 | if [ -z "$answer" ] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 491 | then |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 492 | selection=aosp_arm-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 493 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 494 | then |
| 495 | if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] |
| 496 | then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 497 | selection=${LUNCH_MENU_CHOICES[$(($answer-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 498 | fi |
| 499 | elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") |
| 500 | then |
| 501 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 502 | fi |
| 503 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 504 | if [ -z "$selection" ] |
| 505 | then |
| 506 | echo |
| 507 | echo "Invalid lunch combo: $answer" |
| 508 | return 1 |
| 509 | fi |
| 510 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 511 | export TARGET_BUILD_APPS= |
| 512 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 513 | local product=$(echo -n $selection | sed -e "s/-.*$//") |
| 514 | check_product $product |
| 515 | if [ $? -ne 0 ] |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 516 | then |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 517 | echo |
| 518 | echo "** Don't have a product spec for: '$product'" |
| 519 | echo "** Do you have the right repo manifest?" |
| 520 | product= |
| 521 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 522 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 523 | local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") |
| 524 | check_variant $variant |
| 525 | if [ $? -ne 0 ] |
| 526 | then |
| 527 | echo |
| 528 | echo "** Invalid variant: '$variant'" |
| 529 | echo "** Must be one of ${VARIANT_CHOICES[@]}" |
| 530 | variant= |
| 531 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 532 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 533 | if [ -z "$product" -o -z "$variant" ] |
| 534 | then |
| 535 | echo |
| 536 | return 1 |
| 537 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 538 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 539 | export TARGET_PRODUCT=$product |
| 540 | export TARGET_BUILD_VARIANT=$variant |
| 541 | export TARGET_BUILD_TYPE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 542 | |
| 543 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 544 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 545 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 546 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 549 | # Tab completion for lunch. |
| 550 | function _lunch() |
| 551 | { |
| 552 | local cur prev opts |
| 553 | COMPREPLY=() |
| 554 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 555 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 556 | |
| 557 | COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) ) |
| 558 | return 0 |
| 559 | } |
| 560 | complete -F _lunch lunch |
| 561 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 562 | # Configures the build to build unbundled apps. |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 563 | # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 564 | function tapas() |
| 565 | { |
Ying Wang | b541ab6 | 2014-05-29 17:57:40 -0700 | [diff] [blame] | 566 | local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)" |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 567 | 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] | 568 | local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)" |
| 569 | local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|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] | 570 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 571 | if [ $(echo $arch | wc -w) -gt 1 ]; then |
| 572 | echo "tapas: Error: Multiple build archs supplied: $arch" |
| 573 | return |
| 574 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 575 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 576 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 577 | return |
| 578 | fi |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 579 | if [ $(echo $density | wc -w) -gt 1 ]; then |
| 580 | echo "tapas: Error: Multiple densities supplied: $density" |
| 581 | return |
| 582 | fi |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 583 | |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 584 | local product=aosp_arm |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 585 | case $arch in |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 586 | x86) product=aosp_x86;; |
| 587 | mips) product=aosp_mips;; |
Ying Wang | b541ab6 | 2014-05-29 17:57:40 -0700 | [diff] [blame] | 588 | armv5) product=generic_armv5;; |
| 589 | arm64) product=aosp_arm64;; |
| 590 | x86_64) product=aosp_x86_64;; |
| 591 | mips64) product=aosp_mips64;; |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 592 | esac |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 593 | if [ -z "$variant" ]; then |
| 594 | variant=eng |
| 595 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 596 | if [ -z "$apps" ]; then |
| 597 | apps=all |
| 598 | fi |
Justin Morey | 29d225c | 2014-11-04 13:35:51 -0600 | [diff] [blame] | 599 | if [ -z "$density" ]; then |
| 600 | density=alldpi |
| 601 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 602 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 603 | export TARGET_PRODUCT=$product |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 604 | export TARGET_BUILD_VARIANT=$variant |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 605 | export TARGET_BUILD_DENSITY=$density |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 606 | export TARGET_BUILD_TYPE=release |
| 607 | export TARGET_BUILD_APPS=$apps |
| 608 | |
| 609 | set_stuff_for_environment |
| 610 | printconfig |
| 611 | } |
| 612 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 613 | function gettop |
| 614 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 615 | local TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 616 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
Brian Carlstrom | a5c4f17 | 2014-09-12 00:33:25 -0700 | [diff] [blame] | 617 | # The following circumlocution ensures we remove symlinks from TOP. |
| 618 | (cd $TOP; PWD= /bin/pwd) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 619 | else |
| 620 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 621 | # The following circumlocution (repeated below as well) ensures |
| 622 | # that we record the true directory name and not one that is |
| 623 | # faked up with symlink names. |
| 624 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 625 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 626 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 627 | T= |
| 628 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 629 | \cd .. |
synergy | b112a40 | 2013-07-05 19:47:47 -0700 | [diff] [blame] | 630 | T=`PWD= /bin/pwd -P` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 631 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 632 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 633 | if [ -f "$T/$TOPFILE" ]; then |
| 634 | echo $T |
| 635 | fi |
| 636 | fi |
| 637 | fi |
| 638 | } |
| 639 | |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 640 | # Return driver for "make", if any (eg. static analyzer) |
| 641 | function getdriver() |
| 642 | { |
| 643 | local T="$1" |
| 644 | test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER |
| 645 | if [ -n "$WITH_STATIC_ANALYZER" ]; then |
| 646 | echo "\ |
Andrew Hsieh | c4f7fba | 2014-03-03 16:53:17 +0800 | [diff] [blame] | 647 | $T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \ |
| 648 | --use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \ |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 649 | --status-bugs \ |
| 650 | --top=$T" |
| 651 | fi |
| 652 | } |
| 653 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 654 | function m() |
| 655 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 656 | local T=$(gettop) |
| 657 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 658 | if [ "$T" ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 659 | $DRV make -C $T -f build/core/main.mk $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 660 | else |
| 661 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 662 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 663 | fi |
| 664 | } |
| 665 | |
| 666 | function findmakefile() |
| 667 | { |
| 668 | TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 669 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 670 | T= |
| 671 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 11b15b1 | 2012-10-11 15:05:07 -0700 | [diff] [blame] | 672 | T=`PWD= /bin/pwd` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 673 | if [ -f "$T/Android.mk" ]; then |
| 674 | echo $T/Android.mk |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 675 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 676 | return |
| 677 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 678 | \cd .. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 679 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 680 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | function mm() |
| 684 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 685 | local T=$(gettop) |
| 686 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 687 | # If we're sitting in the root of the build tree, just do a |
| 688 | # normal make. |
| 689 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 690 | $DRV make $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 691 | else |
| 692 | # Find the closest Android.mk file. |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 693 | local M=$(findmakefile) |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 694 | local MODULES= |
| 695 | local GET_INSTALL_PATH= |
| 696 | local ARGS= |
Robert Greenwalt | 3c794d7 | 2009-07-15 15:07:44 -0700 | [diff] [blame] | 697 | # Remove the path to top as the makefilepath needs to be relative |
| 698 | local M=`echo $M|sed 's:'$T'/::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 699 | if [ ! "$T" ]; then |
| 700 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 701 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 702 | elif [ ! "$M" ]; then |
| 703 | echo "Couldn't locate a makefile from the current directory." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 704 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 705 | else |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 706 | for ARG in $@; do |
| 707 | case $ARG in |
| 708 | GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;; |
| 709 | esac |
| 710 | done |
| 711 | if [ -n "$GET_INSTALL_PATH" ]; then |
| 712 | MODULES= |
| 713 | ARGS=GET-INSTALL-PATH |
| 714 | else |
| 715 | MODULES=all_modules |
| 716 | ARGS=$@ |
| 717 | fi |
Andrew Hsieh | 246daf7 | 2013-09-10 18:07:23 -0700 | [diff] [blame] | 718 | ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 719 | fi |
| 720 | fi |
| 721 | } |
| 722 | |
| 723 | function mmm() |
| 724 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 725 | local T=$(gettop) |
| 726 | local DRV=$(getdriver $T) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 727 | if [ "$T" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 728 | local MAKEFILE= |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 729 | local MODULES= |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 730 | local ARGS= |
| 731 | local DIR TO_CHOP |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 732 | local GET_INSTALL_PATH= |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 733 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 734 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 735 | for DIR in $DIRS ; do |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 736 | MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'` |
| 737 | if [ "$MODULES" = "" ]; then |
| 738 | MODULES=all_modules |
| 739 | fi |
| 740 | DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 741 | if [ -f $DIR/Android.mk ]; then |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 742 | local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '` |
| 743 | local TO_CHOP=`expr $TO_CHOP + 1` |
| 744 | local START=`PWD= /bin/pwd` |
| 745 | local MFILE=`echo $START | cut -c${TO_CHOP}-` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 746 | if [ "$MFILE" = "" ] ; then |
| 747 | MFILE=$DIR/Android.mk |
| 748 | else |
| 749 | MFILE=$MFILE/$DIR/Android.mk |
| 750 | fi |
| 751 | MAKEFILE="$MAKEFILE $MFILE" |
| 752 | else |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 753 | case $DIR in |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 754 | showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";; |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 755 | GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;; |
| 756 | *) echo "No Android.mk in $DIR."; return 1;; |
| 757 | esac |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 758 | fi |
| 759 | done |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 760 | if [ -n "$GET_INSTALL_PATH" ]; then |
| 761 | ARGS=$GET_INSTALL_PATH |
| 762 | MODULES= |
| 763 | fi |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 764 | ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 765 | else |
| 766 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 767 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 768 | fi |
| 769 | } |
| 770 | |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 771 | function mma() |
| 772 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 773 | local T=$(gettop) |
| 774 | local DRV=$(getdriver $T) |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 775 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 776 | $DRV make $@ |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 777 | else |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 778 | if [ ! "$T" ]; then |
| 779 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 780 | return 1 |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 781 | fi |
| 782 | local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'` |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 783 | $DRV make -C $T -f build/core/main.mk $@ MODULES-IN/$MY_PWD |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 784 | fi |
| 785 | } |
| 786 | |
| 787 | function mmma() |
| 788 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 789 | local T=$(gettop) |
| 790 | local DRV=$(getdriver $T) |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 791 | if [ "$T" ]; then |
| 792 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 793 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 794 | local MY_PWD=`PWD= /bin/pwd` |
| 795 | if [ "$MY_PWD" = "$T" ]; then |
| 796 | MY_PWD= |
| 797 | else |
| 798 | MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'` |
| 799 | fi |
| 800 | local DIR= |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 801 | local MODULES_IN_PATHS= |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 802 | local ARGS= |
| 803 | for DIR in $DIRS ; do |
| 804 | if [ -d $DIR ]; then |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 805 | # Remove the leading ./ and trailing / if any exists. |
| 806 | DIR=${DIR#./} |
| 807 | DIR=${DIR%/} |
| 808 | if [ "$MY_PWD" != "" ]; then |
| 809 | DIR=$MY_PWD/$DIR |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 810 | fi |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 811 | MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN/$DIR" |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 812 | else |
| 813 | case $DIR in |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 814 | showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";; |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 815 | *) echo "Couldn't find directory $DIR"; return 1;; |
| 816 | esac |
| 817 | fi |
| 818 | done |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 819 | $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS $MODULES_IN_PATHS |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 820 | else |
| 821 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 822 | return 1 |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 823 | fi |
| 824 | } |
| 825 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 826 | function croot() |
| 827 | { |
| 828 | T=$(gettop) |
| 829 | if [ "$T" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 830 | \cd $(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 831 | else |
| 832 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 833 | fi |
| 834 | } |
| 835 | |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 836 | function cproj() |
| 837 | { |
| 838 | TOPFILE=build/core/envsetup.mk |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 839 | local HERE=$PWD |
| 840 | T= |
| 841 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 842 | T=$PWD |
| 843 | if [ -f "$T/Android.mk" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 844 | \cd $T |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 845 | return |
| 846 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 847 | \cd .. |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 848 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 849 | \cd $HERE |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 850 | echo "can't find Android.mk" |
| 851 | } |
| 852 | |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 853 | # simplified version of ps; output in the form |
| 854 | # <pid> <procname> |
| 855 | function qpid() { |
| 856 | local prepend='' |
| 857 | local append='' |
| 858 | if [ "$1" = "--exact" ]; then |
| 859 | prepend=' ' |
| 860 | append='$' |
| 861 | shift |
| 862 | elif [ "$1" = "--help" -o "$1" = "-h" ]; then |
| 863 | echo "usage: qpid [[--exact] <process name|pid>" |
| 864 | return 255 |
| 865 | fi |
| 866 | |
| 867 | local EXE="$1" |
| 868 | if [ "$EXE" ] ; then |
Mathias Agopian | 4458327 | 2013-08-27 14:15:50 -0700 | [diff] [blame] | 869 | qpid | \grep "$prepend$EXE$append" |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 870 | else |
| 871 | adb shell ps \ |
| 872 | | tr -d '\r' \ |
| 873 | | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/' |
| 874 | fi |
| 875 | } |
| 876 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 877 | function pid() |
| 878 | { |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 879 | local prepend='' |
| 880 | local append='' |
| 881 | if [ "$1" = "--exact" ]; then |
| 882 | prepend=' ' |
| 883 | append='$' |
| 884 | shift |
| 885 | fi |
| 886 | local EXE="$1" |
| 887 | if [ "$EXE" ] ; then |
| 888 | local PID=`adb shell ps \ |
| 889 | | tr -d '\r' \ |
Mathias Agopian | 4458327 | 2013-08-27 14:15:50 -0700 | [diff] [blame] | 890 | | \grep "$prepend$EXE$append" \ |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 891 | | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'` |
| 892 | echo "$PID" |
| 893 | else |
| 894 | echo "usage: pid [--exact] <process name>" |
| 895 | return 255 |
| 896 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 897 | } |
| 898 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 899 | # coredump_setup - enable core dumps globally for any process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 900 | # that has the core-file-size limit set correctly |
| 901 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 902 | # NOTE: You must call also coredump_enable for a specific process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 903 | # if its core-file-size limit is not set already. |
| 904 | # NOTE: Core dumps are written to ramdisk; they will not survive a reboot! |
| 905 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 906 | function coredump_setup() |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 907 | { |
| 908 | echo "Getting root..."; |
| 909 | adb root; |
| 910 | adb wait-for-device; |
| 911 | |
| 912 | echo "Remounting root parition read-write..."; |
| 913 | adb shell mount -w -o remount -t rootfs rootfs; |
| 914 | sleep 1; |
| 915 | adb wait-for-device; |
| 916 | adb shell mkdir -p /cores; |
Nick Kralevich | a94282c | 2014-11-04 11:17:20 -0800 | [diff] [blame] | 917 | adb shell mount -t tmpfs tmpfs /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 918 | adb shell chmod 0777 /cores; |
| 919 | |
| 920 | echo "Granting SELinux permission to dump in /cores..."; |
| 921 | adb shell restorecon -R /cores; |
| 922 | |
| 923 | echo "Set core pattern."; |
| 924 | adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern'; |
| 925 | |
| 926 | echo "Done." |
| 927 | } |
| 928 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 929 | # coredump_enable - enable core dumps for the specified process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 930 | # $1 = PID of process (e.g., $(pid mediaserver)) |
| 931 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 932 | # NOTE: coredump_setup must have been called as well for a core |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 933 | # dump to actually be generated. |
| 934 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 935 | function coredump_enable() |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 936 | { |
| 937 | local PID=$1; |
| 938 | if [ -z "$PID" ]; then |
| 939 | printf "Expecting a PID!\n"; |
| 940 | return; |
| 941 | fi; |
| 942 | echo "Setting core limit for $PID to infinite..."; |
| 943 | adb shell prlimit $PID 4 -1 -1 |
| 944 | } |
| 945 | |
| 946 | # core - send SIGV and pull the core for process |
| 947 | # $1 = PID of process (e.g., $(pid mediaserver)) |
| 948 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 949 | # 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] | 950 | # enabled globally. |
| 951 | |
| 952 | function core() |
| 953 | { |
| 954 | local PID=$1; |
| 955 | |
| 956 | if [ -z "$PID" ]; then |
| 957 | printf "Expecting a PID!\n"; |
| 958 | return; |
| 959 | fi; |
| 960 | |
| 961 | local CORENAME=core.$PID; |
| 962 | local COREPATH=/cores/$CORENAME; |
| 963 | local SIG=SEGV; |
| 964 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 965 | coredump_enable $1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 966 | |
| 967 | local done=0; |
| 968 | while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do |
| 969 | printf "\tSending SIG%s to %d...\n" $SIG $PID; |
| 970 | adb shell kill -$SIG $PID; |
| 971 | sleep 1; |
| 972 | done; |
| 973 | |
| 974 | adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done" |
| 975 | echo "Done: core is under $COREPATH on device."; |
| 976 | } |
| 977 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 978 | # systemstack - dump the current stack trace of all threads in the system process |
| 979 | # to the usual ANR traces file |
| 980 | function systemstack() |
| 981 | { |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 982 | stacks system_server |
| 983 | } |
| 984 | |
| 985 | function stacks() |
| 986 | { |
| 987 | if [[ $1 =~ ^[0-9]+$ ]] ; then |
| 988 | local PID="$1" |
| 989 | elif [ "$1" ] ; then |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 990 | local PIDLIST="$(pid $1)" |
| 991 | if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then |
| 992 | local PID="$PIDLIST" |
| 993 | elif [ "$PIDLIST" ] ; then |
| 994 | echo "more than one process: $1" |
| 995 | else |
| 996 | echo "no such process: $1" |
| 997 | fi |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 998 | else |
| 999 | echo "usage: stacks [pid|process name]" |
| 1000 | fi |
| 1001 | |
| 1002 | if [ "$PID" ] ; then |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1003 | # Determine whether the process is native |
| 1004 | if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then |
| 1005 | # Dump stacks of Dalvik process |
| 1006 | local TRACES=/data/anr/traces.txt |
| 1007 | local ORIG=/data/anr/traces.orig |
| 1008 | local TMP=/data/anr/traces.tmp |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1009 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1010 | # Keep original traces to avoid clobbering |
| 1011 | adb shell mv $TRACES $ORIG |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1012 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1013 | # Make sure we have a usable file |
| 1014 | adb shell touch $TRACES |
| 1015 | adb shell chmod 666 $TRACES |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1016 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1017 | # Dump stacks and wait for dump to finish |
| 1018 | adb shell kill -3 $PID |
| 1019 | adb shell notify $TRACES >/dev/null |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1020 | |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1021 | # Restore original stacks, and show current output |
| 1022 | adb shell mv $TRACES $TMP |
| 1023 | adb shell mv $ORIG $TRACES |
| 1024 | adb shell cat $TMP |
| 1025 | else |
| 1026 | # Dump stacks of native process |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1027 | local USE64BIT="$(is64bit $PID)" |
| 1028 | adb shell debuggerd$USE64BIT -b $PID |
Jeff Brown | b12c2e5 | 2013-08-19 15:14:16 -0700 | [diff] [blame] | 1029 | fi |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1030 | fi |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 1031 | } |
| 1032 | |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1033 | # Read the ELF header from /proc/$PID/exe to determine if the process is |
| 1034 | # 64-bit. |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1035 | function is64bit() |
| 1036 | { |
| 1037 | local PID="$1" |
| 1038 | if [ "$PID" ] ; then |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1039 | if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1040 | echo "64" |
| 1041 | else |
| 1042 | echo "" |
| 1043 | fi |
| 1044 | else |
| 1045 | echo "" |
| 1046 | fi |
| 1047 | } |
| 1048 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1049 | case `uname -s` in |
| 1050 | Darwin) |
| 1051 | function sgrep() |
| 1052 | { |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 1053 | find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | ;; |
| 1057 | *) |
| 1058 | function sgrep() |
| 1059 | { |
Jeff Brown | 46cbd20 | 2014-07-26 15:15:41 -0700 | [diff] [blame] | 1060 | find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1061 | } |
| 1062 | ;; |
| 1063 | esac |
| 1064 | |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1065 | function gettargetarch |
| 1066 | { |
| 1067 | get_build_var TARGET_ARCH |
| 1068 | } |
| 1069 | |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 1070 | function ggrep() |
| 1071 | { |
| 1072 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@" |
| 1073 | } |
| 1074 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1075 | function jgrep() |
| 1076 | { |
Anatolii Shuba | 91c72d2 | 2013-07-05 16:09:25 +0300 | [diff] [blame] | 1077 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | function cgrep() |
| 1081 | { |
Dan Albert | 0196119 | 2014-11-22 10:16:01 -0800 | [diff] [blame] | 1082 | 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' \) -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | function resgrep() |
| 1086 | { |
Anatolii Shuba | 91c72d2 | 2013-07-05 16:09:25 +0300 | [diff] [blame] | 1087 | for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Jeff Sharkey | 50b61e9 | 2013-03-08 10:20:47 -0800 | [diff] [blame] | 1090 | function mangrep() |
| 1091 | { |
| 1092 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@" |
| 1093 | } |
| 1094 | |
Alex Klyubin | ba5fc8e | 2013-05-06 14:11:48 -0700 | [diff] [blame] | 1095 | function sepgrep() |
| 1096 | { |
| 1097 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@" |
| 1098 | } |
| 1099 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1100 | case `uname -s` in |
| 1101 | Darwin) |
| 1102 | function mgrep() |
| 1103 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 1104 | find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | function treegrep() |
| 1108 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 1109 | find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|S|java|xml)' -print0 | xargs -0 grep --color -n -i "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | ;; |
| 1113 | *) |
| 1114 | function mgrep() |
| 1115 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 1116 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk)' -type f -print0 | xargs -0 grep --color -n "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | function treegrep() |
| 1120 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 1121 | find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | ;; |
| 1125 | esac |
| 1126 | |
| 1127 | function getprebuilt |
| 1128 | { |
| 1129 | get_abs_build_var ANDROID_PREBUILTS |
| 1130 | } |
| 1131 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1132 | function tracedmdump() |
| 1133 | { |
| 1134 | T=$(gettop) |
| 1135 | if [ ! "$T" ]; then |
| 1136 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 1137 | return |
| 1138 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1139 | local prebuiltdir=$(getprebuilt) |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1140 | local arch=$(gettargetarch) |
| 1141 | local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1142 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1143 | local TRACE=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1144 | if [ ! "$TRACE" ] ; then |
| 1145 | echo "usage: tracedmdump tracename" |
| 1146 | return |
| 1147 | fi |
| 1148 | |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 1149 | if [ ! -r "$KERNEL" ] ; then |
| 1150 | echo "Error: cannot find kernel: '$KERNEL'" |
| 1151 | return |
| 1152 | fi |
| 1153 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1154 | local BASETRACE=$(basename $TRACE) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1155 | if [ "$BASETRACE" = "$TRACE" ] ; then |
| 1156 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 1157 | fi |
| 1158 | |
| 1159 | echo "post-processing traces..." |
| 1160 | rm -f $TRACE/qtrace.dexlist |
| 1161 | post_trace $TRACE |
| 1162 | if [ $? -ne 0 ]; then |
| 1163 | echo "***" |
| 1164 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 1165 | echo "***" |
| 1166 | return |
| 1167 | fi |
| 1168 | echo "generating dexlist output..." |
| 1169 | /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 |
| 1170 | echo "generating dmtrace data..." |
| 1171 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 1172 | echo "generating html file..." |
| 1173 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 1174 | echo "done, see $TRACE/dmtrace.html for details" |
| 1175 | echo "or run:" |
| 1176 | echo " traceview $TRACE/dmtrace" |
| 1177 | } |
| 1178 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1179 | # communicate with a running device or emulator, set up necessary state, |
| 1180 | # and run the hat command. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1181 | function runhat() |
| 1182 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1183 | # process standard adb options |
| 1184 | local adbTarget="" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1185 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1186 | adbTarget=$1 |
| 1187 | shift 1 |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1188 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1189 | adbTarget="$1 $2" |
| 1190 | shift 2 |
| 1191 | fi |
| 1192 | local adbOptions=${adbTarget} |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1193 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1194 | |
| 1195 | # runhat options |
| 1196 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1197 | |
| 1198 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1199 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1200 | return |
| 1201 | fi |
| 1202 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1203 | # confirm hat is available |
| 1204 | if [ -z $(which hat) ]; then |
| 1205 | echo "hat is not available in this configuration." |
| 1206 | return |
| 1207 | fi |
| 1208 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1209 | # issue "am" command to cause the hprof dump |
Nick Kralevich | 9948b1e | 2014-07-18 15:45:38 -0700 | [diff] [blame] | 1210 | local devFile=/data/local/tmp/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1211 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1212 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1213 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1214 | 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] | 1215 | echo -n "> " |
| 1216 | read |
| 1217 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1218 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1219 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1220 | echo "Retrieving file $devFile..." |
| 1221 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1222 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1223 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1224 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1225 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1226 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1227 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1228 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | function getbugreports() |
| 1232 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1233 | 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] | 1234 | |
| 1235 | if [ ! "$reports" ]; then |
| 1236 | echo "Could not locate any bugreports." |
| 1237 | return |
| 1238 | fi |
| 1239 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1240 | local report |
| 1241 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1242 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1243 | echo "/sdcard/bugreports/${report}" |
| 1244 | adb pull /sdcard/bugreports/${report} ${report} |
| 1245 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1246 | done |
| 1247 | } |
| 1248 | |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1249 | function getsdcardpath() |
| 1250 | { |
| 1251 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1252 | } |
| 1253 | |
| 1254 | function getscreenshotpath() |
| 1255 | { |
| 1256 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1257 | } |
| 1258 | |
| 1259 | function getlastscreenshot() |
| 1260 | { |
| 1261 | local screenshot_path=$(getscreenshotpath) |
| 1262 | local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` |
| 1263 | if [ "$screenshot" = "" ]; then |
| 1264 | echo "No screenshots found." |
| 1265 | return |
| 1266 | fi |
| 1267 | echo "${screenshot}" |
| 1268 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1269 | } |
| 1270 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1271 | function startviewserver() |
| 1272 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1273 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1274 | if [ $# -gt 0 ]; then |
| 1275 | port=$1 |
| 1276 | fi |
| 1277 | adb shell service call window 1 i32 $port |
| 1278 | } |
| 1279 | |
| 1280 | function stopviewserver() |
| 1281 | { |
| 1282 | adb shell service call window 2 |
| 1283 | } |
| 1284 | |
| 1285 | function isviewserverstarted() |
| 1286 | { |
| 1287 | adb shell service call window 3 |
| 1288 | } |
| 1289 | |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1290 | function key_home() |
| 1291 | { |
| 1292 | adb shell input keyevent 3 |
| 1293 | } |
| 1294 | |
| 1295 | function key_back() |
| 1296 | { |
| 1297 | adb shell input keyevent 4 |
| 1298 | } |
| 1299 | |
| 1300 | function key_menu() |
| 1301 | { |
| 1302 | adb shell input keyevent 82 |
| 1303 | } |
| 1304 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1305 | function smoketest() |
| 1306 | { |
| 1307 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1308 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1309 | return |
| 1310 | fi |
| 1311 | T=$(gettop) |
| 1312 | if [ ! "$T" ]; then |
| 1313 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1314 | return |
| 1315 | fi |
| 1316 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1317 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1318 | adb uninstall com.android.smoketest > /dev/null && |
| 1319 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1320 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1321 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1322 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1323 | } |
| 1324 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1325 | # simple shortcut to the runtest command |
| 1326 | function runtest() |
| 1327 | { |
| 1328 | T=$(gettop) |
| 1329 | if [ ! "$T" ]; then |
| 1330 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1331 | return |
| 1332 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1333 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1336 | function godir () { |
| 1337 | if [[ -z "$1" ]]; then |
| 1338 | echo "Usage: godir <regex>" |
| 1339 | return |
| 1340 | fi |
Brian Carlstrom | b9915a6 | 2010-01-29 16:39:32 -0800 | [diff] [blame] | 1341 | T=$(gettop) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1342 | if [[ ! -f $T/filelist ]]; then |
| 1343 | echo -n "Creating index..." |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1344 | (\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] | 1345 | echo " Done" |
| 1346 | echo "" |
| 1347 | fi |
| 1348 | local lines |
Jeff Hamilton | 293f939 | 2011-11-18 17:15:25 -0600 | [diff] [blame] | 1349 | lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1350 | if [[ ${#lines[@]} = 0 ]]; then |
| 1351 | echo "Not found" |
| 1352 | return |
| 1353 | fi |
| 1354 | local pathname |
| 1355 | local choice |
| 1356 | if [[ ${#lines[@]} > 1 ]]; then |
| 1357 | while [[ -z "$pathname" ]]; do |
| 1358 | local index=1 |
| 1359 | local line |
| 1360 | for line in ${lines[@]}; do |
| 1361 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1362 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1363 | done |
| 1364 | echo |
| 1365 | echo -n "Select one: " |
| 1366 | unset choice |
| 1367 | read choice |
| 1368 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1369 | echo "Invalid choice" |
| 1370 | continue |
| 1371 | fi |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1372 | pathname=${lines[$(($choice-1))]} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1373 | done |
| 1374 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1375 | pathname=${lines[0]} |
| 1376 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1377 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1378 | } |
| 1379 | |
Neil Fuller | 46e00ea | 2014-10-16 10:23:03 +0100 | [diff] [blame] | 1380 | # Force JAVA_HOME to point to java 1.7 if it isn't already set. |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 1381 | # |
| 1382 | # Note that the MacOS path for java 1.7 includes a minor revision number (sigh). |
| 1383 | # For some reason, installing the JDK doesn't make it show up in the |
| 1384 | # JavaVM.framework/Versions/1.7/ folder. |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1385 | function set_java_home() { |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 1386 | # Clear the existing JAVA_HOME value if we set it ourselves, so that |
Narayan Kamath | c84889b | 2014-04-01 14:16:26 +0100 | [diff] [blame] | 1387 | # we can reset it later, depending on the version of java the build |
| 1388 | # system needs. |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 1389 | # |
| 1390 | # If we don't do this, the JAVA_HOME value set by the first call to |
| 1391 | # build/envsetup.sh will persist forever. |
| 1392 | if [ -n "$ANDROID_SET_JAVA_HOME" ]; then |
| 1393 | export JAVA_HOME="" |
| 1394 | fi |
| 1395 | |
Andy McFadden | bd96094 | 2010-06-24 12:52:51 -0700 | [diff] [blame] | 1396 | if [ ! "$JAVA_HOME" ]; then |
Neil Fuller | 46e00ea | 2014-10-16 10:23:03 +0100 | [diff] [blame] | 1397 | case `uname -s` in |
| 1398 | Darwin) |
| 1399 | export JAVA_HOME=$(/usr/libexec/java_home -v 1.7) |
| 1400 | ;; |
| 1401 | *) |
| 1402 | export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 |
| 1403 | ;; |
| 1404 | esac |
Narayan Kamath | 9260bba | 2014-01-17 10:05:25 +0000 | [diff] [blame] | 1405 | |
| 1406 | # Keep track of the fact that we set JAVA_HOME ourselves, so that |
| 1407 | # we can change it on the next envsetup.sh, if required. |
| 1408 | export ANDROID_SET_JAVA_HOME=true |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1409 | fi |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1410 | } |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1411 | |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1412 | # Print colored exit condition |
| 1413 | function pez { |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1414 | "$@" |
| 1415 | local retval=$? |
| 1416 | if [ $retval -ne 0 ] |
| 1417 | then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1418 | echo $'\E'"[0;31mFAILURE\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1419 | else |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1420 | echo $'\E'"[0;32mSUCCESS\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1421 | fi |
| 1422 | return $retval |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1423 | } |
| 1424 | |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1425 | function get_make_command() |
| 1426 | { |
| 1427 | echo command make |
| 1428 | } |
| 1429 | |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1430 | function make() |
| 1431 | { |
| 1432 | local start_time=$(date +"%s") |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1433 | $(get_make_command) "$@" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1434 | local ret=$? |
| 1435 | local end_time=$(date +"%s") |
| 1436 | local tdiff=$(($end_time-$start_time)) |
| 1437 | local hours=$(($tdiff / 3600 )) |
| 1438 | local mins=$((($tdiff % 3600) / 60)) |
| 1439 | local secs=$(($tdiff % 60)) |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1440 | local ncolors=$(tput colors 2>/dev/null) |
| 1441 | if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1442 | color_failed=$'\E'"[0;31m" |
| 1443 | color_success=$'\E'"[0;32m" |
| 1444 | color_reset=$'\E'"[00m" |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1445 | else |
| 1446 | color_failed="" |
| 1447 | color_success="" |
| 1448 | color_reset="" |
| 1449 | fi |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1450 | echo |
| 1451 | if [ $ret -eq 0 ] ; then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1452 | echo -n "${color_success}#### make completed successfully " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1453 | else |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1454 | echo -n "${color_failed}#### make failed to build some targets " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1455 | fi |
| 1456 | if [ $hours -gt 0 ] ; then |
| 1457 | printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs |
| 1458 | elif [ $mins -gt 0 ] ; then |
| 1459 | printf "(%02g:%02g (mm:ss))" $mins $secs |
| 1460 | elif [ $secs -gt 0 ] ; then |
| 1461 | printf "(%s seconds)" $secs |
| 1462 | fi |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1463 | echo " ####${color_reset}" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1464 | echo |
| 1465 | return $ret |
| 1466 | } |
| 1467 | |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1468 | if [ "x$SHELL" != "x/bin/bash" ]; then |
| 1469 | case `ps -o command -p $$` in |
| 1470 | *bash*) |
| 1471 | ;; |
| 1472 | *) |
| 1473 | echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results" |
| 1474 | ;; |
| 1475 | esac |
| 1476 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1477 | |
| 1478 | # Execute the contents of any vendorsetup.sh files we can find. |
Oleksiy Avramchenko | 15760a8 | 2014-10-06 18:51:58 +0200 | [diff] [blame] | 1479 | for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \ |
| 1480 | `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1481 | do |
| 1482 | echo "including $f" |
| 1483 | . $f |
| 1484 | done |
| 1485 | unset f |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1486 | |
| 1487 | addcompletions |