blob: e7fbcb4899ae6ef157aec74be78d2a920a5c1f70 [file] [log] [blame]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001function help() {
2cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07004- 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 Project88b60792009-03-03 19:28:42 -080011- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070012
13Look at the source to view more functions. The complete list is:
14EOF
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.
25function 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 Carlstrom177285a2010-04-06 13:22:02 -070032 (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 Projectb6c1cf62008-10-21 07:00:00 -070034}
35
36# Get the exact value of a build variable.
37function 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 Projectdcc08f02008-12-17 18:03:49 -080044 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
49function 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 Browne33ba4c2011-07-11 22:11:46 -070057 TARGET_PRODUCT=$1 \
58 TARGET_BUILD_VARIANT= \
59 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070060 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080061 get_build_var TARGET_DEVICE > /dev/null
62 # hide successful answers, but allow the errors to show
63}
64
65VARIANT_CHOICES=(user userdebug eng)
66
67# check to see if the supplied variant is valid
68function 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 Projectb6c1cf62008-10-21 07:00:00 -070078}
79
80function 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 Mollc639c782011-06-20 17:25:01 -070099 # 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 Projectb6c1cf62008-10-21 07:00:00 -0700102 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700103 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700104 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
105 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700106 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700107 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
108 # strip trailing ':', if any
109 export PATH=${PATH/%:/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500110 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700111
112 # and in with the new
113 CODE_REVIEWS=
114 prebuiltdir=$(getprebuilt)
Raphael732936d2011-06-22 14:35:32 -0700115
Raphael Mollc639c782011-06-20 17:25:01 -0700116 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700117 export ANDROID_EABI_TOOLCHAIN=
Mark D Horn7d0ede72012-03-14 14:20:30 -0700118 case $(get_build_var TARGET_ARCH) in
119 x86) toolchaindir=toolchain/i686-android-linux-4.4.3/bin
120 ;;
121 arm|*) toolchaindir=toolchain/arm-linux-androideabi-4.4.x/bin
122 ;;
123 esac
Raphael Mollc639c782011-06-20 17:25:01 -0700124 if [ -d "$prebuiltdir/$toolchaindir" ]; then
125 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700126 fi
Raphael732936d2011-06-22 14:35:32 -0700127
128 export ARM_EABI_TOOLCHAIN=
129 toolchaindir=toolchain/arm-eabi-4.4.3/bin
130 if [ -d "$prebuiltdir/$toolchaindir" ]; then
131 export ARM_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
132 fi
133
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700134 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
135 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700136 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ARM_EABI_TOOLCHAIN$CODE_REVIEWS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800138
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500139 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900140 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500141 if [ -n "$JAVA_HOME" ]; then
142 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900143 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
144 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500145 fi
146
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800147 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700148 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
149 export OUT=$ANDROID_PRODUCT_OUT
150
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700151 unset ANDROID_HOST_OUT
152 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
153
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800154 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700155 # TODO: fix the path
156 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
157}
158
159function printconfig()
160{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800161 T=$(gettop)
162 if [ ! "$T" ]; then
163 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
164 return
165 fi
166 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700167}
168
169function set_stuff_for_environment()
170{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800171 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500172 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800173 setpaths
174 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700175
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800176 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700177}
178
179function set_sequence_number()
180{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700181 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700182}
183
184function settitle()
185{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800186 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700187 local product=$TARGET_PRODUCT
188 local variant=$TARGET_BUILD_VARIANT
189 local apps=$TARGET_BUILD_APPS
190 if [ -z "$apps" ]; then
191 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
192 else
193 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
194 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800195 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700196}
197
Kenny Root52aa81c2011-07-15 11:07:06 -0700198function addcompletions()
199{
200 local T dir f
201
202 # Keep us from trying to run in something that isn't bash.
203 if [ -z "${BASH_VERSION}" ]; then
204 return
205 fi
206
207 # Keep us from trying to run in bash that's too old.
208 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
209 return
210 fi
211
212 dir="sdk/bash_completion"
213 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700214 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700215 echo "including $f"
216 . $f
217 done
218 fi
219}
220
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700221function choosetype()
222{
223 echo "Build type choices are:"
224 echo " 1. release"
225 echo " 2. debug"
226 echo
227
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800228 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700229 DEFAULT_NUM=1
230 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700231
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800232 export TARGET_BUILD_TYPE=
233 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700234 while [ -z $TARGET_BUILD_TYPE ]
235 do
236 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800237 if [ -z "$1" ] ; then
238 read ANSWER
239 else
240 echo $1
241 ANSWER=$1
242 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700243 case $ANSWER in
244 "")
245 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
246 ;;
247 1)
248 export TARGET_BUILD_TYPE=release
249 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800250 release)
251 export TARGET_BUILD_TYPE=release
252 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253 2)
254 export TARGET_BUILD_TYPE=debug
255 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256 debug)
257 export TARGET_BUILD_TYPE=debug
258 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700259 *)
260 echo
261 echo "I didn't understand your response. Please try again."
262 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263 ;;
264 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800265 if [ -n "$1" ] ; then
266 break
267 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268 done
269
270 set_stuff_for_environment
271}
272
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800273#
274# This function isn't really right: It chooses a TARGET_PRODUCT
275# based on the list of boards. Usually, that gets you something
276# that kinda works with a generic product, but really, you should
277# pick a product by name.
278#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700279function chooseproduct()
280{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700281 if [ "x$TARGET_PRODUCT" != x ] ; then
282 default_value=$TARGET_PRODUCT
283 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700284 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700285 fi
286
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800287 export TARGET_PRODUCT=
288 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289 while [ -z "$TARGET_PRODUCT" ]
290 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700291 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800292 if [ -z "$1" ] ; then
293 read ANSWER
294 else
295 echo $1
296 ANSWER=$1
297 fi
298
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299 if [ -z "$ANSWER" ] ; then
300 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800301 else
302 if check_product $ANSWER
303 then
304 export TARGET_PRODUCT=$ANSWER
305 else
306 echo "** Not a valid product: $ANSWER"
307 fi
308 fi
309 if [ -n "$1" ] ; then
310 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311 fi
312 done
313
314 set_stuff_for_environment
315}
316
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800317function choosevariant()
318{
319 echo "Variant choices are:"
320 local index=1
321 local v
322 for v in ${VARIANT_CHOICES[@]}
323 do
324 # The product name is the name of the directory containing
325 # the makefile we found, above.
326 echo " $index. $v"
327 index=$(($index+1))
328 done
329
330 local default_value=eng
331 local ANSWER
332
333 export TARGET_BUILD_VARIANT=
334 while [ -z "$TARGET_BUILD_VARIANT" ]
335 do
336 echo -n "Which would you like? [$default_value] "
337 if [ -z "$1" ] ; then
338 read ANSWER
339 else
340 echo $1
341 ANSWER=$1
342 fi
343
344 if [ -z "$ANSWER" ] ; then
345 export TARGET_BUILD_VARIANT=$default_value
346 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
347 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800348 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349 fi
350 else
351 if check_variant $ANSWER
352 then
353 export TARGET_BUILD_VARIANT=$ANSWER
354 else
355 echo "** Not a valid variant: $ANSWER"
356 fi
357 fi
358 if [ -n "$1" ] ; then
359 break
360 fi
361 done
362}
363
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364function choosecombo()
365{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700366 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367
368 echo
369 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700370 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700371
372 echo
373 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700374 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800375
376 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800378 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700379}
380
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800381# Clear this variable. It will be built up again when the vendorsetup.sh
382# files are included at the end of this file.
383unset LUNCH_MENU_CHOICES
384function add_lunch_combo()
385{
386 local new_combo=$1
387 local c
388 for c in ${LUNCH_MENU_CHOICES[@]} ; do
389 if [ "$new_combo" = "$c" ] ; then
390 return
391 fi
392 done
393 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
394}
395
396# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700397add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700398add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800399add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800400
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700401function print_lunch_menu()
402{
403 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700404 echo
405 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700406 echo
407 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800408
409 local i=1
410 local choice
411 for choice in ${LUNCH_MENU_CHOICES[@]}
412 do
413 echo " $i. $choice"
414 i=$(($i+1))
415 done
416
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700417 echo
418}
419
420function lunch()
421{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800422 local answer
423
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800425 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700426 else
427 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700428 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800429 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700430 fi
431
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800432 local selection=
433
434 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700435 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700436 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800437 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
438 then
439 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
440 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800441 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800442 fi
443 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
444 then
445 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446 fi
447
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448 if [ -z "$selection" ]
449 then
450 echo
451 echo "Invalid lunch combo: $answer"
452 return 1
453 fi
454
Joe Onoratoda12daf2010-06-09 18:18:31 -0700455 export TARGET_BUILD_APPS=
456
Jeff Browne33ba4c2011-07-11 22:11:46 -0700457 local product=$(echo -n $selection | sed -e "s/-.*$//")
458 check_product $product
459 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700461 echo
462 echo "** Don't have a product spec for: '$product'"
463 echo "** Do you have the right repo manifest?"
464 product=
465 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800466
Jeff Browne33ba4c2011-07-11 22:11:46 -0700467 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
468 check_variant $variant
469 if [ $? -ne 0 ]
470 then
471 echo
472 echo "** Invalid variant: '$variant'"
473 echo "** Must be one of ${VARIANT_CHOICES[@]}"
474 variant=
475 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476
Jeff Browne33ba4c2011-07-11 22:11:46 -0700477 if [ -z "$product" -o -z "$variant" ]
478 then
479 echo
480 return 1
481 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482
Jeff Browne33ba4c2011-07-11 22:11:46 -0700483 export TARGET_PRODUCT=$product
484 export TARGET_BUILD_VARIANT=$variant
485 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486
487 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800488
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700489 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491}
492
Jeff Davidson513d7a42010-08-02 10:00:44 -0700493# Tab completion for lunch.
494function _lunch()
495{
496 local cur prev opts
497 COMPREPLY=()
498 cur="${COMP_WORDS[COMP_CWORD]}"
499 prev="${COMP_WORDS[COMP_CWORD-1]}"
500
501 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
502 return 0
503}
504complete -F _lunch lunch
505
Joe Onoratoda12daf2010-06-09 18:18:31 -0700506# Configures the build to build unbundled apps.
507# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
508function tapas()
509{
510 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
511 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
512
513 if [ $(echo $variant | wc -w) -gt 1 ]; then
514 echo "tapas: Error: Multiple build variants supplied: $variant"
515 return
516 fi
517 if [ -z "$variant" ]; then
518 variant=eng
519 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700520 if [ -z "$apps" ]; then
521 apps=all
522 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700523
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700524 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700525 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700526 export TARGET_BUILD_TYPE=release
527 export TARGET_BUILD_APPS=$apps
528
529 set_stuff_for_environment
530 printconfig
531}
532
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533function gettop
534{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800535 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700536 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
537 echo $TOP
538 else
539 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800540 # The following circumlocution (repeated below as well) ensures
541 # that we record the true directory name and not one that is
542 # faked up with symlink names.
543 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700544 else
545 # We redirect cd to /dev/null in case it's aliased to
546 # a command that prints something as a side-effect
547 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800548 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700549 T=
550 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
551 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800552 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700553 done
554 cd $HERE > /dev/null
555 if [ -f "$T/$TOPFILE" ]; then
556 echo $T
557 fi
558 fi
559 fi
560}
561
562function m()
563{
564 T=$(gettop)
565 if [ "$T" ]; then
566 make -C $T $@
567 else
568 echo "Couldn't locate the top of the tree. Try setting TOP."
569 fi
570}
571
572function findmakefile()
573{
574 TOPFILE=build/core/envsetup.mk
575 # We redirect cd to /dev/null in case it's aliased to
576 # a command that prints something as a side-effect
577 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579 T=
580 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
581 T=$PWD
582 if [ -f "$T/Android.mk" ]; then
583 echo $T/Android.mk
584 cd $HERE > /dev/null
585 return
586 fi
587 cd .. > /dev/null
588 done
589 cd $HERE > /dev/null
590}
591
592function mm()
593{
594 # If we're sitting in the root of the build tree, just do a
595 # normal make.
596 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
597 make $@
598 else
599 # Find the closest Android.mk file.
600 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800601 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700602 # Remove the path to top as the makefilepath needs to be relative
603 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 if [ ! "$T" ]; then
605 echo "Couldn't locate the top of the tree. Try setting TOP."
606 elif [ ! "$M" ]; then
607 echo "Couldn't locate a makefile from the current directory."
608 else
Ying Wang01884142010-07-20 16:18:16 -0700609 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700610 fi
611 fi
612}
613
614function mmm()
615{
616 T=$(gettop)
617 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618 local MAKEFILE=
619 local ARGS=
620 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800621 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
622 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
623 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700624 DIR=`echo $DIR | sed -e 's:/$::'`
625 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700626 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800628 START=`PWD= /bin/pwd`
629 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700630 if [ "$MFILE" = "" ] ; then
631 MFILE=$DIR/Android.mk
632 else
633 MFILE=$MFILE/$DIR/Android.mk
634 fi
635 MAKEFILE="$MAKEFILE $MFILE"
636 else
637 if [ "$DIR" = snod ]; then
638 ARGS="$ARGS snod"
639 elif [ "$DIR" = showcommands ]; then
640 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700641 elif [ "$DIR" = dist ]; then
642 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800643 elif [ "$DIR" = incrementaljavac ]; then
644 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 else
646 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400647 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700648 fi
649 fi
650 done
Ying Wang01884142010-07-20 16:18:16 -0700651 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652 else
653 echo "Couldn't locate the top of the tree. Try setting TOP."
654 fi
655}
656
657function croot()
658{
659 T=$(gettop)
660 if [ "$T" ]; then
661 cd $(gettop)
662 else
663 echo "Couldn't locate the top of the tree. Try setting TOP."
664 fi
665}
666
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700667function cproj()
668{
669 TOPFILE=build/core/envsetup.mk
670 # We redirect cd to /dev/null in case it's aliased to
671 # a command that prints something as a side-effect
672 # (like pushd)
673 local HERE=$PWD
674 T=
675 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
676 T=$PWD
677 if [ -f "$T/Android.mk" ]; then
678 cd $T
679 return
680 fi
681 cd .. > /dev/null
682 done
683 cd $HERE > /dev/null
684 echo "can't find Android.mk"
685}
686
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700687function pid()
688{
689 local EXE="$1"
690 if [ "$EXE" ] ; then
691 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
692 echo "$PID"
693 else
694 echo "usage: pid name"
695 fi
696}
697
Christopher Tate744ee802009-11-12 15:33:08 -0800698# systemstack - dump the current stack trace of all threads in the system process
699# to the usual ANR traces file
700function systemstack()
701{
702 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
703}
704
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705function gdbclient()
706{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800707 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
708 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
709 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
710 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
711 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700712 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
713 local EXE="$1"
714 if [ "$EXE" ] ; then
715 EXE=$1
716 else
717 EXE="app_process"
718 fi
719
720 local PORT="$2"
721 if [ "$PORT" ] ; then
722 PORT=$2
723 else
724 PORT=":5039"
725 fi
726
727 local PID
728 local PROG="$3"
729 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700730 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
731 PID="$3"
732 else
733 PID=`pid $3`
734 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700735 adb forward "tcp$PORT" "tcp$PORT"
736 adb shell gdbserver $PORT --attach $PID &
737 sleep 2
738 else
739 echo ""
740 echo "If you haven't done so already, do this first on the device:"
741 echo " gdbserver $PORT /system/bin/$EXE"
742 echo " or"
743 echo " gdbserver $PORT --attach $PID"
744 echo ""
745 fi
746
747 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
748 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
749 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
750 echo >>"$OUT_ROOT/gdbclient.cmds" ""
751
Mark D Horn7d0ede72012-03-14 14:20:30 -0700752 $ANDROID_EABI_TOOLCHAIN/*-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700753 else
754 echo "Unable to determine build system output dir."
755 fi
756
757}
758
759case `uname -s` in
760 Darwin)
761 function sgrep()
762 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700763 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 Projectb6c1cf62008-10-21 07:00:00 -0700764 }
765
766 ;;
767 *)
768 function sgrep()
769 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700770 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 Projectb6c1cf62008-10-21 07:00:00 -0700771 }
772 ;;
773esac
774
775function jgrep()
776{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700777 find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700778}
779
780function cgrep()
781{
Mike Dodd0c26d342011-04-07 13:29:06 -0700782 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 Projectb6c1cf62008-10-21 07:00:00 -0700783}
784
785function resgrep()
786{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700787 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 Projectb6c1cf62008-10-21 07:00:00 -0700788}
789
790case `uname -s` in
791 Darwin)
792 function mgrep()
793 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700794 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 Projectb6c1cf62008-10-21 07:00:00 -0700795 }
796
797 function treegrep()
798 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700799 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 Projectb6c1cf62008-10-21 07:00:00 -0700800 }
801
802 ;;
803 *)
804 function mgrep()
805 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700806 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 Projectb6c1cf62008-10-21 07:00:00 -0700807 }
808
809 function treegrep()
810 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700811 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 Projectb6c1cf62008-10-21 07:00:00 -0700812 }
813
814 ;;
815esac
816
817function getprebuilt
818{
819 get_abs_build_var ANDROID_PREBUILTS
820}
821
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822function tracedmdump()
823{
824 T=$(gettop)
825 if [ ! "$T" ]; then
826 echo "Couldn't locate the top of the tree. Try setting TOP."
827 return
828 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800829 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700830 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800832 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700833 if [ ! "$TRACE" ] ; then
834 echo "usage: tracedmdump tracename"
835 return
836 fi
837
Jack Veenstra60116fc2009-04-09 18:12:34 -0700838 if [ ! -r "$KERNEL" ] ; then
839 echo "Error: cannot find kernel: '$KERNEL'"
840 return
841 fi
842
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800843 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844 if [ "$BASETRACE" = "$TRACE" ] ; then
845 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
846 fi
847
848 echo "post-processing traces..."
849 rm -f $TRACE/qtrace.dexlist
850 post_trace $TRACE
851 if [ $? -ne 0 ]; then
852 echo "***"
853 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
854 echo "***"
855 return
856 fi
857 echo "generating dexlist output..."
858 /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
859 echo "generating dmtrace data..."
860 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
861 echo "generating html file..."
862 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
863 echo "done, see $TRACE/dmtrace.html for details"
864 echo "or run:"
865 echo " traceview $TRACE/dmtrace"
866}
867
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800868# communicate with a running device or emulator, set up necessary state,
869# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870function runhat()
871{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800872 # process standard adb options
873 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700874 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800875 adbTarget=$1
876 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700877 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800878 adbTarget="$1 $2"
879 shift 2
880 fi
881 local adbOptions=${adbTarget}
882 echo adbOptions = ${adbOptions}
883
884 # runhat options
885 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700886
887 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700888 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889 return
890 fi
891
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800892 # confirm hat is available
893 if [ -z $(which hat) ]; then
894 echo "hat is not available in this configuration."
895 return
896 fi
897
Andy McFaddenb6289852010-07-12 08:00:19 -0700898 # issue "am" command to cause the hprof dump
899 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700900 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700901 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800902 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700903 echo -n "> "
904 read
905
The Android Open Source Project88b60792009-03-03 19:28:42 -0800906 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700907
The Android Open Source Project88b60792009-03-03 19:28:42 -0800908 echo "Retrieving file $devFile..."
909 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700910
The Android Open Source Project88b60792009-03-03 19:28:42 -0800911 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700912
The Android Open Source Project88b60792009-03-03 19:28:42 -0800913 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700914 echo "View the output by pointing your browser at http://localhost:7000/"
915 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800916 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700917}
918
919function getbugreports()
920{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800921 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922
923 if [ ! "$reports" ]; then
924 echo "Could not locate any bugreports."
925 return
926 fi
927
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800928 local report
929 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700930 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800931 echo "/sdcard/bugreports/${report}"
932 adb pull /sdcard/bugreports/${report} ${report}
933 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700934 done
935}
936
937function startviewserver()
938{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800939 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700940 if [ $# -gt 0 ]; then
941 port=$1
942 fi
943 adb shell service call window 1 i32 $port
944}
945
946function stopviewserver()
947{
948 adb shell service call window 2
949}
950
951function isviewserverstarted()
952{
953 adb shell service call window 3
954}
955
Romain Guyb84049a2010-10-04 16:56:11 -0700956function key_home()
957{
958 adb shell input keyevent 3
959}
960
961function key_back()
962{
963 adb shell input keyevent 4
964}
965
966function key_menu()
967{
968 adb shell input keyevent 82
969}
970
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700971function smoketest()
972{
973 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
974 echo "Couldn't locate output files. Try running 'lunch' first." >&2
975 return
976 fi
977 T=$(gettop)
978 if [ ! "$T" ]; then
979 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
980 return
981 fi
982
983 (cd "$T" && mmm tests/SmokeTest) &&
984 adb uninstall com.android.smoketest > /dev/null &&
985 adb uninstall com.android.smoketest.tests > /dev/null &&
986 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
987 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
988 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
989}
990
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800991# simple shortcut to the runtest command
992function runtest()
993{
994 T=$(gettop)
995 if [ ! "$T" ]; then
996 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
997 return
998 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -0700999 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001000}
1001
The Android Open Source Project88b60792009-03-03 19:28:42 -08001002function godir () {
1003 if [[ -z "$1" ]]; then
1004 echo "Usage: godir <regex>"
1005 return
1006 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001007 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001008 if [[ ! -f $T/filelist ]]; then
1009 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001010 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001011 echo " Done"
1012 echo ""
1013 fi
1014 local lines
Doug Zongker29034982011-04-22 08:16:56 -07001015 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001016 if [[ ${#lines[@]} = 0 ]]; then
1017 echo "Not found"
1018 return
1019 fi
1020 local pathname
1021 local choice
1022 if [[ ${#lines[@]} > 1 ]]; then
1023 while [[ -z "$pathname" ]]; do
1024 local index=1
1025 local line
1026 for line in ${lines[@]}; do
1027 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001028 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001029 done
1030 echo
1031 echo -n "Select one: "
1032 unset choice
1033 read choice
1034 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1035 echo "Invalid choice"
1036 continue
1037 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001038 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001039 done
1040 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001041 pathname=${lines[0]}
1042 fi
1043 cd $T/$pathname
1044}
1045
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001046# Force JAVA_HOME to point to java 1.6 if it isn't already set
1047function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001048 if [ ! "$JAVA_HOME" ]; then
1049 case `uname -s` in
1050 Darwin)
1051 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1052 ;;
1053 *)
1054 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1055 ;;
1056 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001057 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001058}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001059
Raphael Moll70a86b02011-06-20 16:03:14 -07001060if [ "x$SHELL" != "x/bin/bash" ]; then
1061 case `ps -o command -p $$` in
1062 *bash*)
1063 ;;
1064 *)
1065 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1066 ;;
1067 esac
1068fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001069
1070# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001071for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/*/vendorsetup.sh device/*/*/vendorsetup.sh 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001072do
1073 echo "including $f"
1074 . $f
1075done
1076unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001077
1078addcompletions