blob: 31fd2718d12f32028a42a5ea2225f144471ff2e0 [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
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000761function omnom
762{
763 brunch $*
764 eat
765}
766
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700767function gettop
768{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800769 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700770 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700771 # The following circumlocution ensures we remove symlinks from TOP.
772 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700773 else
774 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800775 # The following circumlocution (repeated below as well) ensures
776 # that we record the true directory name and not one that is
777 # faked up with symlink names.
778 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800780 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 T=
782 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800783 \cd ..
synergyb112a402013-07-05 19:47:47 -0700784 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 done
Ying Wang9cd17642012-12-13 10:52:07 -0800786 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787 if [ -f "$T/$TOPFILE" ]; then
788 echo $T
789 fi
790 fi
791 fi
792}
793
Andrew Hsieh906cb782013-09-10 17:37:14 +0800794# Return driver for "make", if any (eg. static analyzer)
795function getdriver()
796{
797 local T="$1"
798 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
799 if [ -n "$WITH_STATIC_ANALYZER" ]; then
800 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800801$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
802--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800803--status-bugs \
804--top=$T"
805 fi
806}
807
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700808function m()
809{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800810 local T=$(gettop)
811 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700812 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800813 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700814 else
815 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700816 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700817 fi
818}
819
820function findmakefile()
821{
822 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800823 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824 T=
825 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700826 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827 if [ -f "$T/Android.mk" ]; then
828 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800829 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700830 return
831 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800832 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700833 done
Ying Wang9cd17642012-12-13 10:52:07 -0800834 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835}
836
837function mm()
838{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800839 local T=$(gettop)
840 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700841 # If we're sitting in the root of the build tree, just do a
842 # normal make.
843 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800844 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 else
846 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800847 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700848 local MODULES=
849 local GET_INSTALL_PATH=
850 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700851 # Remove the path to top as the makefilepath needs to be relative
852 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700853 if [ ! "$T" ]; then
854 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700855 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700856 elif [ ! "$M" ]; then
857 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700858 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700859 else
Ying Wanga7deb082013-08-16 13:24:47 -0700860 for ARG in $@; do
861 case $ARG in
862 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
863 esac
864 done
865 if [ -n "$GET_INSTALL_PATH" ]; then
866 MODULES=
867 ARGS=GET-INSTALL-PATH
868 else
869 MODULES=all_modules
870 ARGS=$@
871 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700872 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 -0700873 fi
874 fi
875}
876
877function mmm()
878{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800879 local T=$(gettop)
880 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700881 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800882 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800883 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800884 local ARGS=
885 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700886 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800887 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
888 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
889 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800890 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
891 if [ "$MODULES" = "" ]; then
892 MODULES=all_modules
893 fi
894 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700895 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700896 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
897 local TO_CHOP=`expr $TO_CHOP + 1`
898 local START=`PWD= /bin/pwd`
899 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700900 if [ "$MFILE" = "" ] ; then
901 MFILE=$DIR/Android.mk
902 else
903 MFILE=$MFILE/$DIR/Android.mk
904 fi
905 MAKEFILE="$MAKEFILE $MFILE"
906 else
Ying Wanga7deb082013-08-16 13:24:47 -0700907 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100908 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700909 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
910 *) echo "No Android.mk in $DIR."; return 1;;
911 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700912 fi
913 done
Ying Wanga7deb082013-08-16 13:24:47 -0700914 if [ -n "$GET_INSTALL_PATH" ]; then
915 ARGS=$GET_INSTALL_PATH
916 MODULES=
917 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800918 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 -0700919 else
920 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700921 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922 fi
923}
924
Ying Wangb607f7b2013-02-08 18:01:04 -0800925function mma()
926{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800927 local T=$(gettop)
928 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800929 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800930 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800931 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800932 if [ ! "$T" ]; then
933 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700934 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800935 fi
936 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800937 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800938 fi
939}
940
941function mmma()
942{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800943 local T=$(gettop)
944 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800945 if [ "$T" ]; then
946 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
947 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
948 local MY_PWD=`PWD= /bin/pwd`
949 if [ "$MY_PWD" = "$T" ]; then
950 MY_PWD=
951 else
952 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
953 fi
954 local DIR=
955 local MODULE_PATHS=
956 local ARGS=
957 for DIR in $DIRS ; do
958 if [ -d $DIR ]; then
959 if [ "$MY_PWD" = "" ]; then
960 MODULE_PATHS="$MODULE_PATHS $DIR"
961 else
962 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
963 fi
964 else
965 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100966 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800967 *) echo "Couldn't find directory $DIR"; return 1;;
968 esac
969 fi
970 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800971 $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 -0800972 else
973 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700974 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800975 fi
976}
977
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700978function croot()
979{
980 T=$(gettop)
981 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800982 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700983 else
984 echo "Couldn't locate the top of the tree. Try setting TOP."
985 fi
986}
987
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700988function cproj()
989{
990 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700991 local HERE=$PWD
992 T=
993 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
994 T=$PWD
995 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800996 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700997 return
998 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800999 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001000 done
Ying Wang9cd17642012-12-13 10:52:07 -08001001 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001002 echo "can't find Android.mk"
1003}
1004
Daniel Sandler47e0a882013-07-30 13:23:52 -04001005# simplified version of ps; output in the form
1006# <pid> <procname>
1007function qpid() {
1008 local prepend=''
1009 local append=''
1010 if [ "$1" = "--exact" ]; then
1011 prepend=' '
1012 append='$'
1013 shift
1014 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1015 echo "usage: qpid [[--exact] <process name|pid>"
1016 return 255
1017 fi
1018
1019 local EXE="$1"
1020 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001021 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001022 else
1023 adb shell ps \
1024 | tr -d '\r' \
1025 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1026 fi
1027}
1028
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001029function pid()
1030{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001031 local prepend=''
1032 local append=''
1033 if [ "$1" = "--exact" ]; then
1034 prepend=' '
1035 append='$'
1036 shift
1037 fi
1038 local EXE="$1"
1039 if [ "$EXE" ] ; then
1040 local PID=`adb shell ps \
1041 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001042 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001043 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1044 echo "$PID"
1045 else
1046 echo "usage: pid [--exact] <process name>"
1047 return 255
1048 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001049}
1050
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001051# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001052# that has the core-file-size limit set correctly
1053#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001054# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001055# if its core-file-size limit is not set already.
1056# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1057
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001058function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001059{
1060 echo "Getting root...";
1061 adb root;
1062 adb wait-for-device;
1063
1064 echo "Remounting root parition read-write...";
1065 adb shell mount -w -o remount -t rootfs rootfs;
1066 sleep 1;
1067 adb wait-for-device;
1068 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001069 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001070 adb shell chmod 0777 /cores;
1071
1072 echo "Granting SELinux permission to dump in /cores...";
1073 adb shell restorecon -R /cores;
1074
1075 echo "Set core pattern.";
1076 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1077
1078 echo "Done."
1079}
1080
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001081# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001082# $1 = PID of process (e.g., $(pid mediaserver))
1083#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001084# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001085# dump to actually be generated.
1086
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001087function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088{
1089 local PID=$1;
1090 if [ -z "$PID" ]; then
1091 printf "Expecting a PID!\n";
1092 return;
1093 fi;
1094 echo "Setting core limit for $PID to infinite...";
1095 adb shell prlimit $PID 4 -1 -1
1096}
1097
1098# core - send SIGV and pull the core for process
1099# $1 = PID of process (e.g., $(pid mediaserver))
1100#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001101# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001102# enabled globally.
1103
1104function core()
1105{
1106 local PID=$1;
1107
1108 if [ -z "$PID" ]; then
1109 printf "Expecting a PID!\n";
1110 return;
1111 fi;
1112
1113 local CORENAME=core.$PID;
1114 local COREPATH=/cores/$CORENAME;
1115 local SIG=SEGV;
1116
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001117 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001118
1119 local done=0;
1120 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1121 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1122 adb shell kill -$SIG $PID;
1123 sleep 1;
1124 done;
1125
1126 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1127 echo "Done: core is under $COREPATH on device.";
1128}
1129
Christopher Tate744ee802009-11-12 15:33:08 -08001130# systemstack - dump the current stack trace of all threads in the system process
1131# to the usual ANR traces file
1132function systemstack()
1133{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001134 stacks system_server
1135}
1136
1137function stacks()
1138{
1139 if [[ $1 =~ ^[0-9]+$ ]] ; then
1140 local PID="$1"
1141 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001142 local PIDLIST="$(pid $1)"
1143 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1144 local PID="$PIDLIST"
1145 elif [ "$PIDLIST" ] ; then
1146 echo "more than one process: $1"
1147 else
1148 echo "no such process: $1"
1149 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001150 else
1151 echo "usage: stacks [pid|process name]"
1152 fi
1153
1154 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001155 # Determine whether the process is native
1156 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1157 # Dump stacks of Dalvik process
1158 local TRACES=/data/anr/traces.txt
1159 local ORIG=/data/anr/traces.orig
1160 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001161
Jeff Brownb12c2e52013-08-19 15:14:16 -07001162 # Keep original traces to avoid clobbering
1163 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001164
Jeff Brownb12c2e52013-08-19 15:14:16 -07001165 # Make sure we have a usable file
1166 adb shell touch $TRACES
1167 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001168
Jeff Brownb12c2e52013-08-19 15:14:16 -07001169 # Dump stacks and wait for dump to finish
1170 adb shell kill -3 $PID
1171 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001172
Jeff Brownb12c2e52013-08-19 15:14:16 -07001173 # Restore original stacks, and show current output
1174 adb shell mv $TRACES $TMP
1175 adb shell mv $ORIG $TRACES
1176 adb shell cat $TMP
1177 else
1178 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001179 local USE64BIT="$(is64bit $PID)"
1180 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001181 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001182 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001183}
1184
Michael Wrightaeed7212014-06-19 19:58:12 -07001185# Read the ELF header from /proc/$PID/exe to determine if the process is
1186# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001187function is64bit()
1188{
1189 local PID="$1"
1190 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001191 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001192 echo "64"
1193 else
1194 echo ""
1195 fi
1196 else
1197 echo ""
1198 fi
1199}
1200
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001201case `uname -s` in
1202 Darwin)
1203 function sgrep()
1204 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001205 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 -07001206 }
1207
1208 ;;
1209 *)
1210 function sgrep()
1211 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001212 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 -07001213 }
1214 ;;
1215esac
1216
Raghu Gandham8da43102012-07-25 19:57:22 -07001217function gettargetarch
1218{
1219 get_build_var TARGET_ARCH
1220}
1221
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001222function ggrep()
1223{
1224 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1225}
1226
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001227function jgrep()
1228{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001229 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 -07001230}
1231
1232function cgrep()
1233{
Dan Albert01961192014-11-22 10:16:01 -08001234 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 -07001235}
1236
1237function resgrep()
1238{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001239 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 -07001240}
1241
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001242function mangrep()
1243{
1244 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1245}
1246
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001247function sepgrep()
1248{
1249 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 "$@"
1250}
1251
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001252function rcgrep()
1253{
1254 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1255}
1256
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001257case `uname -s` in
1258 Darwin)
1259 function mgrep()
1260 {
Ying Wang324c2b22012-08-17 15:03:20 -07001261 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 -07001262 }
1263
1264 function treegrep()
1265 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001266 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 -07001267 }
1268
1269 ;;
1270 *)
1271 function mgrep()
1272 {
Ying Wang324c2b22012-08-17 15:03:20 -07001273 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 -07001274 }
1275
1276 function treegrep()
1277 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001278 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 -07001279 }
1280
1281 ;;
1282esac
1283
1284function getprebuilt
1285{
1286 get_abs_build_var ANDROID_PREBUILTS
1287}
1288
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001289function tracedmdump()
1290{
1291 T=$(gettop)
1292 if [ ! "$T" ]; then
1293 echo "Couldn't locate the top of the tree. Try setting TOP."
1294 return
1295 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001296 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001297 local arch=$(gettargetarch)
1298 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001299
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001300 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001301 if [ ! "$TRACE" ] ; then
1302 echo "usage: tracedmdump tracename"
1303 return
1304 fi
1305
Jack Veenstra60116fc2009-04-09 18:12:34 -07001306 if [ ! -r "$KERNEL" ] ; then
1307 echo "Error: cannot find kernel: '$KERNEL'"
1308 return
1309 fi
1310
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001311 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001312 if [ "$BASETRACE" = "$TRACE" ] ; then
1313 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1314 fi
1315
1316 echo "post-processing traces..."
1317 rm -f $TRACE/qtrace.dexlist
1318 post_trace $TRACE
1319 if [ $? -ne 0 ]; then
1320 echo "***"
1321 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1322 echo "***"
1323 return
1324 fi
1325 echo "generating dexlist output..."
1326 /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
1327 echo "generating dmtrace data..."
1328 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1329 echo "generating html file..."
1330 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1331 echo "done, see $TRACE/dmtrace.html for details"
1332 echo "or run:"
1333 echo " traceview $TRACE/dmtrace"
1334}
1335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001336# communicate with a running device or emulator, set up necessary state,
1337# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001338function runhat()
1339{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340 # process standard adb options
1341 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001342 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001343 adbTarget=$1
1344 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001345 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001346 adbTarget="$1 $2"
1347 shift 2
1348 fi
1349 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001350 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001351
1352 # runhat options
1353 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001354
1355 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001356 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001357 return
1358 fi
1359
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001360 # confirm hat is available
1361 if [ -z $(which hat) ]; then
1362 echo "hat is not available in this configuration."
1363 return
1364 fi
1365
Andy McFaddenb6289852010-07-12 08:00:19 -07001366 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001367 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001368 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001369 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001370 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001371 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001372 echo -n "> "
1373 read
1374
The Android Open Source Project88b60792009-03-03 19:28:42 -08001375 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001376
The Android Open Source Project88b60792009-03-03 19:28:42 -08001377 echo "Retrieving file $devFile..."
1378 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001379
The Android Open Source Project88b60792009-03-03 19:28:42 -08001380 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001381
The Android Open Source Project88b60792009-03-03 19:28:42 -08001382 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001383 echo "View the output by pointing your browser at http://localhost:7000/"
1384 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001385 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001386}
1387
1388function getbugreports()
1389{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001390 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001391
1392 if [ ! "$reports" ]; then
1393 echo "Could not locate any bugreports."
1394 return
1395 fi
1396
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001397 local report
1398 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001399 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001400 echo "/sdcard/bugreports/${report}"
1401 adb pull /sdcard/bugreports/${report} ${report}
1402 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001403 done
1404}
1405
Victoria Lease1b296b42012-08-21 15:44:06 -07001406function getsdcardpath()
1407{
1408 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1409}
1410
1411function getscreenshotpath()
1412{
1413 echo "$(getsdcardpath)/Pictures/Screenshots"
1414}
1415
1416function getlastscreenshot()
1417{
1418 local screenshot_path=$(getscreenshotpath)
1419 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1420 if [ "$screenshot" = "" ]; then
1421 echo "No screenshots found."
1422 return
1423 fi
1424 echo "${screenshot}"
1425 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1426}
1427
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001428function startviewserver()
1429{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001430 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001431 if [ $# -gt 0 ]; then
1432 port=$1
1433 fi
1434 adb shell service call window 1 i32 $port
1435}
1436
1437function stopviewserver()
1438{
1439 adb shell service call window 2
1440}
1441
1442function isviewserverstarted()
1443{
1444 adb shell service call window 3
1445}
1446
Romain Guyb84049a2010-10-04 16:56:11 -07001447function key_home()
1448{
1449 adb shell input keyevent 3
1450}
1451
1452function key_back()
1453{
1454 adb shell input keyevent 4
1455}
1456
1457function key_menu()
1458{
1459 adb shell input keyevent 82
1460}
1461
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001462function smoketest()
1463{
1464 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1465 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1466 return
1467 fi
1468 T=$(gettop)
1469 if [ ! "$T" ]; then
1470 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1471 return
1472 fi
1473
Ying Wang9cd17642012-12-13 10:52:07 -08001474 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001475 adb uninstall com.android.smoketest > /dev/null &&
1476 adb uninstall com.android.smoketest.tests > /dev/null &&
1477 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1478 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1479 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1480}
1481
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001482# simple shortcut to the runtest command
1483function runtest()
1484{
1485 T=$(gettop)
1486 if [ ! "$T" ]; then
1487 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1488 return
1489 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001490 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001491}
1492
The Android Open Source Project88b60792009-03-03 19:28:42 -08001493function godir () {
1494 if [[ -z "$1" ]]; then
1495 echo "Usage: godir <regex>"
1496 return
1497 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001498 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001499 if [[ ! -f $T/filelist ]]; then
1500 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001501 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001502 echo " Done"
1503 echo ""
1504 fi
1505 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001506 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001507 if [[ ${#lines[@]} = 0 ]]; then
1508 echo "Not found"
1509 return
1510 fi
1511 local pathname
1512 local choice
1513 if [[ ${#lines[@]} > 1 ]]; then
1514 while [[ -z "$pathname" ]]; do
1515 local index=1
1516 local line
1517 for line in ${lines[@]}; do
1518 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001519 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001520 done
1521 echo
1522 echo -n "Select one: "
1523 unset choice
1524 read choice
1525 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1526 echo "Invalid choice"
1527 continue
1528 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001529 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001530 done
1531 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001532 pathname=${lines[0]}
1533 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001534 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001535}
1536
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001537function cmremote()
1538{
1539 git remote rm cmremote 2> /dev/null
1540 if [ ! -d .git ]
1541 then
1542 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1543 fi
1544 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1545 if [ -z "$GERRIT_REMOTE" ]
1546 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001547 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1548 if [ -z "$GERRIT_REMOTE" ]
1549 then
1550 echo Unable to set up the git remote, are you in the root of the repo?
1551 return 0
1552 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001553 fi
1554 CMUSER=`git config --get review.review.cyanogenmod.com.username`
1555 if [ -z "$CMUSER" ]
1556 then
1557 git remote add cmremote ssh://review.cyanogenmod.com:29418/$GERRIT_REMOTE
1558 else
1559 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.com:29418/$GERRIT_REMOTE
1560 fi
1561 echo You can now push to "cmremote".
1562}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001563export -f cmremote
1564
Steve Kondik873fa562012-09-17 11:33:18 -07001565function aospremote()
1566{
1567 git remote rm aosp 2> /dev/null
1568 if [ ! -d .git ]
1569 then
1570 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1571 fi
1572 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1573 if (echo $PROJECT | grep -qv "^device")
1574 then
1575 PFX="platform/"
1576 fi
1577 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1578 echo "Remote 'aosp' created"
1579}
1580export -f aospremote
1581
Steve Kondikf00e7d92012-09-23 23:46:55 -07001582function installboot()
1583{
1584 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1585 then
1586 echo "No recovery.fstab found. Build recovery first."
1587 return 1
1588 fi
1589 if [ ! -e "$OUT/boot.img" ];
1590 then
1591 echo "No boot.img found. Run make bootimage first."
1592 return 1
1593 fi
1594 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1595 if [ -z "$PARTITION" ];
1596 then
1597 echo "Unable to determine boot partition."
1598 return 1
1599 fi
1600 adb start-server
1601 adb root
1602 sleep 1
1603 adb wait-for-device
1604 adb remount
1605 adb wait-for-device
1606 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1607 then
1608 adb push $OUT/boot.img /cache/
1609 for i in $OUT/system/lib/modules/*;
1610 do
1611 adb push $i /system/lib/modules/
1612 done
1613 adb shell dd if=/cache/boot.img of=$PARTITION
1614 adb shell chmod 644 /system/lib/modules/*
1615 echo "Installation complete."
1616 else
1617 echo "The connected device does not appear to be $CM_BUILD, run away!"
1618 fi
1619}
1620
Steve Kondik83c03d52012-10-24 16:40:42 -07001621function installrecovery()
1622{
1623 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1624 then
1625 echo "No recovery.fstab found. Build recovery first."
1626 return 1
1627 fi
1628 if [ ! -e "$OUT/recovery.img" ];
1629 then
1630 echo "No recovery.img found. Run make recoveryimage first."
1631 return 1
1632 fi
1633 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1634 if [ -z "$PARTITION" ];
1635 then
1636 echo "Unable to determine recovery partition."
1637 return 1
1638 fi
1639 adb start-server
1640 adb root
1641 sleep 1
1642 adb wait-for-device
1643 adb remount
1644 adb wait-for-device
1645 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1646 then
1647 adb push $OUT/recovery.img /cache/
1648 adb shell dd if=/cache/recovery.img of=$PARTITION
1649 echo "Installation complete."
1650 else
1651 echo "The connected device does not appear to be $CM_BUILD, run away!"
1652 fi
1653}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001654
Koushik Duttab55f13a2012-05-14 16:14:36 -07001655function makerecipe() {
1656 if [ -z "$1" ]
1657 then
1658 echo "No branch name provided."
1659 return 1
1660 fi
1661 cd android
1662 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1663 git commit -a -m "$1"
1664 cd ..
1665
1666 repo forall -c '
1667
1668 if [ "$REPO_REMOTE" == "github" ]
1669 then
1670 pwd
1671 cmremote
1672 git push cmremote HEAD:refs/heads/'$1'
1673 fi
1674 '
1675}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001676
1677function cmgerrit() {
1678 if [ $# -eq 0 ]; then
1679 $FUNCNAME help
1680 return 1
1681 fi
1682 local user=`git config --get review.review.cyanogenmod.com.username`
1683 local review=`git config --get remote.github.review`
1684 local project=`git config --get remote.github.projectname`
1685 local command=$1
1686 shift
1687 case $command in
1688 help)
1689 if [ $# -eq 0 ]; then
1690 cat <<EOF
1691Usage:
1692 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1693
1694Commands:
1695 fetch Just fetch the change as FETCH_HEAD
1696 help Show this help, or for a specific command
1697 pull Pull a change into current branch
1698 push Push HEAD or a local branch to Gerrit for a specific branch
1699
1700Any other Git commands that support refname would work as:
1701 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1702
1703See '$FUNCNAME help COMMAND' for more information on a specific command.
1704
1705Example:
1706 $FUNCNAME checkout -b topic 1234/5
1707works as:
1708 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1709 && git checkout -b topic FETCH_HEAD
1710will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1711Patch-set 1 will be fetched if omitted.
1712EOF
1713 return
1714 fi
1715 case $1 in
1716 __cmg_*) echo "For internal use only." ;;
1717 changes|for)
1718 if [ "$FUNCNAME" = "cmgerrit" ]; then
1719 echo "'$FUNCNAME $1' is deprecated."
1720 fi
1721 ;;
1722 help) $FUNCNAME help ;;
1723 fetch|pull) cat <<EOF
1724usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1725
1726works as:
1727 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1728 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1729
1730Example:
1731 $FUNCNAME $1 1234
1732will $1 patch-set 1 of change 1234
1733EOF
1734 ;;
1735 push) cat <<EOF
1736usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1737
1738works as:
1739 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1740 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1741
1742Example:
1743 $FUNCNAME push fix6789:gingerbread
1744will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1745HEAD will be pushed from local if omitted.
1746EOF
1747 ;;
1748 *)
1749 $FUNCNAME __cmg_err_not_supported $1 && return
1750 cat <<EOF
1751usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1752
1753works as:
1754 git fetch http://DOMAIN/p/PROJECT \\
1755 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1756 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1757EOF
1758 ;;
1759 esac
1760 ;;
1761 __cmg_get_ref)
1762 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1763 local change_id patchset_id hash
1764 case $1 in
1765 */*)
1766 change_id=${1%%/*}
1767 patchset_id=${1#*/}
1768 ;;
1769 *)
1770 change_id=$1
1771 patchset_id=1
1772 ;;
1773 esac
1774 hash=$(($change_id % 100))
1775 case $hash in
1776 [0-9]) hash="0$hash" ;;
1777 esac
1778 echo "refs/changes/$hash/$change_id/$patchset_id"
1779 ;;
1780 fetch|pull)
1781 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1782 $FUNCNAME __cmg_err_not_repo && return 1
1783 local change=$1
1784 shift
1785 git $command $@ http://$review/p/$project \
1786 $($FUNCNAME __cmg_get_ref $change) || return 1
1787 ;;
1788 push)
1789 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1790 $FUNCNAME __cmg_err_not_repo && return 1
1791 if [ -z "$user" ]; then
1792 echo >&2 "Gerrit username not found."
1793 return 1
1794 fi
1795 local local_branch remote_branch
1796 case $1 in
1797 *:*)
1798 local_branch=${1%:*}
1799 remote_branch=${1##*:}
1800 ;;
1801 *)
1802 local_branch=HEAD
1803 remote_branch=$1
1804 ;;
1805 esac
1806 shift
1807 git push $@ ssh://$user@$review:29418/$project \
1808 $local_branch:refs/for/$remote_branch || return 1
1809 ;;
1810 changes|for)
1811 if [ "$FUNCNAME" = "cmgerrit" ]; then
1812 echo >&2 "'$FUNCNAME $command' is deprecated."
1813 fi
1814 ;;
1815 __cmg_err_no_arg)
1816 if [ $# -lt 2 ]; then
1817 echo >&2 "'$FUNCNAME $command' missing argument."
1818 elif [ $2 -eq 0 ]; then
1819 if [ -n "$3" ]; then
1820 $FUNCNAME help $1
1821 else
1822 echo >&2 "'$FUNCNAME $1' missing argument."
1823 fi
1824 else
1825 return 1
1826 fi
1827 ;;
1828 __cmg_err_not_repo)
1829 if [ -z "$review" -o -z "$project" ]; then
1830 echo >&2 "Not currently in any reviewable repository."
1831 else
1832 return 1
1833 fi
1834 ;;
1835 __cmg_err_not_supported)
1836 $FUNCNAME __cmg_err_no_arg $command $# && return
1837 case $1 in
1838 #TODO: filter more git commands that don't use refname
1839 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1840 echo >&2 "'$FUNCNAME $1' is not supported."
1841 ;;
1842 *) return 1 ;;
1843 esac
1844 ;;
1845 #TODO: other special cases?
1846 *)
1847 $FUNCNAME __cmg_err_not_supported $command && return 1
1848 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1849 $FUNCNAME __cmg_err_not_repo && return 1
1850 local args="$@"
1851 local change pre_args refs_arg post_args
1852 case "$args" in
1853 *--\ *)
1854 pre_args=${args%%-- *}
1855 post_args="-- ${args#*-- }"
1856 ;;
1857 *) pre_args="$args" ;;
1858 esac
1859 args=($pre_args)
1860 pre_args=
1861 if [ ${#args[@]} -gt 0 ]; then
1862 change=${args[${#args[@]}-1]}
1863 fi
1864 if [ ${#args[@]} -gt 1 ]; then
1865 pre_args=${args[0]}
1866 for ((i=1; i<${#args[@]}-1; i++)); do
1867 pre_args="$pre_args ${args[$i]}"
1868 done
1869 fi
1870 while ((1)); do
1871 case $change in
1872 ""|--)
1873 $FUNCNAME help $command
1874 return 1
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 *:*)
1895 if [ -z "$refs_arg" ]; then
1896 refs_arg=":${change#*:}"
1897 change=${change%%:*}
1898 fi
1899 ;;
1900 *) break ;;
1901 esac
1902 done
1903 $FUNCNAME fetch $change \
1904 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1905 || return 1
1906 ;;
1907 esac
1908}
1909
1910function cmrebase() {
1911 local repo=$1
1912 local refs=$2
1913 local pwd="$(pwd)"
1914 local dir="$(gettop)/$repo"
1915
1916 if [ -z $repo ] || [ -z $refs ]; then
1917 echo "CyanogenMod Gerrit Rebase Usage: "
1918 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1919 echo " The patch IDs appear on the Gerrit commands that are offered."
1920 echo " They consist on a series of numbers and slashes, after the text"
1921 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1922 echo ""
1923 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1924 echo ""
1925 return
1926 fi
1927
1928 if [ ! -d $dir ]; then
1929 echo "Directory $dir doesn't exist in tree."
1930 return
1931 fi
1932 cd $dir
1933 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1934 echo "Starting branch..."
1935 repo start tmprebase .
1936 echo "Bringing it up to date..."
1937 repo sync .
1938 echo "Fetching change..."
1939 git fetch "http://review.cyanogenmod.com/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
1940 if [ "$?" != "0" ]; then
1941 echo "Error cherry-picking. Not uploading!"
1942 return
1943 fi
1944 echo "Uploading..."
1945 repo upload .
1946 echo "Cleaning up..."
1947 repo abandon tmprebase .
1948 cd $pwd
1949}
1950
1951function mka() {
1952 case `uname -s` in
1953 Darwin)
1954 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1955 ;;
1956 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001957 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001958 ;;
1959 esac
1960}
1961
1962function reposync() {
1963 case `uname -s` in
1964 Darwin)
1965 repo sync -j 4 "$@"
1966 ;;
1967 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001968 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001969 ;;
1970 esac
1971}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001972
1973function repodiff() {
1974 if [ -z "$*" ]; then
1975 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1976 return
1977 fi
1978 diffopts=$* repo forall -c \
1979 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1980}
1981
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301982# Credit for color strip sed: http://goo.gl/BoIcm
1983function dopush()
1984{
1985 local func=$1
1986 shift
1987
1988 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1989 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
1990 echo "No device is online. Waiting for one..."
1991 echo "Please connect USB and/or enable USB debugging"
1992 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
1993 sleep 1
1994 done
1995 echo "Device Found."
1996 fi
1997
1998 adb root &> /dev/null
1999 sleep 0.3
2000 adb wait-for-device &> /dev/null
2001 sleep 0.3
2002 adb remount &> /dev/null
2003
2004 $func $* | tee $OUT/.log
2005
2006 # Install: <file>
2007 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)
2008
2009 # Copy: <file>
2010 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)
2011
2012 for FILE in $LOC; do
2013 # Get target file name (i.e. system/bin/adb)
2014 TARGET=$(echo $FILE | sed "s#$OUT/##")
2015
2016 # Don't send files that are not in /system.
2017 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2018 continue
2019 else
2020 case $TARGET in
2021 system/app/SystemUI.apk|system/framework/*)
2022 stop_n_start=true
2023 ;;
2024 *)
2025 stop_n_start=false
2026 ;;
2027 esac
2028 if $stop_n_start ; then adb shell stop ; fi
2029 echo "Pushing: $TARGET"
2030 adb push $FILE $TARGET
2031 if $stop_n_start ; then adb shell start ; fi
2032 fi
2033 done
2034 rm -f $OUT/.log
2035 return 0
2036}
2037
2038alias mmp='dopush mm'
2039alias mmmp='dopush mmm'
2040alias mkap='dopush mka'
2041alias cmkap='dopush cmka'
2042
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002043# 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 +00002044#
2045# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2046# For some reason, installing the JDK doesn't make it show up in the
2047# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002048function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002049 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002050 # we can reset it later, depending on the version of java the build
2051 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002052 #
2053 # If we don't do this, the JAVA_HOME value set by the first call to
2054 # build/envsetup.sh will persist forever.
2055 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2056 export JAVA_HOME=""
2057 fi
2058
Andy McFaddenbd960942010-06-24 12:52:51 -07002059 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002060 case `uname -s` in
2061 Darwin)
2062 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2063 ;;
2064 *)
2065 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2066 ;;
2067 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002068
2069 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2070 # we can change it on the next envsetup.sh, if required.
2071 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002072 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002073}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002074
Alex Rayf0d08eb2013-03-08 15:15:06 -08002075# Print colored exit condition
2076function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002077 "$@"
2078 local retval=$?
2079 if [ $retval -ne 0 ]
2080 then
2081 echo -e "\e[0;31mFAILURE\e[00m"
2082 else
2083 echo -e "\e[0;32mSUCCESS\e[00m"
2084 fi
2085 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002086}
2087
Ying Wanged21d4c2014-08-24 22:14:19 -07002088function get_make_command()
2089{
2090 echo command make
2091}
2092
Ed Heylcc6be0a2014-06-18 14:55:58 -07002093function make()
2094{
2095 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002096 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002097 local ret=$?
2098 local end_time=$(date +"%s")
2099 local tdiff=$(($end_time-$start_time))
2100 local hours=$(($tdiff / 3600 ))
2101 local mins=$((($tdiff % 3600) / 60))
2102 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002103 local ncolors=$(tput colors 2>/dev/null)
2104 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2105 color_failed="\e[0;31m"
2106 color_success="\e[0;32m"
2107 color_reset="\e[00m"
2108 else
2109 color_failed=""
2110 color_success=""
2111 color_reset=""
2112 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002113 echo
2114 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002115 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002116 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002117 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002118 fi
2119 if [ $hours -gt 0 ] ; then
2120 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2121 elif [ $mins -gt 0 ] ; then
2122 printf "(%02g:%02g (mm:ss))" $mins $secs
2123 elif [ $secs -gt 0 ] ; then
2124 printf "(%s seconds)" $secs
2125 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002126 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002127 echo
2128 return $ret
2129}
2130
Raphael Moll70a86b02011-06-20 16:03:14 -07002131if [ "x$SHELL" != "x/bin/bash" ]; then
2132 case `ps -o command -p $$` in
2133 *bash*)
2134 ;;
2135 *)
2136 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2137 ;;
2138 esac
2139fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002140
2141# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002142for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2143 `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 -08002144do
2145 echo "including $f"
2146 . $f
2147done
2148unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002149
2150addcompletions