blob: d3344d28068e22e17d603b563745885a65459bc0 [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
121 x86) toolchaindir=x86/i686-android-linux-4.4.3/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
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
Ben Cheng057fde12011-11-28 13:55:14 -0800154 # needed for processing samples collected by perf counters
155 unset OPROFILE_EVENTS_DIR
156 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
157
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800158 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700159 # TODO: fix the path
160 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
161}
162
163function printconfig()
164{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800165 T=$(gettop)
166 if [ ! "$T" ]; then
167 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
168 return
169 fi
170 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700171}
172
173function set_stuff_for_environment()
174{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800175 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500176 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800177 setpaths
178 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700179
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800180 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700181}
182
183function set_sequence_number()
184{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700185 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700186}
187
188function settitle()
189{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800190 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700191 local product=$TARGET_PRODUCT
192 local variant=$TARGET_BUILD_VARIANT
193 local apps=$TARGET_BUILD_APPS
194 if [ -z "$apps" ]; then
195 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
196 else
197 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
198 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800199 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700200}
201
Kenny Root52aa81c2011-07-15 11:07:06 -0700202function addcompletions()
203{
204 local T dir f
205
206 # Keep us from trying to run in something that isn't bash.
207 if [ -z "${BASH_VERSION}" ]; then
208 return
209 fi
210
211 # Keep us from trying to run in bash that's too old.
212 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
213 return
214 fi
215
216 dir="sdk/bash_completion"
217 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700218 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700219 echo "including $f"
220 . $f
221 done
222 fi
223}
224
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700225function choosetype()
226{
227 echo "Build type choices are:"
228 echo " 1. release"
229 echo " 2. debug"
230 echo
231
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800232 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700233 DEFAULT_NUM=1
234 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700235
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 export TARGET_BUILD_TYPE=
237 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700238 while [ -z $TARGET_BUILD_TYPE ]
239 do
240 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800241 if [ -z "$1" ] ; then
242 read ANSWER
243 else
244 echo $1
245 ANSWER=$1
246 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247 case $ANSWER in
248 "")
249 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
250 ;;
251 1)
252 export TARGET_BUILD_TYPE=release
253 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800254 release)
255 export TARGET_BUILD_TYPE=release
256 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700257 2)
258 export TARGET_BUILD_TYPE=debug
259 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800260 debug)
261 export TARGET_BUILD_TYPE=debug
262 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263 *)
264 echo
265 echo "I didn't understand your response. Please try again."
266 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267 ;;
268 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800269 if [ -n "$1" ] ; then
270 break
271 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700272 done
273
274 set_stuff_for_environment
275}
276
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277#
278# This function isn't really right: It chooses a TARGET_PRODUCT
279# based on the list of boards. Usually, that gets you something
280# that kinda works with a generic product, but really, you should
281# pick a product by name.
282#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283function chooseproduct()
284{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700285 if [ "x$TARGET_PRODUCT" != x ] ; then
286 default_value=$TARGET_PRODUCT
287 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700288 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289 fi
290
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800291 export TARGET_PRODUCT=
292 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700293 while [ -z "$TARGET_PRODUCT" ]
294 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700295 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 if [ -z "$1" ] ; then
297 read ANSWER
298 else
299 echo $1
300 ANSWER=$1
301 fi
302
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303 if [ -z "$ANSWER" ] ; then
304 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800305 else
306 if check_product $ANSWER
307 then
308 export TARGET_PRODUCT=$ANSWER
309 else
310 echo "** Not a valid product: $ANSWER"
311 fi
312 fi
313 if [ -n "$1" ] ; then
314 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315 fi
316 done
317
318 set_stuff_for_environment
319}
320
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321function choosevariant()
322{
323 echo "Variant choices are:"
324 local index=1
325 local v
326 for v in ${VARIANT_CHOICES[@]}
327 do
328 # The product name is the name of the directory containing
329 # the makefile we found, above.
330 echo " $index. $v"
331 index=$(($index+1))
332 done
333
334 local default_value=eng
335 local ANSWER
336
337 export TARGET_BUILD_VARIANT=
338 while [ -z "$TARGET_BUILD_VARIANT" ]
339 do
340 echo -n "Which would you like? [$default_value] "
341 if [ -z "$1" ] ; then
342 read ANSWER
343 else
344 echo $1
345 ANSWER=$1
346 fi
347
348 if [ -z "$ANSWER" ] ; then
349 export TARGET_BUILD_VARIANT=$default_value
350 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
351 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800352 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353 fi
354 else
355 if check_variant $ANSWER
356 then
357 export TARGET_BUILD_VARIANT=$ANSWER
358 else
359 echo "** Not a valid variant: $ANSWER"
360 fi
361 fi
362 if [ -n "$1" ] ; then
363 break
364 fi
365 done
366}
367
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368function choosecombo()
369{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700370 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700371
372 echo
373 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700374 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700375
376 echo
377 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700378 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800379
380 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700381 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800382 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383}
384
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800385# Clear this variable. It will be built up again when the vendorsetup.sh
386# files are included at the end of this file.
387unset LUNCH_MENU_CHOICES
388function add_lunch_combo()
389{
390 local new_combo=$1
391 local c
392 for c in ${LUNCH_MENU_CHOICES[@]} ; do
393 if [ "$new_combo" = "$c" ] ; then
394 return
395 fi
396 done
397 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
398}
399
400# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700401add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700402add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800403add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800404
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700405function print_lunch_menu()
406{
407 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700408 echo
409 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700410 echo
411 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800412
413 local i=1
414 local choice
415 for choice in ${LUNCH_MENU_CHOICES[@]}
416 do
417 echo " $i. $choice"
418 i=$(($i+1))
419 done
420
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700421 echo
422}
423
424function lunch()
425{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800426 local answer
427
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700428 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800429 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700430 else
431 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700432 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800433 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700434 fi
435
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800436 local selection=
437
438 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700439 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700440 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800441 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
442 then
443 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
444 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800445 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800446 fi
447 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
448 then
449 selection=$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 if [ -z "$selection" ]
453 then
454 echo
455 echo "Invalid lunch combo: $answer"
456 return 1
457 fi
458
Joe Onoratoda12daf2010-06-09 18:18:31 -0700459 export TARGET_BUILD_APPS=
460
Jeff Browne33ba4c2011-07-11 22:11:46 -0700461 local product=$(echo -n $selection | sed -e "s/-.*$//")
462 check_product $product
463 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800464 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700465 echo
466 echo "** Don't have a product spec for: '$product'"
467 echo "** Do you have the right repo manifest?"
468 product=
469 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800470
Jeff Browne33ba4c2011-07-11 22:11:46 -0700471 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
472 check_variant $variant
473 if [ $? -ne 0 ]
474 then
475 echo
476 echo "** Invalid variant: '$variant'"
477 echo "** Must be one of ${VARIANT_CHOICES[@]}"
478 variant=
479 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480
Jeff Browne33ba4c2011-07-11 22:11:46 -0700481 if [ -z "$product" -o -z "$variant" ]
482 then
483 echo
484 return 1
485 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486
Jeff Browne33ba4c2011-07-11 22:11:46 -0700487 export TARGET_PRODUCT=$product
488 export TARGET_BUILD_VARIANT=$variant
489 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700490
491 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800492
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800494 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700495}
496
Jeff Davidson513d7a42010-08-02 10:00:44 -0700497# Tab completion for lunch.
498function _lunch()
499{
500 local cur prev opts
501 COMPREPLY=()
502 cur="${COMP_WORDS[COMP_CWORD]}"
503 prev="${COMP_WORDS[COMP_CWORD-1]}"
504
505 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
506 return 0
507}
508complete -F _lunch lunch
509
Joe Onoratoda12daf2010-06-09 18:18:31 -0700510# Configures the build to build unbundled apps.
511# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
512function tapas()
513{
Jeff Hamilton293f9392011-11-18 17:15:25 -0600514 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
515 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700516
517 if [ $(echo $variant | wc -w) -gt 1 ]; then
518 echo "tapas: Error: Multiple build variants supplied: $variant"
519 return
520 fi
521 if [ -z "$variant" ]; then
522 variant=eng
523 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700524 if [ -z "$apps" ]; then
525 apps=all
526 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700527
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700528 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700529 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700530 export TARGET_BUILD_TYPE=release
531 export TARGET_BUILD_APPS=$apps
532
533 set_stuff_for_environment
534 printconfig
535}
536
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537function gettop
538{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800539 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700540 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
541 echo $TOP
542 else
543 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800544 # The following circumlocution (repeated below as well) ensures
545 # that we record the true directory name and not one that is
546 # faked up with symlink names.
547 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700548 else
549 # We redirect cd to /dev/null in case it's aliased to
550 # a command that prints something as a side-effect
551 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800552 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700553 T=
554 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
555 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800556 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700557 done
558 cd $HERE > /dev/null
559 if [ -f "$T/$TOPFILE" ]; then
560 echo $T
561 fi
562 fi
563 fi
564}
565
566function m()
567{
568 T=$(gettop)
569 if [ "$T" ]; then
570 make -C $T $@
571 else
572 echo "Couldn't locate the top of the tree. Try setting TOP."
573 fi
574}
575
576function findmakefile()
577{
578 TOPFILE=build/core/envsetup.mk
579 # We redirect cd to /dev/null in case it's aliased to
580 # a command that prints something as a side-effect
581 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800582 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583 T=
584 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
585 T=$PWD
586 if [ -f "$T/Android.mk" ]; then
587 echo $T/Android.mk
588 cd $HERE > /dev/null
589 return
590 fi
591 cd .. > /dev/null
592 done
593 cd $HERE > /dev/null
594}
595
596function mm()
597{
598 # If we're sitting in the root of the build tree, just do a
599 # normal make.
600 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
601 make $@
602 else
603 # Find the closest Android.mk file.
604 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800605 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700606 # Remove the path to top as the makefilepath needs to be relative
607 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700608 if [ ! "$T" ]; then
609 echo "Couldn't locate the top of the tree. Try setting TOP."
610 elif [ ! "$M" ]; then
611 echo "Couldn't locate a makefile from the current directory."
612 else
Ying Wang01884142010-07-20 16:18:16 -0700613 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700614 fi
615 fi
616}
617
618function mmm()
619{
620 T=$(gettop)
621 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800622 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800623 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800624 local ARGS=
625 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800626 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
627 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
628 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800629 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
630 if [ "$MODULES" = "" ]; then
631 MODULES=all_modules
632 fi
633 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700634 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700635 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700636 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800637 START=`PWD= /bin/pwd`
638 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639 if [ "$MFILE" = "" ] ; then
640 MFILE=$DIR/Android.mk
641 else
642 MFILE=$MFILE/$DIR/Android.mk
643 fi
644 MAKEFILE="$MAKEFILE $MFILE"
645 else
646 if [ "$DIR" = snod ]; then
647 ARGS="$ARGS snod"
648 elif [ "$DIR" = showcommands ]; then
649 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700650 elif [ "$DIR" = dist ]; then
651 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800652 elif [ "$DIR" = incrementaljavac ]; then
653 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654 else
655 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400656 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 fi
658 fi
659 done
Alon Albert68895a92011-11-30 12:40:19 -0800660 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661 else
662 echo "Couldn't locate the top of the tree. Try setting TOP."
663 fi
664}
665
666function croot()
667{
668 T=$(gettop)
669 if [ "$T" ]; then
670 cd $(gettop)
671 else
672 echo "Couldn't locate the top of the tree. Try setting TOP."
673 fi
674}
675
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700676function cproj()
677{
678 TOPFILE=build/core/envsetup.mk
679 # We redirect cd to /dev/null in case it's aliased to
680 # a command that prints something as a side-effect
681 # (like pushd)
682 local HERE=$PWD
683 T=
684 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
685 T=$PWD
686 if [ -f "$T/Android.mk" ]; then
687 cd $T
688 return
689 fi
690 cd .. > /dev/null
691 done
692 cd $HERE > /dev/null
693 echo "can't find Android.mk"
694}
695
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700696function pid()
697{
698 local EXE="$1"
699 if [ "$EXE" ] ; then
700 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
701 echo "$PID"
702 else
703 echo "usage: pid name"
704 fi
705}
706
Christopher Tate744ee802009-11-12 15:33:08 -0800707# systemstack - dump the current stack trace of all threads in the system process
708# to the usual ANR traces file
709function systemstack()
710{
711 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
712}
713
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700714function gdbclient()
715{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800716 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
717 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
718 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
719 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
720 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800721 local ARCH=$(get_build_var TARGET_ARCH)
722 local GDB
723 case "$ARCH" in
724 x86) GDB=i686-android-linux-gdb;;
725 arm) GDB=arm-linux-androideabi-gdb;;
726 *) echo "Unknown arch $ARCH"; return 1;;
727 esac
728
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700729 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
730 local EXE="$1"
731 if [ "$EXE" ] ; then
732 EXE=$1
733 else
734 EXE="app_process"
735 fi
736
737 local PORT="$2"
738 if [ "$PORT" ] ; then
739 PORT=$2
740 else
741 PORT=":5039"
742 fi
743
744 local PID
745 local PROG="$3"
746 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700747 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
748 PID="$3"
749 else
750 PID=`pid $3`
751 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700752 adb forward "tcp$PORT" "tcp$PORT"
753 adb shell gdbserver $PORT --attach $PID &
754 sleep 2
755 else
756 echo ""
757 echo "If you haven't done so already, do this first on the device:"
758 echo " gdbserver $PORT /system/bin/$EXE"
759 echo " or"
760 echo " gdbserver $PORT --attach $PID"
761 echo ""
762 fi
763
764 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Kenny Root9bf081e2012-03-26 12:38:16 -0700765 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 -0700766 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
767 echo >>"$OUT_ROOT/gdbclient.cmds" ""
768
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200769 $ANDROID_TOOLCHAIN/$GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700770 else
771 echo "Unable to determine build system output dir."
772 fi
773
774}
775
776case `uname -s` in
777 Darwin)
778 function sgrep()
779 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700780 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 -0700781 }
782
783 ;;
784 *)
785 function sgrep()
786 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700787 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 -0700788 }
789 ;;
790esac
791
792function jgrep()
793{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700794 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 -0700795}
796
797function cgrep()
798{
Mike Dodd0c26d342011-04-07 13:29:06 -0700799 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 -0700800}
801
802function resgrep()
803{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700804 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 -0700805}
806
807case `uname -s` in
808 Darwin)
809 function mgrep()
810 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700811 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 -0700812 }
813
814 function treegrep()
815 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700816 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 -0700817 }
818
819 ;;
820 *)
821 function mgrep()
822 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700823 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 -0700824 }
825
826 function treegrep()
827 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700828 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 -0700829 }
830
831 ;;
832esac
833
834function getprebuilt
835{
836 get_abs_build_var ANDROID_PREBUILTS
837}
838
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839function tracedmdump()
840{
841 T=$(gettop)
842 if [ ! "$T" ]; then
843 echo "Couldn't locate the top of the tree. Try setting TOP."
844 return
845 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800846 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700847 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800849 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850 if [ ! "$TRACE" ] ; then
851 echo "usage: tracedmdump tracename"
852 return
853 fi
854
Jack Veenstra60116fc2009-04-09 18:12:34 -0700855 if [ ! -r "$KERNEL" ] ; then
856 echo "Error: cannot find kernel: '$KERNEL'"
857 return
858 fi
859
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800860 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861 if [ "$BASETRACE" = "$TRACE" ] ; then
862 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
863 fi
864
865 echo "post-processing traces..."
866 rm -f $TRACE/qtrace.dexlist
867 post_trace $TRACE
868 if [ $? -ne 0 ]; then
869 echo "***"
870 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
871 echo "***"
872 return
873 fi
874 echo "generating dexlist output..."
875 /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
876 echo "generating dmtrace data..."
877 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
878 echo "generating html file..."
879 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
880 echo "done, see $TRACE/dmtrace.html for details"
881 echo "or run:"
882 echo " traceview $TRACE/dmtrace"
883}
884
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800885# communicate with a running device or emulator, set up necessary state,
886# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700887function runhat()
888{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800889 # process standard adb options
890 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700891 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800892 adbTarget=$1
893 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700894 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800895 adbTarget="$1 $2"
896 shift 2
897 fi
898 local adbOptions=${adbTarget}
899 echo adbOptions = ${adbOptions}
900
901 # runhat options
902 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700903
904 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700905 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700906 return
907 fi
908
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800909 # confirm hat is available
910 if [ -z $(which hat) ]; then
911 echo "hat is not available in this configuration."
912 return
913 fi
914
Andy McFaddenb6289852010-07-12 08:00:19 -0700915 # issue "am" command to cause the hprof dump
916 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700917 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700918 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800919 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700920 echo -n "> "
921 read
922
The Android Open Source Project88b60792009-03-03 19:28:42 -0800923 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700924
The Android Open Source Project88b60792009-03-03 19:28:42 -0800925 echo "Retrieving file $devFile..."
926 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700927
The Android Open Source Project88b60792009-03-03 19:28:42 -0800928 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700929
The Android Open Source Project88b60792009-03-03 19:28:42 -0800930 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700931 echo "View the output by pointing your browser at http://localhost:7000/"
932 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -0800933 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700934}
935
936function getbugreports()
937{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800938 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700939
940 if [ ! "$reports" ]; then
941 echo "Could not locate any bugreports."
942 return
943 fi
944
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800945 local report
946 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700947 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800948 echo "/sdcard/bugreports/${report}"
949 adb pull /sdcard/bugreports/${report} ${report}
950 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700951 done
952}
953
954function startviewserver()
955{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800956 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700957 if [ $# -gt 0 ]; then
958 port=$1
959 fi
960 adb shell service call window 1 i32 $port
961}
962
963function stopviewserver()
964{
965 adb shell service call window 2
966}
967
968function isviewserverstarted()
969{
970 adb shell service call window 3
971}
972
Romain Guyb84049a2010-10-04 16:56:11 -0700973function key_home()
974{
975 adb shell input keyevent 3
976}
977
978function key_back()
979{
980 adb shell input keyevent 4
981}
982
983function key_menu()
984{
985 adb shell input keyevent 82
986}
987
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988function smoketest()
989{
990 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
991 echo "Couldn't locate output files. Try running 'lunch' first." >&2
992 return
993 fi
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
999
1000 (cd "$T" && mmm tests/SmokeTest) &&
1001 adb uninstall com.android.smoketest > /dev/null &&
1002 adb uninstall com.android.smoketest.tests > /dev/null &&
1003 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1004 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1005 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1006}
1007
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001008# simple shortcut to the runtest command
1009function runtest()
1010{
1011 T=$(gettop)
1012 if [ ! "$T" ]; then
1013 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1014 return
1015 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001016 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001017}
1018
The Android Open Source Project88b60792009-03-03 19:28:42 -08001019function godir () {
1020 if [[ -z "$1" ]]; then
1021 echo "Usage: godir <regex>"
1022 return
1023 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001024 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001025 if [[ ! -f $T/filelist ]]; then
1026 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001027 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001028 echo " Done"
1029 echo ""
1030 fi
1031 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001032 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001033 if [[ ${#lines[@]} = 0 ]]; then
1034 echo "Not found"
1035 return
1036 fi
1037 local pathname
1038 local choice
1039 if [[ ${#lines[@]} > 1 ]]; then
1040 while [[ -z "$pathname" ]]; do
1041 local index=1
1042 local line
1043 for line in ${lines[@]}; do
1044 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001045 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001046 done
1047 echo
1048 echo -n "Select one: "
1049 unset choice
1050 read choice
1051 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1052 echo "Invalid choice"
1053 continue
1054 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001055 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001056 done
1057 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001058 pathname=${lines[0]}
1059 fi
1060 cd $T/$pathname
1061}
1062
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001063# Force JAVA_HOME to point to java 1.6 if it isn't already set
1064function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001065 if [ ! "$JAVA_HOME" ]; then
1066 case `uname -s` in
1067 Darwin)
1068 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1069 ;;
1070 *)
1071 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1072 ;;
1073 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001074 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001075}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001076
Raphael Moll70a86b02011-06-20 16:03:14 -07001077if [ "x$SHELL" != "x/bin/bash" ]; then
1078 case `ps -o command -p $$` in
1079 *bash*)
1080 ;;
1081 *)
1082 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1083 ;;
1084 esac
1085fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001086
1087# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001088for 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 -08001089do
1090 echo "including $f"
1091 . $f
1092done
1093unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001094
1095addcompletions