blob: e2b6b134102efac51573f3adc5747f4d5992afce [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>
Ying Wangf05c4f72013-01-31 11:16:57 -08005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [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
Ying Wang9cd17642012-12-13 10:52:07 -080034 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Brian Carlstrom177285a2010-04-06 13:22:02 -070035 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)
Ben Cheng15266702012-12-10 16:04:39 -0800121 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800122
Raphael Mollc639c782011-06-20 17:25:01 -0700123 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Raphael732936d2011-06-22 14:35:32 -0700124 export ANDROID_EABI_TOOLCHAIN=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200125 local ARCH=$(get_build_var TARGET_ARCH)
126 case $ARCH in
Ben Cheng054ffd22012-12-11 14:01:10 -0800127 x86) toolchaindir=x86/i686-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700128 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800129 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200130 ;;
Ben Cheng054ffd22012-12-11 14:01:10 -0800131 mips) toolchaindir=mips/mipsel-linux-android-$targetgccversion/bin
Raghu Gandham8da43102012-07-25 19:57:22 -0700132 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200133 *)
134 echo "Can't find toolchain for unknown architecture: $ARCH"
135 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700136 ;;
137 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700138 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
139 export ANDROID_EABI_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700140 fi
Raphael732936d2011-06-22 14:35:32 -0700141
Bruce Beare42ced6d2012-07-17 21:40:01 -0700142 unset ARM_EABI_TOOLCHAIN ARM_EABI_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700143 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700144 arm)
Ben Cheng8bc4c432012-11-16 13:29:13 -0800145 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700146 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
147 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
148 ARM_EABI_TOOLCHAIN_PATH=":$gccprebuiltdir/$toolchaindir"
149 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700150 ;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700151 mips) toolchaindir=mips/mips-eabi-4.4.3/bin
152 ;;
Ying Wang08f5e9a2012-04-17 18:10:11 -0700153 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700154 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700155 ;;
156 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700157
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700158 export ANDROID_TOOLCHAIN=$ANDROID_EABI_TOOLCHAIN
159 export ANDROID_QTOOLS=$T/development/emulator/qtools
Robert Greenwalt0987f032012-04-27 10:02:37 -0700160 export ANDROID_DEV_SCRIPTS=$T/development/scripts
Ying Wangaa1c9b52012-11-26 20:51:59 -0800161 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN$ARM_EABI_TOOLCHAIN_PATH$CODE_REVIEWS:$ANDROID_DEV_SCRIPTS:
162 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800163
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500164 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900165 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500166 if [ -n "$JAVA_HOME" ]; then
167 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900168 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
169 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500170 fi
171
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800172 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700173 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
174 export OUT=$ANDROID_PRODUCT_OUT
175
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700176 unset ANDROID_HOST_OUT
177 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
178
Ben Cheng057fde12011-11-28 13:55:14 -0800179 # needed for processing samples collected by perf counters
180 unset OPROFILE_EVENTS_DIR
181 export OPROFILE_EVENTS_DIR=$T/external/oprofile/events
182
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800183 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700184 # TODO: fix the path
185 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
186}
187
188function printconfig()
189{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800190 T=$(gettop)
191 if [ ! "$T" ]; then
192 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
193 return
194 fi
195 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700196}
197
198function set_stuff_for_environment()
199{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800200 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500201 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800202 setpaths
203 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700204
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800205 export ANDROID_BUILD_TOP=$(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700206}
207
208function set_sequence_number()
209{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700210 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700211}
212
213function settitle()
214{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800215 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700216 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700217 local product=$TARGET_PRODUCT
218 local variant=$TARGET_BUILD_VARIANT
219 local apps=$TARGET_BUILD_APPS
220 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700221 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700222 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700223 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700224 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800225 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700226}
227
Kenny Root52aa81c2011-07-15 11:07:06 -0700228function addcompletions()
229{
230 local T dir f
231
232 # Keep us from trying to run in something that isn't bash.
233 if [ -z "${BASH_VERSION}" ]; then
234 return
235 fi
236
237 # Keep us from trying to run in bash that's too old.
238 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
239 return
240 fi
241
242 dir="sdk/bash_completion"
243 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700244 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700245 echo "including $f"
246 . $f
247 done
248 fi
249}
250
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700251function choosetype()
252{
253 echo "Build type choices are:"
254 echo " 1. release"
255 echo " 2. debug"
256 echo
257
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800258 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700259 DEFAULT_NUM=1
260 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800262 export TARGET_BUILD_TYPE=
263 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700264 while [ -z $TARGET_BUILD_TYPE ]
265 do
266 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800267 if [ -z "$1" ] ; then
268 read ANSWER
269 else
270 echo $1
271 ANSWER=$1
272 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700273 case $ANSWER in
274 "")
275 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
276 ;;
277 1)
278 export TARGET_BUILD_TYPE=release
279 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800280 release)
281 export TARGET_BUILD_TYPE=release
282 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700283 2)
284 export TARGET_BUILD_TYPE=debug
285 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800286 debug)
287 export TARGET_BUILD_TYPE=debug
288 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700289 *)
290 echo
291 echo "I didn't understand your response. Please try again."
292 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700293 ;;
294 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800295 if [ -n "$1" ] ; then
296 break
297 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298 done
299
300 set_stuff_for_environment
301}
302
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800303#
304# This function isn't really right: It chooses a TARGET_PRODUCT
305# based on the list of boards. Usually, that gets you something
306# that kinda works with a generic product, but really, you should
307# pick a product by name.
308#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700309function chooseproduct()
310{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700311 if [ "x$TARGET_PRODUCT" != x ] ; then
312 default_value=$TARGET_PRODUCT
313 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700314 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315 fi
316
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800317 export TARGET_PRODUCT=
318 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319 while [ -z "$TARGET_PRODUCT" ]
320 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700321 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800322 if [ -z "$1" ] ; then
323 read ANSWER
324 else
325 echo $1
326 ANSWER=$1
327 fi
328
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329 if [ -z "$ANSWER" ] ; then
330 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 else
332 if check_product $ANSWER
333 then
334 export TARGET_PRODUCT=$ANSWER
335 else
336 echo "** Not a valid product: $ANSWER"
337 fi
338 fi
339 if [ -n "$1" ] ; then
340 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700341 fi
342 done
343
344 set_stuff_for_environment
345}
346
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800347function choosevariant()
348{
349 echo "Variant choices are:"
350 local index=1
351 local v
352 for v in ${VARIANT_CHOICES[@]}
353 do
354 # The product name is the name of the directory containing
355 # the makefile we found, above.
356 echo " $index. $v"
357 index=$(($index+1))
358 done
359
360 local default_value=eng
361 local ANSWER
362
363 export TARGET_BUILD_VARIANT=
364 while [ -z "$TARGET_BUILD_VARIANT" ]
365 do
366 echo -n "Which would you like? [$default_value] "
367 if [ -z "$1" ] ; then
368 read ANSWER
369 else
370 echo $1
371 ANSWER=$1
372 fi
373
374 if [ -z "$ANSWER" ] ; then
375 export TARGET_BUILD_VARIANT=$default_value
376 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
377 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800378 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800379 fi
380 else
381 if check_variant $ANSWER
382 then
383 export TARGET_BUILD_VARIANT=$ANSWER
384 else
385 echo "** Not a valid variant: $ANSWER"
386 fi
387 fi
388 if [ -n "$1" ] ; then
389 break
390 fi
391 done
392}
393
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700394function choosecombo()
395{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700396 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700397
398 echo
399 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700400 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700401
402 echo
403 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700404 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800405
406 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800408 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700409}
410
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800411# Clear this variable. It will be built up again when the vendorsetup.sh
412# files are included at the end of this file.
413unset LUNCH_MENU_CHOICES
414function add_lunch_combo()
415{
416 local new_combo=$1
417 local c
418 for c in ${LUNCH_MENU_CHOICES[@]} ; do
419 if [ "$new_combo" = "$c" ] ; then
420 return
421 fi
422 done
423 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
424}
425
426# add the default one here
Jean-Baptiste Queru45038e02010-07-01 09:22:53 -0700427add_lunch_combo full-eng
Jean-Baptiste Queru6c2df3e2010-07-15 14:04:39 -0700428add_lunch_combo full_x86-eng
Bruce Beareba366c42011-02-15 16:46:08 -0800429add_lunch_combo vbox_x86-eng
Raghu Gandham8da43102012-07-25 19:57:22 -0700430add_lunch_combo full_mips-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800431
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700432function print_lunch_menu()
433{
434 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700435 echo
436 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700437 echo
438 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800439
440 local i=1
441 local choice
442 for choice in ${LUNCH_MENU_CHOICES[@]}
443 do
444 echo " $i. $choice"
445 i=$(($i+1))
446 done
447
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448 echo
449}
450
451function lunch()
452{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453 local answer
454
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457 else
458 print_lunch_menu
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700459 echo -n "Which would you like? [full-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 fi
462
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800463 local selection=
464
465 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466 then
Jean-Baptiste Queru0332f0a2010-10-22 09:52:09 -0700467 selection=full-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
469 then
470 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
471 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800472 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473 fi
474 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
475 then
476 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477 fi
478
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 if [ -z "$selection" ]
480 then
481 echo
482 echo "Invalid lunch combo: $answer"
483 return 1
484 fi
485
Joe Onoratoda12daf2010-06-09 18:18:31 -0700486 export TARGET_BUILD_APPS=
487
Jeff Browne33ba4c2011-07-11 22:11:46 -0700488 local product=$(echo -n $selection | sed -e "s/-.*$//")
489 check_product $product
490 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800491 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700492 echo
493 echo "** Don't have a product spec for: '$product'"
494 echo "** Do you have the right repo manifest?"
495 product=
496 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800497
Jeff Browne33ba4c2011-07-11 22:11:46 -0700498 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
499 check_variant $variant
500 if [ $? -ne 0 ]
501 then
502 echo
503 echo "** Invalid variant: '$variant'"
504 echo "** Must be one of ${VARIANT_CHOICES[@]}"
505 variant=
506 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507
Jeff Browne33ba4c2011-07-11 22:11:46 -0700508 if [ -z "$product" -o -z "$variant" ]
509 then
510 echo
511 return 1
512 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800513
Jeff Browne33ba4c2011-07-11 22:11:46 -0700514 export TARGET_PRODUCT=$product
515 export TARGET_BUILD_VARIANT=$variant
516 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517
518 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700520 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700522}
523
Jeff Davidson513d7a42010-08-02 10:00:44 -0700524# Tab completion for lunch.
525function _lunch()
526{
527 local cur prev opts
528 COMPREPLY=()
529 cur="${COMP_WORDS[COMP_CWORD]}"
530 prev="${COMP_WORDS[COMP_CWORD-1]}"
531
532 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
533 return 0
534}
535complete -F _lunch lunch
536
Joe Onoratoda12daf2010-06-09 18:18:31 -0700537# Configures the build to build unbundled apps.
538# Run tapas with one ore more app names (from LOCAL_PACKAGE_NAME)
539function tapas()
540{
Ying Wangf05c4f72013-01-31 11:16:57 -0800541 local arch=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5)$'))
Jeff Hamilton293f9392011-11-18 17:15:25 -0600542 local variant=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$'))
Ying Wangf05c4f72013-01-31 11:16:57 -0800543 local apps=$(echo -n $(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5)$'))
Joe Onoratoda12daf2010-06-09 18:18:31 -0700544
Ying Wang67f02922012-08-22 10:25:20 -0700545 if [ $(echo $arch | wc -w) -gt 1 ]; then
546 echo "tapas: Error: Multiple build archs supplied: $arch"
547 return
548 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700549 if [ $(echo $variant | wc -w) -gt 1 ]; then
550 echo "tapas: Error: Multiple build variants supplied: $variant"
551 return
552 fi
Ying Wang67f02922012-08-22 10:25:20 -0700553
554 local product=full
555 case $arch in
556 x86) product=full_x86;;
557 mips) product=full_mips;;
Ying Wangf05c4f72013-01-31 11:16:57 -0800558 armv5) product=generic_armv5;;
Ying Wang67f02922012-08-22 10:25:20 -0700559 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700560 if [ -z "$variant" ]; then
561 variant=eng
562 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700563 if [ -z "$apps" ]; then
564 apps=all
565 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700566
Ying Wang67f02922012-08-22 10:25:20 -0700567 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700568 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700569 export TARGET_BUILD_TYPE=release
570 export TARGET_BUILD_APPS=$apps
571
572 set_stuff_for_environment
573 printconfig
574}
575
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700576function gettop
577{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
580 echo $TOP
581 else
582 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800583 # The following circumlocution (repeated below as well) ensures
584 # that we record the true directory name and not one that is
585 # faked up with symlink names.
586 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 T=
590 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800591 \cd ..
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800592 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700593 done
Ying Wang9cd17642012-12-13 10:52:07 -0800594 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595 if [ -f "$T/$TOPFILE" ]; then
596 echo $T
597 fi
598 fi
599 fi
600}
601
602function m()
603{
604 T=$(gettop)
605 if [ "$T" ]; then
606 make -C $T $@
607 else
608 echo "Couldn't locate the top of the tree. Try setting TOP."
609 fi
610}
611
612function findmakefile()
613{
614 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700616 T=
617 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700618 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700619 if [ -f "$T/Android.mk" ]; then
620 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800621 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700622 return
623 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800624 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700625 done
Ying Wang9cd17642012-12-13 10:52:07 -0800626 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700627}
628
629function mm()
630{
631 # If we're sitting in the root of the build tree, just do a
632 # normal make.
633 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
634 make $@
635 else
636 # Find the closest Android.mk file.
637 T=$(gettop)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800638 local M=$(findmakefile)
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700639 # Remove the path to top as the makefilepath needs to be relative
640 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700641 if [ ! "$T" ]; then
642 echo "Couldn't locate the top of the tree. Try setting TOP."
643 elif [ ! "$M" ]; then
644 echo "Couldn't locate a makefile from the current directory."
645 else
Ying Wang01884142010-07-20 16:18:16 -0700646 ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700647 fi
648 fi
649}
650
651function mmm()
652{
653 T=$(gettop)
654 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800655 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800656 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800657 local ARGS=
658 local DIR TO_CHOP
The Android Open Source Project88b60792009-03-03 19:28:42 -0800659 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
660 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
661 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800662 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
663 if [ "$MODULES" = "" ]; then
664 MODULES=all_modules
665 fi
666 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667 if [ -f $DIR/Android.mk ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800668 TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700669 TO_CHOP=`expr $TO_CHOP + 1`
Gilles Debunne8a20f582010-02-17 15:56:45 -0800670 START=`PWD= /bin/pwd`
671 MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672 if [ "$MFILE" = "" ] ; then
673 MFILE=$DIR/Android.mk
674 else
675 MFILE=$MFILE/$DIR/Android.mk
676 fi
677 MAKEFILE="$MAKEFILE $MFILE"
678 else
679 if [ "$DIR" = snod ]; then
680 ARGS="$ARGS snod"
681 elif [ "$DIR" = showcommands ]; then
682 ARGS="$ARGS showcommands"
Ying Wang01884142010-07-20 16:18:16 -0700683 elif [ "$DIR" = dist ]; then
684 ARGS="$ARGS dist"
Ying Wang015edd22011-01-20 15:01:56 -0800685 elif [ "$DIR" = incrementaljavac ]; then
686 ARGS="$ARGS incrementaljavac"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700687 else
688 echo "No Android.mk in $DIR."
Joe Onorato51e61822009-04-13 15:36:15 -0400689 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700690 fi
691 fi
692 done
Alon Albert68895a92011-11-30 12:40:19 -0800693 ONE_SHOT_MAKEFILE="$MAKEFILE" make -C $T $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700694 else
695 echo "Couldn't locate the top of the tree. Try setting TOP."
696 fi
697}
698
699function croot()
700{
701 T=$(gettop)
702 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800703 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700704 else
705 echo "Couldn't locate the top of the tree. Try setting TOP."
706 fi
707}
708
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700709function cproj()
710{
711 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700712 local HERE=$PWD
713 T=
714 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
715 T=$PWD
716 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800717 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700718 return
719 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800720 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700721 done
Ying Wang9cd17642012-12-13 10:52:07 -0800722 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700723 echo "can't find Android.mk"
724}
725
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700726function pid()
727{
728 local EXE="$1"
729 if [ "$EXE" ] ; then
730 local PID=`adb shell ps | fgrep $1 | sed -e 's/[^ ]* *\([0-9]*\).*/\1/'`
731 echo "$PID"
732 else
733 echo "usage: pid name"
734 fi
735}
736
Christopher Tate744ee802009-11-12 15:33:08 -0800737# systemstack - dump the current stack trace of all threads in the system process
738# to the usual ANR traces file
739function systemstack()
740{
741 adb shell echo '""' '>>' /data/anr/traces.txt && adb shell chmod 776 /data/anr/traces.txt && adb shell kill -3 $(pid system_server)
742}
743
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700744function gdbclient()
745{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800746 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
747 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
748 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
749 local OUT_EXE_SYMBOLS=$(get_abs_build_var TARGET_OUT_EXECUTABLES_UNSTRIPPED)
750 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800751 local ARCH=$(get_build_var TARGET_ARCH)
752 local GDB
753 case "$ARCH" in
Jean-Baptiste Querufeec98b2012-05-16 13:18:39 -0700754 x86) GDB=i686-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800755 arm) GDB=arm-linux-androideabi-gdb;;
Raghu Gandham8da43102012-07-25 19:57:22 -0700756 mips) GDB=mipsel-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -0800757 *) echo "Unknown arch $ARCH"; return 1;;
758 esac
759
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700760 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
761 local EXE="$1"
762 if [ "$EXE" ] ; then
763 EXE=$1
764 else
765 EXE="app_process"
766 fi
767
768 local PORT="$2"
769 if [ "$PORT" ] ; then
770 PORT=$2
771 else
772 PORT=":5039"
773 fi
774
Chris Craik20c136a2012-11-09 18:02:19 -0800775 local PID="$3"
776 if [ "$PID" ] ; then
777 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -0700778 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -0800779 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
780 # that likely didn't work because of returning multiple processes
781 # try again, filtering by root processes (don't contain colon)
782 PID=`adb shell ps | grep $3 | grep -v ":" | awk '{print $2}'`
783 if [[ ! "$PID" =~ ^[0-9]+$ ]]
784 then
785 echo "Couldn't resolve '$3' to single PID"
786 return 1
787 else
788 echo ""
789 echo "WARNING: multiple processes matching '$3' observed, using root process"
790 echo ""
791 fi
792 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -0700793 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 adb forward "tcp$PORT" "tcp$PORT"
795 adb shell gdbserver $PORT --attach $PID &
796 sleep 2
797 else
798 echo ""
799 echo "If you haven't done so already, do this first on the device:"
800 echo " gdbserver $PORT /system/bin/$EXE"
801 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -0800802 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 echo ""
804 fi
805
806 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Chris Dearman6858d512012-02-02 14:16:52 -0800807 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 -0700808 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
809 echo >>"$OUT_ROOT/gdbclient.cmds" ""
810
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200811 $ANDROID_TOOLCHAIN/$GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700812 else
813 echo "Unable to determine build system output dir."
814 fi
815
816}
817
818case `uname -s` in
819 Darwin)
820 function sgrep()
821 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700822 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 -0700823 }
824
825 ;;
826 *)
827 function sgrep()
828 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700829 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 -0700830 }
831 ;;
832esac
833
Raghu Gandham8da43102012-07-25 19:57:22 -0700834function gettargetarch
835{
836 get_build_var TARGET_ARCH
837}
838
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839function jgrep()
840{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700841 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 -0700842}
843
844function cgrep()
845{
Mike Dodd0c26d342011-04-07 13:29:06 -0700846 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 -0700847}
848
849function resgrep()
850{
Joe Onoratof50e84b2011-03-15 14:15:46 -0700851 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 -0700852}
853
854case `uname -s` in
855 Darwin)
856 function mgrep()
857 {
Ying Wang324c2b22012-08-17 15:03:20 -0700858 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 -0700859 }
860
861 function treegrep()
862 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700863 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 -0700864 }
865
866 ;;
867 *)
868 function mgrep()
869 {
Ying Wang324c2b22012-08-17 15:03:20 -0700870 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 -0700871 }
872
873 function treegrep()
874 {
Joe Onoratof50e84b2011-03-15 14:15:46 -0700875 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 -0700876 }
877
878 ;;
879esac
880
881function getprebuilt
882{
883 get_abs_build_var ANDROID_PREBUILTS
884}
885
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700886function tracedmdump()
887{
888 T=$(gettop)
889 if [ ! "$T" ]; then
890 echo "Couldn't locate the top of the tree. Try setting TOP."
891 return
892 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800893 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -0700894 local arch=$(gettargetarch)
895 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700896
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800897 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700898 if [ ! "$TRACE" ] ; then
899 echo "usage: tracedmdump tracename"
900 return
901 fi
902
Jack Veenstra60116fc2009-04-09 18:12:34 -0700903 if [ ! -r "$KERNEL" ] ; then
904 echo "Error: cannot find kernel: '$KERNEL'"
905 return
906 fi
907
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800908 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 if [ "$BASETRACE" = "$TRACE" ] ; then
910 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
911 fi
912
913 echo "post-processing traces..."
914 rm -f $TRACE/qtrace.dexlist
915 post_trace $TRACE
916 if [ $? -ne 0 ]; then
917 echo "***"
918 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
919 echo "***"
920 return
921 fi
922 echo "generating dexlist output..."
923 /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
924 echo "generating dmtrace data..."
925 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
926 echo "generating html file..."
927 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
928 echo "done, see $TRACE/dmtrace.html for details"
929 echo "or run:"
930 echo " traceview $TRACE/dmtrace"
931}
932
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800933# communicate with a running device or emulator, set up necessary state,
934# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700935function runhat()
936{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800937 # process standard adb options
938 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -0700939 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800940 adbTarget=$1
941 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -0700942 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800943 adbTarget="$1 $2"
944 shift 2
945 fi
946 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -0700947 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800948
949 # runhat options
950 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700951
952 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -0700953 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954 return
955 fi
956
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800957 # confirm hat is available
958 if [ -z $(which hat) ]; then
959 echo "hat is not available in this configuration."
960 return
961 fi
962
Andy McFaddenb6289852010-07-12 08:00:19 -0700963 # issue "am" command to cause the hprof dump
Dianne Hackborn6b9549f2012-09-26 15:00:59 -0700964 local sdcard=$(adb shell echo -n '$EXTERNAL_STORAGE')
965 local devFile=$sdcard/hprof-$targetPid
966 #local devFile=/data/local/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700967 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -0700968 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -0700969 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -0800970 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700971 echo -n "> "
972 read
973
The Android Open Source Project88b60792009-03-03 19:28:42 -0800974 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700975
The Android Open Source Project88b60792009-03-03 19:28:42 -0800976 echo "Retrieving file $devFile..."
977 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700978
The Android Open Source Project88b60792009-03-03 19:28:42 -0800979 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700980
The Android Open Source Project88b60792009-03-03 19:28:42 -0800981 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700982 echo "View the output by pointing your browser at http://localhost:7000/"
983 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -0800984 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700985}
986
987function getbugreports()
988{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800989 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700990
991 if [ ! "$reports" ]; then
992 echo "Could not locate any bugreports."
993 return
994 fi
995
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800996 local report
997 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800999 echo "/sdcard/bugreports/${report}"
1000 adb pull /sdcard/bugreports/${report} ${report}
1001 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001002 done
1003}
1004
Victoria Lease1b296b42012-08-21 15:44:06 -07001005function getsdcardpath()
1006{
1007 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1008}
1009
1010function getscreenshotpath()
1011{
1012 echo "$(getsdcardpath)/Pictures/Screenshots"
1013}
1014
1015function getlastscreenshot()
1016{
1017 local screenshot_path=$(getscreenshotpath)
1018 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1019 if [ "$screenshot" = "" ]; then
1020 echo "No screenshots found."
1021 return
1022 fi
1023 echo "${screenshot}"
1024 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1025}
1026
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001027function startviewserver()
1028{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001029 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001030 if [ $# -gt 0 ]; then
1031 port=$1
1032 fi
1033 adb shell service call window 1 i32 $port
1034}
1035
1036function stopviewserver()
1037{
1038 adb shell service call window 2
1039}
1040
1041function isviewserverstarted()
1042{
1043 adb shell service call window 3
1044}
1045
Romain Guyb84049a2010-10-04 16:56:11 -07001046function key_home()
1047{
1048 adb shell input keyevent 3
1049}
1050
1051function key_back()
1052{
1053 adb shell input keyevent 4
1054}
1055
1056function key_menu()
1057{
1058 adb shell input keyevent 82
1059}
1060
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001061function smoketest()
1062{
1063 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1064 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1065 return
1066 fi
1067 T=$(gettop)
1068 if [ ! "$T" ]; then
1069 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1070 return
1071 fi
1072
Ying Wang9cd17642012-12-13 10:52:07 -08001073 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001074 adb uninstall com.android.smoketest > /dev/null &&
1075 adb uninstall com.android.smoketest.tests > /dev/null &&
1076 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1077 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1078 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1079}
1080
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001081# simple shortcut to the runtest command
1082function runtest()
1083{
1084 T=$(gettop)
1085 if [ ! "$T" ]; then
1086 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1087 return
1088 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001089 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001090}
1091
The Android Open Source Project88b60792009-03-03 19:28:42 -08001092function godir () {
1093 if [[ -z "$1" ]]; then
1094 echo "Usage: godir <regex>"
1095 return
1096 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001097 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001098 if [[ ! -f $T/filelist ]]; then
1099 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001100 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001101 echo " Done"
1102 echo ""
1103 fi
1104 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001105 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001106 if [[ ${#lines[@]} = 0 ]]; then
1107 echo "Not found"
1108 return
1109 fi
1110 local pathname
1111 local choice
1112 if [[ ${#lines[@]} > 1 ]]; then
1113 while [[ -z "$pathname" ]]; do
1114 local index=1
1115 local line
1116 for line in ${lines[@]}; do
1117 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001118 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001119 done
1120 echo
1121 echo -n "Select one: "
1122 unset choice
1123 read choice
1124 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1125 echo "Invalid choice"
1126 continue
1127 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001128 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001129 done
1130 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001131 pathname=${lines[0]}
1132 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001133 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001134}
1135
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001136# Force JAVA_HOME to point to java 1.6 if it isn't already set
1137function set_java_home() {
Andy McFaddenbd960942010-06-24 12:52:51 -07001138 if [ ! "$JAVA_HOME" ]; then
1139 case `uname -s` in
1140 Darwin)
1141 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1142 ;;
1143 *)
1144 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1145 ;;
1146 esac
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001147 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001148}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001149
Raphael Moll70a86b02011-06-20 16:03:14 -07001150if [ "x$SHELL" != "x/bin/bash" ]; then
1151 case `ps -o command -p $$` in
1152 *bash*)
1153 ;;
1154 *)
1155 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1156 ;;
1157 esac
1158fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001159
1160# Execute the contents of any vendorsetup.sh files we can find.
Bruce Beare6f8410b2010-06-24 13:51:35 -07001161for 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 -08001162do
1163 echo "including $f"
1164 . $f
1165done
1166unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001167
1168addcompletions