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