blob: ae1e944ad8bd955094ea0afafe0a4c1382dc971e [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:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
5- tapas: tapas [<App1> <App2> ...] [arm|x86|mips] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
7- m: Makes from the top of the tree.
8- mm: Builds all of the modules in the current directory.
9- mmm: Builds all of the modules in the supplied directories.
10- cgrep: Greps on all local C/C++ files.
11- jgrep: Greps on all local Java files.
12- resgrep: Greps on all local res/*.xml files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080013- godir: Go to the directory containing a file.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070014
15Look at the source to view more functions. The complete list is:
16EOF
17 T=$(gettop)
18 local A
19 A=""
20 for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
21 A="$A $i"
22 done
23 echo $A
24}
25
26# Get the value of a build variable as an absolute path.
27function get_abs_build_var()
28{
29 T=$(gettop)
30 if [ ! "$T" ]; then
31 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
32 return
33 fi
Brian Carlstrom177285a2010-04-06 13:22:02 -070034 (cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
35 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070036}
37
38# Get the exact value of a build variable.
39function get_build_var()
40{
41 T=$(gettop)
42 if [ ! "$T" ]; then
43 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
44 return
45 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080046 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
47 make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1
48}
49
50# check to see if the supplied product is one we can build
51function check_product()
52{
53 T=$(gettop)
54 if [ ! "$T" ]; then
55 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
56 return
57 fi
58 CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Jeff Browne33ba4c2011-07-11 22:11:46 -070059 TARGET_PRODUCT=$1 \
60 TARGET_BUILD_VARIANT= \
61 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070062 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080063 get_build_var TARGET_DEVICE > /dev/null
64 # hide successful answers, but allow the errors to show
65}
66
67VARIANT_CHOICES=(user userdebug eng)
68
69# check to see if the supplied variant is valid
70function check_variant()
71{
72 for v in ${VARIANT_CHOICES[@]}
73 do
74 if [ "$v" = "$1" ]
75 then
76 return 0
77 fi
78 done
79 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070080}
81
82function setpaths()
83{
84 T=$(gettop)
85 if [ ! "$T" ]; then
86 echo "Couldn't locate the top of the tree. Try setting TOP."
87 return
88 fi
89
90 ##################################################################
91 # #
92 # Read me before you modify this code #
93 # #
94 # This function sets ANDROID_BUILD_PATHS to what it is adding #
95 # to PATH, and the next time it is run, it removes that from #
96 # PATH. This is required so lunch can be run more than once #
97 # and still have working paths. #
98 # #
99 ##################################################################
100
Raphael Mollc639c782011-06-20 17:25:01 -0700101 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
102 # due to "C:\Program Files" being in the path.
103
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700104 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700105 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700106 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
107 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700108 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700109 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800110 # strip leading ':', if any
111 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500112 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700113
114 # and in with the new
115 CODE_REVIEWS=
116 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700117 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700118
Ben Cheng8bc4c432012-11-16 13:29:13 -0800119 # defined in core/config.mk
120 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
121
Raphael Mollc639c782011-06-20 17:25:01 -0700122 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700123 export ANDROID_EABI_TOOLCHAIN=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200124 local ARCH=$(get_build_var TARGET_ARCH)
125 case $ARCH in
H.J. Lu402d7f32012-04-29 07:34:54 -0700126 x86) toolchaindir=x86/i686-linux-android-4.6/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700127 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800128 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200129 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700130 mips) toolchaindir=mips/mipsel-linux-android-4.6/bin
131 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200132 *)
133 echo "Can't find toolchain for unknown architecture: $ARCH"
134 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700135 ;;
136 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700137 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
138 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700139 fi
Raphael732936d2011-06-22 14:35:32 -0700140
Bruce Beare42ced6d2012-07-17 21:40:01 -0700141 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700142 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700143 arm)
Ben Cheng8bc4c432012-11-16 13:29:13 -0800144 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700145 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
146 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
147 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
148 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700149 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700150 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
151 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700152 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700153 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700154 ;;
155 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700156
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700157 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
158 export ANDROID_QTOOLS=$T/development/emulator/qtools
Robert Greenwalt0987f032012-04-27 10:02:37 -0700159 export ANDROID_DEV_SCRIPTS=$T/development/scripts
Ying Wangaa1c9b52012-11-26 20:51:59 -0800160 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
161 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800162
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500163 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900164 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500165 if [ -n "$JAVA_HOME" ]; then
166 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900167 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
168 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500169 fi
170
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800171 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700172 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
173 export OUT=$ANDROID_PRODUCT_OUT
174
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700175 unset ANDROID_HOST_OUT
176 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
177
Ben Cheng057fde12011-11-28 13:55:14 -0800178 # needed for processing samples collected by perf counters
179 unset OPROFILE_EVENTS_DIR
180 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
181
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800182 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700183 # TODO: fix the path
184 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
185}
186
187function printconfig()
188{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800189 T=$(gettop)
190 if [ ! "$T" ]; then
191 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
192 return
193 fi
194 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700195}
196
197function set_stuff_for_environment()
198{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800199 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500200 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800201 setpaths
202 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700203
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800204 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700205}
206
207function set_sequence_number()
208{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700209 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700210}
211
212function settitle()
213{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800214 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700215 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700216 local product=$TARGET_PRODUCT
217 local variant=$TARGET_BUILD_VARIANT
218 local apps=$TARGET_BUILD_APPS
219 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700220 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700221 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700222 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700223 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800224 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700225}
226
Kenny Root52aa81c2011-07-15 11:07:06 -0700227function addcompletions()
228{
229 local T dir f
230
231 # Keep us from trying to run in something that isn't bash.
232 if [ -z "${BASH_VERSION}" ]; then
233 return
234 fi
235
236 # Keep us from trying to run in bash that's too old.
237 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
238 return
239 fi
240
241 dir="sdk/bash_completion"
242 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700243 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700244 echo "including $f"
245 . $f
246 done
247 fi
248}
249
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250function choosetype()
251{
252 echo "Build type choices are:"
253 echo " 1. release"
254 echo " 2. debug"
255 echo
256
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800257 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700258 DEFAULT_NUM=1
259 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800261 export TARGET_BUILD_TYPE=
262 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263 while [ -z $TARGET_BUILD_TYPE ]
264 do
265 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 if [ -z "$1" ] ; then
267 read ANSWER
268 else
269 echo $1
270 ANSWER=$1
271 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700272 case $ANSWER in
273 "")
274 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
275 ;;
276 1)
277 export TARGET_BUILD_TYPE=release
278 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800279 release)
280 export TARGET_BUILD_TYPE=release
281 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700282 2)
283 export TARGET_BUILD_TYPE=debug
284 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800285 debug)
286 export TARGET_BUILD_TYPE=debug
287 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700288 *)
289 echo
290 echo "I didn't understand your response. Please try again."
291 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700292 ;;
293 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 if [ -n "$1" ] ; then
295 break
296 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297 done
298
299 set_stuff_for_environment
300}
301
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800302#
303# This function isn't really right: It chooses a TARGET_PRODUCT
304# based on the list of boards. Usually, that gets you something
305# that kinda works with a generic product, but really, you should
306# pick a product by name.
307#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308function chooseproduct()
309{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310 if [ "x$TARGET_PRODUCT" != x ] ; then
311 default_value=$TARGET_PRODUCT
312 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700313 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314 fi
315
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 export TARGET_PRODUCT=
317 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318 while [ -z "$TARGET_PRODUCT" ]
319 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700320 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 if [ -z "$1" ] ; then
322 read ANSWER
323 else
324 echo $1
325 ANSWER=$1
326 fi
327
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328 if [ -z "$ANSWER" ] ; then
329 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 else
331 if check_product $ANSWER
332 then
333 export TARGET_PRODUCT=$ANSWER
334 else
335 echo "** Not a valid product: $ANSWER"
336 fi
337 fi
338 if [ -n "$1" ] ; then
339 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700340 fi
341 done
342
343 set_stuff_for_environment
344}
345
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800346function choosevariant()
347{
348 echo "Variant choices are:"
349 local index=1
350 local v
351 for v in ${VARIANT_CHOICES[@]}
352 do
353 # The product name is the name of the directory containing
354 # the makefile we found, above.
355 echo " $index. $v"
356 index=$(($index+1))
357 done
358
359 local default_value=eng
360 local ANSWER
361
362 export TARGET_BUILD_VARIANT=
363 while [ -z "$TARGET_BUILD_VARIANT" ]
364 do
365 echo -n "Which would you like? [$default_value] "
366 if [ -z "$1" ] ; then
367 read ANSWER
368 else
369 echo $1
370 ANSWER=$1
371 fi
372
373 if [ -z "$ANSWER" ] ; then
374 export TARGET_BUILD_VARIANT=$default_value
375 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
376 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800377 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800378 fi
379 else
380 if check_variant $ANSWER
381 then
382 export TARGET_BUILD_VARIANT=$ANSWER
383 else
384 echo "** Not a valid variant: $ANSWER"
385 fi
386 fi
387 if [ -n "$1" ] ; then
388 break
389 fi
390 done
391}
392
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700393function choosecombo()
394{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700395 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700396
397 echo
398 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700399 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700400
401 echo
402 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700403 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800404
405 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700406 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800407 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700408}
409
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800410# Clear this variable. It will be built up again when the vendorsetup.sh
411# files are included at the end of this file.
412unset LUNCH_MENU_CHOICES
413function add_lunch_combo()
414{
415 local new_combo=$1
416 local c
417 for c in ${LUNCH_MENU_CHOICES[@]} ; do
418 if [ "$new_combo" = "$c" ] ; then
419 return
420 fi
421 done
422 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
423}
424
425# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700426add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700427add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800428add_lunch_combo vbox_x86-eng
Raghu Gandham8da43102012-07-25 19:57:22 -0700429add_lunch_combo full_mips-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800430
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700431function print_lunch_menu()
432{
433 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700434 echo
435 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700436 echo
437 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800438
439 local i=1
440 local choice
441 for choice in ${LUNCH_MENU_CHOICES[@]}
442 do
443 echo " $i. $choice"
444 i=$(($i+1))
445 done
446
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700447 echo
448}
449
450function lunch()
451{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452 local answer
453
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700454 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800455 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700456 else
457 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700458 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460 fi
461
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462 local selection=
463
464 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700466 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800467 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
468 then
469 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
470 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800471 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 fi
473 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
474 then
475 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476 fi
477
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800478 if [ -z "$selection" ]
479 then
480 echo
481 echo "Invalid lunch combo: $answer"
482 return 1
483 fi
484
Joe Onoratoda12daf2010-06-09 18:18:31 -0700485 export TARGET_BUILD_APPS=
486
Jeff Browne33ba4c2011-07-11 22:11:46 -0700487 local product=$(echo -n $selection | sed -e "s/-.*$//")
488 check_product $product
489 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700491 echo
492 echo "** Don't have a product spec for: '$product'"
493 echo "** Do you have the right repo manifest?"
494 product=
495 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496
Jeff Browne33ba4c2011-07-11 22:11:46 -0700497 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
498 check_variant $variant
499 if [ $? -ne 0 ]
500 then
501 echo
502 echo "** Invalid variant: '$variant'"
503 echo "** Must be one of ${VARIANT_CHOICES[@]}"
504 variant=
505 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506
Jeff Browne33ba4c2011-07-11 22:11:46 -0700507 if [ -z "$product" -o -z "$variant" ]
508 then
509 echo
510 return 1
511 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512
Jeff Browne33ba4c2011-07-11 22:11:46 -0700513 export TARGET_PRODUCT=$product
514 export TARGET_BUILD_VARIANT=$variant
515 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516
517 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700519 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700521}
522
Jeff Davidson513d7a42010-08-02 10:00:44 -0700523# Tab completion for lunch.
524function _lunch()
525{
526 local cur prev opts
527 COMPREPLY=()
528 cur="${COMP_WORDS[COMP_CWORD]}"
529 prev="${COMP_WORDS[COMP_CWORD-1]}"
530
531 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
532 return 0
533}
534complete -F _lunch lunch
535
Joe Onoratoda12daf2010-06-09 18:18:31 -0700536# Configures the build to build unbundled apps.
537# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
538function tapas()
539{
Ying Wang67f02922012-08-22 10:25:20 -0700540 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600541 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wang67f02922012-08-22 10:25:20 -0700542 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700543
Ying Wang67f02922012-08-22 10:25:20 -0700544 if [ $(echo $arch | wc -w) -gt 1 ]; then
545 echo "tapas: Error: Multiple build archs supplied: $arch"
546 return
547 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700548 if [ $(echo $variant | wc -w) -gt 1 ]; then
549 echo "tapas: Error: Multiple build variants supplied: $variant"
550 return
551 fi
Ying Wang67f02922012-08-22 10:25:20 -0700552
553 local product=full
554 case $arch in
555 x86) product=full_x86;;
556 mips) product=full_mips;;
557 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700558 if [ -z "$variant" ]; then
559 variant=eng
560 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700561 if [ -z "$apps" ]; then
562 apps=all
563 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700564
Ying Wang67f02922012-08-22 10:25:20 -0700565 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700566 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700567 export TARGET_BUILD_TYPE=release
568 export TARGET_BUILD_APPS=$apps
569
570 set_stuff_for_environment
571 printconfig
572}
573
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700574function gettop
575{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800576 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700577 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
578 echo $TOP
579 else
580 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800581 # The following circumlocution (repeated below as well) ensures
582 # that we record the true directory name and not one that is
583 # faked up with symlink names.
584 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 else
586 # We redirect cd to /dev/null in case it's aliased to
587 # a command that prints something as a side-effect
588 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 T=
591 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
592 cd .. > /dev/null
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800593 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700594 done
595 cd $HERE > /dev/null
596 if [ -f "$T/$TOPFILE" ]; then
597 echo $T
598 fi
599 fi
600 fi
601}
602
603function m()
604{
605 T=$(gettop)
606 if [ "$T" ]; then
607 make -C $T $@
608 else
609 echo "Couldn't locate the top of the tree. Try setting TOP."
610 fi
611}
612
613function findmakefile()
614{
615 TOPFILE=build/core/envsetup.mk
616 # We redirect cd to /dev/null in case it's aliased to
617 # a command that prints something as a side-effect
618 # (like pushd)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800619 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700620 T=
621 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700622 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700623 if [ -f "$T/Android.mk" ]; then
624 echo $T/Android.mk
625 cd $HERE > /dev/null
626 return
627 fi
628 cd .. > /dev/null
629 done
630 cd $HERE > /dev/null
631}
632
633function mm()
634{
635 # If we're sitting in the root of the build tree, just do a
636 # normal make.
637 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
638 make $@
639 else
640 # Find the closest Android.mk file.
641 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700643 # Remove the path to top as the makefilepath needs to be relative
644 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 if [ ! "$T" ]; then
646 echo "Couldn't locate the top of the tree. Try setting TOP."
647 elif [ ! "$M" ]; then
648 echo "Couldn't locate a makefile from the current directory."
649 else
Ying Wang01884142010-07-20 16:18:16 -0700650 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 fi
652 fi
653}
654
655function mmm()
656{
657 T=$(gettop)
658 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800660 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800661 local ARGS=
662 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800663 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
664 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
665 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800666 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
667 if [ "$MODULES" = "" ]; then
668 MODULES=all_modules
669 fi
670 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671 if [ -f $DIR/Android.mk ]; then
Brian Carlstromc634d2c2010-09-17 12:25:50 -0700672 TO_CHOP=`(cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700673 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800674 START=`PWD= /bin/pwd`
675 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700676 if [ "$MFILE" = "" ] ; then
677 MFILE=$DIR/Android.mk
678 else
679 MFILE=$MFILE/$DIR/Android.mk
680 fi
681 MAKEFILE="$MAKEFILE $MFILE"
682 else
683 if [ "$DIR" = snod ]; then
684 ARGS="$ARGS snod"
685 elif [ "$DIR" = showcommands ]; then
686 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700687 elif [ "$DIR" = dist ]; then
688 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800689 elif [ "$DIR" = incrementaljavac ]; then
690 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700691 else
692 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400693 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700694 fi
695 fi
696 done
Alon Albert68895a92011-11-30 12:40:19 -0800697 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700698 else
699 echo "Couldn't locate the top of the tree. Try setting TOP."
700 fi
701}
702
703function croot()
704{
705 T=$(gettop)
706 if [ "$T" ]; then
707 cd $(gettop)
708 else
709 echo "Couldn't locate the top of the tree. Try setting TOP."
710 fi
711}
712
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700713function cproj()
714{
715 TOPFILE=build/core/envsetup.mk
716 # We redirect cd to /dev/null in case it's aliased to
717 # a command that prints something as a side-effect
718 # (like pushd)
719 local HERE=$PWD
720 T=
721 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
722 T=$PWD
723 if [ -f "$T/Android.mk" ]; then
724 cd $T
725 return
726 fi
727 cd .. > /dev/null
728 done
729 cd $HERE > /dev/null
730 echo "can't find Android.mk"
731}
732
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700733function pid()
734{
735 local EXE="$1"
736 if [ "$EXE" ] ; then
737 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
738 echo "$PID"
739 else
740 echo "usage: pid name"
741 fi
742}
743
Christopher Tate744ee802009-11-12 15:33:08 -0800744# systemstack - dump the current stack trace of all threads in the system process
745# to the usual ANR traces file
746function systemstack()
747{
748 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
749}
750
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700751function gdbclient()
752{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800753 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
754 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
755 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
756 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
757 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800758 local ARCH=$(get_build_var TARGET_ARCH)
759 local GDB
760 case "$ARCH" in
Jean-Baptiste Querufeec98b2012-05-16 13:18:39 -0700761 x86) GDB=i686-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800762 arm) GDB=arm-linux-androideabi-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700763 mips) GDB=mipsel-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800764 *) echo "Unknown arch $ARCH"; return 1;;
765 esac
766
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
768 local EXE="$1"
769 if [ "$EXE" ] ; then
770 EXE=$1
771 else
772 EXE="app_process"
773 fi
774
775 local PORT="$2"
776 if [ "$PORT" ] ; then
777 PORT=$2
778 else
779 PORT=":5039"
780 fi
781
Chris Craik20c136a2012-11-09 18:02:19 -0800782 local PID="$3"
783 if [ "$PID" ] ; then
784 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700785 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800786 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
787 # that likely didn't work because of returning multiple processes
788 # try again, filtering by root processes (don't contain colon)
789 PID=`adb shell ps | grep $3 | grep -v ":" | awk '{print $2}'`
790 if [[ ! "$PID" =~ ^[0-9]+$ ]]
791 then
792 echo "Couldn't resolve '$3' to single PID"
793 return 1
794 else
795 echo ""
796 echo "WARNING: multiple processes matching '$3' observed, using root process"
797 echo ""
798 fi
799 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -0700800 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 adb forward "tcp$PORT" "tcp$PORT"
802 adb shell gdbserver $PORT --attach $PID &
803 sleep 2
804 else
805 echo ""
806 echo "If you haven't done so already, do this first on the device:"
807 echo " gdbserver $PORT /system/bin/$EXE"
808 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -0800809 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700810 echo ""
811 fi
812
813 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Chris Dearman6858d512012-02-02 14:16:52 -0800814 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700815 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
816 echo >>"$OUT_ROOT/gdbclient.cmds" ""
817
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200818 $ANDROID_TOOLCHAIN/$GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819 else
820 echo "Unable to determine build system output dir."
821 fi
822
823}
824
825case `uname -s` in
826 Darwin)
827 function sgrep()
828 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700829 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 -0700830 }
831
832 ;;
833 *)
834 function sgrep()
835 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700836 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 -0700837 }
838 ;;
839esac
840
Raghu Gandham8da43102012-07-25 19:57:22 -0700841function gettargetarch
842{
843 get_build_var TARGET_ARCH
844}
845
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846function jgrep()
847{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700848 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 -0700849}
850
851function cgrep()
852{
Mike Dodd0c26d342011-04-07 13:29:06 -0700853 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 -0700854}
855
856function resgrep()
857{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700858 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 -0700859}
860
861case `uname -s` in
862 Darwin)
863 function mgrep()
864 {
Ying Wang324c2b22012-08-17 15:03:20 -0700865 find -E . -name .repo -prune -o -name .git -prune -o -path ./out -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 -0700866 }
867
868 function treegrep()
869 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700870 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 -0700871 }
872
873 ;;
874 *)
875 function mgrep()
876 {
Ying Wang324c2b22012-08-17 15:03:20 -0700877 find . -name .repo -prune -o -name .git -prune -o -path ./out -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 -0700878 }
879
880 function treegrep()
881 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700882 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 -0700883 }
884
885 ;;
886esac
887
888function getprebuilt
889{
890 get_abs_build_var ANDROID_PREBUILTS
891}
892
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700893function tracedmdump()
894{
895 T=$(gettop)
896 if [ ! "$T" ]; then
897 echo "Couldn't locate the top of the tree. Try setting TOP."
898 return
899 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800900 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -0700901 local arch=$(gettargetarch)
902 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700903
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800904 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700905 if [ ! "$TRACE" ] ; then
906 echo "usage: tracedmdump tracename"
907 return
908 fi
909
Jack Veenstra60116fc2009-04-09 18:12:34 -0700910 if [ ! -r "$KERNEL" ] ; then
911 echo "Error: cannot find kernel: '$KERNEL'"
912 return
913 fi
914
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800915 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700916 if [ "$BASETRACE" = "$TRACE" ] ; then
917 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
918 fi
919
920 echo "post-processing traces..."
921 rm -f $TRACE/qtrace.dexlist
922 post_trace $TRACE
923 if [ $? -ne 0 ]; then
924 echo "***"
925 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
926 echo "***"
927 return
928 fi
929 echo "generating dexlist output..."
930 /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
931 echo "generating dmtrace data..."
932 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
933 echo "generating html file..."
934 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
935 echo "done, see $TRACE/dmtrace.html for details"
936 echo "or run:"
937 echo " traceview $TRACE/dmtrace"
938}
939
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800940# communicate with a running device or emulator, set up necessary state,
941# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942function runhat()
943{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800944 # process standard adb options
945 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700946 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800947 adbTarget=$1
948 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700949 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800950 adbTarget="$1 $2"
951 shift 2
952 fi
953 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -0700954 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800955
956 # runhat options
957 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700958
959 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700960 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700961 return
962 fi
963
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800964 # confirm hat is available
965 if [ -z $(which hat) ]; then
966 echo "hat is not available in this configuration."
967 return
968 fi
969
Andy McFaddenb6289852010-07-12 08:00:19 -0700970 # issue "am" command to cause the hprof dump
Dianne Hackborn6b9549f2012-09-26 15:00:59 -0700971 local sdcard=$(adb shell echo -n '$EXTERNAL_STORAGE')
972 local devFile=$sdcard/hprof-$targetPid
973 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700974 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -0700975 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -0700976 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800977 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700978 echo -n "> "
979 read
980
The Android Open Source Project88b60792009-03-03 19:28:42 -0800981 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700982
The Android Open Source Project88b60792009-03-03 19:28:42 -0800983 echo "Retrieving file $devFile..."
984 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700985
The Android Open Source Project88b60792009-03-03 19:28:42 -0800986 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700987
The Android Open Source Project88b60792009-03-03 19:28:42 -0800988 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700989 echo "View the output by pointing your browser at http://localhost:7000/"
990 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -0800991 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992}
993
994function getbugreports()
995{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800996 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700997
998 if [ ! "$reports" ]; then
999 echo "Could not locate any bugreports."
1000 return
1001 fi
1002
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001003 local report
1004 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001005 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001006 echo "/sdcard/bugreports/${report}"
1007 adb pull /sdcard/bugreports/${report} ${report}
1008 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001009 done
1010}
1011
Victoria Lease1b296b42012-08-21 15:44:06 -07001012function getsdcardpath()
1013{
1014 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1015}
1016
1017function getscreenshotpath()
1018{
1019 echo "$(getsdcardpath)/Pictures/Screenshots"
1020}
1021
1022function getlastscreenshot()
1023{
1024 local screenshot_path=$(getscreenshotpath)
1025 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1026 if [ "$screenshot" = "" ]; then
1027 echo "No screenshots found."
1028 return
1029 fi
1030 echo "${screenshot}"
1031 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1032}
1033
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001034function startviewserver()
1035{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001036 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001037 if [ $# -gt 0 ]; then
1038 port=$1
1039 fi
1040 adb shell service call window 1 i32 $port
1041}
1042
1043function stopviewserver()
1044{
1045 adb shell service call window 2
1046}
1047
1048function isviewserverstarted()
1049{
1050 adb shell service call window 3
1051}
1052
Romain Guyb84049a2010-10-04 16:56:11 -07001053function key_home()
1054{
1055 adb shell input keyevent 3
1056}
1057
1058function key_back()
1059{
1060 adb shell input keyevent 4
1061}
1062
1063function key_menu()
1064{
1065 adb shell input keyevent 82
1066}
1067
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001068function smoketest()
1069{
1070 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1071 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1072 return
1073 fi
1074 T=$(gettop)
1075 if [ ! "$T" ]; then
1076 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1077 return
1078 fi
1079
1080 (cd "$T" && mmm tests/SmokeTest) &&
1081 adb uninstall com.android.smoketest > /dev/null &&
1082 adb uninstall com.android.smoketest.tests > /dev/null &&
1083 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1084 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1085 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1086}
1087
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001088# simple shortcut to the runtest command
1089function runtest()
1090{
1091 T=$(gettop)
1092 if [ ! "$T" ]; then
1093 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1094 return
1095 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001096 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001097}
1098
The Android Open Source Project88b60792009-03-03 19:28:42 -08001099function godir () {
1100 if [[ -z "$1" ]]; then
1101 echo "Usage: godir <regex>"
1102 return
1103 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001104 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001105 if [[ ! -f $T/filelist ]]; then
1106 echo -n "Creating index..."
Brian Carlstrom259e5b72010-01-30 11:45:03 -08001107 (cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001108 echo " Done"
1109 echo ""
1110 fi
1111 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001112 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001113 if [[ ${#lines[@]} = 0 ]]; then
1114 echo "Not found"
1115 return
1116 fi
1117 local pathname
1118 local choice
1119 if [[ ${#lines[@]} > 1 ]]; then
1120 while [[ -z "$pathname" ]]; do
1121 local index=1
1122 local line
1123 for line in ${lines[@]}; do
1124 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001125 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001126 done
1127 echo
1128 echo -n "Select one: "
1129 unset choice
1130 read choice
1131 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1132 echo "Invalid choice"
1133 continue
1134 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001135 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001136 done
1137 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001138 pathname=${lines[0]}
1139 fi
1140 cd $T/$pathname
1141}
1142
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001143# Force JAVA_HOME to point to java 1.6 if it isn't already set
1144function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001145 if [ ! "$JAVA_HOME" ]; then
1146 case `uname -s` in
1147 Darwin)
1148 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1149 ;;
1150 *)
1151 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1152 ;;
1153 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001154 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001155}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001156
Raphael Moll70a86b02011-06-20 16:03:14 -07001157if [ "x$SHELL" != "x/bin/bash" ]; then
1158 case `ps -o command -p $$` in
1159 *bash*)
1160 ;;
1161 *)
1162 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1163 ;;
1164 esac
1165fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001166
1167# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001168for 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 -08001169do
1170 echo "including $f"
1171 . $f
1172done
1173unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001174
1175addcompletions