blob: ae1e4c5f3fafffe08118cb7efe092f3d6c403c38 [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 Wangb541ab62014-05-29 17:57:40 -07005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [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.
Ying Wangb607f7b2013-02-08 18:01:04 -08008- mm: Builds all of the modules in the current directory, but not their dependencies.
9- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000010 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080011- mma: Builds all of the modules in the current directory, and their dependencies.
12- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070013- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070014- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- jgrep: Greps on all local Java files.
16- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000017- mangrep: Greps on all local AndroidManifest.xml files.
18- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070019- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080020- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060021- cmremote: Add git remote for CM Gerrit Review
22- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
23- cmrebase: Rebase a Gerrit change and push it again
24- mka: Builds using SCHED_BATCH on all processors
25- reposync: Parallel repo sync using ionice and SCHED_BATCH
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070026
Dan Albert4ae5d4b2014-10-31 16:23:08 -070027Environemnt options:
28- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
29 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
30 build is leak-check clean.
31
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070032Look at the source to view more functions. The complete list is:
33EOF
34 T=$(gettop)
35 local A
36 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070037 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070038 A="$A $i"
39 done
40 echo $A
41}
42
43# Get the value of a build variable as an absolute path.
44function get_abs_build_var()
45{
46 T=$(gettop)
47 if [ ! "$T" ]; then
48 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
49 return
50 fi
Ying Wang9cd17642012-12-13 10:52:07 -080051 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070052 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070053}
54
55# Get the exact value of a build variable.
56function get_build_var()
57{
58 T=$(gettop)
59 if [ ! "$T" ]; then
60 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
61 return
62 fi
Andrew Boie6905e212013-12-19 13:21:46 -080063 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070064 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080065}
66
67# check to see if the supplied product is one we can build
68function check_product()
69{
70 T=$(gettop)
71 if [ ! "$T" ]; then
72 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
73 return
74 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000075
76 if (echo -n $1 | grep -q -e "^cm_") ; then
77 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
78 else
79 CM_BUILD=
80 fi
81 export CM_BUILD
82
Jeff Browne33ba4c2011-07-11 22:11:46 -070083 TARGET_PRODUCT=$1 \
84 TARGET_BUILD_VARIANT= \
85 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070086 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080087 get_build_var TARGET_DEVICE > /dev/null
88 # hide successful answers, but allow the errors to show
89}
90
91VARIANT_CHOICES=(user userdebug eng)
92
93# check to see if the supplied variant is valid
94function check_variant()
95{
96 for v in ${VARIANT_CHOICES[@]}
97 do
98 if [ "$v" = "$1" ]
99 then
100 return 0
101 fi
102 done
103 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700104}
105
106function setpaths()
107{
108 T=$(gettop)
109 if [ ! "$T" ]; then
110 echo "Couldn't locate the top of the tree. Try setting TOP."
111 return
112 fi
113
114 ##################################################################
115 # #
116 # Read me before you modify this code #
117 # #
118 # This function sets ANDROID_BUILD_PATHS to what it is adding #
119 # to PATH, and the next time it is run, it removes that from #
120 # PATH. This is required so lunch can be run more than once #
121 # and still have working paths. #
122 # #
123 ##################################################################
124
Raphael Mollc639c782011-06-20 17:25:01 -0700125 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
126 # due to "C:\Program Files" being in the path.
127
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700128 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700129 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700130 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
131 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700132 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700133 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800134 # strip leading ':', if any
135 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500136 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137
138 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700139 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700140 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700141
Ben Cheng8bc4c432012-11-16 13:29:13 -0800142 # defined in core/config.mk
143 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700144 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800145 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800146
Raphael Mollc639c782011-06-20 17:25:01 -0700147 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800148 export ANDROID_TOOLCHAIN=
149 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200150 local ARCH=$(get_build_var TARGET_ARCH)
151 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400152 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700153 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400154 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
155 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800156 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200157 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800158 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700159 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700160 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700161 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000162 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200163 *)
164 echo "Can't find toolchain for unknown architecture: $ARCH"
165 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700166 ;;
167 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700168 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800169 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700170 fi
Raphael732936d2011-06-22 14:35:32 -0700171
Ben Chengfba67bf2014-02-25 10:27:07 -0800172 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
173 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
174 fi
175
176 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700177 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700178 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800179 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800180 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700181 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100182 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
183 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700184 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700185 ;;
186 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700187 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700188 ;;
189 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700190
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700191 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700192 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200193
194 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
195 # to ensure that the corresponding 'emulator' binaries are used.
196 case $(uname -s) in
197 Darwin)
198 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
199 ;;
200 Linux)
201 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
202 ;;
203 *)
204 ANDROID_EMULATOR_PREBUILTS=
205 ;;
206 esac
207 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700208 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200209 export ANDROID_EMULATOR_PREBUILTS
210 fi
211
Ying Wangaa1c9b52012-11-26 20:51:59 -0800212 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800213
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500214 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900215 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500216 if [ -n "$JAVA_HOME" ]; then
217 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900218 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
219 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500220 fi
221
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800222 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700223 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
224 export OUT=$ANDROID_PRODUCT_OUT
225
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700226 unset ANDROID_HOST_OUT
227 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
228
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230 # TODO: fix the path
231 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
232}
233
234function printconfig()
235{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 T=$(gettop)
237 if [ ! "$T" ]; then
238 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
239 return
240 fi
241 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700242}
243
244function set_stuff_for_environment()
245{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800246 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500247 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 setpaths
249 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700252 # With this environment variable new GCC can apply colors to warnings/errors
253 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700254 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255}
256
257function set_sequence_number()
258{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700259 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260}
261
262function settitle()
263{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800264 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700265 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700266 local product=$TARGET_PRODUCT
267 local variant=$TARGET_BUILD_VARIANT
268 local apps=$TARGET_BUILD_APPS
269 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700270 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700271 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700272 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700273 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800274 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700275}
276
Kenny Root52aa81c2011-07-15 11:07:06 -0700277function addcompletions()
278{
279 local T dir f
280
281 # Keep us from trying to run in something that isn't bash.
282 if [ -z "${BASH_VERSION}" ]; then
283 return
284 fi
285
286 # Keep us from trying to run in bash that's too old.
287 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
288 return
289 fi
290
291 dir="sdk/bash_completion"
292 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700293 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700294 echo "including $f"
295 . $f
296 done
297 fi
298}
299
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300function choosetype()
301{
302 echo "Build type choices are:"
303 echo " 1. release"
304 echo " 2. debug"
305 echo
306
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800307 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700308 DEFAULT_NUM=1
309 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700310
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800311 export TARGET_BUILD_TYPE=
312 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700313 while [ -z $TARGET_BUILD_TYPE ]
314 do
315 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 if [ -z "$1" ] ; then
317 read ANSWER
318 else
319 echo $1
320 ANSWER=$1
321 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322 case $ANSWER in
323 "")
324 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
325 ;;
326 1)
327 export TARGET_BUILD_TYPE=release
328 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800329 release)
330 export TARGET_BUILD_TYPE=release
331 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 2)
333 export TARGET_BUILD_TYPE=debug
334 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 debug)
336 export TARGET_BUILD_TYPE=debug
337 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 *)
339 echo
340 echo "I didn't understand your response. Please try again."
341 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 ;;
343 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344 if [ -n "$1" ] ; then
345 break
346 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 done
348
349 set_stuff_for_environment
350}
351
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352#
353# This function isn't really right: It chooses a TARGET_PRODUCT
354# based on the list of boards. Usually, that gets you something
355# that kinda works with a generic product, but really, you should
356# pick a product by name.
357#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700358function chooseproduct()
359{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700360 if [ "x$TARGET_PRODUCT" != x ] ; then
361 default_value=$TARGET_PRODUCT
362 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700363 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 fi
365
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800366 export TARGET_PRODUCT=
367 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368 while [ -z "$TARGET_PRODUCT" ]
369 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700370 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800371 if [ -z "$1" ] ; then
372 read ANSWER
373 else
374 echo $1
375 ANSWER=$1
376 fi
377
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378 if [ -z "$ANSWER" ] ; then
379 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800380 else
381 if check_product $ANSWER
382 then
383 export TARGET_PRODUCT=$ANSWER
384 else
385 echo "** Not a valid product: $ANSWER"
386 fi
387 fi
388 if [ -n "$1" ] ; then
389 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700390 fi
391 done
392
393 set_stuff_for_environment
394}
395
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800396function choosevariant()
397{
398 echo "Variant choices are:"
399 local index=1
400 local v
401 for v in ${VARIANT_CHOICES[@]}
402 do
403 # The product name is the name of the directory containing
404 # the makefile we found, above.
405 echo " $index. $v"
406 index=$(($index+1))
407 done
408
409 local default_value=eng
410 local ANSWER
411
412 export TARGET_BUILD_VARIANT=
413 while [ -z "$TARGET_BUILD_VARIANT" ]
414 do
415 echo -n "Which would you like? [$default_value] "
416 if [ -z "$1" ] ; then
417 read ANSWER
418 else
419 echo $1
420 ANSWER=$1
421 fi
422
423 if [ -z "$ANSWER" ] ; then
424 export TARGET_BUILD_VARIANT=$default_value
425 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
426 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800427 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800428 fi
429 else
430 if check_variant $ANSWER
431 then
432 export TARGET_BUILD_VARIANT=$ANSWER
433 else
434 echo "** Not a valid variant: $ANSWER"
435 fi
436 fi
437 if [ -n "$1" ] ; then
438 break
439 fi
440 done
441}
442
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700443function choosecombo()
444{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700445 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700446
447 echo
448 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700449 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700450
451 echo
452 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700453 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454
455 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700456 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800457 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458}
459
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800460# Clear this variable. It will be built up again when the vendorsetup.sh
461# files are included at the end of this file.
462unset LUNCH_MENU_CHOICES
463function add_lunch_combo()
464{
465 local new_combo=$1
466 local c
467 for c in ${LUNCH_MENU_CHOICES[@]} ; do
468 if [ "$new_combo" = "$c" ] ; then
469 return
470 fi
471 done
472 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
473}
474
475# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700476add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800477add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000478add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800479add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000480add_lunch_combo aosp_x86-eng
481add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483function print_lunch_menu()
484{
485 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700486 echo
487 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 echo
489 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490
491 local i=1
492 local choice
493 for choice in ${LUNCH_MENU_CHOICES[@]}
494 do
495 echo " $i. $choice"
496 i=$(($i+1))
497 done
498
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700499 echo
500}
501
502function lunch()
503{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 local answer
505
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 else
509 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700510 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700512 fi
513
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514 local selection=
515
516 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700518 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
520 then
521 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
522 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800523 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524 fi
525 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
526 then
527 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700528 fi
529
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530 if [ -z "$selection" ]
531 then
532 echo
533 echo "Invalid lunch combo: $answer"
534 return 1
535 fi
536
Joe Onoratoda12daf2010-06-09 18:18:31 -0700537 export TARGET_BUILD_APPS=
538
Jeff Browne33ba4c2011-07-11 22:11:46 -0700539 local product=$(echo -n $selection | sed -e "s/-.*$//")
540 check_product $product
541 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800542 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700543 echo
544 echo "** Don't have a product spec for: '$product'"
545 echo "** Do you have the right repo manifest?"
546 product=
547 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800548
Jeff Browne33ba4c2011-07-11 22:11:46 -0700549 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
550 check_variant $variant
551 if [ $? -ne 0 ]
552 then
553 echo
554 echo "** Invalid variant: '$variant'"
555 echo "** Must be one of ${VARIANT_CHOICES[@]}"
556 variant=
557 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800558
Jeff Browne33ba4c2011-07-11 22:11:46 -0700559 if [ -z "$product" -o -z "$variant" ]
560 then
561 echo
562 return 1
563 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800564
Jeff Browne33ba4c2011-07-11 22:11:46 -0700565 export TARGET_PRODUCT=$product
566 export TARGET_BUILD_VARIANT=$variant
567 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700568
569 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800570
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700571 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800572 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700573}
574
Jeff Davidson513d7a42010-08-02 10:00:44 -0700575# Tab completion for lunch.
576function _lunch()
577{
578 local cur prev opts
579 COMPREPLY=()
580 cur="${COMP_WORDS[COMP_CWORD]}"
581 prev="${COMP_WORDS[COMP_CWORD-1]}"
582
583 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
584 return 0
585}
586complete -F _lunch lunch
587
Joe Onoratoda12daf2010-06-09 18:18:31 -0700588# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700589# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700590function tapas()
591{
Ying Wangb541ab62014-05-29 17:57:40 -0700592 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700593 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700594 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
595 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700596
Ying Wang67f02922012-08-22 10:25:20 -0700597 if [ $(echo $arch | wc -w) -gt 1 ]; then
598 echo "tapas: Error: Multiple build archs supplied: $arch"
599 return
600 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700601 if [ $(echo $variant | wc -w) -gt 1 ]; then
602 echo "tapas: Error: Multiple build variants supplied: $variant"
603 return
604 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700605 if [ $(echo $density | wc -w) -gt 1 ]; then
606 echo "tapas: Error: Multiple densities supplied: $density"
607 return
608 fi
Ying Wang67f02922012-08-22 10:25:20 -0700609
610 local product=full
611 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700612 x86) product=full_x86;;
613 mips) product=full_mips;;
614 armv5) product=generic_armv5;;
615 arm64) product=aosp_arm64;;
616 x86_64) product=aosp_x86_64;;
617 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700618 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700619 if [ -z "$variant" ]; then
620 variant=eng
621 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700622 if [ -z "$apps" ]; then
623 apps=all
624 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600625 if [ -z "$density" ]; then
626 density=alldpi
627 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700628
Ying Wang67f02922012-08-22 10:25:20 -0700629 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700630 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700631 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700632 export TARGET_BUILD_TYPE=release
633 export TARGET_BUILD_APPS=$apps
634
635 set_stuff_for_environment
636 printconfig
637}
638
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700639function gettop
640{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800641 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700642 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700643 # The following circumlocution ensures we remove symlinks from TOP.
644 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700645 else
646 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800647 # The following circumlocution (repeated below as well) ensures
648 # that we record the true directory name and not one that is
649 # faked up with symlink names.
650 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700651 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800652 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 T=
654 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800655 \cd ..
synergyb112a402013-07-05 19:47:47 -0700656 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 done
Ying Wang9cd17642012-12-13 10:52:07 -0800658 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659 if [ -f "$T/$TOPFILE" ]; then
660 echo $T
661 fi
662 fi
663 fi
664}
665
Andrew Hsieh906cb782013-09-10 17:37:14 +0800666# Return driver for "make", if any (eg. static analyzer)
667function getdriver()
668{
669 local T="$1"
670 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
671 if [ -n "$WITH_STATIC_ANALYZER" ]; then
672 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800673$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
674--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800675--status-bugs \
676--top=$T"
677 fi
678}
679
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700680function m()
681{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800682 local T=$(gettop)
683 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700684 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800685 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700686 else
687 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700688 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700689 fi
690}
691
692function findmakefile()
693{
694 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800695 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700696 T=
697 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700698 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700699 if [ -f "$T/Android.mk" ]; then
700 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800701 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700702 return
703 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800704 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700705 done
Ying Wang9cd17642012-12-13 10:52:07 -0800706 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700707}
708
709function mm()
710{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800711 local T=$(gettop)
712 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700713 # If we're sitting in the root of the build tree, just do a
714 # normal make.
715 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800716 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700717 else
718 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800719 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700720 local MODULES=
721 local GET_INSTALL_PATH=
722 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700723 # Remove the path to top as the makefilepath needs to be relative
724 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700725 if [ ! "$T" ]; then
726 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700727 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700728 elif [ ! "$M" ]; then
729 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700730 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700731 else
Ying Wanga7deb082013-08-16 13:24:47 -0700732 for ARG in $@; do
733 case $ARG in
734 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
735 esac
736 done
737 if [ -n "$GET_INSTALL_PATH" ]; then
738 MODULES=
739 ARGS=GET-INSTALL-PATH
740 else
741 MODULES=all_modules
742 ARGS=$@
743 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700744 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700745 fi
746 fi
747}
748
749function mmm()
750{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800751 local T=$(gettop)
752 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700753 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800754 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800755 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800756 local ARGS=
757 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700758 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800759 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
760 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
761 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800762 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
763 if [ "$MODULES" = "" ]; then
764 MODULES=all_modules
765 fi
766 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700768 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
769 local TO_CHOP=`expr $TO_CHOP + 1`
770 local START=`PWD= /bin/pwd`
771 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772 if [ "$MFILE" = "" ] ; then
773 MFILE=$DIR/Android.mk
774 else
775 MFILE=$MFILE/$DIR/Android.mk
776 fi
777 MAKEFILE="$MAKEFILE $MFILE"
778 else
Ying Wanga7deb082013-08-16 13:24:47 -0700779 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100780 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700781 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
782 *) echo "No Android.mk in $DIR."; return 1;;
783 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 fi
785 done
Ying Wanga7deb082013-08-16 13:24:47 -0700786 if [ -n "$GET_INSTALL_PATH" ]; then
787 ARGS=$GET_INSTALL_PATH
788 MODULES=
789 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800790 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 else
792 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700793 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 fi
795}
796
Ying Wangb607f7b2013-02-08 18:01:04 -0800797function mma()
798{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800799 local T=$(gettop)
800 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800801 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800802 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800803 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800804 if [ ! "$T" ]; then
805 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700806 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800807 fi
808 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800809 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800810 fi
811}
812
813function mmma()
814{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800815 local T=$(gettop)
816 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800817 if [ "$T" ]; then
818 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
819 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
820 local MY_PWD=`PWD= /bin/pwd`
821 if [ "$MY_PWD" = "$T" ]; then
822 MY_PWD=
823 else
824 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
825 fi
826 local DIR=
827 local MODULE_PATHS=
828 local ARGS=
829 for DIR in $DIRS ; do
830 if [ -d $DIR ]; then
831 if [ "$MY_PWD" = "" ]; then
832 MODULE_PATHS="$MODULE_PATHS $DIR"
833 else
834 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
835 fi
836 else
837 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100838 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800839 *) echo "Couldn't find directory $DIR"; return 1;;
840 esac
841 fi
842 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800843 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
Ying Wangb607f7b2013-02-08 18:01:04 -0800844 else
845 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700846 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800847 fi
848}
849
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850function croot()
851{
852 T=$(gettop)
853 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800854 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855 else
856 echo "Couldn't locate the top of the tree. Try setting TOP."
857 fi
858}
859
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700860function cproj()
861{
862 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700863 local HERE=$PWD
864 T=
865 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
866 T=$PWD
867 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800868 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700869 return
870 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800871 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700872 done
Ying Wang9cd17642012-12-13 10:52:07 -0800873 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700874 echo "can't find Android.mk"
875}
876
Daniel Sandler47e0a882013-07-30 13:23:52 -0400877# simplified version of ps; output in the form
878# <pid> <procname>
879function qpid() {
880 local prepend=''
881 local append=''
882 if [ "$1" = "--exact" ]; then
883 prepend=' '
884 append='$'
885 shift
886 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
887 echo "usage: qpid [[--exact] <process name|pid>"
888 return 255
889 fi
890
891 local EXE="$1"
892 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -0700893 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -0400894 else
895 adb shell ps \
896 | tr -d '\r' \
897 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
898 fi
899}
900
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700901function pid()
902{
Daniel Sandler47e0a882013-07-30 13:23:52 -0400903 local prepend=''
904 local append=''
905 if [ "$1" = "--exact" ]; then
906 prepend=' '
907 append='$'
908 shift
909 fi
910 local EXE="$1"
911 if [ "$EXE" ] ; then
912 local PID=`adb shell ps \
913 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -0700914 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -0400915 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
916 echo "$PID"
917 else
918 echo "usage: pid [--exact] <process name>"
919 return 255
920 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700921}
922
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800923# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700924# that has the core-file-size limit set correctly
925#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800926# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700927# if its core-file-size limit is not set already.
928# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
929
Iliyan Malcheve675cfb2014-11-03 17:04:47 -0800930function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700931{
932 echo "Getting root...";
933 adb root;
934 adb wait-for-device;
935
936 echo "Remounting root parition read-write...";
937 adb shell mount -w -o remount -t rootfs rootfs;
938 sleep 1;
939 adb wait-for-device;
940 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -0800941 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700942 adb shell chmod 0777 /cores;
943
944 echo "Granting SELinux permission to dump in /cores...";
945 adb shell restorecon -R /cores;
946
947 echo "Set core pattern.";
948 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
949
950 echo "Done."
951}
952
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800953# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700954# $1 = PID of process (e.g., $(pid mediaserver))
955#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800956# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700957# dump to actually be generated.
958
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800959function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700960{
961 local PID=$1;
962 if [ -z "$PID" ]; then
963 printf "Expecting a PID!\n";
964 return;
965 fi;
966 echo "Setting core limit for $PID to infinite...";
967 adb shell prlimit $PID 4 -1 -1
968}
969
970# core - send SIGV and pull the core for process
971# $1 = PID of process (e.g., $(pid mediaserver))
972#
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800973# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700974# enabled globally.
975
976function core()
977{
978 local PID=$1;
979
980 if [ -z "$PID" ]; then
981 printf "Expecting a PID!\n";
982 return;
983 fi;
984
985 local CORENAME=core.$PID;
986 local COREPATH=/cores/$CORENAME;
987 local SIG=SEGV;
988
Iliyan Malchevaf5de972014-11-04 20:57:37 -0800989 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -0700990
991 local done=0;
992 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
993 printf "\tSending SIG%s to %d...\n" $SIG $PID;
994 adb shell kill -$SIG $PID;
995 sleep 1;
996 done;
997
998 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
999 echo "Done: core is under $COREPATH on device.";
1000}
1001
Christopher Tate744ee802009-11-12 15:33:08 -08001002# systemstack - dump the current stack trace of all threads in the system process
1003# to the usual ANR traces file
1004function systemstack()
1005{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001006 stacks system_server
1007}
1008
1009function stacks()
1010{
1011 if [[ $1 =~ ^[0-9]+$ ]] ; then
1012 local PID="$1"
1013 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001014 local PIDLIST="$(pid $1)"
1015 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1016 local PID="$PIDLIST"
1017 elif [ "$PIDLIST" ] ; then
1018 echo "more than one process: $1"
1019 else
1020 echo "no such process: $1"
1021 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001022 else
1023 echo "usage: stacks [pid|process name]"
1024 fi
1025
1026 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001027 # Determine whether the process is native
1028 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1029 # Dump stacks of Dalvik process
1030 local TRACES=/data/anr/traces.txt
1031 local ORIG=/data/anr/traces.orig
1032 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001033
Jeff Brownb12c2e52013-08-19 15:14:16 -07001034 # Keep original traces to avoid clobbering
1035 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001036
Jeff Brownb12c2e52013-08-19 15:14:16 -07001037 # Make sure we have a usable file
1038 adb shell touch $TRACES
1039 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001040
Jeff Brownb12c2e52013-08-19 15:14:16 -07001041 # Dump stacks and wait for dump to finish
1042 adb shell kill -3 $PID
1043 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001044
Jeff Brownb12c2e52013-08-19 15:14:16 -07001045 # Restore original stacks, and show current output
1046 adb shell mv $TRACES $TMP
1047 adb shell mv $ORIG $TRACES
1048 adb shell cat $TMP
1049 else
1050 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001051 local USE64BIT="$(is64bit $PID)"
1052 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001053 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001054 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001055}
1056
Michael Wrightaeed7212014-06-19 19:58:12 -07001057# Read the ELF header from /proc/$PID/exe to determine if the process is
1058# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001059function is64bit()
1060{
1061 local PID="$1"
1062 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001063 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001064 echo "64"
1065 else
1066 echo ""
1067 fi
1068 else
1069 echo ""
1070 fi
1071}
1072
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001073case `uname -s` in
1074 Darwin)
1075 function sgrep()
1076 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001077 find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|S|java|xml|sh|mk|aidl)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001078 }
1079
1080 ;;
1081 *)
1082 function sgrep()
1083 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001084 find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|S\|java\|xml\|sh\|mk\|aidl\)' -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001085 }
1086 ;;
1087esac
1088
Raghu Gandham8da43102012-07-25 19:57:22 -07001089function gettargetarch
1090{
1091 get_build_var TARGET_ARCH
1092}
1093
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001094function ggrep()
1095{
1096 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1097}
1098
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001099function jgrep()
1100{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001101 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001102}
1103
1104function cgrep()
1105{
Dan Albert01961192014-11-22 10:16:01 -08001106 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001107}
1108
1109function resgrep()
1110{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001111 for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -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 -07001112}
1113
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001114function mangrep()
1115{
1116 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1117}
1118
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001119function sepgrep()
1120{
1121 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d -print0 | xargs -0 grep --color -n -r --exclude-dir=\.git "$@"
1122}
1123
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001124function rcgrep()
1125{
1126 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1127}
1128
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001129case `uname -s` in
1130 Darwin)
1131 function mgrep()
1132 {
Ying Wang324c2b22012-08-17 15:03:20 -07001133 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 -07001134 }
1135
1136 function treegrep()
1137 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001138 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 -07001139 }
1140
1141 ;;
1142 *)
1143 function mgrep()
1144 {
Ying Wang324c2b22012-08-17 15:03:20 -07001145 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 -07001146 }
1147
1148 function treegrep()
1149 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001150 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 -07001151 }
1152
1153 ;;
1154esac
1155
1156function getprebuilt
1157{
1158 get_abs_build_var ANDROID_PREBUILTS
1159}
1160
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001161function tracedmdump()
1162{
1163 T=$(gettop)
1164 if [ ! "$T" ]; then
1165 echo "Couldn't locate the top of the tree. Try setting TOP."
1166 return
1167 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001168 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001169 local arch=$(gettargetarch)
1170 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001171
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001172 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001173 if [ ! "$TRACE" ] ; then
1174 echo "usage: tracedmdump tracename"
1175 return
1176 fi
1177
Jack Veenstra60116fc2009-04-09 18:12:34 -07001178 if [ ! -r "$KERNEL" ] ; then
1179 echo "Error: cannot find kernel: '$KERNEL'"
1180 return
1181 fi
1182
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001183 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001184 if [ "$BASETRACE" = "$TRACE" ] ; then
1185 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1186 fi
1187
1188 echo "post-processing traces..."
1189 rm -f $TRACE/qtrace.dexlist
1190 post_trace $TRACE
1191 if [ $? -ne 0 ]; then
1192 echo "***"
1193 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1194 echo "***"
1195 return
1196 fi
1197 echo "generating dexlist output..."
1198 /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
1199 echo "generating dmtrace data..."
1200 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1201 echo "generating html file..."
1202 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1203 echo "done, see $TRACE/dmtrace.html for details"
1204 echo "or run:"
1205 echo " traceview $TRACE/dmtrace"
1206}
1207
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001208# communicate with a running device or emulator, set up necessary state,
1209# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210function runhat()
1211{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001212 # process standard adb options
1213 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001214 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001215 adbTarget=$1
1216 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001217 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001218 adbTarget="$1 $2"
1219 shift 2
1220 fi
1221 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001222 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001223
1224 # runhat options
1225 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001226
1227 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001228 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229 return
1230 fi
1231
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001232 # confirm hat is available
1233 if [ -z $(which hat) ]; then
1234 echo "hat is not available in this configuration."
1235 return
1236 fi
1237
Andy McFaddenb6289852010-07-12 08:00:19 -07001238 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001239 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001240 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001241 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001242 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001243 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001244 echo -n "> "
1245 read
1246
The Android Open Source Project88b60792009-03-03 19:28:42 -08001247 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001248
The Android Open Source Project88b60792009-03-03 19:28:42 -08001249 echo "Retrieving file $devFile..."
1250 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001251
The Android Open Source Project88b60792009-03-03 19:28:42 -08001252 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001253
The Android Open Source Project88b60792009-03-03 19:28:42 -08001254 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255 echo "View the output by pointing your browser at http://localhost:7000/"
1256 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001257 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001258}
1259
1260function getbugreports()
1261{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001262 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001263
1264 if [ ! "$reports" ]; then
1265 echo "Could not locate any bugreports."
1266 return
1267 fi
1268
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001269 local report
1270 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001272 echo "/sdcard/bugreports/${report}"
1273 adb pull /sdcard/bugreports/${report} ${report}
1274 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001275 done
1276}
1277
Victoria Lease1b296b42012-08-21 15:44:06 -07001278function getsdcardpath()
1279{
1280 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1281}
1282
1283function getscreenshotpath()
1284{
1285 echo "$(getsdcardpath)/Pictures/Screenshots"
1286}
1287
1288function getlastscreenshot()
1289{
1290 local screenshot_path=$(getscreenshotpath)
1291 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1292 if [ "$screenshot" = "" ]; then
1293 echo "No screenshots found."
1294 return
1295 fi
1296 echo "${screenshot}"
1297 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1298}
1299
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001300function startviewserver()
1301{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001302 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001303 if [ $# -gt 0 ]; then
1304 port=$1
1305 fi
1306 adb shell service call window 1 i32 $port
1307}
1308
1309function stopviewserver()
1310{
1311 adb shell service call window 2
1312}
1313
1314function isviewserverstarted()
1315{
1316 adb shell service call window 3
1317}
1318
Romain Guyb84049a2010-10-04 16:56:11 -07001319function key_home()
1320{
1321 adb shell input keyevent 3
1322}
1323
1324function key_back()
1325{
1326 adb shell input keyevent 4
1327}
1328
1329function key_menu()
1330{
1331 adb shell input keyevent 82
1332}
1333
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001334function smoketest()
1335{
1336 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1337 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1338 return
1339 fi
1340 T=$(gettop)
1341 if [ ! "$T" ]; then
1342 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1343 return
1344 fi
1345
Ying Wang9cd17642012-12-13 10:52:07 -08001346 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001347 adb uninstall com.android.smoketest > /dev/null &&
1348 adb uninstall com.android.smoketest.tests > /dev/null &&
1349 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1350 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1351 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1352}
1353
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001354# simple shortcut to the runtest command
1355function runtest()
1356{
1357 T=$(gettop)
1358 if [ ! "$T" ]; then
1359 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1360 return
1361 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001362 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001363}
1364
The Android Open Source Project88b60792009-03-03 19:28:42 -08001365function godir () {
1366 if [[ -z "$1" ]]; then
1367 echo "Usage: godir <regex>"
1368 return
1369 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001370 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371 if [[ ! -f $T/filelist ]]; then
1372 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001373 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374 echo " Done"
1375 echo ""
1376 fi
1377 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001378 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001379 if [[ ${#lines[@]} = 0 ]]; then
1380 echo "Not found"
1381 return
1382 fi
1383 local pathname
1384 local choice
1385 if [[ ${#lines[@]} > 1 ]]; then
1386 while [[ -z "$pathname" ]]; do
1387 local index=1
1388 local line
1389 for line in ${lines[@]}; do
1390 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001391 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001392 done
1393 echo
1394 echo -n "Select one: "
1395 unset choice
1396 read choice
1397 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1398 echo "Invalid choice"
1399 continue
1400 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001401 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001402 done
1403 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001404 pathname=${lines[0]}
1405 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001406 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001407}
1408
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001409function cmremote()
1410{
1411 git remote rm cmremote 2> /dev/null
1412 if [ ! -d .git ]
1413 then
1414 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1415 fi
1416 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1417 if [ -z "$GERRIT_REMOTE" ]
1418 then
1419 echo Unable to set up the git remote, are you in the root of the repo?
1420 return 0
1421 fi
1422 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1423 if [ -z "$CMUSER" ]
1424 then
1425 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1426 else
1427 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1428 fi
1429 echo You can now push to "cmremote".
1430}
1431
1432function cmgerrit() {
1433 if [ $# -eq 0 ]; then
1434 $FUNCNAME help
1435 return 1
1436 fi
1437 local user=`git config --get review.review.cyanogenmod.com.username`
1438 local review=`git config --get remote.github.review`
1439 local project=`git config --get remote.github.projectname`
1440 local command=$1
1441 shift
1442 case $command in
1443 help)
1444 if [ $# -eq 0 ]; then
1445 cat <<EOF
1446Usage:
1447 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1448
1449Commands:
1450 fetch Just fetch the change as FETCH_HEAD
1451 help Show this help, or for a specific command
1452 pull Pull a change into current branch
1453 push Push HEAD or a local branch to Gerrit for a specific branch
1454
1455Any other Git commands that support refname would work as:
1456 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1457
1458See '$FUNCNAME help COMMAND' for more information on a specific command.
1459
1460Example:
1461 $FUNCNAME checkout -b topic 1234/5
1462works as:
1463 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1464 && git checkout -b topic FETCH_HEAD
1465will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1466Patch-set 1 will be fetched if omitted.
1467EOF
1468 return
1469 fi
1470 case $1 in
1471 __cmg_*) echo "For internal use only." ;;
1472 changes|for)
1473 if [ "$FUNCNAME" = "cmgerrit" ]; then
1474 echo "'$FUNCNAME $1' is deprecated."
1475 fi
1476 ;;
1477 help) $FUNCNAME help ;;
1478 fetch|pull) cat <<EOF
1479usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1480
1481works as:
1482 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1483 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1484
1485Example:
1486 $FUNCNAME $1 1234
1487will $1 patch-set 1 of change 1234
1488EOF
1489 ;;
1490 push) cat <<EOF
1491usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1492
1493works as:
1494 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1495 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1496
1497Example:
1498 $FUNCNAME push fix6789:gingerbread
1499will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1500HEAD will be pushed from local if omitted.
1501EOF
1502 ;;
1503 *)
1504 $FUNCNAME __cmg_err_not_supported $1 && return
1505 cat <<EOF
1506usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1507
1508works as:
1509 git fetch http://DOMAIN/p/PROJECT \\
1510 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1511 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1512EOF
1513 ;;
1514 esac
1515 ;;
1516 __cmg_get_ref)
1517 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1518 local change_id patchset_id hash
1519 case $1 in
1520 */*)
1521 change_id=${1%%/*}
1522 patchset_id=${1#*/}
1523 ;;
1524 *)
1525 change_id=$1
1526 patchset_id=1
1527 ;;
1528 esac
1529 hash=$(($change_id % 100))
1530 case $hash in
1531 [0-9]) hash="0$hash" ;;
1532 esac
1533 echo "refs/changes/$hash/$change_id/$patchset_id"
1534 ;;
1535 fetch|pull)
1536 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1537 $FUNCNAME __cmg_err_not_repo && return 1
1538 local change=$1
1539 shift
1540 git $command $@ http://$review/p/$project \
1541 $($FUNCNAME __cmg_get_ref $change) || return 1
1542 ;;
1543 push)
1544 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1545 $FUNCNAME __cmg_err_not_repo && return 1
1546 if [ -z "$user" ]; then
1547 echo >&2 "Gerrit username not found."
1548 return 1
1549 fi
1550 local local_branch remote_branch
1551 case $1 in
1552 *:*)
1553 local_branch=${1%:*}
1554 remote_branch=${1##*:}
1555 ;;
1556 *)
1557 local_branch=HEAD
1558 remote_branch=$1
1559 ;;
1560 esac
1561 shift
1562 git push $@ ssh://$user@$review:29418/$project \
1563 $local_branch:refs/for/$remote_branch || return 1
1564 ;;
1565 changes|for)
1566 if [ "$FUNCNAME" = "cmgerrit" ]; then
1567 echo >&2 "'$FUNCNAME $command' is deprecated."
1568 fi
1569 ;;
1570 __cmg_err_no_arg)
1571 if [ $# -lt 2 ]; then
1572 echo >&2 "'$FUNCNAME $command' missing argument."
1573 elif [ $2 -eq 0 ]; then
1574 if [ -n "$3" ]; then
1575 $FUNCNAME help $1
1576 else
1577 echo >&2 "'$FUNCNAME $1' missing argument."
1578 fi
1579 else
1580 return 1
1581 fi
1582 ;;
1583 __cmg_err_not_repo)
1584 if [ -z "$review" -o -z "$project" ]; then
1585 echo >&2 "Not currently in any reviewable repository."
1586 else
1587 return 1
1588 fi
1589 ;;
1590 __cmg_err_not_supported)
1591 $FUNCNAME __cmg_err_no_arg $command $# && return
1592 case $1 in
1593 #TODO: filter more git commands that don't use refname
1594 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1595 echo >&2 "'$FUNCNAME $1' is not supported."
1596 ;;
1597 *) return 1 ;;
1598 esac
1599 ;;
1600 #TODO: other special cases?
1601 *)
1602 $FUNCNAME __cmg_err_not_supported $command && return 1
1603 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1604 $FUNCNAME __cmg_err_not_repo && return 1
1605 local args="$@"
1606 local change pre_args refs_arg post_args
1607 case "$args" in
1608 *--\ *)
1609 pre_args=${args%%-- *}
1610 post_args="-- ${args#*-- }"
1611 ;;
1612 *) pre_args="$args" ;;
1613 esac
1614 args=($pre_args)
1615 pre_args=
1616 if [ ${#args[@]} -gt 0 ]; then
1617 change=${args[${#args[@]}-1]}
1618 fi
1619 if [ ${#args[@]} -gt 1 ]; then
1620 pre_args=${args[0]}
1621 for ((i=1; i<${#args[@]}-1; i++)); do
1622 pre_args="$pre_args ${args[$i]}"
1623 done
1624 fi
1625 while ((1)); do
1626 case $change in
1627 ""|--)
1628 $FUNCNAME help $command
1629 return 1
1630 ;;
1631 *@*)
1632 if [ -z "$refs_arg" ]; then
1633 refs_arg="@${change#*@}"
1634 change=${change%%@*}
1635 fi
1636 ;;
1637 *~*)
1638 if [ -z "$refs_arg" ]; then
1639 refs_arg="~${change#*~}"
1640 change=${change%%~*}
1641 fi
1642 ;;
1643 *^*)
1644 if [ -z "$refs_arg" ]; then
1645 refs_arg="^${change#*^}"
1646 change=${change%%^*}
1647 fi
1648 ;;
1649 *:*)
1650 if [ -z "$refs_arg" ]; then
1651 refs_arg=":${change#*:}"
1652 change=${change%%:*}
1653 fi
1654 ;;
1655 *) break ;;
1656 esac
1657 done
1658 $FUNCNAME fetch $change \
1659 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1660 || return 1
1661 ;;
1662 esac
1663}
1664
1665function cmrebase() {
1666 local repo=$1
1667 local refs=$2
1668 local pwd="$(pwd)"
1669 local dir="$(gettop)/$repo"
1670
1671 if [ -z $repo ] || [ -z $refs ]; then
1672 echo "CyanogenMod Gerrit Rebase Usage: "
1673 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1674 echo " The patch IDs appear on the Gerrit commands that are offered."
1675 echo " They consist on a series of numbers and slashes, after the text"
1676 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1677 echo ""
1678 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1679 echo ""
1680 return
1681 fi
1682
1683 if [ ! -d $dir ]; then
1684 echo "Directory $dir doesn't exist in tree."
1685 return
1686 fi
1687 cd $dir
1688 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1689 echo "Starting branch..."
1690 repo start tmprebase .
1691 echo "Bringing it up to date..."
1692 repo sync .
1693 echo "Fetching change..."
1694 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
1695 if [ "$?" != "0" ]; then
1696 echo "Error cherry-picking. Not uploading!"
1697 return
1698 fi
1699 echo "Uploading..."
1700 repo upload .
1701 echo "Cleaning up..."
1702 repo abandon tmprebase .
1703 cd $pwd
1704}
1705
1706function mka() {
1707 case `uname -s` in
1708 Darwin)
1709 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1710 ;;
1711 *)
1712 schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
1713 ;;
1714 esac
1715}
1716
1717function reposync() {
1718 case `uname -s` in
1719 Darwin)
1720 repo sync -j 4 "$@"
1721 ;;
1722 *)
1723 schedtool -B -n 1 -e ionice -n 1 repo sync -j 4 "$@"
1724 ;;
1725 esac
1726}
1727# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001728#
1729# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1730# For some reason, installing the JDK doesn't make it show up in the
1731# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001732function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001733 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001734 # we can reset it later, depending on the version of java the build
1735 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001736 #
1737 # If we don't do this, the JAVA_HOME value set by the first call to
1738 # build/envsetup.sh will persist forever.
1739 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1740 export JAVA_HOME=""
1741 fi
1742
Andy McFaddenbd960942010-06-24 12:52:51 -07001743 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001744 case `uname -s` in
1745 Darwin)
1746 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1747 ;;
1748 *)
1749 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1750 ;;
1751 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001752
1753 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1754 # we can change it on the next envsetup.sh, if required.
1755 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001756 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001757}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001758
Alex Rayf0d08eb2013-03-08 15:15:06 -08001759# Print colored exit condition
1760function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001761 "$@"
1762 local retval=$?
1763 if [ $retval -ne 0 ]
1764 then
1765 echo -e "\e[0;31mFAILURE\e[00m"
1766 else
1767 echo -e "\e[0;32mSUCCESS\e[00m"
1768 fi
1769 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001770}
1771
Ying Wanged21d4c2014-08-24 22:14:19 -07001772function get_make_command()
1773{
1774 echo command make
1775}
1776
Ed Heylcc6be0a2014-06-18 14:55:58 -07001777function make()
1778{
1779 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001780 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001781 local ret=$?
1782 local end_time=$(date +"%s")
1783 local tdiff=$(($end_time-$start_time))
1784 local hours=$(($tdiff / 3600 ))
1785 local mins=$((($tdiff % 3600) / 60))
1786 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001787 local ncolors=$(tput colors 2>/dev/null)
1788 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
1789 color_failed="\e[0;31m"
1790 color_success="\e[0;32m"
1791 color_reset="\e[00m"
1792 else
1793 color_failed=""
1794 color_success=""
1795 color_reset=""
1796 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07001797 echo
1798 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001799 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001800 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001801 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001802 fi
1803 if [ $hours -gt 0 ] ; then
1804 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1805 elif [ $mins -gt 0 ] ; then
1806 printf "(%02g:%02g (mm:ss))" $mins $secs
1807 elif [ $secs -gt 0 ] ; then
1808 printf "(%s seconds)" $secs
1809 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001810 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001811 echo
1812 return $ret
1813}
1814
Raphael Moll70a86b02011-06-20 16:03:14 -07001815if [ "x$SHELL" != "x/bin/bash" ]; then
1816 case `ps -o command -p $$` in
1817 *bash*)
1818 ;;
1819 *)
1820 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
1821 ;;
1822 esac
1823fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001824
1825# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02001826for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
1827 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001828do
1829 echo "including $f"
1830 . $f
1831done
1832unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001833
1834addcompletions