blob: 84ec3e538c5aa208c6fe6b16949d6e6435915f83 [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<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)
Jing Yuf5172c72012-03-29 20:45:50 -0700115 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700116
Raphael Mollc639c782011-06-20 17:25:01 -0700117 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700118 export ANDROID_EABI_TOOLCHAIN=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200119 local ARCH=$(get_build_var TARGET_ARCH)
120 case $ARCH in
H.J. Lu402d7f32012-04-29 07:34:54 -0700121 x86) toolchaindir=x86/i686-linux-android-4.6/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700122 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200123 arm) toolchaindir=arm/arm-linux-androideabi-4.6/bin
124 ;;
125 *)
126 echo "Can't find toolchain for unknown architecture: $ARCH"
127 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700128 ;;
129 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700130 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
131 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700132 fi
Raphael732936d2011-06-22 14:35:32 -0700133
Ying Wang08f5e9a2012-04-17 18:10:11 -0700134 export ARM_EABI_TOOLCHAIN=
135 case $ARCH in
136 x86) toolchaindir=x86/i686-eabi-4.4.3/bin
137 ;;
138 arm) toolchaindir=arm/arm-eabi-4.6/bin
139 ;;
140 *)
141 echo "Can't find toolchain for unknown architecture: $ARCH"
142 toolchaindir=xxxxxxxxx
143 ;;
144 esac
145 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
146 export ARM_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
147 fi
148
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700149 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
150 export ANDROID_QTOOLS=$T/development/emulator/qtools
Robert Greenwalt0987f032012-04-27 10:02:37 -0700151 export ANDROID_DEV_SCRIPTS=$T/development/scripts
152 export ANDROID_BUILD_PATHS=:$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ARM_EABI_TOOLCHAIN$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700153 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800154
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500155 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900156 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500157 if [ -n "$JAVA_HOME" ]; then
158 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900159 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
160 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500161 fi
162
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800163 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700164 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
165 export OUT=$ANDROID_PRODUCT_OUT
166
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700167 unset ANDROID_HOST_OUT
168 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
169
Ben Cheng057fde12011-11-28 13:55:14 -0800170 # needed for processing samples collected by perf counters
171 unset OPROFILE_EVENTS_DIR
172 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
173
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800174 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700175 # TODO: fix the path
176 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
177}
178
179function printconfig()
180{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800181 T=$(gettop)
182 if [ ! "$T" ]; then
183 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
184 return
185 fi
186 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700187}
188
189function set_stuff_for_environment()
190{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800191 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500192 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800193 setpaths
194 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700195
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800196 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700197}
198
199function set_sequence_number()
200{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700201 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700202}
203
204function settitle()
205{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800206 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700207 local product=$TARGET_PRODUCT
208 local variant=$TARGET_BUILD_VARIANT
209 local apps=$TARGET_BUILD_APPS
210 if [ -z "$apps" ]; then
211 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
212 else
213 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
214 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800215 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700216}
217
Kenny Root52aa81c2011-07-15 11:07:06 -0700218function addcompletions()
219{
220 local T dir f
221
222 # Keep us from trying to run in something that isn't bash.
223 if [ -z "${BASH_VERSION}" ]; then
224 return
225 fi
226
227 # Keep us from trying to run in bash that's too old.
228 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
229 return
230 fi
231
232 dir="sdk/bash_completion"
233 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700234 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700235 echo "including $f"
236 . $f
237 done
238 fi
239}
240
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700241function choosetype()
242{
243 echo "Build type choices are:"
244 echo " 1. release"
245 echo " 2. debug"
246 echo
247
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700249 DEFAULT_NUM=1
250 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700251
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800252 export TARGET_BUILD_TYPE=
253 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700254 while [ -z $TARGET_BUILD_TYPE ]
255 do
256 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800257 if [ -z "$1" ] ; then
258 read ANSWER
259 else
260 echo $1
261 ANSWER=$1
262 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263 case $ANSWER in
264 "")
265 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
266 ;;
267 1)
268 export TARGET_BUILD_TYPE=release
269 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800270 release)
271 export TARGET_BUILD_TYPE=release
272 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700273 2)
274 export TARGET_BUILD_TYPE=debug
275 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800276 debug)
277 export TARGET_BUILD_TYPE=debug
278 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700279 *)
280 echo
281 echo "I didn't understand your response. Please try again."
282 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283 ;;
284 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800285 if [ -n "$1" ] ; then
286 break
287 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700288 done
289
290 set_stuff_for_environment
291}
292
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800293#
294# This function isn't really right: It chooses a TARGET_PRODUCT
295# based on the list of boards. Usually, that gets you something
296# that kinda works with a generic product, but really, you should
297# pick a product by name.
298#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299function chooseproduct()
300{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700301 if [ "x$TARGET_PRODUCT" != x ] ; then
302 default_value=$TARGET_PRODUCT
303 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700304 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700305 fi
306
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800307 export TARGET_PRODUCT=
308 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309 while [ -z "$TARGET_PRODUCT" ]
310 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700311 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312 if [ -z "$1" ] ; then
313 read ANSWER
314 else
315 echo $1
316 ANSWER=$1
317 fi
318
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 if [ -z "$ANSWER" ] ; then
320 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 else
322 if check_product $ANSWER
323 then
324 export TARGET_PRODUCT=$ANSWER
325 else
326 echo "** Not a valid product: $ANSWER"
327 fi
328 fi
329 if [ -n "$1" ] ; then
330 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700331 fi
332 done
333
334 set_stuff_for_environment
335}
336
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800337function choosevariant()
338{
339 echo "Variant choices are:"
340 local index=1
341 local v
342 for v in ${VARIANT_CHOICES[@]}
343 do
344 # The product name is the name of the directory containing
345 # the makefile we found, above.
346 echo " $index. $v"
347 index=$(($index+1))
348 done
349
350 local default_value=eng
351 local ANSWER
352
353 export TARGET_BUILD_VARIANT=
354 while [ -z "$TARGET_BUILD_VARIANT" ]
355 do
356 echo -n "Which would you like? [$default_value] "
357 if [ -z "$1" ] ; then
358 read ANSWER
359 else
360 echo $1
361 ANSWER=$1
362 fi
363
364 if [ -z "$ANSWER" ] ; then
365 export TARGET_BUILD_VARIANT=$default_value
366 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
367 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800368 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800369 fi
370 else
371 if check_variant $ANSWER
372 then
373 export TARGET_BUILD_VARIANT=$ANSWER
374 else
375 echo "** Not a valid variant: $ANSWER"
376 fi
377 fi
378 if [ -n "$1" ] ; then
379 break
380 fi
381 done
382}
383
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384function choosecombo()
385{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700386 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700387
388 echo
389 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700390 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700391
392 echo
393 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700394 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395
396 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700397 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800398 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700399}
400
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800401# Clear this variable. It will be built up again when the vendorsetup.sh
402# files are included at the end of this file.
403unset LUNCH_MENU_CHOICES
404function add_lunch_combo()
405{
406 local new_combo=$1
407 local c
408 for c in ${LUNCH_MENU_CHOICES[@]} ; do
409 if [ "$new_combo" = "$c" ] ; then
410 return
411 fi
412 done
413 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
414}
415
416# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700417add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700418add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800419add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800420
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700421function print_lunch_menu()
422{
423 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700424 echo
425 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700426 echo
427 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428
429 local i=1
430 local choice
431 for choice in ${LUNCH_MENU_CHOICES[@]}
432 do
433 echo " $i. $choice"
434 i=$(($i+1))
435 done
436
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437 echo
438}
439
440function lunch()
441{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800442 local answer
443
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700444 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800445 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446 else
447 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700448 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800449 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450 fi
451
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452 local selection=
453
454 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700456 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
458 then
459 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
460 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800461 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462 fi
463 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
464 then
465 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466 fi
467
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468 if [ -z "$selection" ]
469 then
470 echo
471 echo "Invalid lunch combo: $answer"
472 return 1
473 fi
474
Joe Onoratoda12daf2010-06-09 18:18:31 -0700475 export TARGET_BUILD_APPS=
476
Jeff Browne33ba4c2011-07-11 22:11:46 -0700477 local product=$(echo -n $selection | sed -e "s/-.*$//")
478 check_product $product
479 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700481 echo
482 echo "** Don't have a product spec for: '$product'"
483 echo "** Do you have the right repo manifest?"
484 product=
485 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486
Jeff Browne33ba4c2011-07-11 22:11:46 -0700487 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
488 check_variant $variant
489 if [ $? -ne 0 ]
490 then
491 echo
492 echo "** Invalid variant: '$variant'"
493 echo "** Must be one of ${VARIANT_CHOICES[@]}"
494 variant=
495 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496
Jeff Browne33ba4c2011-07-11 22:11:46 -0700497 if [ -z "$product" -o -z "$variant" ]
498 then
499 echo
500 return 1
501 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502
Jeff Browne33ba4c2011-07-11 22:11:46 -0700503 export TARGET_PRODUCT=$product
504 export TARGET_BUILD_VARIANT=$variant
505 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506
507 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800508
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800510 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700511}
512
Jeff Davidson513d7a42010-08-02 10:00:44 -0700513# Tab completion for lunch.
514function _lunch()
515{
516 local cur prev opts
517 COMPREPLY=()
518 cur="${COMP_WORDS[COMP_CWORD]}"
519 prev="${COMP_WORDS[COMP_CWORD-1]}"
520
521 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
522 return 0
523}
524complete -F _lunch lunch
525
Joe Onoratoda12daf2010-06-09 18:18:31 -0700526# Configures the build to build unbundled apps.
527# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
528function tapas()
529{
Jeff Hamilton293f9392011-11-18 17:15:25 -0600530 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
531 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700532
533 if [ $(echo $variant | wc -w) -gt 1 ]; then
534 echo "tapas: Error: Multiple build variants supplied: $variant"
535 return
536 fi
537 if [ -z "$variant" ]; then
538 variant=eng
539 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700540 if [ -z "$apps" ]; then
541 apps=all
542 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700543
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700544 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700545 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700546 export TARGET_BUILD_TYPE=release
547 export TARGET_BUILD_APPS=$apps
548
549 set_stuff_for_environment
550 printconfig
551}
552
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700553function gettop
554{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800555 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700556 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
557 echo $TOP
558 else
559 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800560 # The following circumlocution (repeated below as well) ensures
561 # that we record the true directory name and not one that is
562 # faked up with symlink names.
563 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700564 else
565 # We redirect cd to /dev/null in case it's aliased to
566 # a command that prints something as a side-effect
567 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800568 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700569 T=
570 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
571 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800572 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700573 done
574 cd $HERE > /dev/null
575 if [ -f "$T/$TOPFILE" ]; then
576 echo $T
577 fi
578 fi
579 fi
580}
581
582function m()
583{
584 T=$(gettop)
585 if [ "$T" ]; then
586 make -C $T $@
587 else
588 echo "Couldn't locate the top of the tree. Try setting TOP."
589 fi
590}
591
592function findmakefile()
593{
594 TOPFILE=build/core/envsetup.mk
595 # We redirect cd to /dev/null in case it's aliased to
596 # a command that prints something as a side-effect
597 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599 T=
600 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
601 T=$PWD
602 if [ -f "$T/Android.mk" ]; then
603 echo $T/Android.mk
604 cd $HERE > /dev/null
605 return
606 fi
607 cd .. > /dev/null
608 done
609 cd $HERE > /dev/null
610}
611
612function mm()
613{
614 # If we're sitting in the root of the build tree, just do a
615 # normal make.
616 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
617 make $@
618 else
619 # Find the closest Android.mk file.
620 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800621 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700622 # Remove the path to top as the makefilepath needs to be relative
623 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700624 if [ ! "$T" ]; then
625 echo "Couldn't locate the top of the tree. Try setting TOP."
626 elif [ ! "$M" ]; then
627 echo "Couldn't locate a makefile from the current directory."
628 else
Ying Wang01884142010-07-20 16:18:16 -0700629 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700630 fi
631 fi
632}
633
634function mmm()
635{
636 T=$(gettop)
637 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800638 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800639 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800640 local ARGS=
641 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800642 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
643 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
644 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800645 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
646 if [ "$MODULES" = "" ]; then
647 MODULES=all_modules
648 fi
649 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700650 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700651 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800653 START=`PWD= /bin/pwd`
654 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655 if [ "$MFILE" = "" ] ; then
656 MFILE=$DIR/Android.mk
657 else
658 MFILE=$MFILE/$DIR/Android.mk
659 fi
660 MAKEFILE="$MAKEFILE $MFILE"
661 else
662 if [ "$DIR" = snod ]; then
663 ARGS="$ARGS snod"
664 elif [ "$DIR" = showcommands ]; then
665 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700666 elif [ "$DIR" = dist ]; then
667 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800668 elif [ "$DIR" = incrementaljavac ]; then
669 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 else
671 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400672 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 fi
674 fi
675 done
Alon Albert68895a92011-11-30 12:40:19 -0800676 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700677 else
678 echo "Couldn't locate the top of the tree. Try setting TOP."
679 fi
680}
681
682function croot()
683{
684 T=$(gettop)
685 if [ "$T" ]; then
686 cd $(gettop)
687 else
688 echo "Couldn't locate the top of the tree. Try setting TOP."
689 fi
690}
691
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700692function cproj()
693{
694 TOPFILE=build/core/envsetup.mk
695 # We redirect cd to /dev/null in case it's aliased to
696 # a command that prints something as a side-effect
697 # (like pushd)
698 local HERE=$PWD
699 T=
700 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
701 T=$PWD
702 if [ -f "$T/Android.mk" ]; then
703 cd $T
704 return
705 fi
706 cd .. > /dev/null
707 done
708 cd $HERE > /dev/null
709 echo "can't find Android.mk"
710}
711
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700712function pid()
713{
714 local EXE="$1"
715 if [ "$EXE" ] ; then
716 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
717 echo "$PID"
718 else
719 echo "usage: pid name"
720 fi
721}
722
Christopher Tate744ee802009-11-12 15:33:08 -0800723# systemstack - dump the current stack trace of all threads in the system process
724# to the usual ANR traces file
725function systemstack()
726{
727 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
728}
729
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700730function gdbclient()
731{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800732 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
733 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
734 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
735 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
736 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800737 local ARCH=$(get_build_var TARGET_ARCH)
738 local GDB
739 case "$ARCH" in
Jean-Baptiste Querufeec98b2012-05-16 13:18:39 -0700740 x86) GDB=i686-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800741 arm) GDB=arm-linux-androideabi-gdb;;
742 *) echo "Unknown arch $ARCH"; return 1;;
743 esac
744
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700745 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
746 local EXE="$1"
747 if [ "$EXE" ] ; then
748 EXE=$1
749 else
750 EXE="app_process"
751 fi
752
753 local PORT="$2"
754 if [ "$PORT" ] ; then
755 PORT=$2
756 else
757 PORT=":5039"
758 fi
759
760 local PID
761 local PROG="$3"
762 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700763 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
764 PID="$3"
765 else
766 PID=`pid $3`
767 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700768 adb forward "tcp$PORT" "tcp$PORT"
769 adb shell gdbserver $PORT --attach $PID &
770 sleep 2
771 else
772 echo ""
773 echo "If you haven't done so already, do this first on the device:"
774 echo " gdbserver $PORT /system/bin/$EXE"
775 echo " or"
776 echo " gdbserver $PORT --attach $PID"
777 echo ""
778 fi
779
780 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Kenny Root9bf081e2012-03-26 12:38:16 -0700781 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
783 echo >>"$OUT_ROOT/gdbclient.cmds" ""
784
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200785 $ANDROID_TOOLCHAIN/$GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700786 else
787 echo "Unable to determine build system output dir."
788 fi
789
790}
791
792case `uname -s` in
793 Darwin)
794 function sgrep()
795 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700796 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 -0700797 }
798
799 ;;
800 *)
801 function sgrep()
802 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700803 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 -0700804 }
805 ;;
806esac
807
808function jgrep()
809{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700810 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 -0700811}
812
813function cgrep()
814{
Mike Dodd0c26d342011-04-07 13:29:06 -0700815 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 -0700816}
817
818function resgrep()
819{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700820 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 -0700821}
822
823case `uname -s` in
824 Darwin)
825 function mgrep()
826 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700827 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 -0700828 }
829
830 function treegrep()
831 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700832 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 -0700833 }
834
835 ;;
836 *)
837 function mgrep()
838 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700839 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 -0700840 }
841
842 function treegrep()
843 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700844 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 -0700845 }
846
847 ;;
848esac
849
850function getprebuilt
851{
852 get_abs_build_var ANDROID_PREBUILTS
853}
854
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855function tracedmdump()
856{
857 T=$(gettop)
858 if [ ! "$T" ]; then
859 echo "Couldn't locate the top of the tree. Try setting TOP."
860 return
861 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800862 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700863 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800865 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700866 if [ ! "$TRACE" ] ; then
867 echo "usage: tracedmdump tracename"
868 return
869 fi
870
Jack Veenstra60116fc2009-04-09 18:12:34 -0700871 if [ ! -r "$KERNEL" ] ; then
872 echo "Error: cannot find kernel: '$KERNEL'"
873 return
874 fi
875
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800876 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700877 if [ "$BASETRACE" = "$TRACE" ] ; then
878 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
879 fi
880
881 echo "post-processing traces..."
882 rm -f $TRACE/qtrace.dexlist
883 post_trace $TRACE
884 if [ $? -ne 0 ]; then
885 echo "***"
886 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
887 echo "***"
888 return
889 fi
890 echo "generating dexlist output..."
891 /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
892 echo "generating dmtrace data..."
893 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
894 echo "generating html file..."
895 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
896 echo "done, see $TRACE/dmtrace.html for details"
897 echo "or run:"
898 echo " traceview $TRACE/dmtrace"
899}
900
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800901# communicate with a running device or emulator, set up necessary state,
902# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700903function runhat()
904{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800905 # process standard adb options
906 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700907 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800908 adbTarget=$1
909 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700910 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800911 adbTarget="$1 $2"
912 shift 2
913 fi
914 local adbOptions=${adbTarget}
915 echo adbOptions = ${adbOptions}
916
917 # runhat options
918 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700919
920 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700921 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922 return
923 fi
924
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800925 # confirm hat is available
926 if [ -z $(which hat) ]; then
927 echo "hat is not available in this configuration."
928 return
929 fi
930
Andy McFaddenb6289852010-07-12 08:00:19 -0700931 # issue "am" command to cause the hprof dump
932 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700933 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700934 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800935 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700936 echo -n "> "
937 read
938
The Android Open Source Project88b60792009-03-03 19:28:42 -0800939 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700940
The Android Open Source Project88b60792009-03-03 19:28:42 -0800941 echo "Retrieving file $devFile..."
942 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700943
The Android Open Source Project88b60792009-03-03 19:28:42 -0800944 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700945
The Android Open Source Project88b60792009-03-03 19:28:42 -0800946 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700947 echo "View the output by pointing your browser at http://localhost:7000/"
948 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -0800949 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700950}
951
952function getbugreports()
953{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800954 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700955
956 if [ ! "$reports" ]; then
957 echo "Could not locate any bugreports."
958 return
959 fi
960
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800961 local report
962 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700963 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800964 echo "/sdcard/bugreports/${report}"
965 adb pull /sdcard/bugreports/${report} ${report}
966 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 done
968}
969
970function startviewserver()
971{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800972 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700973 if [ $# -gt 0 ]; then
974 port=$1
975 fi
976 adb shell service call window 1 i32 $port
977}
978
979function stopviewserver()
980{
981 adb shell service call window 2
982}
983
984function isviewserverstarted()
985{
986 adb shell service call window 3
987}
988
Romain Guyb84049a2010-10-04 16:56:11 -0700989function key_home()
990{
991 adb shell input keyevent 3
992}
993
994function key_back()
995{
996 adb shell input keyevent 4
997}
998
999function key_menu()
1000{
1001 adb shell input keyevent 82
1002}
1003
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001004function smoketest()
1005{
1006 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1007 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1008 return
1009 fi
1010 T=$(gettop)
1011 if [ ! "$T" ]; then
1012 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1013 return
1014 fi
1015
1016 (cd "$T" && mmm tests/SmokeTest) &&
1017 adb uninstall com.android.smoketest > /dev/null &&
1018 adb uninstall com.android.smoketest.tests > /dev/null &&
1019 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1020 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1021 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1022}
1023
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001024# simple shortcut to the runtest command
1025function runtest()
1026{
1027 T=$(gettop)
1028 if [ ! "$T" ]; then
1029 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1030 return
1031 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001032 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001033}
1034
The Android Open Source Project88b60792009-03-03 19:28:42 -08001035function godir () {
1036 if [[ -z "$1" ]]; then
1037 echo "Usage: godir <regex>"
1038 return
1039 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001040 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001041 if [[ ! -f $T/filelist ]]; then
1042 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001043 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001044 echo " Done"
1045 echo ""
1046 fi
1047 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001048 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001049 if [[ ${#lines[@]} = 0 ]]; then
1050 echo "Not found"
1051 return
1052 fi
1053 local pathname
1054 local choice
1055 if [[ ${#lines[@]} > 1 ]]; then
1056 while [[ -z "$pathname" ]]; do
1057 local index=1
1058 local line
1059 for line in ${lines[@]}; do
1060 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001061 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001062 done
1063 echo
1064 echo -n "Select one: "
1065 unset choice
1066 read choice
1067 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1068 echo "Invalid choice"
1069 continue
1070 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001071 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001072 done
1073 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001074 pathname=${lines[0]}
1075 fi
1076 cd $T/$pathname
1077}
1078
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001079# Force JAVA_HOME to point to java 1.6 if it isn't already set
1080function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001081 if [ ! "$JAVA_HOME" ]; then
1082 case `uname -s` in
1083 Darwin)
1084 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1085 ;;
1086 *)
1087 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1088 ;;
1089 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001090 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001091}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001092
Raphael Moll70a86b02011-06-20 16:03:14 -07001093if [ "x$SHELL" != "x/bin/bash" ]; then
1094 case `ps -o command -p $$` in
1095 *bash*)
1096 ;;
1097 *)
1098 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1099 ;;
1100 esac
1101fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001102
1103# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001104for 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 -08001105do
1106 echo "including $f"
1107 . $f
1108done
1109unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001110
1111addcompletions