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