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