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> |
| 5 | - tapas: tapas [<App1> <App2> ...] [arm|x86|mips] [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. |
| 8 | - mm: Builds all of the modules in the current directory. |
| 9 | - mmm: Builds all of the modules in the supplied directories. |
| 10 | - cgrep: Greps on all local C/C++ files. |
| 11 | - jgrep: Greps on all local Java files. |
| 12 | - resgrep: Greps on all local res/*.xml files. |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 13 | - godir: Go to the directory containing a file. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 14 | |
| 15 | Look at the source to view more functions. The complete list is: |
| 16 | EOF |
| 17 | T=$(gettop) |
| 18 | local A |
| 19 | A="" |
| 20 | for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do |
| 21 | A="$A $i" |
| 22 | done |
| 23 | echo $A |
| 24 | } |
| 25 | |
| 26 | # Get the value of a build variable as an absolute path. |
| 27 | function get_abs_build_var() |
| 28 | { |
| 29 | T=$(gettop) |
| 30 | if [ ! "$T" ]; then |
| 31 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 32 | return |
| 33 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 34 | (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
Brian Carlstrom | 177285a | 2010-04-06 13:22:02 -0700 | [diff] [blame] | 35 | make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | # Get the exact value of a build variable. |
| 39 | function get_build_var() |
| 40 | { |
| 41 | T=$(gettop) |
| 42 | if [ ! "$T" ]; then |
| 43 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 44 | return |
| 45 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 46 | CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
| 47 | make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1 |
| 48 | } |
| 49 | |
| 50 | # check to see if the supplied product is one we can build |
| 51 | function check_product() |
| 52 | { |
| 53 | T=$(gettop) |
| 54 | if [ ! "$T" ]; then |
| 55 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 56 | return |
| 57 | fi |
| 58 | CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 59 | TARGET_PRODUCT=$1 \ |
| 60 | TARGET_BUILD_VARIANT= \ |
| 61 | TARGET_BUILD_TYPE= \ |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 62 | TARGET_BUILD_APPS= \ |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 63 | get_build_var TARGET_DEVICE > /dev/null |
| 64 | # hide successful answers, but allow the errors to show |
| 65 | } |
| 66 | |
| 67 | VARIANT_CHOICES=(user userdebug eng) |
| 68 | |
| 69 | # check to see if the supplied variant is valid |
| 70 | function check_variant() |
| 71 | { |
| 72 | for v in ${VARIANT_CHOICES[@]} |
| 73 | do |
| 74 | if [ "$v" = "$1" ] |
| 75 | then |
| 76 | return 0 |
| 77 | fi |
| 78 | done |
| 79 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | function setpaths() |
| 83 | { |
| 84 | T=$(gettop) |
| 85 | if [ ! "$T" ]; then |
| 86 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 87 | return |
| 88 | fi |
| 89 | |
| 90 | ################################################################## |
| 91 | # # |
| 92 | # Read me before you modify this code # |
| 93 | # # |
| 94 | # This function sets ANDROID_BUILD_PATHS to what it is adding # |
| 95 | # to PATH, and the next time it is run, it removes that from # |
| 96 | # PATH. This is required so lunch can be run more than once # |
| 97 | # and still have working paths. # |
| 98 | # # |
| 99 | ################################################################## |
| 100 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 101 | # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces |
| 102 | # due to "C:\Program Files" being in the path. |
| 103 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 104 | # out with the old |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 105 | if [ -n "$ANDROID_BUILD_PATHS" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 106 | export PATH=${PATH/$ANDROID_BUILD_PATHS/} |
| 107 | fi |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 108 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 109 | export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} |
Ying Wang | c69b773 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 110 | # strip leading ':', if any |
| 111 | export PATH=${PATH/:%/} |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 112 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 113 | |
| 114 | # and in with the new |
| 115 | CODE_REVIEWS= |
| 116 | prebuiltdir=$(getprebuilt) |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 117 | gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS) |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 118 | |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 119 | # defined in core/config.mk |
| 120 | targetgccversion=$(get_build_var TARGET_GCC_VERSION) |
Ben Cheng | 1526670 | 2012-12-10 16:04:39 -0800 | [diff] [blame] | 121 | export TARGET_GCC_VERSION=$targetgccversion |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 122 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 123 | # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it. |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 124 | export ANDROID_EABI_TOOLCHAIN= |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 125 | local ARCH=$(get_build_var TARGET_ARCH) |
| 126 | case $ARCH in |
Ben Cheng | 054ffd2 | 2012-12-11 14:01:10 -0800 | [diff] [blame] | 127 | x86) toolchaindir=x86/i686-linux-android-$targetgccversion/bin |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 128 | ;; |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 129 | arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 130 | ;; |
Ben Cheng | 054ffd2 | 2012-12-11 14:01:10 -0800 | [diff] [blame] | 131 | mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 132 | ;; |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 133 | *) |
| 134 | echo "Can't find toolchain for unknown architecture: $ARCH" |
| 135 | toolchaindir=xxxxxxxxx |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 136 | ;; |
| 137 | esac |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 138 | if [ -d "$gccprebuiltdir/$toolchaindir" ]; then |
| 139 | export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 140 | fi |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 141 | |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 142 | unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 143 | case $ARCH in |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 144 | arm) |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 145 | toolchaindir=arm/arm-eabi-$targetgccversion/bin |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 146 | if [ -d "$gccprebuiltdir/$toolchaindir" ]; then |
| 147 | export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir" |
| 148 | ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir" |
| 149 | fi |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 150 | ;; |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 151 | mips) toolchaindir=mips/mips-eabi-4.4.3/bin |
| 152 | ;; |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 153 | *) |
Bruce Beare | 42ced6d | 2012-07-17 21:40:01 -0700 | [diff] [blame] | 154 | # No need to set ARM_EABI_TOOLCHAIN for other ARCHs |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 155 | ;; |
| 156 | esac |
Ying Wang | 08f5e9a | 2012-04-17 18:10:11 -0700 | [diff] [blame] | 157 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 158 | export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN |
| 159 | export ANDROID_QTOOLS=$T/development/emulator/qtools |
Ying Wang | 564f912 | 2013-03-29 17:40:14 -0700 | [diff] [blame] | 160 | export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools |
Ying Wang | c69b773 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 161 | export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS: |
| 162 | export PATH=$ANDROID_BUILD_PATHS$PATH |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 163 | |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 164 | unset ANDROID_JAVA_TOOLCHAIN |
Ji-Hwan Lee | 752ad06 | 2011-07-04 14:09:47 +0900 | [diff] [blame] | 165 | unset ANDROID_PRE_BUILD_PATHS |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 166 | if [ -n "$JAVA_HOME" ]; then |
| 167 | export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin |
Ji-Hwan Lee | 752ad06 | 2011-07-04 14:09:47 +0900 | [diff] [blame] | 168 | export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN: |
| 169 | export PATH=$ANDROID_PRE_BUILD_PATHS$PATH |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 170 | fi |
| 171 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 172 | unset ANDROID_PRODUCT_OUT |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 173 | export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) |
| 174 | export OUT=$ANDROID_PRODUCT_OUT |
| 175 | |
Jeff Brown | 8fd5cce | 2011-03-24 17:03:06 -0700 | [diff] [blame] | 176 | unset ANDROID_HOST_OUT |
| 177 | export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) |
| 178 | |
Ben Cheng | 057fde1 | 2011-11-28 13:55:14 -0800 | [diff] [blame] | 179 | # needed for processing samples collected by perf counters |
| 180 | unset OPROFILE_EVENTS_DIR |
| 181 | export OPROFILE_EVENTS_DIR=$T/external/oprofile/events |
| 182 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 183 | # needed for building linux on MacOS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 184 | # TODO: fix the path |
| 185 | #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include |
| 186 | } |
| 187 | |
| 188 | function printconfig() |
| 189 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 190 | T=$(gettop) |
| 191 | if [ ! "$T" ]; then |
| 192 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 193 | return |
| 194 | fi |
| 195 | get_build_var report_config |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | function set_stuff_for_environment() |
| 199 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 200 | settitle |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 201 | set_java_home |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 202 | setpaths |
| 203 | set_sequence_number |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 204 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 205 | export ANDROID_BUILD_TOP=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | function set_sequence_number() |
| 209 | { |
Joe Onorato | aee4daa | 2010-06-23 14:03:13 -0700 | [diff] [blame] | 210 | export BUILD_ENV_SEQUENCE_NUMBER=10 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | function settitle() |
| 214 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 215 | if [ "$STAY_OFF_MY_LAWN" = "" ]; then |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 216 | local arch=$(gettargetarch) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 217 | local product=$TARGET_PRODUCT |
| 218 | local variant=$TARGET_BUILD_VARIANT |
| 219 | local apps=$TARGET_BUILD_APPS |
| 220 | if [ -z "$apps" ]; then |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 221 | 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] | 222 | else |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 223 | 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] | 224 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 225 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 228 | function addcompletions() |
| 229 | { |
| 230 | local T dir f |
| 231 | |
| 232 | # Keep us from trying to run in something that isn't bash. |
| 233 | if [ -z "${BASH_VERSION}" ]; then |
| 234 | return |
| 235 | fi |
| 236 | |
| 237 | # Keep us from trying to run in bash that's too old. |
| 238 | if [ ${BASH_VERSINFO[0]} -lt 3 ]; then |
| 239 | return |
| 240 | fi |
| 241 | |
| 242 | dir="sdk/bash_completion" |
| 243 | if [ -d ${dir} ]; then |
Kenny Root | 7546d61 | 2011-07-18 13:11:34 -0700 | [diff] [blame] | 244 | 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] | 245 | echo "including $f" |
| 246 | . $f |
| 247 | done |
| 248 | fi |
| 249 | } |
| 250 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 251 | function choosetype() |
| 252 | { |
| 253 | echo "Build type choices are:" |
| 254 | echo " 1. release" |
| 255 | echo " 2. debug" |
| 256 | echo |
| 257 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 258 | local DEFAULT_NUM DEFAULT_VALUE |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 259 | DEFAULT_NUM=1 |
| 260 | DEFAULT_VALUE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 261 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 262 | export TARGET_BUILD_TYPE= |
| 263 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 264 | while [ -z $TARGET_BUILD_TYPE ] |
| 265 | do |
| 266 | echo -n "Which would you like? ["$DEFAULT_NUM"] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 267 | if [ -z "$1" ] ; then |
| 268 | read ANSWER |
| 269 | else |
| 270 | echo $1 |
| 271 | ANSWER=$1 |
| 272 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 273 | case $ANSWER in |
| 274 | "") |
| 275 | export TARGET_BUILD_TYPE=$DEFAULT_VALUE |
| 276 | ;; |
| 277 | 1) |
| 278 | export TARGET_BUILD_TYPE=release |
| 279 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 280 | release) |
| 281 | export TARGET_BUILD_TYPE=release |
| 282 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 283 | 2) |
| 284 | export TARGET_BUILD_TYPE=debug |
| 285 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 286 | debug) |
| 287 | export TARGET_BUILD_TYPE=debug |
| 288 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 289 | *) |
| 290 | echo |
| 291 | echo "I didn't understand your response. Please try again." |
| 292 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 293 | ;; |
| 294 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 295 | if [ -n "$1" ] ; then |
| 296 | break |
| 297 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 298 | done |
| 299 | |
| 300 | set_stuff_for_environment |
| 301 | } |
| 302 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 303 | # |
| 304 | # This function isn't really right: It chooses a TARGET_PRODUCT |
| 305 | # based on the list of boards. Usually, that gets you something |
| 306 | # that kinda works with a generic product, but really, you should |
| 307 | # pick a product by name. |
| 308 | # |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 309 | function chooseproduct() |
| 310 | { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 311 | if [ "x$TARGET_PRODUCT" != x ] ; then |
| 312 | default_value=$TARGET_PRODUCT |
| 313 | else |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 314 | default_value=full |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 315 | fi |
| 316 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 317 | export TARGET_PRODUCT= |
| 318 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 319 | while [ -z "$TARGET_PRODUCT" ] |
| 320 | do |
Joe Onorato | 8849aed | 2009-04-29 15:56:47 -0700 | [diff] [blame] | 321 | echo -n "Which product would you like? [$default_value] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 322 | if [ -z "$1" ] ; then |
| 323 | read ANSWER |
| 324 | else |
| 325 | echo $1 |
| 326 | ANSWER=$1 |
| 327 | fi |
| 328 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 329 | if [ -z "$ANSWER" ] ; then |
| 330 | export TARGET_PRODUCT=$default_value |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 331 | else |
| 332 | if check_product $ANSWER |
| 333 | then |
| 334 | export TARGET_PRODUCT=$ANSWER |
| 335 | else |
| 336 | echo "** Not a valid product: $ANSWER" |
| 337 | fi |
| 338 | fi |
| 339 | if [ -n "$1" ] ; then |
| 340 | break |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 341 | fi |
| 342 | done |
| 343 | |
| 344 | set_stuff_for_environment |
| 345 | } |
| 346 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 347 | function choosevariant() |
| 348 | { |
| 349 | echo "Variant choices are:" |
| 350 | local index=1 |
| 351 | local v |
| 352 | for v in ${VARIANT_CHOICES[@]} |
| 353 | do |
| 354 | # The product name is the name of the directory containing |
| 355 | # the makefile we found, above. |
| 356 | echo " $index. $v" |
| 357 | index=$(($index+1)) |
| 358 | done |
| 359 | |
| 360 | local default_value=eng |
| 361 | local ANSWER |
| 362 | |
| 363 | export TARGET_BUILD_VARIANT= |
| 364 | while [ -z "$TARGET_BUILD_VARIANT" ] |
| 365 | do |
| 366 | echo -n "Which would you like? [$default_value] " |
| 367 | if [ -z "$1" ] ; then |
| 368 | read ANSWER |
| 369 | else |
| 370 | echo $1 |
| 371 | ANSWER=$1 |
| 372 | fi |
| 373 | |
| 374 | if [ -z "$ANSWER" ] ; then |
| 375 | export TARGET_BUILD_VARIANT=$default_value |
| 376 | elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then |
| 377 | if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 378 | export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 379 | fi |
| 380 | else |
| 381 | if check_variant $ANSWER |
| 382 | then |
| 383 | export TARGET_BUILD_VARIANT=$ANSWER |
| 384 | else |
| 385 | echo "** Not a valid variant: $ANSWER" |
| 386 | fi |
| 387 | fi |
| 388 | if [ -n "$1" ] ; then |
| 389 | break |
| 390 | fi |
| 391 | done |
| 392 | } |
| 393 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 394 | function choosecombo() |
| 395 | { |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 396 | choosetype $1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 397 | |
| 398 | echo |
| 399 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 400 | chooseproduct $2 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 401 | |
| 402 | echo |
| 403 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 404 | choosevariant $3 |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 405 | |
| 406 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 407 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 408 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 409 | } |
| 410 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 411 | # Clear this variable. It will be built up again when the vendorsetup.sh |
| 412 | # files are included at the end of this file. |
| 413 | unset LUNCH_MENU_CHOICES |
| 414 | function add_lunch_combo() |
| 415 | { |
| 416 | local new_combo=$1 |
| 417 | local c |
| 418 | for c in ${LUNCH_MENU_CHOICES[@]} ; do |
| 419 | if [ "$new_combo" = "$c" ] ; then |
| 420 | return |
| 421 | fi |
| 422 | done |
| 423 | LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) |
| 424 | } |
| 425 | |
| 426 | # add the default one here |
Jean-Baptiste Queru | 45038e0 | 2010-07-01 09:22:53 -0700 | [diff] [blame] | 427 | add_lunch_combo full-eng |
Jean-Baptiste Queru | 6c2df3e | 2010-07-15 14:04:39 -0700 | [diff] [blame] | 428 | add_lunch_combo full_x86-eng |
Bruce Beare | ba366c4 | 2011-02-15 16:46:08 -0800 | [diff] [blame] | 429 | add_lunch_combo vbox_x86-eng |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 430 | add_lunch_combo full_mips-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 431 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 432 | function print_lunch_menu() |
| 433 | { |
| 434 | local uname=$(uname) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 435 | echo |
| 436 | echo "You're building on" $uname |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 437 | echo |
| 438 | echo "Lunch menu... pick a combo:" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 439 | |
| 440 | local i=1 |
| 441 | local choice |
| 442 | for choice in ${LUNCH_MENU_CHOICES[@]} |
| 443 | do |
| 444 | echo " $i. $choice" |
| 445 | i=$(($i+1)) |
| 446 | done |
| 447 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 448 | echo |
| 449 | } |
| 450 | |
| 451 | function lunch() |
| 452 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 453 | local answer |
| 454 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 455 | if [ "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 456 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 457 | else |
| 458 | print_lunch_menu |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 459 | echo -n "Which would you like? [full-eng] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 460 | read answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 461 | fi |
| 462 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 463 | local selection= |
| 464 | |
| 465 | if [ -z "$answer" ] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 466 | then |
Jean-Baptiste Queru | 0332f0a | 2010-10-22 09:52:09 -0700 | [diff] [blame] | 467 | selection=full-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 468 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 469 | then |
| 470 | if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ] |
| 471 | then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 472 | selection=${LUNCH_MENU_CHOICES[$(($answer-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 473 | fi |
| 474 | elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$") |
| 475 | then |
| 476 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 477 | fi |
| 478 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 479 | if [ -z "$selection" ] |
| 480 | then |
| 481 | echo |
| 482 | echo "Invalid lunch combo: $answer" |
| 483 | return 1 |
| 484 | fi |
| 485 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 486 | export TARGET_BUILD_APPS= |
| 487 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 488 | local product=$(echo -n $selection | sed -e "s/-.*$//") |
| 489 | check_product $product |
| 490 | if [ $? -ne 0 ] |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 491 | then |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 492 | echo |
| 493 | echo "** Don't have a product spec for: '$product'" |
| 494 | echo "** Do you have the right repo manifest?" |
| 495 | product= |
| 496 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 497 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 498 | local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//") |
| 499 | check_variant $variant |
| 500 | if [ $? -ne 0 ] |
| 501 | then |
| 502 | echo |
| 503 | echo "** Invalid variant: '$variant'" |
| 504 | echo "** Must be one of ${VARIANT_CHOICES[@]}" |
| 505 | variant= |
| 506 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 507 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 508 | if [ -z "$product" -o -z "$variant" ] |
| 509 | then |
| 510 | echo |
| 511 | return 1 |
| 512 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 513 | |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 514 | export TARGET_PRODUCT=$product |
| 515 | export TARGET_BUILD_VARIANT=$variant |
| 516 | export TARGET_BUILD_TYPE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 517 | |
| 518 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 519 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 520 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 521 | printconfig |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 524 | # Tab completion for lunch. |
| 525 | function _lunch() |
| 526 | { |
| 527 | local cur prev opts |
| 528 | COMPREPLY=() |
| 529 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 530 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 531 | |
| 532 | COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) ) |
| 533 | return 0 |
| 534 | } |
| 535 | complete -F _lunch lunch |
| 536 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 537 | # Configures the build to build unbundled apps. |
| 538 | # Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME) |
| 539 | function tapas() |
| 540 | { |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 541 | local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips)$')) |
Jeff Hamilton | 293f939 | 2011-11-18 17:15:25 -0600 | [diff] [blame] | 542 | local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$')) |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 543 | local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips)$')) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 544 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 545 | if [ $(echo $arch | wc -w) -gt 1 ]; then |
| 546 | echo "tapas: Error: Multiple build archs supplied: $arch" |
| 547 | return |
| 548 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 549 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 550 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 551 | return |
| 552 | fi |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 553 | |
| 554 | local product=full |
| 555 | case $arch in |
| 556 | x86) product=full_x86;; |
| 557 | mips) product=full_mips;; |
| 558 | esac |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 559 | if [ -z "$variant" ]; then |
| 560 | variant=eng |
| 561 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 562 | if [ -z "$apps" ]; then |
| 563 | apps=all |
| 564 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 565 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 566 | export TARGET_PRODUCT=$product |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 567 | export TARGET_BUILD_VARIANT=$variant |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 568 | export TARGET_BUILD_TYPE=release |
| 569 | export TARGET_BUILD_APPS=$apps |
| 570 | |
| 571 | set_stuff_for_environment |
| 572 | printconfig |
| 573 | } |
| 574 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 575 | function gettop |
| 576 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 577 | local TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 578 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
| 579 | echo $TOP |
| 580 | else |
| 581 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 582 | # The following circumlocution (repeated below as well) ensures |
| 583 | # that we record the true directory name and not one that is |
| 584 | # faked up with symlink names. |
| 585 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 586 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 587 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 588 | T= |
| 589 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 590 | \cd .. |
synergy | b112a40 | 2013-07-05 19:47:47 -0700 | [diff] [blame^] | 591 | T=`PWD= /bin/pwd -P` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 592 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 593 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 594 | if [ -f "$T/$TOPFILE" ]; then |
| 595 | echo $T |
| 596 | fi |
| 597 | fi |
| 598 | fi |
| 599 | } |
| 600 | |
| 601 | function m() |
| 602 | { |
| 603 | T=$(gettop) |
| 604 | if [ "$T" ]; then |
| 605 | make -C $T $@ |
| 606 | else |
| 607 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 608 | fi |
| 609 | } |
| 610 | |
| 611 | function findmakefile() |
| 612 | { |
| 613 | TOPFILE=build/core/envsetup.mk |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 614 | local HERE=$PWD |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 615 | T= |
| 616 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 11b15b1 | 2012-10-11 15:05:07 -0700 | [diff] [blame] | 617 | T=`PWD= /bin/pwd` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 618 | if [ -f "$T/Android.mk" ]; then |
| 619 | echo $T/Android.mk |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 620 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 621 | return |
| 622 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 623 | \cd .. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 624 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 625 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | function mm() |
| 629 | { |
| 630 | # If we're sitting in the root of the build tree, just do a |
| 631 | # normal make. |
| 632 | if [ -f build/core/envsetup.mk -a -f Makefile ]; then |
| 633 | make $@ |
| 634 | else |
| 635 | # Find the closest Android.mk file. |
| 636 | T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 637 | local M=$(findmakefile) |
Robert Greenwalt | 3c794d7 | 2009-07-15 15:07:44 -0700 | [diff] [blame] | 638 | # Remove the path to top as the makefilepath needs to be relative |
| 639 | local M=`echo $M|sed 's:'$T'/::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 640 | if [ ! "$T" ]; then |
| 641 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 642 | elif [ ! "$M" ]; then |
| 643 | echo "Couldn't locate a makefile from the current directory." |
| 644 | else |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 645 | ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 646 | fi |
| 647 | fi |
| 648 | } |
| 649 | |
| 650 | function mmm() |
| 651 | { |
| 652 | T=$(gettop) |
| 653 | if [ "$T" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 654 | local MAKEFILE= |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 655 | local MODULES= |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 656 | local ARGS= |
| 657 | local DIR TO_CHOP |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 658 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 659 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 660 | for DIR in $DIRS ; do |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 661 | MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'` |
| 662 | if [ "$MODULES" = "" ]; then |
| 663 | MODULES=all_modules |
| 664 | fi |
| 665 | DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 666 | if [ -f $DIR/Android.mk ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 667 | TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 668 | TO_CHOP=`expr $TO_CHOP + 1` |
Gilles Debunne | 8a20f58 | 2010-02-17 15:56:45 -0800 | [diff] [blame] | 669 | START=`PWD= /bin/pwd` |
| 670 | MFILE=`echo $START | cut -c${TO_CHOP}-` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 671 | if [ "$MFILE" = "" ] ; then |
| 672 | MFILE=$DIR/Android.mk |
| 673 | else |
| 674 | MFILE=$MFILE/$DIR/Android.mk |
| 675 | fi |
| 676 | MAKEFILE="$MAKEFILE $MFILE" |
| 677 | else |
| 678 | if [ "$DIR" = snod ]; then |
| 679 | ARGS="$ARGS snod" |
| 680 | elif [ "$DIR" = showcommands ]; then |
| 681 | ARGS="$ARGS showcommands" |
Ying Wang | 0188414 | 2010-07-20 16:18:16 -0700 | [diff] [blame] | 682 | elif [ "$DIR" = dist ]; then |
| 683 | ARGS="$ARGS dist" |
Ying Wang | 015edd2 | 2011-01-20 15:01:56 -0800 | [diff] [blame] | 684 | elif [ "$DIR" = incrementaljavac ]; then |
| 685 | ARGS="$ARGS incrementaljavac" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 686 | else |
| 687 | echo "No Android.mk in $DIR." |
Joe Onorato | 51e6182 | 2009-04-13 15:36:15 -0400 | [diff] [blame] | 688 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 689 | fi |
| 690 | fi |
| 691 | done |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 692 | ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 693 | else |
| 694 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 695 | fi |
| 696 | } |
| 697 | |
| 698 | function croot() |
| 699 | { |
| 700 | T=$(gettop) |
| 701 | if [ "$T" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 702 | \cd $(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 703 | else |
| 704 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 705 | fi |
| 706 | } |
| 707 | |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 708 | function cproj() |
| 709 | { |
| 710 | TOPFILE=build/core/envsetup.mk |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 711 | local HERE=$PWD |
| 712 | T= |
| 713 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 714 | T=$PWD |
| 715 | if [ -f "$T/Android.mk" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 716 | \cd $T |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 717 | return |
| 718 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 719 | \cd .. |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 720 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 721 | \cd $HERE |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 722 | echo "can't find Android.mk" |
| 723 | } |
| 724 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 725 | function pid() |
| 726 | { |
| 727 | local EXE="$1" |
| 728 | if [ "$EXE" ] ; then |
| 729 | local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'` |
| 730 | echo "$PID" |
| 731 | else |
| 732 | echo "usage: pid name" |
| 733 | fi |
| 734 | } |
| 735 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 736 | # systemstack - dump the current stack trace of all threads in the system process |
| 737 | # to the usual ANR traces file |
| 738 | function systemstack() |
| 739 | { |
Jeff Sharkey | cfe0969 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 740 | stacks system_server |
| 741 | } |
| 742 | |
| 743 | function stacks() |
| 744 | { |
| 745 | if [[ $1 =~ ^[0-9]+$ ]] ; then |
| 746 | local PID="$1" |
| 747 | elif [ "$1" ] ; then |
| 748 | local PID=$(pid $1) |
| 749 | else |
| 750 | echo "usage: stacks [pid|process name]" |
| 751 | fi |
| 752 | |
| 753 | if [ "$PID" ] ; then |
| 754 | local TRACES=/data/anr/traces.txt |
| 755 | local ORIG=/data/anr/traces.orig |
| 756 | local TMP=/data/anr/traces.tmp |
| 757 | |
| 758 | # Keep original traces to avoid clobbering |
| 759 | adb shell mv $TRACES $ORIG |
| 760 | |
| 761 | # Make sure we have a usable file |
| 762 | adb shell touch $TRACES |
| 763 | adb shell chmod 666 $TRACES |
| 764 | |
| 765 | # Dump stacks and wait for dump to finish |
| 766 | adb shell kill -3 $PID |
| 767 | adb shell notify $TRACES |
| 768 | |
| 769 | # Restore original stacks, and show current output |
| 770 | adb shell mv $TRACES $TMP |
| 771 | adb shell mv $ORIG $TRACES |
| 772 | adb shell cat $TMP | less -S |
| 773 | fi |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 774 | } |
| 775 | |
John Michelau | 5020025 | 2012-11-09 11:48:04 -0600 | [diff] [blame] | 776 | function gdbwrapper() |
| 777 | { |
| 778 | $ANDROID_TOOLCHAIN/$GDB -x "$@" |
| 779 | } |
| 780 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 781 | function gdbclient() |
| 782 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 783 | local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT) |
| 784 | local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED) |
| 785 | local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED) |
| 786 | local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED) |
| 787 | local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS) |
Nick Kralevich | 0ab21d3 | 2011-11-11 09:02:01 -0800 | [diff] [blame] | 788 | local ARCH=$(get_build_var TARGET_ARCH) |
| 789 | local GDB |
| 790 | case "$ARCH" in |
Jean-Baptiste Queru | feec98b | 2012-05-16 13:18:39 -0700 | [diff] [blame] | 791 | x86) GDB=i686-linux-android-gdb;; |
Nick Kralevich | 0ab21d3 | 2011-11-11 09:02:01 -0800 | [diff] [blame] | 792 | arm) GDB=arm-linux-androideabi-gdb;; |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 793 | mips) GDB=mipsel-linux-android-gdb;; |
Nick Kralevich | 0ab21d3 | 2011-11-11 09:02:01 -0800 | [diff] [blame] | 794 | *) echo "Unknown arch $ARCH"; return 1;; |
| 795 | esac |
| 796 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 797 | if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then |
| 798 | local EXE="$1" |
| 799 | if [ "$EXE" ] ; then |
| 800 | EXE=$1 |
| 801 | else |
| 802 | EXE="app_process" |
| 803 | fi |
| 804 | |
| 805 | local PORT="$2" |
| 806 | if [ "$PORT" ] ; then |
| 807 | PORT=$2 |
| 808 | else |
| 809 | PORT=":5039" |
| 810 | fi |
| 811 | |
| 812 | local PID |
| 813 | local PROG="$3" |
| 814 | if [ "$PROG" ] ; then |
Grace Kloba | e9d04bf | 2011-04-30 11:04:05 -0700 | [diff] [blame] | 815 | if [[ "$PROG" =~ ^[0-9]+$ ]] ; then |
| 816 | PID="$3" |
| 817 | else |
| 818 | PID=`pid $3` |
| 819 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 820 | adb forward "tcp$PORT" "tcp$PORT" |
| 821 | adb shell gdbserver $PORT --attach $PID & |
| 822 | sleep 2 |
| 823 | else |
| 824 | echo "" |
| 825 | echo "If you haven't done so already, do this first on the device:" |
| 826 | echo " gdbserver $PORT /system/bin/$EXE" |
| 827 | echo " or" |
| 828 | echo " gdbserver $PORT --attach $PID" |
| 829 | echo "" |
| 830 | fi |
| 831 | |
| 832 | echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS" |
Chris Dearman | 6858d51 | 2012-02-02 14:16:52 -0800 | [diff] [blame] | 833 | 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" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 834 | echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT" |
| 835 | echo >>"$OUT_ROOT/gdbclient.cmds" "" |
| 836 | |
John Michelau | 5020025 | 2012-11-09 11:48:04 -0600 | [diff] [blame] | 837 | gdbwrapper "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 838 | else |
| 839 | echo "Unable to determine build system output dir." |
| 840 | fi |
| 841 | |
| 842 | } |
| 843 | |
| 844 | case `uname -s` in |
| 845 | Darwin) |
| 846 | function sgrep() |
| 847 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 848 | 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] | 849 | } |
| 850 | |
| 851 | ;; |
| 852 | *) |
| 853 | function sgrep() |
| 854 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 855 | 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] | 856 | } |
| 857 | ;; |
| 858 | esac |
| 859 | |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 860 | function gettargetarch |
| 861 | { |
| 862 | get_build_var TARGET_ARCH |
| 863 | } |
| 864 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 865 | function jgrep() |
| 866 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 867 | find . -name .repo -prune -o -name .git -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] | 868 | } |
| 869 | |
| 870 | function cgrep() |
| 871 | { |
Mike Dodd | 0c26d34 | 2011-04-07 13:29:06 -0700 | [diff] [blame] | 872 | find . -name .repo -prune -o -name .git -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] | 873 | } |
| 874 | |
| 875 | function resgrep() |
| 876 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 877 | for dir in `find . -name .repo -prune -o -name .git -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] | 878 | } |
| 879 | |
Jeff Sharkey | 301bbad | 2013-03-08 10:20:47 -0800 | [diff] [blame] | 880 | function mangrep() |
| 881 | { |
| 882 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@" |
| 883 | } |
| 884 | |
Alex Klyubin | ba5fc8e | 2013-05-06 14:11:48 -0700 | [diff] [blame] | 885 | function sepgrep() |
| 886 | { |
| 887 | 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 "$@" |
| 888 | } |
| 889 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 890 | case `uname -s` in |
| 891 | Darwin) |
| 892 | function mgrep() |
| 893 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 894 | 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] | 895 | } |
| 896 | |
| 897 | function treegrep() |
| 898 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 899 | 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] | 900 | } |
| 901 | |
| 902 | ;; |
| 903 | *) |
| 904 | function mgrep() |
| 905 | { |
Ying Wang | 324c2b2 | 2012-08-17 15:03:20 -0700 | [diff] [blame] | 906 | 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] | 907 | } |
| 908 | |
| 909 | function treegrep() |
| 910 | { |
Joe Onorato | f50e84b | 2011-03-15 14:15:46 -0700 | [diff] [blame] | 911 | 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] | 912 | } |
| 913 | |
| 914 | ;; |
| 915 | esac |
| 916 | |
| 917 | function getprebuilt |
| 918 | { |
| 919 | get_abs_build_var ANDROID_PREBUILTS |
| 920 | } |
| 921 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 922 | function tracedmdump() |
| 923 | { |
| 924 | T=$(gettop) |
| 925 | if [ ! "$T" ]; then |
| 926 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 927 | return |
| 928 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 929 | local prebuiltdir=$(getprebuilt) |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 930 | local arch=$(gettargetarch) |
| 931 | local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 932 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 933 | local TRACE=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 934 | if [ ! "$TRACE" ] ; then |
| 935 | echo "usage: tracedmdump tracename" |
| 936 | return |
| 937 | fi |
| 938 | |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 939 | if [ ! -r "$KERNEL" ] ; then |
| 940 | echo "Error: cannot find kernel: '$KERNEL'" |
| 941 | return |
| 942 | fi |
| 943 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 944 | local BASETRACE=$(basename $TRACE) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 945 | if [ "$BASETRACE" = "$TRACE" ] ; then |
| 946 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 947 | fi |
| 948 | |
| 949 | echo "post-processing traces..." |
| 950 | rm -f $TRACE/qtrace.dexlist |
| 951 | post_trace $TRACE |
| 952 | if [ $? -ne 0 ]; then |
| 953 | echo "***" |
| 954 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 955 | echo "***" |
| 956 | return |
| 957 | fi |
| 958 | echo "generating dexlist output..." |
| 959 | /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 |
| 960 | echo "generating dmtrace data..." |
| 961 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 962 | echo "generating html file..." |
| 963 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 964 | echo "done, see $TRACE/dmtrace.html for details" |
| 965 | echo "or run:" |
| 966 | echo " traceview $TRACE/dmtrace" |
| 967 | } |
| 968 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 969 | # communicate with a running device or emulator, set up necessary state, |
| 970 | # and run the hat command. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 971 | function runhat() |
| 972 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 973 | # process standard adb options |
| 974 | local adbTarget="" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 975 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 976 | adbTarget=$1 |
| 977 | shift 1 |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 978 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 979 | adbTarget="$1 $2" |
| 980 | shift 2 |
| 981 | fi |
| 982 | local adbOptions=${adbTarget} |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 983 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 984 | |
| 985 | # runhat options |
| 986 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 987 | |
| 988 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 989 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 990 | return |
| 991 | fi |
| 992 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 993 | # confirm hat is available |
| 994 | if [ -z $(which hat) ]; then |
| 995 | echo "hat is not available in this configuration." |
| 996 | return |
| 997 | fi |
| 998 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 999 | # issue "am" command to cause the hprof dump |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1000 | local sdcard=$(adb shell echo -n '$EXTERNAL_STORAGE') |
| 1001 | local devFile=$sdcard/hprof-$targetPid |
| 1002 | #local devFile=/data/local/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1003 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1004 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1005 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1006 | 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] | 1007 | echo -n "> " |
| 1008 | read |
| 1009 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1010 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1011 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1012 | echo "Retrieving file $devFile..." |
| 1013 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1014 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1015 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1016 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1017 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1018 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1019 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1020 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | function getbugreports() |
| 1024 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1025 | 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] | 1026 | |
| 1027 | if [ ! "$reports" ]; then |
| 1028 | echo "Could not locate any bugreports." |
| 1029 | return |
| 1030 | fi |
| 1031 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1032 | local report |
| 1033 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1034 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1035 | echo "/sdcard/bugreports/${report}" |
| 1036 | adb pull /sdcard/bugreports/${report} ${report} |
| 1037 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1038 | done |
| 1039 | } |
| 1040 | |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1041 | function getsdcardpath() |
| 1042 | { |
| 1043 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1044 | } |
| 1045 | |
| 1046 | function getscreenshotpath() |
| 1047 | { |
| 1048 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1049 | } |
| 1050 | |
| 1051 | function getlastscreenshot() |
| 1052 | { |
| 1053 | local screenshot_path=$(getscreenshotpath) |
| 1054 | local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` |
| 1055 | if [ "$screenshot" = "" ]; then |
| 1056 | echo "No screenshots found." |
| 1057 | return |
| 1058 | fi |
| 1059 | echo "${screenshot}" |
| 1060 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1061 | } |
| 1062 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1063 | function startviewserver() |
| 1064 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1065 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1066 | if [ $# -gt 0 ]; then |
| 1067 | port=$1 |
| 1068 | fi |
| 1069 | adb shell service call window 1 i32 $port |
| 1070 | } |
| 1071 | |
| 1072 | function stopviewserver() |
| 1073 | { |
| 1074 | adb shell service call window 2 |
| 1075 | } |
| 1076 | |
| 1077 | function isviewserverstarted() |
| 1078 | { |
| 1079 | adb shell service call window 3 |
| 1080 | } |
| 1081 | |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1082 | function key_home() |
| 1083 | { |
| 1084 | adb shell input keyevent 3 |
| 1085 | } |
| 1086 | |
| 1087 | function key_back() |
| 1088 | { |
| 1089 | adb shell input keyevent 4 |
| 1090 | } |
| 1091 | |
| 1092 | function key_menu() |
| 1093 | { |
| 1094 | adb shell input keyevent 82 |
| 1095 | } |
| 1096 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1097 | function smoketest() |
| 1098 | { |
| 1099 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1100 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1101 | return |
| 1102 | fi |
| 1103 | T=$(gettop) |
| 1104 | if [ ! "$T" ]; then |
| 1105 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1106 | return |
| 1107 | fi |
| 1108 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1109 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1110 | adb uninstall com.android.smoketest > /dev/null && |
| 1111 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1112 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1113 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1114 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1115 | } |
| 1116 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1117 | # simple shortcut to the runtest command |
| 1118 | function runtest() |
| 1119 | { |
| 1120 | T=$(gettop) |
| 1121 | if [ ! "$T" ]; then |
| 1122 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1123 | return |
| 1124 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1125 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1128 | function godir () { |
| 1129 | if [[ -z "$1" ]]; then |
| 1130 | echo "Usage: godir <regex>" |
| 1131 | return |
| 1132 | fi |
Brian Carlstrom | b9915a6 | 2010-01-29 16:39:32 -0800 | [diff] [blame] | 1133 | T=$(gettop) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1134 | if [[ ! -f $T/filelist ]]; then |
| 1135 | echo -n "Creating index..." |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1136 | (\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] | 1137 | echo " Done" |
| 1138 | echo "" |
| 1139 | fi |
| 1140 | local lines |
Jeff Hamilton | 293f939 | 2011-11-18 17:15:25 -0600 | [diff] [blame] | 1141 | 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] | 1142 | if [[ ${#lines[@]} = 0 ]]; then |
| 1143 | echo "Not found" |
| 1144 | return |
| 1145 | fi |
| 1146 | local pathname |
| 1147 | local choice |
| 1148 | if [[ ${#lines[@]} > 1 ]]; then |
| 1149 | while [[ -z "$pathname" ]]; do |
| 1150 | local index=1 |
| 1151 | local line |
| 1152 | for line in ${lines[@]}; do |
| 1153 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1154 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1155 | done |
| 1156 | echo |
| 1157 | echo -n "Select one: " |
| 1158 | unset choice |
| 1159 | read choice |
| 1160 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1161 | echo "Invalid choice" |
| 1162 | continue |
| 1163 | fi |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1164 | pathname=${lines[$(($choice-1))]} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1165 | done |
| 1166 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1167 | pathname=${lines[0]} |
| 1168 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1169 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1170 | } |
| 1171 | |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1172 | # Force JAVA_HOME to point to java 1.6 if it isn't already set |
| 1173 | function set_java_home() { |
Andy McFadden | bd96094 | 2010-06-24 12:52:51 -0700 | [diff] [blame] | 1174 | if [ ! "$JAVA_HOME" ]; then |
| 1175 | case `uname -s` in |
| 1176 | Darwin) |
| 1177 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home |
| 1178 | ;; |
| 1179 | *) |
| 1180 | export JAVA_HOME=/usr/lib/jvm/java-6-sun |
| 1181 | ;; |
| 1182 | esac |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1183 | fi |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 1184 | } |
Jeff Hamilton | 04be0d8 | 2010-06-07 15:03:54 -0500 | [diff] [blame] | 1185 | |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1186 | if [ "x$SHELL" != "x/bin/bash" ]; then |
| 1187 | case `ps -o command -p $$` in |
| 1188 | *bash*) |
| 1189 | ;; |
| 1190 | *) |
| 1191 | echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results" |
| 1192 | ;; |
| 1193 | esac |
| 1194 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1195 | |
| 1196 | # Execute the contents of any vendorsetup.sh files we can find. |
Bruce Beare | 6f8410b | 2010-06-24 13:51:35 -0700 | [diff] [blame] | 1197 | for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/*/vendorsetup.sh device/*/*/vendorsetup.sh 2> /dev/null` |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1198 | do |
| 1199 | echo "including $f" |
| 1200 | . $f |
| 1201 | done |
| 1202 | unset f |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1203 | |
| 1204 | addcompletions |