blob: 6ad4600ce4612a48b297b2c8e89c3d97daaaaff6 [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)
Jean-Baptiste Querua50ef1c2012-04-20 16:15:42 -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=
Mark D Horn7d0ede72012-03-14 14:20:30 -0700119 case $(get_build_var TARGET_ARCH) in
H.J. Lu402d7f32012-04-29 07:34:54 -0700120 x86) toolchaindir=x86/i686-linux-android-4.6/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700121 ;;
Jean-Baptiste Querua50ef1c2012-04-20 16:15:42 -0700122 arm|*) toolchaindir=arm/arm-linux-androideabi-4.6/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700123 ;;
124 esac
Raphael Mollc639c782011-06-20 17:25:01 -0700125 if [ -d "$prebuiltdir/$toolchaindir" ]; then
126 export ANDROID_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700127 fi
Raphael732936d2011-06-22 14:35:32 -0700128
129 export ARM_EABI_TOOLCHAIN=
130 toolchaindir=toolchain/arm-eabi-4.4.3/bin
131 if [ -d "$prebuiltdir/$toolchaindir" ]; then
132 export ARM_EABI_TOOLCHAIN=$prebuiltdir/$toolchaindir
133 fi
134
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
136 export ANDROID_QTOOLS=$T/development/emulator/qtools
Jing Yu9d396e32010-07-29 15:07:31 -0700137 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 -0700138 export PATH=$PATH$ANDROID_BUILD_PATHS
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800139
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500140 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900141 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500142 if [ -n "$JAVA_HOME" ]; then
143 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900144 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
145 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500146 fi
147
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800148 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700149 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
150 export OUT=$ANDROID_PRODUCT_OUT
151
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700152 unset ANDROID_HOST_OUT
153 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
154
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800155 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700156 # TODO: fix the path
157 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
158}
159
160function printconfig()
161{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800162 T=$(gettop)
163 if [ ! "$T" ]; then
164 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
165 return
166 fi
167 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700168}
169
170function set_stuff_for_environment()
171{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800172 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500173 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800174 setpaths
175 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700176
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800177 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700178}
179
180function set_sequence_number()
181{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700182 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700183}
184
185function settitle()
186{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800187 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Joe Onoratoda12daf2010-06-09 18:18:31 -0700188 local product=$TARGET_PRODUCT
189 local variant=$TARGET_BUILD_VARIANT
190 local apps=$TARGET_BUILD_APPS
191 if [ -z "$apps" ]; then
192 export PROMPT_COMMAND="echo -ne \"\033]0;[${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
193 else
194 export PROMPT_COMMAND="echo -ne \"\033]0;[$apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
195 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800196 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700197}
198
Kenny Root52aa81c2011-07-15 11:07:06 -0700199function addcompletions()
200{
201 local T dir f
202
203 # Keep us from trying to run in something that isn't bash.
204 if [ -z "${BASH_VERSION}" ]; then
205 return
206 fi
207
208 # Keep us from trying to run in bash that's too old.
209 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
210 return
211 fi
212
213 dir="sdk/bash_completion"
214 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700215 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700216 echo "including $f"
217 . $f
218 done
219 fi
220}
221
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700222function choosetype()
223{
224 echo "Build type choices are:"
225 echo " 1. release"
226 echo " 2. debug"
227 echo
228
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700230 DEFAULT_NUM=1
231 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700232
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 export TARGET_BUILD_TYPE=
234 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700235 while [ -z $TARGET_BUILD_TYPE ]
236 do
237 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 if [ -z "$1" ] ; then
239 read ANSWER
240 else
241 echo $1
242 ANSWER=$1
243 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700244 case $ANSWER in
245 "")
246 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
247 ;;
248 1)
249 export TARGET_BUILD_TYPE=release
250 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 release)
252 export TARGET_BUILD_TYPE=release
253 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700254 2)
255 export TARGET_BUILD_TYPE=debug
256 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800257 debug)
258 export TARGET_BUILD_TYPE=debug
259 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260 *)
261 echo
262 echo "I didn't understand your response. Please try again."
263 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700264 ;;
265 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 if [ -n "$1" ] ; then
267 break
268 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700269 done
270
271 set_stuff_for_environment
272}
273
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800274#
275# This function isn't really right: It chooses a TARGET_PRODUCT
276# based on the list of boards. Usually, that gets you something
277# that kinda works with a generic product, but really, you should
278# pick a product by name.
279#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700280function chooseproduct()
281{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700282 if [ "x$TARGET_PRODUCT" != x ] ; then
283 default_value=$TARGET_PRODUCT
284 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700285 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700286 fi
287
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800288 export TARGET_PRODUCT=
289 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700290 while [ -z "$TARGET_PRODUCT" ]
291 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700292 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800293 if [ -z "$1" ] ; then
294 read ANSWER
295 else
296 echo $1
297 ANSWER=$1
298 fi
299
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300 if [ -z "$ANSWER" ] ; then
301 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800302 else
303 if check_product $ANSWER
304 then
305 export TARGET_PRODUCT=$ANSWER
306 else
307 echo "** Not a valid product: $ANSWER"
308 fi
309 fi
310 if [ -n "$1" ] ; then
311 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312 fi
313 done
314
315 set_stuff_for_environment
316}
317
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800318function choosevariant()
319{
320 echo "Variant choices are:"
321 local index=1
322 local v
323 for v in ${VARIANT_CHOICES[@]}
324 do
325 # The product name is the name of the directory containing
326 # the makefile we found, above.
327 echo " $index. $v"
328 index=$(($index+1))
329 done
330
331 local default_value=eng
332 local ANSWER
333
334 export TARGET_BUILD_VARIANT=
335 while [ -z "$TARGET_BUILD_VARIANT" ]
336 do
337 echo -n "Which would you like? [$default_value] "
338 if [ -z "$1" ] ; then
339 read ANSWER
340 else
341 echo $1
342 ANSWER=$1
343 fi
344
345 if [ -z "$ANSWER" ] ; then
346 export TARGET_BUILD_VARIANT=$default_value
347 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
348 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800349 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350 fi
351 else
352 if check_variant $ANSWER
353 then
354 export TARGET_BUILD_VARIANT=$ANSWER
355 else
356 echo "** Not a valid variant: $ANSWER"
357 fi
358 fi
359 if [ -n "$1" ] ; then
360 break
361 fi
362 done
363}
364
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365function choosecombo()
366{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700367 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368
369 echo
370 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700371 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700372
373 echo
374 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700375 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800376
377 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800379 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700380}
381
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800382# Clear this variable. It will be built up again when the vendorsetup.sh
383# files are included at the end of this file.
384unset LUNCH_MENU_CHOICES
385function add_lunch_combo()
386{
387 local new_combo=$1
388 local c
389 for c in ${LUNCH_MENU_CHOICES[@]} ; do
390 if [ "$new_combo" = "$c" ] ; then
391 return
392 fi
393 done
394 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
395}
396
397# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700398add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700399add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800400add_lunch_combo vbox_x86-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800401
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700402function print_lunch_menu()
403{
404 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700405 echo
406 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407 echo
408 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800409
410 local i=1
411 local choice
412 for choice in ${LUNCH_MENU_CHOICES[@]}
413 do
414 echo " $i. $choice"
415 i=$(($i+1))
416 done
417
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700418 echo
419}
420
421function lunch()
422{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800423 local answer
424
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700425 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800426 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700427 else
428 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700429 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800430 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431 fi
432
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800433 local selection=
434
435 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700436 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700437 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800438 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
439 then
440 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
441 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800442 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800443 fi
444 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
445 then
446 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447 fi
448
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800449 if [ -z "$selection" ]
450 then
451 echo
452 echo "Invalid lunch combo: $answer"
453 return 1
454 fi
455
Joe Onoratoda12daf2010-06-09 18:18:31 -0700456 export TARGET_BUILD_APPS=
457
Jeff Browne33ba4c2011-07-11 22:11:46 -0700458 local product=$(echo -n $selection | sed -e "s/-.*$//")
459 check_product $product
460 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800461 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700462 echo
463 echo "** Don't have a product spec for: '$product'"
464 echo "** Do you have the right repo manifest?"
465 product=
466 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800467
Jeff Browne33ba4c2011-07-11 22:11:46 -0700468 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
469 check_variant $variant
470 if [ $? -ne 0 ]
471 then
472 echo
473 echo "** Invalid variant: '$variant'"
474 echo "** Must be one of ${VARIANT_CHOICES[@]}"
475 variant=
476 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477
Jeff Browne33ba4c2011-07-11 22:11:46 -0700478 if [ -z "$product" -o -z "$variant" ]
479 then
480 echo
481 return 1
482 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483
Jeff Browne33ba4c2011-07-11 22:11:46 -0700484 export TARGET_PRODUCT=$product
485 export TARGET_BUILD_VARIANT=$variant
486 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700487
488 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800489
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700490 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700492}
493
Jeff Davidson513d7a42010-08-02 10:00:44 -0700494# Tab completion for lunch.
495function _lunch()
496{
497 local cur prev opts
498 COMPREPLY=()
499 cur="${COMP_WORDS[COMP_CWORD]}"
500 prev="${COMP_WORDS[COMP_CWORD-1]}"
501
502 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
503 return 0
504}
505complete -F _lunch lunch
506
Joe Onoratoda12daf2010-06-09 18:18:31 -0700507# Configures the build to build unbundled apps.
508# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
509function tapas()
510{
511 local variant=$(echo -n $(echo $* | xargs -n 1 echo | grep -E '^(user|userdebug|eng)$'))
512 local apps=$(echo -n $(echo $* | xargs -n 1 echo | grep -E -v '^(user|userdebug|eng)$'))
513
514 if [ $(echo $variant | wc -w) -gt 1 ]; then
515 echo "tapas: Error: Multiple build variants supplied: $variant"
516 return
517 fi
518 if [ -z "$variant" ]; then
519 variant=eng
520 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700521 if [ -z "$apps" ]; then
522 apps=all
523 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700524
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700525 export TARGET_PRODUCT=full
Joe Onoratoda12daf2010-06-09 18:18:31 -0700526 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700527 export TARGET_BUILD_TYPE=release
528 export TARGET_BUILD_APPS=$apps
529
530 set_stuff_for_environment
531 printconfig
532}
533
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700534function gettop
535{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800536 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700537 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
538 echo $TOP
539 else
540 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800541 # The following circumlocution (repeated below as well) ensures
542 # that we record the true directory name and not one that is
543 # faked up with symlink names.
544 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700545 else
546 # We redirect cd to /dev/null in case it's aliased to
547 # a command that prints something as a side-effect
548 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800549 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700550 T=
551 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
552 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800553 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700554 done
555 cd $HERE > /dev/null
556 if [ -f "$T/$TOPFILE" ]; then
557 echo $T
558 fi
559 fi
560 fi
561}
562
563function m()
564{
565 T=$(gettop)
566 if [ "$T" ]; then
567 make -C $T $@
568 else
569 echo "Couldn't locate the top of the tree. Try setting TOP."
570 fi
571}
572
573function findmakefile()
574{
575 TOPFILE=build/core/envsetup.mk
576 # We redirect cd to /dev/null in case it's aliased to
577 # a command that prints something as a side-effect
578 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800579 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580 T=
581 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
582 T=$PWD
583 if [ -f "$T/Android.mk" ]; then
584 echo $T/Android.mk
585 cd $HERE > /dev/null
586 return
587 fi
588 cd .. > /dev/null
589 done
590 cd $HERE > /dev/null
591}
592
593function mm()
594{
595 # If we're sitting in the root of the build tree, just do a
596 # normal make.
597 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
598 make $@
599 else
600 # Find the closest Android.mk file.
601 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700603 # Remove the path to top as the makefilepath needs to be relative
604 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700605 if [ ! "$T" ]; then
606 echo "Couldn't locate the top of the tree. Try setting TOP."
607 elif [ ! "$M" ]; then
608 echo "Couldn't locate a makefile from the current directory."
609 else
Ying Wang01884142010-07-20 16:18:16 -0700610 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700611 fi
612 fi
613}
614
615function mmm()
616{
617 T=$(gettop)
618 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800619 local MAKEFILE=
620 local ARGS=
621 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800622 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
623 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
624 for DIR in $DIRS ; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700625 DIR=`echo $DIR | sed -e 's:/$::'`
626 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700627 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700628 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800629 START=`PWD= /bin/pwd`
630 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700631 if [ "$MFILE" = "" ] ; then
632 MFILE=$DIR/Android.mk
633 else
634 MFILE=$MFILE/$DIR/Android.mk
635 fi
636 MAKEFILE="$MAKEFILE $MFILE"
637 else
638 if [ "$DIR" = snod ]; then
639 ARGS="$ARGS snod"
640 elif [ "$DIR" = showcommands ]; then
641 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700642 elif [ "$DIR" = dist ]; then
643 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800644 elif [ "$DIR" = incrementaljavac ]; then
645 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700646 else
647 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400648 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700649 fi
650 fi
651 done
Ying Wang01884142010-07-20 16:18:16 -0700652 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS all_modules $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 else
654 echo "Couldn't locate the top of the tree. Try setting TOP."
655 fi
656}
657
658function croot()
659{
660 T=$(gettop)
661 if [ "$T" ]; then
662 cd $(gettop)
663 else
664 echo "Couldn't locate the top of the tree. Try setting TOP."
665 fi
666}
667
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700668function cproj()
669{
670 TOPFILE=build/core/envsetup.mk
671 # We redirect cd to /dev/null in case it's aliased to
672 # a command that prints something as a side-effect
673 # (like pushd)
674 local HERE=$PWD
675 T=
676 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
677 T=$PWD
678 if [ -f "$T/Android.mk" ]; then
679 cd $T
680 return
681 fi
682 cd .. > /dev/null
683 done
684 cd $HERE > /dev/null
685 echo "can't find Android.mk"
686}
687
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700688function pid()
689{
690 local EXE="$1"
691 if [ "$EXE" ] ; then
692 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
693 echo "$PID"
694 else
695 echo "usage: pid name"
696 fi
697}
698
Christopher Tate744ee802009-11-12 15:33:08 -0800699# systemstack - dump the current stack trace of all threads in the system process
700# to the usual ANR traces file
701function systemstack()
702{
703 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
704}
705
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700706function gdbclient()
707{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800708 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
709 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
710 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
711 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
712 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700713 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
714 local EXE="$1"
715 if [ "$EXE" ] ; then
716 EXE=$1
717 else
718 EXE="app_process"
719 fi
720
721 local PORT="$2"
722 if [ "$PORT" ] ; then
723 PORT=$2
724 else
725 PORT=":5039"
726 fi
727
728 local PID
729 local PROG="$3"
730 if [ "$PROG" ] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700731 if [[ "$PROG" =~ ^[0-9]+$ ]] ; then
732 PID="$3"
733 else
734 PID=`pid $3`
735 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700736 adb forward "tcp$PORT" "tcp$PORT"
737 adb shell gdbserver $PORT --attach $PID &
738 sleep 2
739 else
740 echo ""
741 echo "If you haven't done so already, do this first on the device:"
742 echo " gdbserver $PORT /system/bin/$EXE"
743 echo " or"
744 echo " gdbserver $PORT --attach $PID"
745 echo ""
746 fi
747
748 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
749 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS"
750 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
751 echo >>"$OUT_ROOT/gdbclient.cmds" ""
752
Mark D Horn7d0ede72012-03-14 14:20:30 -0700753 $ANDROID_EABI_TOOLCHAIN/*-gdb -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700754 else
755 echo "Unable to determine build system output dir."
756 fi
757
758}
759
760case `uname -s` in
761 Darwin)
762 function sgrep()
763 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700764 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 -0700765 }
766
767 ;;
768 *)
769 function sgrep()
770 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700771 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 -0700772 }
773 ;;
774esac
775
776function jgrep()
777{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700778 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 -0700779}
780
781function cgrep()
782{
Mike Dodd0c26d342011-04-07 13:29:06 -0700783 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 -0700784}
785
786function resgrep()
787{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700788 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 -0700789}
790
791case `uname -s` in
792 Darwin)
793 function mgrep()
794 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700795 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 -0700796 }
797
798 function treegrep()
799 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700800 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 -0700801 }
802
803 ;;
804 *)
805 function mgrep()
806 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700807 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 -0700808 }
809
810 function treegrep()
811 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700812 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 -0700813 }
814
815 ;;
816esac
817
818function getprebuilt
819{
820 get_abs_build_var ANDROID_PREBUILTS
821}
822
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823function tracedmdump()
824{
825 T=$(gettop)
826 if [ ! "$T" ]; then
827 echo "Couldn't locate the top of the tree. Try setting TOP."
828 return
829 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800830 local prebuiltdir=$(getprebuilt)
Jack Veenstra60116fc2009-04-09 18:12:34 -0700831 local KERNEL=$T/prebuilt/android-arm/kernel/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700832
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800833 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834 if [ ! "$TRACE" ] ; then
835 echo "usage: tracedmdump tracename"
836 return
837 fi
838
Jack Veenstra60116fc2009-04-09 18:12:34 -0700839 if [ ! -r "$KERNEL" ] ; then
840 echo "Error: cannot find kernel: '$KERNEL'"
841 return
842 fi
843
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800844 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 if [ "$BASETRACE" = "$TRACE" ] ; then
846 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
847 fi
848
849 echo "post-processing traces..."
850 rm -f $TRACE/qtrace.dexlist
851 post_trace $TRACE
852 if [ $? -ne 0 ]; then
853 echo "***"
854 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
855 echo "***"
856 return
857 fi
858 echo "generating dexlist output..."
859 /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
860 echo "generating dmtrace data..."
861 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
862 echo "generating html file..."
863 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
864 echo "done, see $TRACE/dmtrace.html for details"
865 echo "or run:"
866 echo " traceview $TRACE/dmtrace"
867}
868
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800869# communicate with a running device or emulator, set up necessary state,
870# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871function runhat()
872{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800873 # process standard adb options
874 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700875 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800876 adbTarget=$1
877 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700878 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800879 adbTarget="$1 $2"
880 shift 2
881 fi
882 local adbOptions=${adbTarget}
883 echo adbOptions = ${adbOptions}
884
885 # runhat options
886 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700887
888 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700889 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700890 return
891 fi
892
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800893 # confirm hat is available
894 if [ -z $(which hat) ]; then
895 echo "hat is not available in this configuration."
896 return
897 fi
898
Andy McFaddenb6289852010-07-12 08:00:19 -0700899 # issue "am" command to cause the hprof dump
900 local devFile=/sdcard/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700901 echo "Poking $targetPid and waiting for data..."
Andy McFaddenb6289852010-07-12 08:00:19 -0700902 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800903 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700904 echo -n "> "
905 read
906
The Android Open Source Project88b60792009-03-03 19:28:42 -0800907 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700908
The Android Open Source Project88b60792009-03-03 19:28:42 -0800909 echo "Retrieving file $devFile..."
910 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911
The Android Open Source Project88b60792009-03-03 19:28:42 -0800912 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700913
The Android Open Source Project88b60792009-03-03 19:28:42 -0800914 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915 echo "View the output by pointing your browser at http://localhost:7000/"
916 echo ""
The Android Open Source Project88b60792009-03-03 19:28:42 -0800917 hat $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700918}
919
920function getbugreports()
921{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800922 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700923
924 if [ ! "$reports" ]; then
925 echo "Could not locate any bugreports."
926 return
927 fi
928
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800929 local report
930 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700931 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800932 echo "/sdcard/bugreports/${report}"
933 adb pull /sdcard/bugreports/${report} ${report}
934 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700935 done
936}
937
938function startviewserver()
939{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800940 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700941 if [ $# -gt 0 ]; then
942 port=$1
943 fi
944 adb shell service call window 1 i32 $port
945}
946
947function stopviewserver()
948{
949 adb shell service call window 2
950}
951
952function isviewserverstarted()
953{
954 adb shell service call window 3
955}
956
Romain Guyb84049a2010-10-04 16:56:11 -0700957function key_home()
958{
959 adb shell input keyevent 3
960}
961
962function key_back()
963{
964 adb shell input keyevent 4
965}
966
967function key_menu()
968{
969 adb shell input keyevent 82
970}
971
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700972function smoketest()
973{
974 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
975 echo "Couldn't locate output files. Try running 'lunch' first." >&2
976 return
977 fi
978 T=$(gettop)
979 if [ ! "$T" ]; then
980 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
981 return
982 fi
983
984 (cd "$T" && mmm tests/SmokeTest) &&
985 adb uninstall com.android.smoketest > /dev/null &&
986 adb uninstall com.android.smoketest.tests > /dev/null &&
987 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
988 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
989 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
990}
991
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800992# simple shortcut to the runtest command
993function runtest()
994{
995 T=$(gettop)
996 if [ ! "$T" ]; then
997 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
998 return
999 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001000 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001001}
1002
The Android Open Source Project88b60792009-03-03 19:28:42 -08001003function godir () {
1004 if [[ -z "$1" ]]; then
1005 echo "Usage: godir <regex>"
1006 return
1007 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001008 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001009 if [[ ! -f $T/filelist ]]; then
1010 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001011 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001012 echo " Done"
1013 echo ""
1014 fi
1015 local lines
Doug Zongker29034982011-04-22 08:16:56 -07001016 lines=($(grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001017 if [[ ${#lines[@]} = 0 ]]; then
1018 echo "Not found"
1019 return
1020 fi
1021 local pathname
1022 local choice
1023 if [[ ${#lines[@]} > 1 ]]; then
1024 while [[ -z "$pathname" ]]; do
1025 local index=1
1026 local line
1027 for line in ${lines[@]}; do
1028 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001029 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001030 done
1031 echo
1032 echo -n "Select one: "
1033 unset choice
1034 read choice
1035 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1036 echo "Invalid choice"
1037 continue
1038 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001039 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001040 done
1041 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001042 pathname=${lines[0]}
1043 fi
1044 cd $T/$pathname
1045}
1046
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001047# Force JAVA_HOME to point to java 1.6 if it isn't already set
1048function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001049 if [ ! "$JAVA_HOME" ]; then
1050 case `uname -s` in
1051 Darwin)
1052 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1053 ;;
1054 *)
1055 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1056 ;;
1057 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001058 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001059}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001060
Raphael Moll70a86b02011-06-20 16:03:14 -07001061if [ "x$SHELL" != "x/bin/bash" ]; then
1062 case `ps -o command -p $$` in
1063 *bash*)
1064 ;;
1065 *)
1066 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1067 ;;
1068 esac
1069fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001070
1071# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001072for 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 -08001073do
1074 echo "including $f"
1075 . $f
1076done
1077unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001078
1079addcompletions