blob: b851370173eacdecc2dbba098474dc82905f510e [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
Steve Kondik873fa562012-09-17 11:33:18 -070026- aospremote: Add git remote for matching AOSP repository
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060027- mka: Builds using SCHED_BATCH on all processors
28- reposync: Parallel repo sync using ionice and SCHED_BATCH
Steve Kondik83c03d52012-10-24 16:40:42 -070029- installboot: Installs a boot.img to the connected device.
30- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070031
Dan Albert4ae5d4b2014-10-31 16:23:08 -070032Environemnt options:
33- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
34 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
35 build is leak-check clean.
36
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070037Look at the source to view more functions. The complete list is:
38EOF
39 T=$(gettop)
40 local A
41 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070042 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 -070043 A="$A $i"
44 done
45 echo $A
46}
47
48# Get the value of a build variable as an absolute path.
49function get_abs_build_var()
50{
51 T=$(gettop)
52 if [ ! "$T" ]; then
53 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
54 return
55 fi
Ying Wang9cd17642012-12-13 10:52:07 -080056 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070057 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070058}
59
60# Get the exact value of a build variable.
61function get_build_var()
62{
63 T=$(gettop)
64 if [ ! "$T" ]; then
65 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
66 return
67 fi
Andrew Boie6905e212013-12-19 13:21:46 -080068 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070069 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080070}
71
72# check to see if the supplied product is one we can build
73function check_product()
74{
75 T=$(gettop)
76 if [ ! "$T" ]; then
77 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
78 return
79 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000080
81 if (echo -n $1 | grep -q -e "^cm_") ; then
82 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
83 else
84 CM_BUILD=
85 fi
86 export CM_BUILD
87
Jeff Browne33ba4c2011-07-11 22:11:46 -070088 TARGET_PRODUCT=$1 \
89 TARGET_BUILD_VARIANT= \
90 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070091 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080092 get_build_var TARGET_DEVICE > /dev/null
93 # hide successful answers, but allow the errors to show
94}
95
96VARIANT_CHOICES=(user userdebug eng)
97
98# check to see if the supplied variant is valid
99function check_variant()
100{
101 for v in ${VARIANT_CHOICES[@]}
102 do
103 if [ "$v" = "$1" ]
104 then
105 return 0
106 fi
107 done
108 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700109}
110
111function setpaths()
112{
113 T=$(gettop)
114 if [ ! "$T" ]; then
115 echo "Couldn't locate the top of the tree. Try setting TOP."
116 return
117 fi
118
119 ##################################################################
120 # #
121 # Read me before you modify this code #
122 # #
123 # This function sets ANDROID_BUILD_PATHS to what it is adding #
124 # to PATH, and the next time it is run, it removes that from #
125 # PATH. This is required so lunch can be run more than once #
126 # and still have working paths. #
127 # #
128 ##################################################################
129
Raphael Mollc639c782011-06-20 17:25:01 -0700130 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
131 # due to "C:\Program Files" being in the path.
132
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700133 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700134 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
136 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700137 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700138 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800139 # strip leading ':', if any
140 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500141 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700142
143 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700144 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700145 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700146
Ben Cheng8bc4c432012-11-16 13:29:13 -0800147 # defined in core/config.mk
148 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700149 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800150 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800151
Raphael Mollc639c782011-06-20 17:25:01 -0700152 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800153 export ANDROID_TOOLCHAIN=
154 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200155 local ARCH=$(get_build_var TARGET_ARCH)
156 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400157 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700158 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400159 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
160 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800161 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200162 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800163 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700164 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700165 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700166 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000167 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200168 *)
169 echo "Can't find toolchain for unknown architecture: $ARCH"
170 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700171 ;;
172 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700173 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800174 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700175 fi
Raphael732936d2011-06-22 14:35:32 -0700176
Ben Chengfba67bf2014-02-25 10:27:07 -0800177 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
178 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
179 fi
180
181 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700182 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700183 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800184 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800185 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700186 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100187 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
188 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700189 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700190 ;;
191 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700192 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700193 ;;
194 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700195
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700196 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700197 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 +0200198
199 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
200 # to ensure that the corresponding 'emulator' binaries are used.
201 case $(uname -s) in
202 Darwin)
203 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
204 ;;
205 Linux)
206 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
207 ;;
208 *)
209 ANDROID_EMULATOR_PREBUILTS=
210 ;;
211 esac
212 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700213 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200214 export ANDROID_EMULATOR_PREBUILTS
215 fi
216
Ying Wangaa1c9b52012-11-26 20:51:59 -0800217 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800218
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500219 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900220 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500221 if [ -n "$JAVA_HOME" ]; then
222 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900223 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
224 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500225 fi
226
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800227 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700228 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
229 export OUT=$ANDROID_PRODUCT_OUT
230
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700231 unset ANDROID_HOST_OUT
232 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
233
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800234 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700235 # TODO: fix the path
236 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
237}
238
239function printconfig()
240{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800241 T=$(gettop)
242 if [ ! "$T" ]; then
243 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
244 return
245 fi
246 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247}
248
249function set_stuff_for_environment()
250{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500252 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800253 setpaths
254 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700257 # With this environment variable new GCC can apply colors to warnings/errors
258 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 -0700259 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260}
261
262function set_sequence_number()
263{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700264 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700265}
266
267function settitle()
268{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800269 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700270 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700271 local product=$TARGET_PRODUCT
272 local variant=$TARGET_BUILD_VARIANT
273 local apps=$TARGET_BUILD_APPS
274 if [ -z "$apps" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700275 export PROMPT_COMMAND="echo -ne \"\033]0;[${arch}-${product}-${variant}] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700276 else
Raghu Gandham8da43102012-07-25 19:57:22 -0700277 export PROMPT_COMMAND="echo -ne \"\033]0;[$arch $apps $variant] ${USER}@${HOSTNAME}: ${PWD}\007\""
Joe Onoratoda12daf2010-06-09 18:18:31 -0700278 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800279 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700280}
281
Kenny Root52aa81c2011-07-15 11:07:06 -0700282function addcompletions()
283{
284 local T dir f
285
286 # Keep us from trying to run in something that isn't bash.
287 if [ -z "${BASH_VERSION}" ]; then
288 return
289 fi
290
291 # Keep us from trying to run in bash that's too old.
292 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
293 return
294 fi
295
296 dir="sdk/bash_completion"
297 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700298 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700299 echo "including $f"
300 . $f
301 done
302 fi
303}
304
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700305function choosetype()
306{
307 echo "Build type choices are:"
308 echo " 1. release"
309 echo " 2. debug"
310 echo
311
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800312 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700313 DEFAULT_NUM=1
314 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800316 export TARGET_BUILD_TYPE=
317 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318 while [ -z $TARGET_BUILD_TYPE ]
319 do
320 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 if [ -z "$1" ] ; then
322 read ANSWER
323 else
324 echo $1
325 ANSWER=$1
326 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 case $ANSWER in
328 "")
329 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
330 ;;
331 1)
332 export TARGET_BUILD_TYPE=release
333 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800334 release)
335 export TARGET_BUILD_TYPE=release
336 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 2)
338 export TARGET_BUILD_TYPE=debug
339 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800340 debug)
341 export TARGET_BUILD_TYPE=debug
342 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700343 *)
344 echo
345 echo "I didn't understand your response. Please try again."
346 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 ;;
348 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349 if [ -n "$1" ] ; then
350 break
351 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700352 done
353
354 set_stuff_for_environment
355}
356
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800357#
358# This function isn't really right: It chooses a TARGET_PRODUCT
359# based on the list of boards. Usually, that gets you something
360# that kinda works with a generic product, but really, you should
361# pick a product by name.
362#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700363function chooseproduct()
364{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365 if [ "x$TARGET_PRODUCT" != x ] ; then
366 default_value=$TARGET_PRODUCT
367 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700368 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700369 fi
370
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800371 export TARGET_PRODUCT=
372 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700373 while [ -z "$TARGET_PRODUCT" ]
374 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700375 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800376 if [ -z "$1" ] ; then
377 read ANSWER
378 else
379 echo $1
380 ANSWER=$1
381 fi
382
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383 if [ -z "$ANSWER" ] ; then
384 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800385 else
386 if check_product $ANSWER
387 then
388 export TARGET_PRODUCT=$ANSWER
389 else
390 echo "** Not a valid product: $ANSWER"
391 fi
392 fi
393 if [ -n "$1" ] ; then
394 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700395 fi
396 done
397
398 set_stuff_for_environment
399}
400
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800401function choosevariant()
402{
403 echo "Variant choices are:"
404 local index=1
405 local v
406 for v in ${VARIANT_CHOICES[@]}
407 do
408 # The product name is the name of the directory containing
409 # the makefile we found, above.
410 echo " $index. $v"
411 index=$(($index+1))
412 done
413
414 local default_value=eng
415 local ANSWER
416
417 export TARGET_BUILD_VARIANT=
418 while [ -z "$TARGET_BUILD_VARIANT" ]
419 do
420 echo -n "Which would you like? [$default_value] "
421 if [ -z "$1" ] ; then
422 read ANSWER
423 else
424 echo $1
425 ANSWER=$1
426 fi
427
428 if [ -z "$ANSWER" ] ; then
429 export TARGET_BUILD_VARIANT=$default_value
430 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
431 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800432 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800433 fi
434 else
435 if check_variant $ANSWER
436 then
437 export TARGET_BUILD_VARIANT=$ANSWER
438 else
439 echo "** Not a valid variant: $ANSWER"
440 fi
441 fi
442 if [ -n "$1" ] ; then
443 break
444 fi
445 done
446}
447
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700448function choosecombo()
449{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700450 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451
452 echo
453 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700454 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700455
456 echo
457 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700458 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800459
460 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463}
464
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800465# Clear this variable. It will be built up again when the vendorsetup.sh
466# files are included at the end of this file.
467unset LUNCH_MENU_CHOICES
468function add_lunch_combo()
469{
470 local new_combo=$1
471 local c
472 for c in ${LUNCH_MENU_CHOICES[@]} ; do
473 if [ "$new_combo" = "$c" ] ; then
474 return
475 fi
476 done
477 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
478}
479
480# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700481add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800482add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000483add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800484add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000485add_lunch_combo aosp_x86-eng
486add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800487
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700488function print_lunch_menu()
489{
490 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491 echo
492 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000493 if [ "$(uname)" = "Darwin" ] ; then
494 echo " (ohai, koush!)"
495 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000497 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
498 echo "Breakfast menu... pick a combo:"
499 else
500 echo "Lunch menu... pick a combo:"
501 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502
503 local i=1
504 local choice
505 for choice in ${LUNCH_MENU_CHOICES[@]}
506 do
507 echo " $i. $choice"
508 i=$(($i+1))
509 done
510
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000511 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
512 echo "... and don't forget the bacon!"
513 fi
514
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 echo
516}
517
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000518function brunch()
519{
520 breakfast $*
521 if [ $? -eq 0 ]; then
522 mka bacon
523 else
524 echo "No such item in brunch menu. Try 'breakfast'"
525 return 1
526 fi
527 return $?
528}
529
530function breakfast()
531{
532 target=$1
533 CM_DEVICES_ONLY="true"
534 unset LUNCH_MENU_CHOICES
535 add_lunch_combo full-eng
536 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
537 do
538 echo "including $f"
539 . $f
540 done
541 unset f
542
543 if [ $# -eq 0 ]; then
544 # No arguments, so let's have the full menu
545 lunch
546 else
547 echo "z$target" | grep -q "-"
548 if [ $? -eq 0 ]; then
549 # A buildtype was specified, assume a full device name
550 lunch $target
551 else
552 # This is probably just the CM model name
553 lunch cm_$target-userdebug
554 fi
555 fi
556 return $?
557}
558
559alias bib=breakfast
560
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700561function lunch()
562{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800563 local answer
564
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700565 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800566 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700567 else
568 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700569 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800570 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700571 fi
572
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800573 local selection=
574
575 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700576 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700577 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
579 then
580 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
581 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800582 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583 fi
584 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
585 then
586 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587 fi
588
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 if [ -z "$selection" ]
590 then
591 echo
592 echo "Invalid lunch combo: $answer"
593 return 1
594 fi
595
Joe Onoratoda12daf2010-06-09 18:18:31 -0700596 export TARGET_BUILD_APPS=
597
Jeff Browne33ba4c2011-07-11 22:11:46 -0700598 local product=$(echo -n $selection | sed -e "s/-.*$//")
599 check_product $product
600 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800601 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800602 # if we can't find a product, try to grab it off the CM github
603 T=$(gettop)
604 pushd $T > /dev/null
605 build/tools/roomservice.py $product
606 popd > /dev/null
607 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000608 else
609 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800610 fi
611 if [ $? -ne 0 ]
612 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700613 echo
614 echo "** Don't have a product spec for: '$product'"
615 echo "** Do you have the right repo manifest?"
616 product=
617 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618
Jeff Browne33ba4c2011-07-11 22:11:46 -0700619 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
620 check_variant $variant
621 if [ $? -ne 0 ]
622 then
623 echo
624 echo "** Invalid variant: '$variant'"
625 echo "** Must be one of ${VARIANT_CHOICES[@]}"
626 variant=
627 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800628
Jeff Browne33ba4c2011-07-11 22:11:46 -0700629 if [ -z "$product" -o -z "$variant" ]
630 then
631 echo
632 return 1
633 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800634
Jeff Browne33ba4c2011-07-11 22:11:46 -0700635 export TARGET_PRODUCT=$product
636 export TARGET_BUILD_VARIANT=$variant
637 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700638
639 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800640
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700641 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700643}
644
Jeff Davidson513d7a42010-08-02 10:00:44 -0700645# Tab completion for lunch.
646function _lunch()
647{
648 local cur prev opts
649 COMPREPLY=()
650 cur="${COMP_WORDS[COMP_CWORD]}"
651 prev="${COMP_WORDS[COMP_CWORD-1]}"
652
653 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
654 return 0
655}
656complete -F _lunch lunch
657
Joe Onoratoda12daf2010-06-09 18:18:31 -0700658# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700659# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700660function tapas()
661{
Ying Wangb541ab62014-05-29 17:57:40 -0700662 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 -0700663 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700664 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
665 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 -0700666
Ying Wang67f02922012-08-22 10:25:20 -0700667 if [ $(echo $arch | wc -w) -gt 1 ]; then
668 echo "tapas: Error: Multiple build archs supplied: $arch"
669 return
670 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700671 if [ $(echo $variant | wc -w) -gt 1 ]; then
672 echo "tapas: Error: Multiple build variants supplied: $variant"
673 return
674 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700675 if [ $(echo $density | wc -w) -gt 1 ]; then
676 echo "tapas: Error: Multiple densities supplied: $density"
677 return
678 fi
Ying Wang67f02922012-08-22 10:25:20 -0700679
680 local product=full
681 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700682 x86) product=full_x86;;
683 mips) product=full_mips;;
684 armv5) product=generic_armv5;;
685 arm64) product=aosp_arm64;;
686 x86_64) product=aosp_x86_64;;
687 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700688 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700689 if [ -z "$variant" ]; then
690 variant=eng
691 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700692 if [ -z "$apps" ]; then
693 apps=all
694 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600695 if [ -z "$density" ]; then
696 density=alldpi
697 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700698
Ying Wang67f02922012-08-22 10:25:20 -0700699 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700700 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700701 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700702 export TARGET_BUILD_TYPE=release
703 export TARGET_BUILD_APPS=$apps
704
705 set_stuff_for_environment
706 printconfig
707}
708
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100709function eat()
710{
711 if [ "$OUT" ] ; then
712 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
713 ZIPFILE=cm-$MODVERSION.zip
714 ZIPPATH=$OUT/$ZIPFILE
715 if [ ! -f $ZIPPATH ] ; then
716 echo "Nothing to eat"
717 return 1
718 fi
719 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
720 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
721 echo "No device is online. Waiting for one..."
722 echo "Please connect USB and/or enable USB debugging"
723 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
724 sleep 1
725 done
726 echo "Device Found.."
727 fi
728 # if adbd isn't root we can't write to /cache/recovery/
729 adb root
730 sleep 1
731 adb wait-for-device
732 SZ=`stat -c %s $ZIPPATH`
733 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
734 if [ $CACHESIZE -gt $SZ ];
735 then
736 PUSHDIR=/cache/
737 DIR=cache
738 else
739 PUSHDIR=/storage/sdcard0/
740 # Optional path for sdcard0 in recovery
741 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
742 fi
743 echo "Pushing $ZIPFILE to $PUSHDIR"
744 if adb push $ZIPPATH $PUSHDIR ; then
745 cat << EOF > /tmp/command
746--update_package=/$DIR/$ZIPFILE
747EOF
748 if adb push /tmp/command /cache/recovery/ ; then
749 echo "Rebooting into recovery for installation"
750 adb reboot recovery
751 fi
752 rm /tmp/command
753 fi
754 else
755 echo "Nothing to eat"
756 return 1
757 fi
758 return $?
759}
760
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700761function gettop
762{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800763 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700764 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700765 # The following circumlocution ensures we remove symlinks from TOP.
766 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767 else
768 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800769 # The following circumlocution (repeated below as well) ensures
770 # that we record the true directory name and not one that is
771 # faked up with symlink names.
772 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700773 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800774 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700775 T=
776 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800777 \cd ..
synergyb112a402013-07-05 19:47:47 -0700778 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 done
Ying Wang9cd17642012-12-13 10:52:07 -0800780 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 if [ -f "$T/$TOPFILE" ]; then
782 echo $T
783 fi
784 fi
785 fi
786}
787
Andrew Hsieh906cb782013-09-10 17:37:14 +0800788# Return driver for "make", if any (eg. static analyzer)
789function getdriver()
790{
791 local T="$1"
792 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
793 if [ -n "$WITH_STATIC_ANALYZER" ]; then
794 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800795$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
796--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800797--status-bugs \
798--top=$T"
799 fi
800}
801
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802function m()
803{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800804 local T=$(gettop)
805 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700806 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800807 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700808 else
809 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700810 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700811 fi
812}
813
814function findmakefile()
815{
816 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800817 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700818 T=
819 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700820 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700821 if [ -f "$T/Android.mk" ]; then
822 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800823 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824 return
825 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800826 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827 done
Ying Wang9cd17642012-12-13 10:52:07 -0800828 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829}
830
831function mm()
832{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800833 local T=$(gettop)
834 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835 # If we're sitting in the root of the build tree, just do a
836 # normal make.
837 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800838 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 else
840 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800841 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700842 local MODULES=
843 local GET_INSTALL_PATH=
844 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700845 # Remove the path to top as the makefilepath needs to be relative
846 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847 if [ ! "$T" ]; then
848 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700849 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850 elif [ ! "$M" ]; then
851 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700852 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700853 else
Ying Wanga7deb082013-08-16 13:24:47 -0700854 for ARG in $@; do
855 case $ARG in
856 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
857 esac
858 done
859 if [ -n "$GET_INSTALL_PATH" ]; then
860 MODULES=
861 ARGS=GET-INSTALL-PATH
862 else
863 MODULES=all_modules
864 ARGS=$@
865 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700866 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 -0700867 fi
868 fi
869}
870
871function mmm()
872{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800873 local T=$(gettop)
874 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700875 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800876 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800877 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800878 local ARGS=
879 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700880 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800881 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
882 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
883 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800884 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
885 if [ "$MODULES" = "" ]; then
886 MODULES=all_modules
887 fi
888 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700889 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700890 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
891 local TO_CHOP=`expr $TO_CHOP + 1`
892 local START=`PWD= /bin/pwd`
893 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700894 if [ "$MFILE" = "" ] ; then
895 MFILE=$DIR/Android.mk
896 else
897 MFILE=$MFILE/$DIR/Android.mk
898 fi
899 MAKEFILE="$MAKEFILE $MFILE"
900 else
Ying Wanga7deb082013-08-16 13:24:47 -0700901 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100902 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700903 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
904 *) echo "No Android.mk in $DIR."; return 1;;
905 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700906 fi
907 done
Ying Wanga7deb082013-08-16 13:24:47 -0700908 if [ -n "$GET_INSTALL_PATH" ]; then
909 ARGS=$GET_INSTALL_PATH
910 MODULES=
911 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800912 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 -0700913 else
914 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700915 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700916 fi
917}
918
Ying Wangb607f7b2013-02-08 18:01:04 -0800919function mma()
920{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800921 local T=$(gettop)
922 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800923 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800924 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800925 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800926 if [ ! "$T" ]; then
927 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700928 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800929 fi
930 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800931 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800932 fi
933}
934
935function mmma()
936{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800937 local T=$(gettop)
938 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800939 if [ "$T" ]; then
940 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
941 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
942 local MY_PWD=`PWD= /bin/pwd`
943 if [ "$MY_PWD" = "$T" ]; then
944 MY_PWD=
945 else
946 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
947 fi
948 local DIR=
949 local MODULE_PATHS=
950 local ARGS=
951 for DIR in $DIRS ; do
952 if [ -d $DIR ]; then
953 if [ "$MY_PWD" = "" ]; then
954 MODULE_PATHS="$MODULE_PATHS $DIR"
955 else
956 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
957 fi
958 else
959 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100960 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800961 *) echo "Couldn't find directory $DIR"; return 1;;
962 esac
963 fi
964 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800965 $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 -0800966 else
967 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700968 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800969 fi
970}
971
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700972function croot()
973{
974 T=$(gettop)
975 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800976 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700977 else
978 echo "Couldn't locate the top of the tree. Try setting TOP."
979 fi
980}
981
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700982function cproj()
983{
984 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700985 local HERE=$PWD
986 T=
987 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
988 T=$PWD
989 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800990 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700991 return
992 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800993 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700994 done
Ying Wang9cd17642012-12-13 10:52:07 -0800995 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700996 echo "can't find Android.mk"
997}
998
Daniel Sandler47e0a882013-07-30 13:23:52 -0400999# simplified version of ps; output in the form
1000# <pid> <procname>
1001function qpid() {
1002 local prepend=''
1003 local append=''
1004 if [ "$1" = "--exact" ]; then
1005 prepend=' '
1006 append='$'
1007 shift
1008 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1009 echo "usage: qpid [[--exact] <process name|pid>"
1010 return 255
1011 fi
1012
1013 local EXE="$1"
1014 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001015 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001016 else
1017 adb shell ps \
1018 | tr -d '\r' \
1019 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1020 fi
1021}
1022
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001023function pid()
1024{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001025 local prepend=''
1026 local append=''
1027 if [ "$1" = "--exact" ]; then
1028 prepend=' '
1029 append='$'
1030 shift
1031 fi
1032 local EXE="$1"
1033 if [ "$EXE" ] ; then
1034 local PID=`adb shell ps \
1035 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001036 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001037 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1038 echo "$PID"
1039 else
1040 echo "usage: pid [--exact] <process name>"
1041 return 255
1042 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001043}
1044
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001045# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001046# that has the core-file-size limit set correctly
1047#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001048# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001049# if its core-file-size limit is not set already.
1050# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1051
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001052function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001053{
1054 echo "Getting root...";
1055 adb root;
1056 adb wait-for-device;
1057
1058 echo "Remounting root parition read-write...";
1059 adb shell mount -w -o remount -t rootfs rootfs;
1060 sleep 1;
1061 adb wait-for-device;
1062 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001063 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064 adb shell chmod 0777 /cores;
1065
1066 echo "Granting SELinux permission to dump in /cores...";
1067 adb shell restorecon -R /cores;
1068
1069 echo "Set core pattern.";
1070 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1071
1072 echo "Done."
1073}
1074
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001075# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001076# $1 = PID of process (e.g., $(pid mediaserver))
1077#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001078# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001079# dump to actually be generated.
1080
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001081function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001082{
1083 local PID=$1;
1084 if [ -z "$PID" ]; then
1085 printf "Expecting a PID!\n";
1086 return;
1087 fi;
1088 echo "Setting core limit for $PID to infinite...";
1089 adb shell prlimit $PID 4 -1 -1
1090}
1091
1092# core - send SIGV and pull the core for process
1093# $1 = PID of process (e.g., $(pid mediaserver))
1094#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001095# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001096# enabled globally.
1097
1098function core()
1099{
1100 local PID=$1;
1101
1102 if [ -z "$PID" ]; then
1103 printf "Expecting a PID!\n";
1104 return;
1105 fi;
1106
1107 local CORENAME=core.$PID;
1108 local COREPATH=/cores/$CORENAME;
1109 local SIG=SEGV;
1110
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001111 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001112
1113 local done=0;
1114 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1115 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1116 adb shell kill -$SIG $PID;
1117 sleep 1;
1118 done;
1119
1120 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1121 echo "Done: core is under $COREPATH on device.";
1122}
1123
Christopher Tate744ee802009-11-12 15:33:08 -08001124# systemstack - dump the current stack trace of all threads in the system process
1125# to the usual ANR traces file
1126function systemstack()
1127{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001128 stacks system_server
1129}
1130
1131function stacks()
1132{
1133 if [[ $1 =~ ^[0-9]+$ ]] ; then
1134 local PID="$1"
1135 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001136 local PIDLIST="$(pid $1)"
1137 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1138 local PID="$PIDLIST"
1139 elif [ "$PIDLIST" ] ; then
1140 echo "more than one process: $1"
1141 else
1142 echo "no such process: $1"
1143 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001144 else
1145 echo "usage: stacks [pid|process name]"
1146 fi
1147
1148 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001149 # Determine whether the process is native
1150 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1151 # Dump stacks of Dalvik process
1152 local TRACES=/data/anr/traces.txt
1153 local ORIG=/data/anr/traces.orig
1154 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001155
Jeff Brownb12c2e52013-08-19 15:14:16 -07001156 # Keep original traces to avoid clobbering
1157 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001158
Jeff Brownb12c2e52013-08-19 15:14:16 -07001159 # Make sure we have a usable file
1160 adb shell touch $TRACES
1161 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001162
Jeff Brownb12c2e52013-08-19 15:14:16 -07001163 # Dump stacks and wait for dump to finish
1164 adb shell kill -3 $PID
1165 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001166
Jeff Brownb12c2e52013-08-19 15:14:16 -07001167 # Restore original stacks, and show current output
1168 adb shell mv $TRACES $TMP
1169 adb shell mv $ORIG $TRACES
1170 adb shell cat $TMP
1171 else
1172 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001173 local USE64BIT="$(is64bit $PID)"
1174 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001175 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001176 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001177}
1178
Michael Wrightaeed7212014-06-19 19:58:12 -07001179# Read the ELF header from /proc/$PID/exe to determine if the process is
1180# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001181function is64bit()
1182{
1183 local PID="$1"
1184 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001185 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001186 echo "64"
1187 else
1188 echo ""
1189 fi
1190 else
1191 echo ""
1192 fi
1193}
1194
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001195case `uname -s` in
1196 Darwin)
1197 function sgrep()
1198 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001199 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 -07001200 }
1201
1202 ;;
1203 *)
1204 function sgrep()
1205 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001206 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 -07001207 }
1208 ;;
1209esac
1210
Raghu Gandham8da43102012-07-25 19:57:22 -07001211function gettargetarch
1212{
1213 get_build_var TARGET_ARCH
1214}
1215
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001216function ggrep()
1217{
1218 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1219}
1220
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001221function jgrep()
1222{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001223 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 -07001224}
1225
1226function cgrep()
1227{
Dan Albert01961192014-11-22 10:16:01 -08001228 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 -07001229}
1230
1231function resgrep()
1232{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001233 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 -07001234}
1235
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001236function mangrep()
1237{
1238 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1239}
1240
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001241function sepgrep()
1242{
1243 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 "$@"
1244}
1245
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001246function rcgrep()
1247{
1248 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1249}
1250
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001251case `uname -s` in
1252 Darwin)
1253 function mgrep()
1254 {
Ying Wang324c2b22012-08-17 15:03:20 -07001255 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 -07001256 }
1257
1258 function treegrep()
1259 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001260 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 -07001261 }
1262
1263 ;;
1264 *)
1265 function mgrep()
1266 {
Ying Wang324c2b22012-08-17 15:03:20 -07001267 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 -07001268 }
1269
1270 function treegrep()
1271 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001272 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 -07001273 }
1274
1275 ;;
1276esac
1277
1278function getprebuilt
1279{
1280 get_abs_build_var ANDROID_PREBUILTS
1281}
1282
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001283function tracedmdump()
1284{
1285 T=$(gettop)
1286 if [ ! "$T" ]; then
1287 echo "Couldn't locate the top of the tree. Try setting TOP."
1288 return
1289 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001290 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001291 local arch=$(gettargetarch)
1292 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001293
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001294 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001295 if [ ! "$TRACE" ] ; then
1296 echo "usage: tracedmdump tracename"
1297 return
1298 fi
1299
Jack Veenstra60116fc2009-04-09 18:12:34 -07001300 if [ ! -r "$KERNEL" ] ; then
1301 echo "Error: cannot find kernel: '$KERNEL'"
1302 return
1303 fi
1304
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001305 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001306 if [ "$BASETRACE" = "$TRACE" ] ; then
1307 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1308 fi
1309
1310 echo "post-processing traces..."
1311 rm -f $TRACE/qtrace.dexlist
1312 post_trace $TRACE
1313 if [ $? -ne 0 ]; then
1314 echo "***"
1315 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1316 echo "***"
1317 return
1318 fi
1319 echo "generating dexlist output..."
1320 /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
1321 echo "generating dmtrace data..."
1322 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1323 echo "generating html file..."
1324 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1325 echo "done, see $TRACE/dmtrace.html for details"
1326 echo "or run:"
1327 echo " traceview $TRACE/dmtrace"
1328}
1329
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001330# communicate with a running device or emulator, set up necessary state,
1331# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001332function runhat()
1333{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001334 # process standard adb options
1335 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001336 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001337 adbTarget=$1
1338 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001339 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340 adbTarget="$1 $2"
1341 shift 2
1342 fi
1343 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001344 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001345
1346 # runhat options
1347 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001348
1349 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001350 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001351 return
1352 fi
1353
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001354 # confirm hat is available
1355 if [ -z $(which hat) ]; then
1356 echo "hat is not available in this configuration."
1357 return
1358 fi
1359
Andy McFaddenb6289852010-07-12 08:00:19 -07001360 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001361 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001362 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001363 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001364 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001365 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001366 echo -n "> "
1367 read
1368
The Android Open Source Project88b60792009-03-03 19:28:42 -08001369 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001370
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371 echo "Retrieving file $devFile..."
1372 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001373
The Android Open Source Project88b60792009-03-03 19:28:42 -08001374 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001375
The Android Open Source Project88b60792009-03-03 19:28:42 -08001376 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377 echo "View the output by pointing your browser at http://localhost:7000/"
1378 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001379 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380}
1381
1382function getbugreports()
1383{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001384 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001385
1386 if [ ! "$reports" ]; then
1387 echo "Could not locate any bugreports."
1388 return
1389 fi
1390
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001391 local report
1392 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001393 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001394 echo "/sdcard/bugreports/${report}"
1395 adb pull /sdcard/bugreports/${report} ${report}
1396 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397 done
1398}
1399
Victoria Lease1b296b42012-08-21 15:44:06 -07001400function getsdcardpath()
1401{
1402 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1403}
1404
1405function getscreenshotpath()
1406{
1407 echo "$(getsdcardpath)/Pictures/Screenshots"
1408}
1409
1410function getlastscreenshot()
1411{
1412 local screenshot_path=$(getscreenshotpath)
1413 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1414 if [ "$screenshot" = "" ]; then
1415 echo "No screenshots found."
1416 return
1417 fi
1418 echo "${screenshot}"
1419 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1420}
1421
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001422function startviewserver()
1423{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001424 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001425 if [ $# -gt 0 ]; then
1426 port=$1
1427 fi
1428 adb shell service call window 1 i32 $port
1429}
1430
1431function stopviewserver()
1432{
1433 adb shell service call window 2
1434}
1435
1436function isviewserverstarted()
1437{
1438 adb shell service call window 3
1439}
1440
Romain Guyb84049a2010-10-04 16:56:11 -07001441function key_home()
1442{
1443 adb shell input keyevent 3
1444}
1445
1446function key_back()
1447{
1448 adb shell input keyevent 4
1449}
1450
1451function key_menu()
1452{
1453 adb shell input keyevent 82
1454}
1455
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001456function smoketest()
1457{
1458 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1459 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1460 return
1461 fi
1462 T=$(gettop)
1463 if [ ! "$T" ]; then
1464 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1465 return
1466 fi
1467
Ying Wang9cd17642012-12-13 10:52:07 -08001468 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001469 adb uninstall com.android.smoketest > /dev/null &&
1470 adb uninstall com.android.smoketest.tests > /dev/null &&
1471 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1472 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1473 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1474}
1475
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001476# simple shortcut to the runtest command
1477function runtest()
1478{
1479 T=$(gettop)
1480 if [ ! "$T" ]; then
1481 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1482 return
1483 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001484 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001485}
1486
The Android Open Source Project88b60792009-03-03 19:28:42 -08001487function godir () {
1488 if [[ -z "$1" ]]; then
1489 echo "Usage: godir <regex>"
1490 return
1491 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001492 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001493 if [[ ! -f $T/filelist ]]; then
1494 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001495 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001496 echo " Done"
1497 echo ""
1498 fi
1499 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001500 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001501 if [[ ${#lines[@]} = 0 ]]; then
1502 echo "Not found"
1503 return
1504 fi
1505 local pathname
1506 local choice
1507 if [[ ${#lines[@]} > 1 ]]; then
1508 while [[ -z "$pathname" ]]; do
1509 local index=1
1510 local line
1511 for line in ${lines[@]}; do
1512 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001513 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001514 done
1515 echo
1516 echo -n "Select one: "
1517 unset choice
1518 read choice
1519 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1520 echo "Invalid choice"
1521 continue
1522 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001523 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001524 done
1525 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001526 pathname=${lines[0]}
1527 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001528 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001529}
1530
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001531function cmremote()
1532{
1533 git remote rm cmremote 2> /dev/null
1534 if [ ! -d .git ]
1535 then
1536 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1537 fi
1538 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1539 if [ -z "$GERRIT_REMOTE" ]
1540 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001541 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1542 if [ -z "$GERRIT_REMOTE" ]
1543 then
1544 echo Unable to set up the git remote, are you in the root of the repo?
1545 return 0
1546 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001547 fi
1548 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1549 if [ -z "$CMUSER" ]
1550 then
1551 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1552 else
1553 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1554 fi
1555 echo You can now push to "cmremote".
1556}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001557export -f cmremote
1558
Steve Kondik873fa562012-09-17 11:33:18 -07001559function aospremote()
1560{
1561 git remote rm aosp 2> /dev/null
1562 if [ ! -d .git ]
1563 then
1564 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1565 fi
1566 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1567 if (echo $PROJECT | grep -qv "^device")
1568 then
1569 PFX="platform/"
1570 fi
1571 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1572 echo "Remote 'aosp' created"
1573}
1574export -f aospremote
1575
Steve Kondikf00e7d92012-09-23 23:46:55 -07001576function installboot()
1577{
1578 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1579 then
1580 echo "No recovery.fstab found. Build recovery first."
1581 return 1
1582 fi
1583 if [ ! -e "$OUT/boot.img" ];
1584 then
1585 echo "No boot.img found. Run make bootimage first."
1586 return 1
1587 fi
1588 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1589 if [ -z "$PARTITION" ];
1590 then
1591 echo "Unable to determine boot partition."
1592 return 1
1593 fi
1594 adb start-server
1595 adb root
1596 sleep 1
1597 adb wait-for-device
1598 adb remount
1599 adb wait-for-device
1600 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1601 then
1602 adb push $OUT/boot.img /cache/
1603 for i in $OUT/system/lib/modules/*;
1604 do
1605 adb push $i /system/lib/modules/
1606 done
1607 adb shell dd if=/cache/boot.img of=$PARTITION
1608 adb shell chmod 644 /system/lib/modules/*
1609 echo "Installation complete."
1610 else
1611 echo "The connected device does not appear to be $CM_BUILD, run away!"
1612 fi
1613}
1614
Steve Kondik83c03d52012-10-24 16:40:42 -07001615function installrecovery()
1616{
1617 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1618 then
1619 echo "No recovery.fstab found. Build recovery first."
1620 return 1
1621 fi
1622 if [ ! -e "$OUT/recovery.img" ];
1623 then
1624 echo "No recovery.img found. Run make recoveryimage first."
1625 return 1
1626 fi
1627 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1628 if [ -z "$PARTITION" ];
1629 then
1630 echo "Unable to determine recovery partition."
1631 return 1
1632 fi
1633 adb start-server
1634 adb root
1635 sleep 1
1636 adb wait-for-device
1637 adb remount
1638 adb wait-for-device
1639 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1640 then
1641 adb push $OUT/recovery.img /cache/
1642 adb shell dd if=/cache/recovery.img of=$PARTITION
1643 echo "Installation complete."
1644 else
1645 echo "The connected device does not appear to be $CM_BUILD, run away!"
1646 fi
1647}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001648
Koushik Duttab55f13a2012-05-14 16:14:36 -07001649function makerecipe() {
1650 if [ -z "$1" ]
1651 then
1652 echo "No branch name provided."
1653 return 1
1654 fi
1655 cd android
1656 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1657 git commit -a -m "$1"
1658 cd ..
1659
1660 repo forall -c '
1661
1662 if [ "$REPO_REMOTE" == "github" ]
1663 then
1664 pwd
1665 cmremote
1666 git push cmremote HEAD:refs/heads/'$1'
1667 fi
1668 '
1669}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001670
1671function cmgerrit() {
1672 if [ $# -eq 0 ]; then
1673 $FUNCNAME help
1674 return 1
1675 fi
1676 local user=`git config --get review.review.cyanogenmod.com.username`
1677 local review=`git config --get remote.github.review`
1678 local project=`git config --get remote.github.projectname`
1679 local command=$1
1680 shift
1681 case $command in
1682 help)
1683 if [ $# -eq 0 ]; then
1684 cat <<EOF
1685Usage:
1686 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1687
1688Commands:
1689 fetch Just fetch the change as FETCH_HEAD
1690 help Show this help, or for a specific command
1691 pull Pull a change into current branch
1692 push Push HEAD or a local branch to Gerrit for a specific branch
1693
1694Any other Git commands that support refname would work as:
1695 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1696
1697See '$FUNCNAME help COMMAND' for more information on a specific command.
1698
1699Example:
1700 $FUNCNAME checkout -b topic 1234/5
1701works as:
1702 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1703 && git checkout -b topic FETCH_HEAD
1704will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1705Patch-set 1 will be fetched if omitted.
1706EOF
1707 return
1708 fi
1709 case $1 in
1710 __cmg_*) echo "For internal use only." ;;
1711 changes|for)
1712 if [ "$FUNCNAME" = "cmgerrit" ]; then
1713 echo "'$FUNCNAME $1' is deprecated."
1714 fi
1715 ;;
1716 help) $FUNCNAME help ;;
1717 fetch|pull) cat <<EOF
1718usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1719
1720works as:
1721 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1722 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1723
1724Example:
1725 $FUNCNAME $1 1234
1726will $1 patch-set 1 of change 1234
1727EOF
1728 ;;
1729 push) cat <<EOF
1730usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1731
1732works as:
1733 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1734 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1735
1736Example:
1737 $FUNCNAME push fix6789:gingerbread
1738will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1739HEAD will be pushed from local if omitted.
1740EOF
1741 ;;
1742 *)
1743 $FUNCNAME __cmg_err_not_supported $1 && return
1744 cat <<EOF
1745usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1746
1747works as:
1748 git fetch http://DOMAIN/p/PROJECT \\
1749 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1750 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1751EOF
1752 ;;
1753 esac
1754 ;;
1755 __cmg_get_ref)
1756 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1757 local change_id patchset_id hash
1758 case $1 in
1759 */*)
1760 change_id=${1%%/*}
1761 patchset_id=${1#*/}
1762 ;;
1763 *)
1764 change_id=$1
1765 patchset_id=1
1766 ;;
1767 esac
1768 hash=$(($change_id % 100))
1769 case $hash in
1770 [0-9]) hash="0$hash" ;;
1771 esac
1772 echo "refs/changes/$hash/$change_id/$patchset_id"
1773 ;;
1774 fetch|pull)
1775 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1776 $FUNCNAME __cmg_err_not_repo && return 1
1777 local change=$1
1778 shift
1779 git $command $@ http://$review/p/$project \
1780 $($FUNCNAME __cmg_get_ref $change) || return 1
1781 ;;
1782 push)
1783 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1784 $FUNCNAME __cmg_err_not_repo && return 1
1785 if [ -z "$user" ]; then
1786 echo >&2 "Gerrit username not found."
1787 return 1
1788 fi
1789 local local_branch remote_branch
1790 case $1 in
1791 *:*)
1792 local_branch=${1%:*}
1793 remote_branch=${1##*:}
1794 ;;
1795 *)
1796 local_branch=HEAD
1797 remote_branch=$1
1798 ;;
1799 esac
1800 shift
1801 git push $@ ssh://$user@$review:29418/$project \
1802 $local_branch:refs/for/$remote_branch || return 1
1803 ;;
1804 changes|for)
1805 if [ "$FUNCNAME" = "cmgerrit" ]; then
1806 echo >&2 "'$FUNCNAME $command' is deprecated."
1807 fi
1808 ;;
1809 __cmg_err_no_arg)
1810 if [ $# -lt 2 ]; then
1811 echo >&2 "'$FUNCNAME $command' missing argument."
1812 elif [ $2 -eq 0 ]; then
1813 if [ -n "$3" ]; then
1814 $FUNCNAME help $1
1815 else
1816 echo >&2 "'$FUNCNAME $1' missing argument."
1817 fi
1818 else
1819 return 1
1820 fi
1821 ;;
1822 __cmg_err_not_repo)
1823 if [ -z "$review" -o -z "$project" ]; then
1824 echo >&2 "Not currently in any reviewable repository."
1825 else
1826 return 1
1827 fi
1828 ;;
1829 __cmg_err_not_supported)
1830 $FUNCNAME __cmg_err_no_arg $command $# && return
1831 case $1 in
1832 #TODO: filter more git commands that don't use refname
1833 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1834 echo >&2 "'$FUNCNAME $1' is not supported."
1835 ;;
1836 *) return 1 ;;
1837 esac
1838 ;;
1839 #TODO: other special cases?
1840 *)
1841 $FUNCNAME __cmg_err_not_supported $command && return 1
1842 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1843 $FUNCNAME __cmg_err_not_repo && return 1
1844 local args="$@"
1845 local change pre_args refs_arg post_args
1846 case "$args" in
1847 *--\ *)
1848 pre_args=${args%%-- *}
1849 post_args="-- ${args#*-- }"
1850 ;;
1851 *) pre_args="$args" ;;
1852 esac
1853 args=($pre_args)
1854 pre_args=
1855 if [ ${#args[@]} -gt 0 ]; then
1856 change=${args[${#args[@]}-1]}
1857 fi
1858 if [ ${#args[@]} -gt 1 ]; then
1859 pre_args=${args[0]}
1860 for ((i=1; i<${#args[@]}-1; i++)); do
1861 pre_args="$pre_args ${args[$i]}"
1862 done
1863 fi
1864 while ((1)); do
1865 case $change in
1866 ""|--)
1867 $FUNCNAME help $command
1868 return 1
1869 ;;
1870 *@*)
1871 if [ -z "$refs_arg" ]; then
1872 refs_arg="@${change#*@}"
1873 change=${change%%@*}
1874 fi
1875 ;;
1876 *~*)
1877 if [ -z "$refs_arg" ]; then
1878 refs_arg="~${change#*~}"
1879 change=${change%%~*}
1880 fi
1881 ;;
1882 *^*)
1883 if [ -z "$refs_arg" ]; then
1884 refs_arg="^${change#*^}"
1885 change=${change%%^*}
1886 fi
1887 ;;
1888 *:*)
1889 if [ -z "$refs_arg" ]; then
1890 refs_arg=":${change#*:}"
1891 change=${change%%:*}
1892 fi
1893 ;;
1894 *) break ;;
1895 esac
1896 done
1897 $FUNCNAME fetch $change \
1898 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1899 || return 1
1900 ;;
1901 esac
1902}
1903
1904function cmrebase() {
1905 local repo=$1
1906 local refs=$2
1907 local pwd="$(pwd)"
1908 local dir="$(gettop)/$repo"
1909
1910 if [ -z $repo ] || [ -z $refs ]; then
1911 echo "CyanogenMod Gerrit Rebase Usage: "
1912 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1913 echo " The patch IDs appear on the Gerrit commands that are offered."
1914 echo " They consist on a series of numbers and slashes, after the text"
1915 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1916 echo ""
1917 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1918 echo ""
1919 return
1920 fi
1921
1922 if [ ! -d $dir ]; then
1923 echo "Directory $dir doesn't exist in tree."
1924 return
1925 fi
1926 cd $dir
1927 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1928 echo "Starting branch..."
1929 repo start tmprebase .
1930 echo "Bringing it up to date..."
1931 repo sync .
1932 echo "Fetching change..."
1933 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
1934 if [ "$?" != "0" ]; then
1935 echo "Error cherry-picking. Not uploading!"
1936 return
1937 fi
1938 echo "Uploading..."
1939 repo upload .
1940 echo "Cleaning up..."
1941 repo abandon tmprebase .
1942 cd $pwd
1943}
1944
1945function mka() {
1946 case `uname -s` in
1947 Darwin)
1948 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1949 ;;
1950 *)
1951 schedtool -B -n 1 -e ionice -n 1 make -j `cat /proc/cpuinfo | grep "^processor" | wc -l` "$@"
1952 ;;
1953 esac
1954}
1955
1956function reposync() {
1957 case `uname -s` in
1958 Darwin)
1959 repo sync -j 4 "$@"
1960 ;;
1961 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001962 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001963 ;;
1964 esac
1965}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001966
1967function repodiff() {
1968 if [ -z "$*" ]; then
1969 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1970 return
1971 fi
1972 diffopts=$* repo forall -c \
1973 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1974}
1975
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301976# Credit for color strip sed: http://goo.gl/BoIcm
1977function dopush()
1978{
1979 local func=$1
1980 shift
1981
1982 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1983 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
1984 echo "No device is online. Waiting for one..."
1985 echo "Please connect USB and/or enable USB debugging"
1986 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
1987 sleep 1
1988 done
1989 echo "Device Found."
1990 fi
1991
1992 adb root &> /dev/null
1993 sleep 0.3
1994 adb wait-for-device &> /dev/null
1995 sleep 0.3
1996 adb remount &> /dev/null
1997
1998 $func $* | tee $OUT/.log
1999
2000 # Install: <file>
2001 LOC=$(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Install' | cut -d ':' -f 2)
2002
2003 # Copy: <file>
2004 LOC=$LOC $(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Copy' | cut -d ':' -f 2)
2005
2006 for FILE in $LOC; do
2007 # Get target file name (i.e. system/bin/adb)
2008 TARGET=$(echo $FILE | sed "s#$OUT/##")
2009
2010 # Don't send files that are not in /system.
2011 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2012 continue
2013 else
2014 case $TARGET in
2015 system/app/SystemUI.apk|system/framework/*)
2016 stop_n_start=true
2017 ;;
2018 *)
2019 stop_n_start=false
2020 ;;
2021 esac
2022 if $stop_n_start ; then adb shell stop ; fi
2023 echo "Pushing: $TARGET"
2024 adb push $FILE $TARGET
2025 if $stop_n_start ; then adb shell start ; fi
2026 fi
2027 done
2028 rm -f $OUT/.log
2029 return 0
2030}
2031
2032alias mmp='dopush mm'
2033alias mmmp='dopush mmm'
2034alias mkap='dopush mka'
2035alias cmkap='dopush cmka'
2036
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002037# 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 +00002038#
2039# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2040# For some reason, installing the JDK doesn't make it show up in the
2041# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002042function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002043 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002044 # we can reset it later, depending on the version of java the build
2045 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002046 #
2047 # If we don't do this, the JAVA_HOME value set by the first call to
2048 # build/envsetup.sh will persist forever.
2049 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2050 export JAVA_HOME=""
2051 fi
2052
Andy McFaddenbd960942010-06-24 12:52:51 -07002053 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002054 case `uname -s` in
2055 Darwin)
2056 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2057 ;;
2058 *)
2059 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2060 ;;
2061 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002062
2063 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2064 # we can change it on the next envsetup.sh, if required.
2065 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002066 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002067}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002068
Alex Rayf0d08eb2013-03-08 15:15:06 -08002069# Print colored exit condition
2070function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002071 "$@"
2072 local retval=$?
2073 if [ $retval -ne 0 ]
2074 then
2075 echo -e "\e[0;31mFAILURE\e[00m"
2076 else
2077 echo -e "\e[0;32mSUCCESS\e[00m"
2078 fi
2079 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002080}
2081
Ying Wanged21d4c2014-08-24 22:14:19 -07002082function get_make_command()
2083{
2084 echo command make
2085}
2086
Ed Heylcc6be0a2014-06-18 14:55:58 -07002087function make()
2088{
2089 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002090 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002091 local ret=$?
2092 local end_time=$(date +"%s")
2093 local tdiff=$(($end_time-$start_time))
2094 local hours=$(($tdiff / 3600 ))
2095 local mins=$((($tdiff % 3600) / 60))
2096 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002097 local ncolors=$(tput colors 2>/dev/null)
2098 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2099 color_failed="\e[0;31m"
2100 color_success="\e[0;32m"
2101 color_reset="\e[00m"
2102 else
2103 color_failed=""
2104 color_success=""
2105 color_reset=""
2106 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002107 echo
2108 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002109 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002110 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002111 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002112 fi
2113 if [ $hours -gt 0 ] ; then
2114 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2115 elif [ $mins -gt 0 ] ; then
2116 printf "(%02g:%02g (mm:ss))" $mins $secs
2117 elif [ $secs -gt 0 ] ; then
2118 printf "(%s seconds)" $secs
2119 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002120 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002121 echo
2122 return $ret
2123}
2124
Raphael Moll70a86b02011-06-20 16:03:14 -07002125if [ "x$SHELL" != "x/bin/bash" ]; then
2126 case `ps -o command -p $$` in
2127 *bash*)
2128 ;;
2129 *)
2130 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2131 ;;
2132 esac
2133fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002134
2135# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002136for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2137 `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 -08002138do
2139 echo "including $f"
2140 . $f
2141done
2142unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002143
2144addcompletions