blob: bd22cfa95f999fe255d2d955b19fe5d8622bd578 [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.
Daniel Bateman22185ba2012-08-04 03:48:09 -050012- mmp: Builds all of the modules in the current directory and pushes them to the device.
13- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080014- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070016- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070017- jgrep: Greps on all local Java files.
18- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000019- mangrep: Greps on all local AndroidManifest.xml files.
20- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070021- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080022- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060023- cmremote: Add git remote for CM Gerrit Review
24- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
25- cmrebase: Rebase a Gerrit change and push it again
26- mka: Builds using SCHED_BATCH on all processors
27- reposync: Parallel repo sync using ionice and SCHED_BATCH
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070028
Dan Albert4ae5d4b2014-10-31 16:23:08 -070029Environemnt options:
30- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
31 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
32 build is leak-check clean.
33
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070034Look at the source to view more functions. The complete list is:
35EOF
36 T=$(gettop)
37 local A
38 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070039 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 -070040 A="$A $i"
41 done
42 echo $A
43}
44
45# Get the value of a build variable as an absolute path.
46function get_abs_build_var()
47{
48 T=$(gettop)
49 if [ ! "$T" ]; then
50 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
51 return
52 fi
Ying Wang9cd17642012-12-13 10:52:07 -080053 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070054 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070055}
56
57# Get the exact value of a build variable.
58function get_build_var()
59{
60 T=$(gettop)
61 if [ ! "$T" ]; then
62 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
63 return
64 fi
Andrew Boie6905e212013-12-19 13:21:46 -080065 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070066 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080067}
68
69# check to see if the supplied product is one we can build
70function check_product()
71{
72 T=$(gettop)
73 if [ ! "$T" ]; then
74 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
75 return
76 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000077
78 if (echo -n $1 | grep -q -e "^cm_") ; then
79 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
80 else
81 CM_BUILD=
82 fi
83 export CM_BUILD
84
Jeff Browne33ba4c2011-07-11 22:11:46 -070085 TARGET_PRODUCT=$1 \
86 TARGET_BUILD_VARIANT= \
87 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070088 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080089 get_build_var TARGET_DEVICE > /dev/null
90 # hide successful answers, but allow the errors to show
91}
92
93VARIANT_CHOICES=(user userdebug eng)
94
95# check to see if the supplied variant is valid
96function check_variant()
97{
98 for v in ${VARIANT_CHOICES[@]}
99 do
100 if [ "$v" = "$1" ]
101 then
102 return 0
103 fi
104 done
105 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700106}
107
108function setpaths()
109{
110 T=$(gettop)
111 if [ ! "$T" ]; then
112 echo "Couldn't locate the top of the tree. Try setting TOP."
113 return
114 fi
115
116 ##################################################################
117 # #
118 # Read me before you modify this code #
119 # #
120 # This function sets ANDROID_BUILD_PATHS to what it is adding #
121 # to PATH, and the next time it is run, it removes that from #
122 # PATH. This is required so lunch can be run more than once #
123 # and still have working paths. #
124 # #
125 ##################################################################
126
Raphael Mollc639c782011-06-20 17:25:01 -0700127 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
128 # due to "C:\Program Files" being in the path.
129
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700130 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700131 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700132 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
133 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700134 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700135 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800136 # strip leading ':', if any
137 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500138 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700139
140 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700141 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700142 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700143
Ben Cheng8bc4c432012-11-16 13:29:13 -0800144 # defined in core/config.mk
145 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700146 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800147 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800148
Raphael Mollc639c782011-06-20 17:25:01 -0700149 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800150 export ANDROID_TOOLCHAIN=
151 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200152 local ARCH=$(get_build_var TARGET_ARCH)
153 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400154 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700155 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400156 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
157 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800158 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200159 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800160 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700161 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700162 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700163 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000164 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200165 *)
166 echo "Can't find toolchain for unknown architecture: $ARCH"
167 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700168 ;;
169 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700170 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800171 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700172 fi
Raphael732936d2011-06-22 14:35:32 -0700173
Ben Chengfba67bf2014-02-25 10:27:07 -0800174 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
175 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
176 fi
177
178 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700179 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700180 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800181 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800182 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700183 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100184 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
185 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700186 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700187 ;;
188 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700189 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700190 ;;
191 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700192
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700193 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700194 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 +0200195
196 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
197 # to ensure that the corresponding 'emulator' binaries are used.
198 case $(uname -s) in
199 Darwin)
200 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
201 ;;
202 Linux)
203 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
204 ;;
205 *)
206 ANDROID_EMULATOR_PREBUILTS=
207 ;;
208 esac
209 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700210 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200211 export ANDROID_EMULATOR_PREBUILTS
212 fi
213
Ying Wangaa1c9b52012-11-26 20:51:59 -0800214 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800215
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500216 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900217 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500218 if [ -n "$JAVA_HOME" ]; then
219 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900220 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
221 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500222 fi
223
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800224 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700225 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
226 export OUT=$ANDROID_PRODUCT_OUT
227
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700228 unset ANDROID_HOST_OUT
229 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
230
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800231 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700232 # TODO: fix the path
233 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
234}
235
236function printconfig()
237{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 T=$(gettop)
239 if [ ! "$T" ]; then
240 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
241 return
242 fi
243 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700244}
245
246function set_stuff_for_environment()
247{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500249 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800250 setpaths
251 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700252
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800253 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700254 # With this environment variable new GCC can apply colors to warnings/errors
255 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 -0700256 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700257}
258
259function set_sequence_number()
260{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700261 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700262}
263
264function settitle()
265{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700267 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700268 local product=$TARGET_PRODUCT
269 local variant=$TARGET_BUILD_VARIANT
270 local apps=$TARGET_BUILD_APPS
271 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700272 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700273 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700274 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700275 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800276 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700277}
278
Kenny Root52aa81c2011-07-15 11:07:06 -0700279function addcompletions()
280{
281 local T dir f
282
283 # Keep us from trying to run in something that isn't bash.
284 if [ -z "${BASH_VERSION}" ]; then
285 return
286 fi
287
288 # Keep us from trying to run in bash that's too old.
289 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
290 return
291 fi
292
293 dir="sdk/bash_completion"
294 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700295 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700296 echo "including $f"
297 . $f
298 done
299 fi
300}
301
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700302function choosetype()
303{
304 echo "Build type choices are:"
305 echo " 1. release"
306 echo " 2. debug"
307 echo
308
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800309 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700310 DEFAULT_NUM=1
311 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700312
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800313 export TARGET_BUILD_TYPE=
314 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315 while [ -z $TARGET_BUILD_TYPE ]
316 do
317 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800318 if [ -z "$1" ] ; then
319 read ANSWER
320 else
321 echo $1
322 ANSWER=$1
323 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324 case $ANSWER in
325 "")
326 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
327 ;;
328 1)
329 export TARGET_BUILD_TYPE=release
330 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 release)
332 export TARGET_BUILD_TYPE=release
333 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334 2)
335 export TARGET_BUILD_TYPE=debug
336 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800337 debug)
338 export TARGET_BUILD_TYPE=debug
339 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700340 *)
341 echo
342 echo "I didn't understand your response. Please try again."
343 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700344 ;;
345 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800346 if [ -n "$1" ] ; then
347 break
348 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700349 done
350
351 set_stuff_for_environment
352}
353
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800354#
355# This function isn't really right: It chooses a TARGET_PRODUCT
356# based on the list of boards. Usually, that gets you something
357# that kinda works with a generic product, but really, you should
358# pick a product by name.
359#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700360function chooseproduct()
361{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 if [ "x$TARGET_PRODUCT" != x ] ; then
363 default_value=$TARGET_PRODUCT
364 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700365 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700366 fi
367
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800368 export TARGET_PRODUCT=
369 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700370 while [ -z "$TARGET_PRODUCT" ]
371 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700372 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800373 if [ -z "$1" ] ; then
374 read ANSWER
375 else
376 echo $1
377 ANSWER=$1
378 fi
379
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700380 if [ -z "$ANSWER" ] ; then
381 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800382 else
383 if check_product $ANSWER
384 then
385 export TARGET_PRODUCT=$ANSWER
386 else
387 echo "** Not a valid product: $ANSWER"
388 fi
389 fi
390 if [ -n "$1" ] ; then
391 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700392 fi
393 done
394
395 set_stuff_for_environment
396}
397
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800398function choosevariant()
399{
400 echo "Variant choices are:"
401 local index=1
402 local v
403 for v in ${VARIANT_CHOICES[@]}
404 do
405 # The product name is the name of the directory containing
406 # the makefile we found, above.
407 echo " $index. $v"
408 index=$(($index+1))
409 done
410
411 local default_value=eng
412 local ANSWER
413
414 export TARGET_BUILD_VARIANT=
415 while [ -z "$TARGET_BUILD_VARIANT" ]
416 do
417 echo -n "Which would you like? [$default_value] "
418 if [ -z "$1" ] ; then
419 read ANSWER
420 else
421 echo $1
422 ANSWER=$1
423 fi
424
425 if [ -z "$ANSWER" ] ; then
426 export TARGET_BUILD_VARIANT=$default_value
427 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
428 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800429 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800430 fi
431 else
432 if check_variant $ANSWER
433 then
434 export TARGET_BUILD_VARIANT=$ANSWER
435 else
436 echo "** Not a valid variant: $ANSWER"
437 fi
438 fi
439 if [ -n "$1" ] ; then
440 break
441 fi
442 done
443}
444
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700445function choosecombo()
446{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700447 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448
449 echo
450 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700451 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700452
453 echo
454 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700455 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800456
457 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460}
461
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462# Clear this variable. It will be built up again when the vendorsetup.sh
463# files are included at the end of this file.
464unset LUNCH_MENU_CHOICES
465function add_lunch_combo()
466{
467 local new_combo=$1
468 local c
469 for c in ${LUNCH_MENU_CHOICES[@]} ; do
470 if [ "$new_combo" = "$c" ] ; then
471 return
472 fi
473 done
474 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
475}
476
477# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700478add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800479add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000480add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800481add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000482add_lunch_combo aosp_x86-eng
483add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700485function print_lunch_menu()
486{
487 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488 echo
489 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000490 if [ "$(uname)" = "Darwin" ] ; then
491 echo " (ohai, koush!)"
492 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700493 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000494 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
495 echo "Breakfast menu... pick a combo:"
496 else
497 echo "Lunch menu... pick a combo:"
498 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499
500 local i=1
501 local choice
502 for choice in ${LUNCH_MENU_CHOICES[@]}
503 do
504 echo " $i. $choice"
505 i=$(($i+1))
506 done
507
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000508 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
509 echo "... and don't forget the bacon!"
510 fi
511
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700512 echo
513}
514
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000515function brunch()
516{
517 breakfast $*
518 if [ $? -eq 0 ]; then
519 mka bacon
520 else
521 echo "No such item in brunch menu. Try 'breakfast'"
522 return 1
523 fi
524 return $?
525}
526
527function breakfast()
528{
529 target=$1
530 CM_DEVICES_ONLY="true"
531 unset LUNCH_MENU_CHOICES
532 add_lunch_combo full-eng
533 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
534 do
535 echo "including $f"
536 . $f
537 done
538 unset f
539
540 if [ $# -eq 0 ]; then
541 # No arguments, so let's have the full menu
542 lunch
543 else
544 echo "z$target" | grep -q "-"
545 if [ $? -eq 0 ]; then
546 # A buildtype was specified, assume a full device name
547 lunch $target
548 else
549 # This is probably just the CM model name
550 lunch cm_$target-userdebug
551 fi
552 fi
553 return $?
554}
555
556alias bib=breakfast
557
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700558function lunch()
559{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800560 local answer
561
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700562 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800563 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700564 else
565 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700566 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800567 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700568 fi
569
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800570 local selection=
571
572 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700573 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700574 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800575 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
576 then
577 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
578 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800579 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 fi
581 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
582 then
583 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584 fi
585
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 if [ -z "$selection" ]
587 then
588 echo
589 echo "Invalid lunch combo: $answer"
590 return 1
591 fi
592
Joe Onoratoda12daf2010-06-09 18:18:31 -0700593 export TARGET_BUILD_APPS=
594
Jeff Browne33ba4c2011-07-11 22:11:46 -0700595 local product=$(echo -n $selection | sed -e "s/-.*$//")
596 check_product $product
597 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800599 # if we can't find a product, try to grab it off the CM github
600 T=$(gettop)
601 pushd $T > /dev/null
602 build/tools/roomservice.py $product
603 popd > /dev/null
604 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000605 else
606 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800607 fi
608 if [ $? -ne 0 ]
609 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700610 echo
611 echo "** Don't have a product spec for: '$product'"
612 echo "** Do you have the right repo manifest?"
613 product=
614 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615
Jeff Browne33ba4c2011-07-11 22:11:46 -0700616 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
617 check_variant $variant
618 if [ $? -ne 0 ]
619 then
620 echo
621 echo "** Invalid variant: '$variant'"
622 echo "** Must be one of ${VARIANT_CHOICES[@]}"
623 variant=
624 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800625
Jeff Browne33ba4c2011-07-11 22:11:46 -0700626 if [ -z "$product" -o -z "$variant" ]
627 then
628 echo
629 return 1
630 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800631
Jeff Browne33ba4c2011-07-11 22:11:46 -0700632 export TARGET_PRODUCT=$product
633 export TARGET_BUILD_VARIANT=$variant
634 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700635
636 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800637
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700640}
641
Jeff Davidson513d7a42010-08-02 10:00:44 -0700642# Tab completion for lunch.
643function _lunch()
644{
645 local cur prev opts
646 COMPREPLY=()
647 cur="${COMP_WORDS[COMP_CWORD]}"
648 prev="${COMP_WORDS[COMP_CWORD-1]}"
649
650 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
651 return 0
652}
653complete -F _lunch lunch
654
Joe Onoratoda12daf2010-06-09 18:18:31 -0700655# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700656# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700657function tapas()
658{
Ying Wangb541ab62014-05-29 17:57:40 -0700659 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 -0700660 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700661 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
662 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 -0700663
Ying Wang67f02922012-08-22 10:25:20 -0700664 if [ $(echo $arch | wc -w) -gt 1 ]; then
665 echo "tapas: Error: Multiple build archs supplied: $arch"
666 return
667 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700668 if [ $(echo $variant | wc -w) -gt 1 ]; then
669 echo "tapas: Error: Multiple build variants supplied: $variant"
670 return
671 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700672 if [ $(echo $density | wc -w) -gt 1 ]; then
673 echo "tapas: Error: Multiple densities supplied: $density"
674 return
675 fi
Ying Wang67f02922012-08-22 10:25:20 -0700676
677 local product=full
678 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700679 x86) product=full_x86;;
680 mips) product=full_mips;;
681 armv5) product=generic_armv5;;
682 arm64) product=aosp_arm64;;
683 x86_64) product=aosp_x86_64;;
684 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700685 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700686 if [ -z "$variant" ]; then
687 variant=eng
688 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700689 if [ -z "$apps" ]; then
690 apps=all
691 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600692 if [ -z "$density" ]; then
693 density=alldpi
694 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700695
Ying Wang67f02922012-08-22 10:25:20 -0700696 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700697 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700698 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700699 export TARGET_BUILD_TYPE=release
700 export TARGET_BUILD_APPS=$apps
701
702 set_stuff_for_environment
703 printconfig
704}
705
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100706function eat()
707{
708 if [ "$OUT" ] ; then
709 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
710 ZIPFILE=cm-$MODVERSION.zip
711 ZIPPATH=$OUT/$ZIPFILE
712 if [ ! -f $ZIPPATH ] ; then
713 echo "Nothing to eat"
714 return 1
715 fi
716 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
717 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
718 echo "No device is online. Waiting for one..."
719 echo "Please connect USB and/or enable USB debugging"
720 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
721 sleep 1
722 done
723 echo "Device Found.."
724 fi
725 # if adbd isn't root we can't write to /cache/recovery/
726 adb root
727 sleep 1
728 adb wait-for-device
729 SZ=`stat -c %s $ZIPPATH`
730 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
731 if [ $CACHESIZE -gt $SZ ];
732 then
733 PUSHDIR=/cache/
734 DIR=cache
735 else
736 PUSHDIR=/storage/sdcard0/
737 # Optional path for sdcard0 in recovery
738 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
739 fi
740 echo "Pushing $ZIPFILE to $PUSHDIR"
741 if adb push $ZIPPATH $PUSHDIR ; then
742 cat << EOF > /tmp/command
743--update_package=/$DIR/$ZIPFILE
744EOF
745 if adb push /tmp/command /cache/recovery/ ; then
746 echo "Rebooting into recovery for installation"
747 adb reboot recovery
748 fi
749 rm /tmp/command
750 fi
751 else
752 echo "Nothing to eat"
753 return 1
754 fi
755 return $?
756}
757
Daniel Bateman22185ba2012-08-04 03:48:09 -0500758# Credit for color strip sed: http://goo.gl/BoIcm
759function mmmp()
760{
761 if [[ $# < 1 || $1 == "--help" || $1 == "-h" ]]; then
762 echo "mmmp [make arguments] <path-to-project>"
763 return 1
764 fi
765
766 # Get product name from cm_<product>
767 PRODUCT=`echo $TARGET_PRODUCT | tr "_" "\n" | tail -n 1`
768
769 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
770 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
771 echo "No device is online. Waiting for one..."
772 echo "Please connect USB and/or enable USB debugging"
773 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
774 sleep 1
775 done
776 echo "Device Found.."
777 fi
778
779 adb root &> /dev/null
780 sleep 0.3
781 adb wait-for-device &> /dev/null
782 sleep 0.3
783 adb remount &> /dev/null
784
785 mmm $* | tee .log
786
787 # Install: <file>
788 LOC=$(cat .log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Install' | cut -d ':' -f 2)
789
790 # Copy: <file>
791 LOC=$LOC $(cat .log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Copy' | cut -d ':' -f 2)
792
793 for FILE in $LOC; do
794 # Get target file name (i.e. system/bin/adb)
795 TARGET=$(echo $FILE | sed "s/\/$PRODUCT\//\n/" | tail -n 1)
796
797 # Don't send files that are not in /system.
798 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
799 continue
800 else
801 echo "Pushing: $TARGET"
802 adb push $FILE $TARGET
803 fi
804 done
805 rm -f .log
806 return 0
807}
808
809alias mmp='mmmp .'
810
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700811function gettop
812{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800813 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700814 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700815 # The following circumlocution ensures we remove symlinks from TOP.
816 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700817 else
818 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800819 # The following circumlocution (repeated below as well) ensures
820 # that we record the true directory name and not one that is
821 # faked up with symlink names.
822 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800824 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700825 T=
826 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800827 \cd ..
synergyb112a402013-07-05 19:47:47 -0700828 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829 done
Ying Wang9cd17642012-12-13 10:52:07 -0800830 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831 if [ -f "$T/$TOPFILE" ]; then
832 echo $T
833 fi
834 fi
835 fi
836}
837
Andrew Hsieh906cb782013-09-10 17:37:14 +0800838# Return driver for "make", if any (eg. static analyzer)
839function getdriver()
840{
841 local T="$1"
842 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
843 if [ -n "$WITH_STATIC_ANALYZER" ]; then
844 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800845$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
846--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800847--status-bugs \
848--top=$T"
849 fi
850}
851
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700852function m()
853{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800854 local T=$(gettop)
855 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700856 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800857 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700858 else
859 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700860 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861 fi
862}
863
864function findmakefile()
865{
866 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800867 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868 T=
869 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700870 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871 if [ -f "$T/Android.mk" ]; then
872 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800873 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700874 return
875 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800876 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700877 done
Ying Wang9cd17642012-12-13 10:52:07 -0800878 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700879}
880
881function mm()
882{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800883 local T=$(gettop)
884 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700885 # If we're sitting in the root of the build tree, just do a
886 # normal make.
887 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800888 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889 else
890 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800891 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700892 local MODULES=
893 local GET_INSTALL_PATH=
894 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700895 # Remove the path to top as the makefilepath needs to be relative
896 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700897 if [ ! "$T" ]; then
898 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700899 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700900 elif [ ! "$M" ]; then
901 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700902 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700903 else
Ying Wanga7deb082013-08-16 13:24:47 -0700904 for ARG in $@; do
905 case $ARG in
906 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
907 esac
908 done
909 if [ -n "$GET_INSTALL_PATH" ]; then
910 MODULES=
911 ARGS=GET-INSTALL-PATH
912 else
913 MODULES=all_modules
914 ARGS=$@
915 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700916 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 -0700917 fi
918 fi
919}
920
921function mmm()
922{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800923 local T=$(gettop)
924 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700925 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800926 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800927 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800928 local ARGS=
929 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700930 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800931 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
932 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
933 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800934 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
935 if [ "$MODULES" = "" ]; then
936 MODULES=all_modules
937 fi
938 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700939 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700940 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
941 local TO_CHOP=`expr $TO_CHOP + 1`
942 local START=`PWD= /bin/pwd`
943 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700944 if [ "$MFILE" = "" ] ; then
945 MFILE=$DIR/Android.mk
946 else
947 MFILE=$MFILE/$DIR/Android.mk
948 fi
949 MAKEFILE="$MAKEFILE $MFILE"
950 else
Ying Wanga7deb082013-08-16 13:24:47 -0700951 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100952 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700953 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
954 *) echo "No Android.mk in $DIR."; return 1;;
955 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700956 fi
957 done
Ying Wanga7deb082013-08-16 13:24:47 -0700958 if [ -n "$GET_INSTALL_PATH" ]; then
959 ARGS=$GET_INSTALL_PATH
960 MODULES=
961 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800962 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 -0700963 else
964 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700965 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700966 fi
967}
968
Ying Wangb607f7b2013-02-08 18:01:04 -0800969function mma()
970{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800971 local T=$(gettop)
972 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800973 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800974 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800975 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800976 if [ ! "$T" ]; then
977 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700978 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800979 fi
980 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800981 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800982 fi
983}
984
985function mmma()
986{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800987 local T=$(gettop)
988 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800989 if [ "$T" ]; then
990 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
991 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
992 local MY_PWD=`PWD= /bin/pwd`
993 if [ "$MY_PWD" = "$T" ]; then
994 MY_PWD=
995 else
996 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
997 fi
998 local DIR=
999 local MODULE_PATHS=
1000 local ARGS=
1001 for DIR in $DIRS ; do
1002 if [ -d $DIR ]; then
1003 if [ "$MY_PWD" = "" ]; then
1004 MODULE_PATHS="$MODULE_PATHS $DIR"
1005 else
1006 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
1007 fi
1008 else
1009 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +01001010 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -08001011 *) echo "Couldn't find directory $DIR"; return 1;;
1012 esac
1013 fi
1014 done
Andrew Hsieh906cb782013-09-10 17:37:14 +08001015 $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 -08001016 else
1017 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -07001018 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -08001019 fi
1020}
1021
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001022function croot()
1023{
1024 T=$(gettop)
1025 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001026 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001027 else
1028 echo "Couldn't locate the top of the tree. Try setting TOP."
1029 fi
1030}
1031
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001032function cproj()
1033{
1034 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001035 local HERE=$PWD
1036 T=
1037 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1038 T=$PWD
1039 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001040 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001041 return
1042 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001043 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001044 done
Ying Wang9cd17642012-12-13 10:52:07 -08001045 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001046 echo "can't find Android.mk"
1047}
1048
Daniel Sandler47e0a882013-07-30 13:23:52 -04001049# simplified version of ps; output in the form
1050# <pid> <procname>
1051function qpid() {
1052 local prepend=''
1053 local append=''
1054 if [ "$1" = "--exact" ]; then
1055 prepend=' '
1056 append='$'
1057 shift
1058 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1059 echo "usage: qpid [[--exact] <process name|pid>"
1060 return 255
1061 fi
1062
1063 local EXE="$1"
1064 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001065 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001066 else
1067 adb shell ps \
1068 | tr -d '\r' \
1069 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1070 fi
1071}
1072
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001073function pid()
1074{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001075 local prepend=''
1076 local append=''
1077 if [ "$1" = "--exact" ]; then
1078 prepend=' '
1079 append='$'
1080 shift
1081 fi
1082 local EXE="$1"
1083 if [ "$EXE" ] ; then
1084 local PID=`adb shell ps \
1085 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001086 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001087 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1088 echo "$PID"
1089 else
1090 echo "usage: pid [--exact] <process name>"
1091 return 255
1092 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001093}
1094
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001095# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001096# that has the core-file-size limit set correctly
1097#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001098# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001099# if its core-file-size limit is not set already.
1100# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1101
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001102function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103{
1104 echo "Getting root...";
1105 adb root;
1106 adb wait-for-device;
1107
1108 echo "Remounting root parition read-write...";
1109 adb shell mount -w -o remount -t rootfs rootfs;
1110 sleep 1;
1111 adb wait-for-device;
1112 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001113 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001114 adb shell chmod 0777 /cores;
1115
1116 echo "Granting SELinux permission to dump in /cores...";
1117 adb shell restorecon -R /cores;
1118
1119 echo "Set core pattern.";
1120 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1121
1122 echo "Done."
1123}
1124
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001125# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001126# $1 = PID of process (e.g., $(pid mediaserver))
1127#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001128# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001129# dump to actually be generated.
1130
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001131function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001132{
1133 local PID=$1;
1134 if [ -z "$PID" ]; then
1135 printf "Expecting a PID!\n";
1136 return;
1137 fi;
1138 echo "Setting core limit for $PID to infinite...";
1139 adb shell prlimit $PID 4 -1 -1
1140}
1141
1142# core - send SIGV and pull the core for process
1143# $1 = PID of process (e.g., $(pid mediaserver))
1144#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001145# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001146# enabled globally.
1147
1148function core()
1149{
1150 local PID=$1;
1151
1152 if [ -z "$PID" ]; then
1153 printf "Expecting a PID!\n";
1154 return;
1155 fi;
1156
1157 local CORENAME=core.$PID;
1158 local COREPATH=/cores/$CORENAME;
1159 local SIG=SEGV;
1160
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001161 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001162
1163 local done=0;
1164 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1165 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1166 adb shell kill -$SIG $PID;
1167 sleep 1;
1168 done;
1169
1170 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1171 echo "Done: core is under $COREPATH on device.";
1172}
1173
Christopher Tate744ee802009-11-12 15:33:08 -08001174# systemstack - dump the current stack trace of all threads in the system process
1175# to the usual ANR traces file
1176function systemstack()
1177{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001178 stacks system_server
1179}
1180
1181function stacks()
1182{
1183 if [[ $1 =~ ^[0-9]+$ ]] ; then
1184 local PID="$1"
1185 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001186 local PIDLIST="$(pid $1)"
1187 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1188 local PID="$PIDLIST"
1189 elif [ "$PIDLIST" ] ; then
1190 echo "more than one process: $1"
1191 else
1192 echo "no such process: $1"
1193 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001194 else
1195 echo "usage: stacks [pid|process name]"
1196 fi
1197
1198 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001199 # Determine whether the process is native
1200 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1201 # Dump stacks of Dalvik process
1202 local TRACES=/data/anr/traces.txt
1203 local ORIG=/data/anr/traces.orig
1204 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001205
Jeff Brownb12c2e52013-08-19 15:14:16 -07001206 # Keep original traces to avoid clobbering
1207 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001208
Jeff Brownb12c2e52013-08-19 15:14:16 -07001209 # Make sure we have a usable file
1210 adb shell touch $TRACES
1211 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001212
Jeff Brownb12c2e52013-08-19 15:14:16 -07001213 # Dump stacks and wait for dump to finish
1214 adb shell kill -3 $PID
1215 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001216
Jeff Brownb12c2e52013-08-19 15:14:16 -07001217 # Restore original stacks, and show current output
1218 adb shell mv $TRACES $TMP
1219 adb shell mv $ORIG $TRACES
1220 adb shell cat $TMP
1221 else
1222 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001223 local USE64BIT="$(is64bit $PID)"
1224 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001225 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001226 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001227}
1228
Michael Wrightaeed7212014-06-19 19:58:12 -07001229# Read the ELF header from /proc/$PID/exe to determine if the process is
1230# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001231function is64bit()
1232{
1233 local PID="$1"
1234 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001235 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001236 echo "64"
1237 else
1238 echo ""
1239 fi
1240 else
1241 echo ""
1242 fi
1243}
1244
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001245case `uname -s` in
1246 Darwin)
1247 function sgrep()
1248 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001249 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 -07001250 }
1251
1252 ;;
1253 *)
1254 function sgrep()
1255 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001256 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 -07001257 }
1258 ;;
1259esac
1260
Raghu Gandham8da43102012-07-25 19:57:22 -07001261function gettargetarch
1262{
1263 get_build_var TARGET_ARCH
1264}
1265
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001266function ggrep()
1267{
1268 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1269}
1270
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001271function jgrep()
1272{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001273 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 -07001274}
1275
1276function cgrep()
1277{
Dan Albert01961192014-11-22 10:16:01 -08001278 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 -07001279}
1280
1281function resgrep()
1282{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001283 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 -07001284}
1285
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001286function mangrep()
1287{
1288 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1289}
1290
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001291function sepgrep()
1292{
1293 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 "$@"
1294}
1295
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001296function rcgrep()
1297{
1298 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1299}
1300
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001301case `uname -s` in
1302 Darwin)
1303 function mgrep()
1304 {
Ying Wang324c2b22012-08-17 15:03:20 -07001305 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 -07001306 }
1307
1308 function treegrep()
1309 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001310 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 -07001311 }
1312
1313 ;;
1314 *)
1315 function mgrep()
1316 {
Ying Wang324c2b22012-08-17 15:03:20 -07001317 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 -07001318 }
1319
1320 function treegrep()
1321 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001322 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 -07001323 }
1324
1325 ;;
1326esac
1327
1328function getprebuilt
1329{
1330 get_abs_build_var ANDROID_PREBUILTS
1331}
1332
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001333function tracedmdump()
1334{
1335 T=$(gettop)
1336 if [ ! "$T" ]; then
1337 echo "Couldn't locate the top of the tree. Try setting TOP."
1338 return
1339 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001341 local arch=$(gettargetarch)
1342 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001343
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001344 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001345 if [ ! "$TRACE" ] ; then
1346 echo "usage: tracedmdump tracename"
1347 return
1348 fi
1349
Jack Veenstra60116fc2009-04-09 18:12:34 -07001350 if [ ! -r "$KERNEL" ] ; then
1351 echo "Error: cannot find kernel: '$KERNEL'"
1352 return
1353 fi
1354
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001355 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001356 if [ "$BASETRACE" = "$TRACE" ] ; then
1357 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1358 fi
1359
1360 echo "post-processing traces..."
1361 rm -f $TRACE/qtrace.dexlist
1362 post_trace $TRACE
1363 if [ $? -ne 0 ]; then
1364 echo "***"
1365 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1366 echo "***"
1367 return
1368 fi
1369 echo "generating dexlist output..."
1370 /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
1371 echo "generating dmtrace data..."
1372 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1373 echo "generating html file..."
1374 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1375 echo "done, see $TRACE/dmtrace.html for details"
1376 echo "or run:"
1377 echo " traceview $TRACE/dmtrace"
1378}
1379
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380# communicate with a running device or emulator, set up necessary state,
1381# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001382function runhat()
1383{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001384 # process standard adb options
1385 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001386 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001387 adbTarget=$1
1388 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001389 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001390 adbTarget="$1 $2"
1391 shift 2
1392 fi
1393 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001394 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001395
1396 # runhat options
1397 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001398
1399 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001400 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401 return
1402 fi
1403
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001404 # confirm hat is available
1405 if [ -z $(which hat) ]; then
1406 echo "hat is not available in this configuration."
1407 return
1408 fi
1409
Andy McFaddenb6289852010-07-12 08:00:19 -07001410 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001411 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001412 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001413 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001414 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001415 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001416 echo -n "> "
1417 read
1418
The Android Open Source Project88b60792009-03-03 19:28:42 -08001419 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420
The Android Open Source Project88b60792009-03-03 19:28:42 -08001421 echo "Retrieving file $devFile..."
1422 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001423
The Android Open Source Project88b60792009-03-03 19:28:42 -08001424 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001425
The Android Open Source Project88b60792009-03-03 19:28:42 -08001426 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001427 echo "View the output by pointing your browser at http://localhost:7000/"
1428 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001429 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001430}
1431
1432function getbugreports()
1433{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001434 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001435
1436 if [ ! "$reports" ]; then
1437 echo "Could not locate any bugreports."
1438 return
1439 fi
1440
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001441 local report
1442 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001443 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001444 echo "/sdcard/bugreports/${report}"
1445 adb pull /sdcard/bugreports/${report} ${report}
1446 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001447 done
1448}
1449
Victoria Lease1b296b42012-08-21 15:44:06 -07001450function getsdcardpath()
1451{
1452 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1453}
1454
1455function getscreenshotpath()
1456{
1457 echo "$(getsdcardpath)/Pictures/Screenshots"
1458}
1459
1460function getlastscreenshot()
1461{
1462 local screenshot_path=$(getscreenshotpath)
1463 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1464 if [ "$screenshot" = "" ]; then
1465 echo "No screenshots found."
1466 return
1467 fi
1468 echo "${screenshot}"
1469 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1470}
1471
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001472function startviewserver()
1473{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001474 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001475 if [ $# -gt 0 ]; then
1476 port=$1
1477 fi
1478 adb shell service call window 1 i32 $port
1479}
1480
1481function stopviewserver()
1482{
1483 adb shell service call window 2
1484}
1485
1486function isviewserverstarted()
1487{
1488 adb shell service call window 3
1489}
1490
Romain Guyb84049a2010-10-04 16:56:11 -07001491function key_home()
1492{
1493 adb shell input keyevent 3
1494}
1495
1496function key_back()
1497{
1498 adb shell input keyevent 4
1499}
1500
1501function key_menu()
1502{
1503 adb shell input keyevent 82
1504}
1505
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001506function smoketest()
1507{
1508 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1509 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1510 return
1511 fi
1512 T=$(gettop)
1513 if [ ! "$T" ]; then
1514 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1515 return
1516 fi
1517
Ying Wang9cd17642012-12-13 10:52:07 -08001518 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001519 adb uninstall com.android.smoketest > /dev/null &&
1520 adb uninstall com.android.smoketest.tests > /dev/null &&
1521 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1522 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1523 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1524}
1525
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001526# simple shortcut to the runtest command
1527function runtest()
1528{
1529 T=$(gettop)
1530 if [ ! "$T" ]; then
1531 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1532 return
1533 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001534 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001535}
1536
The Android Open Source Project88b60792009-03-03 19:28:42 -08001537function godir () {
1538 if [[ -z "$1" ]]; then
1539 echo "Usage: godir <regex>"
1540 return
1541 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001542 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001543 if [[ ! -f $T/filelist ]]; then
1544 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001545 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001546 echo " Done"
1547 echo ""
1548 fi
1549 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001550 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001551 if [[ ${#lines[@]} = 0 ]]; then
1552 echo "Not found"
1553 return
1554 fi
1555 local pathname
1556 local choice
1557 if [[ ${#lines[@]} > 1 ]]; then
1558 while [[ -z "$pathname" ]]; do
1559 local index=1
1560 local line
1561 for line in ${lines[@]}; do
1562 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001563 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001564 done
1565 echo
1566 echo -n "Select one: "
1567 unset choice
1568 read choice
1569 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1570 echo "Invalid choice"
1571 continue
1572 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001573 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001574 done
1575 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001576 pathname=${lines[0]}
1577 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001578 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001579}
1580
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001581function cmremote()
1582{
1583 git remote rm cmremote 2> /dev/null
1584 if [ ! -d .git ]
1585 then
1586 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1587 fi
1588 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1589 if [ -z "$GERRIT_REMOTE" ]
1590 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001591 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1592 if [ -z "$GERRIT_REMOTE" ]
1593 then
1594 echo Unable to set up the git remote, are you in the root of the repo?
1595 return 0
1596 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001597 fi
1598 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1599 if [ -z "$CMUSER" ]
1600 then
1601 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1602 else
1603 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1604 fi
1605 echo You can now push to "cmremote".
1606}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001607export -f cmremote
1608
1609function makerecipe() {
1610 if [ -z "$1" ]
1611 then
1612 echo "No branch name provided."
1613 return 1
1614 fi
1615 cd android
1616 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1617 git commit -a -m "$1"
1618 cd ..
1619
1620 repo forall -c '
1621
1622 if [ "$REPO_REMOTE" == "github" ]
1623 then
1624 pwd
1625 cmremote
1626 git push cmremote HEAD:refs/heads/'$1'
1627 fi
1628 '
1629}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001630
1631function cmgerrit() {
1632 if [ $# -eq 0 ]; then
1633 $FUNCNAME help
1634 return 1
1635 fi
1636 local user=`git config --get review.review.cyanogenmod.com.username`
1637 local review=`git config --get remote.github.review`
1638 local project=`git config --get remote.github.projectname`
1639 local command=$1
1640 shift
1641 case $command in
1642 help)
1643 if [ $# -eq 0 ]; then
1644 cat <<EOF
1645Usage:
1646 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1647
1648Commands:
1649 fetch Just fetch the change as FETCH_HEAD
1650 help Show this help, or for a specific command
1651 pull Pull a change into current branch
1652 push Push HEAD or a local branch to Gerrit for a specific branch
1653
1654Any other Git commands that support refname would work as:
1655 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1656
1657See '$FUNCNAME help COMMAND' for more information on a specific command.
1658
1659Example:
1660 $FUNCNAME checkout -b topic 1234/5
1661works as:
1662 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1663 && git checkout -b topic FETCH_HEAD
1664will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1665Patch-set 1 will be fetched if omitted.
1666EOF
1667 return
1668 fi
1669 case $1 in
1670 __cmg_*) echo "For internal use only." ;;
1671 changes|for)
1672 if [ "$FUNCNAME" = "cmgerrit" ]; then
1673 echo "'$FUNCNAME $1' is deprecated."
1674 fi
1675 ;;
1676 help) $FUNCNAME help ;;
1677 fetch|pull) cat <<EOF
1678usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1679
1680works as:
1681 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1682 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1683
1684Example:
1685 $FUNCNAME $1 1234
1686will $1 patch-set 1 of change 1234
1687EOF
1688 ;;
1689 push) cat <<EOF
1690usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1691
1692works as:
1693 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1694 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1695
1696Example:
1697 $FUNCNAME push fix6789:gingerbread
1698will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1699HEAD will be pushed from local if omitted.
1700EOF
1701 ;;
1702 *)
1703 $FUNCNAME __cmg_err_not_supported $1 && return
1704 cat <<EOF
1705usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1706
1707works as:
1708 git fetch http://DOMAIN/p/PROJECT \\
1709 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1710 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1711EOF
1712 ;;
1713 esac
1714 ;;
1715 __cmg_get_ref)
1716 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1717 local change_id patchset_id hash
1718 case $1 in
1719 */*)
1720 change_id=${1%%/*}
1721 patchset_id=${1#*/}
1722 ;;
1723 *)
1724 change_id=$1
1725 patchset_id=1
1726 ;;
1727 esac
1728 hash=$(($change_id % 100))
1729 case $hash in
1730 [0-9]) hash="0$hash" ;;
1731 esac
1732 echo "refs/changes/$hash/$change_id/$patchset_id"
1733 ;;
1734 fetch|pull)
1735 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1736 $FUNCNAME __cmg_err_not_repo && return 1
1737 local change=$1
1738 shift
1739 git $command $@ http://$review/p/$project \
1740 $($FUNCNAME __cmg_get_ref $change) || return 1
1741 ;;
1742 push)
1743 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1744 $FUNCNAME __cmg_err_not_repo && return 1
1745 if [ -z "$user" ]; then
1746 echo >&2 "Gerrit username not found."
1747 return 1
1748 fi
1749 local local_branch remote_branch
1750 case $1 in
1751 *:*)
1752 local_branch=${1%:*}
1753 remote_branch=${1##*:}
1754 ;;
1755 *)
1756 local_branch=HEAD
1757 remote_branch=$1
1758 ;;
1759 esac
1760 shift
1761 git push $@ ssh://$user@$review:29418/$project \
1762 $local_branch:refs/for/$remote_branch || return 1
1763 ;;
1764 changes|for)
1765 if [ "$FUNCNAME" = "cmgerrit" ]; then
1766 echo >&2 "'$FUNCNAME $command' is deprecated."
1767 fi
1768 ;;
1769 __cmg_err_no_arg)
1770 if [ $# -lt 2 ]; then
1771 echo >&2 "'$FUNCNAME $command' missing argument."
1772 elif [ $2 -eq 0 ]; then
1773 if [ -n "$3" ]; then
1774 $FUNCNAME help $1
1775 else
1776 echo >&2 "'$FUNCNAME $1' missing argument."
1777 fi
1778 else
1779 return 1
1780 fi
1781 ;;
1782 __cmg_err_not_repo)
1783 if [ -z "$review" -o -z "$project" ]; then
1784 echo >&2 "Not currently in any reviewable repository."
1785 else
1786 return 1
1787 fi
1788 ;;
1789 __cmg_err_not_supported)
1790 $FUNCNAME __cmg_err_no_arg $command $# && return
1791 case $1 in
1792 #TODO: filter more git commands that don't use refname
1793 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1794 echo >&2 "'$FUNCNAME $1' is not supported."
1795 ;;
1796 *) return 1 ;;
1797 esac
1798 ;;
1799 #TODO: other special cases?
1800 *)
1801 $FUNCNAME __cmg_err_not_supported $command && return 1
1802 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1803 $FUNCNAME __cmg_err_not_repo && return 1
1804 local args="$@"
1805 local change pre_args refs_arg post_args
1806 case "$args" in
1807 *--\ *)
1808 pre_args=${args%%-- *}
1809 post_args="-- ${args#*-- }"
1810 ;;
1811 *) pre_args="$args" ;;
1812 esac
1813 args=($pre_args)
1814 pre_args=
1815 if [ ${#args[@]} -gt 0 ]; then
1816 change=${args[${#args[@]}-1]}
1817 fi
1818 if [ ${#args[@]} -gt 1 ]; then
1819 pre_args=${args[0]}
1820 for ((i=1; i<${#args[@]}-1; i++)); do
1821 pre_args="$pre_args ${args[$i]}"
1822 done
1823 fi
1824 while ((1)); do
1825 case $change in
1826 ""|--)
1827 $FUNCNAME help $command
1828 return 1
1829 ;;
1830 *@*)
1831 if [ -z "$refs_arg" ]; then
1832 refs_arg="@${change#*@}"
1833 change=${change%%@*}
1834 fi
1835 ;;
1836 *~*)
1837 if [ -z "$refs_arg" ]; then
1838 refs_arg="~${change#*~}"
1839 change=${change%%~*}
1840 fi
1841 ;;
1842 *^*)
1843 if [ -z "$refs_arg" ]; then
1844 refs_arg="^${change#*^}"
1845 change=${change%%^*}
1846 fi
1847 ;;
1848 *:*)
1849 if [ -z "$refs_arg" ]; then
1850 refs_arg=":${change#*:}"
1851 change=${change%%:*}
1852 fi
1853 ;;
1854 *) break ;;
1855 esac
1856 done
1857 $FUNCNAME fetch $change \
1858 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1859 || return 1
1860 ;;
1861 esac
1862}
1863
1864function cmrebase() {
1865 local repo=$1
1866 local refs=$2
1867 local pwd="$(pwd)"
1868 local dir="$(gettop)/$repo"
1869
1870 if [ -z $repo ] || [ -z $refs ]; then
1871 echo "CyanogenMod Gerrit Rebase Usage: "
1872 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1873 echo " The patch IDs appear on the Gerrit commands that are offered."
1874 echo " They consist on a series of numbers and slashes, after the text"
1875 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1876 echo ""
1877 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1878 echo ""
1879 return
1880 fi
1881
1882 if [ ! -d $dir ]; then
1883 echo "Directory $dir doesn't exist in tree."
1884 return
1885 fi
1886 cd $dir
1887 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1888 echo "Starting branch..."
1889 repo start tmprebase .
1890 echo "Bringing it up to date..."
1891 repo sync .
1892 echo "Fetching change..."
1893 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
1894 if [ "$?" != "0" ]; then
1895 echo "Error cherry-picking. Not uploading!"
1896 return
1897 fi
1898 echo "Uploading..."
1899 repo upload .
1900 echo "Cleaning up..."
1901 repo abandon tmprebase .
1902 cd $pwd
1903}
1904
1905function mka() {
1906 case `uname -s` in
1907 Darwin)
1908 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1909 ;;
1910 *)
1911 schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
1912 ;;
1913 esac
1914}
1915
1916function reposync() {
1917 case `uname -s` in
1918 Darwin)
1919 repo sync -j 4 "$@"
1920 ;;
1921 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001922 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001923 ;;
1924 esac
1925}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001926
1927function repodiff() {
1928 if [ -z "$*" ]; then
1929 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1930 return
1931 fi
1932 diffopts=$* repo forall -c \
1933 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1934}
1935
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001936# 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 +00001937#
1938# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1939# For some reason, installing the JDK doesn't make it show up in the
1940# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001941function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001942 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001943 # we can reset it later, depending on the version of java the build
1944 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001945 #
1946 # If we don't do this, the JAVA_HOME value set by the first call to
1947 # build/envsetup.sh will persist forever.
1948 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1949 export JAVA_HOME=""
1950 fi
1951
Andy McFaddenbd960942010-06-24 12:52:51 -07001952 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01001953 case `uname -s` in
1954 Darwin)
1955 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
1956 ;;
1957 *)
1958 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1959 ;;
1960 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001961
1962 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1963 # we can change it on the next envsetup.sh, if required.
1964 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001965 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001966}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001967
Alex Rayf0d08eb2013-03-08 15:15:06 -08001968# Print colored exit condition
1969function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001970 "$@"
1971 local retval=$?
1972 if [ $retval -ne 0 ]
1973 then
1974 echo -e "\e[0;31mFAILURE\e[00m"
1975 else
1976 echo -e "\e[0;32mSUCCESS\e[00m"
1977 fi
1978 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001979}
1980
Ying Wanged21d4c2014-08-24 22:14:19 -07001981function get_make_command()
1982{
1983 echo command make
1984}
1985
Ed Heylcc6be0a2014-06-18 14:55:58 -07001986function make()
1987{
1988 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001989 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001990 local ret=$?
1991 local end_time=$(date +"%s")
1992 local tdiff=$(($end_time-$start_time))
1993 local hours=$(($tdiff / 3600 ))
1994 local mins=$((($tdiff % 3600) / 60))
1995 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07001996 local ncolors=$(tput colors 2>/dev/null)
1997 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
1998 color_failed="\e[0;31m"
1999 color_success="\e[0;32m"
2000 color_reset="\e[00m"
2001 else
2002 color_failed=""
2003 color_success=""
2004 color_reset=""
2005 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002006 echo
2007 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002008 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002009 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002010 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002011 fi
2012 if [ $hours -gt 0 ] ; then
2013 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2014 elif [ $mins -gt 0 ] ; then
2015 printf "(%02g:%02g (mm:ss))" $mins $secs
2016 elif [ $secs -gt 0 ] ; then
2017 printf "(%s seconds)" $secs
2018 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002019 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002020 echo
2021 return $ret
2022}
2023
Raphael Moll70a86b02011-06-20 16:03:14 -07002024if [ "x$SHELL" != "x/bin/bash" ]; then
2025 case `ps -o command -p $$` in
2026 *bash*)
2027 ;;
2028 *)
2029 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2030 ;;
2031 esac
2032fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002033
2034# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002035for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2036 `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 -08002037do
2038 echo "including $f"
2039 . $f
2040done
2041unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002042
2043addcompletions