blob: 22a4c910792e6b8cd93c736b266ee4a1dbc62c83 [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
Chirayu Desai6dadb572012-12-26 10:53:58 +0530728 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
729 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100730 # if adbd isn't root we can't write to /cache/recovery/
731 adb root
732 sleep 1
733 adb wait-for-device
734 SZ=`stat -c %s $ZIPPATH`
735 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
736 if [ $CACHESIZE -gt $SZ ];
737 then
738 PUSHDIR=/cache/
739 DIR=cache
740 else
741 PUSHDIR=/storage/sdcard0/
742 # Optional path for sdcard0 in recovery
743 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
744 fi
745 echo "Pushing $ZIPFILE to $PUSHDIR"
746 if adb push $ZIPPATH $PUSHDIR ; then
747 cat << EOF > /tmp/command
748--update_package=/$DIR/$ZIPFILE
749EOF
750 if adb push /tmp/command /cache/recovery/ ; then
751 echo "Rebooting into recovery for installation"
752 adb reboot recovery
753 fi
754 rm /tmp/command
755 fi
756 else
757 echo "Nothing to eat"
758 return 1
759 fi
760 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530761 else
762 echo "The connected device does not appear to be $CM_BUILD, run away!"
763 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100764}
765
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000766function omnom
767{
768 brunch $*
769 eat
770}
771
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700772function gettop
773{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800774 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700775 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700776 # The following circumlocution ensures we remove symlinks from TOP.
777 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700778 else
779 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800780 # The following circumlocution (repeated below as well) ensures
781 # that we record the true directory name and not one that is
782 # faked up with symlink names.
783 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800785 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700786 T=
787 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800788 \cd ..
synergyb112a402013-07-05 19:47:47 -0700789 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 done
Ying Wang9cd17642012-12-13 10:52:07 -0800791 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792 if [ -f "$T/$TOPFILE" ]; then
793 echo $T
794 fi
795 fi
796 fi
797}
798
Andrew Hsieh906cb782013-09-10 17:37:14 +0800799# Return driver for "make", if any (eg. static analyzer)
800function getdriver()
801{
802 local T="$1"
803 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
804 if [ -n "$WITH_STATIC_ANALYZER" ]; then
805 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800806$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
807--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800808--status-bugs \
809--top=$T"
810 fi
811}
812
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700813function m()
814{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800815 local T=$(gettop)
816 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700817 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800818 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819 else
820 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700821 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822 fi
823}
824
825function findmakefile()
826{
827 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800828 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829 T=
830 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700831 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700832 if [ -f "$T/Android.mk" ]; then
833 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800834 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835 return
836 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800837 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838 done
Ying Wang9cd17642012-12-13 10:52:07 -0800839 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700840}
841
842function mm()
843{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800844 local T=$(gettop)
845 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846 # If we're sitting in the root of the build tree, just do a
847 # normal make.
848 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800849 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850 else
851 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800852 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700853 local MODULES=
854 local GET_INSTALL_PATH=
855 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700856 # Remove the path to top as the makefilepath needs to be relative
857 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700858 if [ ! "$T" ]; then
859 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700860 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861 elif [ ! "$M" ]; then
862 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700863 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864 else
Ying Wanga7deb082013-08-16 13:24:47 -0700865 for ARG in $@; do
866 case $ARG in
867 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
868 esac
869 done
870 if [ -n "$GET_INSTALL_PATH" ]; then
871 MODULES=
872 ARGS=GET-INSTALL-PATH
873 else
874 MODULES=all_modules
875 ARGS=$@
876 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700877 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 -0700878 fi
879 fi
880}
881
882function mmm()
883{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800884 local T=$(gettop)
885 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700886 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800887 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800888 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800889 local ARGS=
890 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700891 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800892 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
893 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
894 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800895 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
896 if [ "$MODULES" = "" ]; then
897 MODULES=all_modules
898 fi
899 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700900 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700901 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
902 local TO_CHOP=`expr $TO_CHOP + 1`
903 local START=`PWD= /bin/pwd`
904 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700905 if [ "$MFILE" = "" ] ; then
906 MFILE=$DIR/Android.mk
907 else
908 MFILE=$MFILE/$DIR/Android.mk
909 fi
910 MAKEFILE="$MAKEFILE $MFILE"
911 else
Ying Wanga7deb082013-08-16 13:24:47 -0700912 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100913 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700914 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
915 *) echo "No Android.mk in $DIR."; return 1;;
916 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700917 fi
918 done
Ying Wanga7deb082013-08-16 13:24:47 -0700919 if [ -n "$GET_INSTALL_PATH" ]; then
920 ARGS=$GET_INSTALL_PATH
921 MODULES=
922 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800923 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 -0700924 else
925 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700926 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700927 fi
928}
929
Ying Wangb607f7b2013-02-08 18:01:04 -0800930function mma()
931{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800932 local T=$(gettop)
933 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800934 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800935 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800936 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800937 if [ ! "$T" ]; then
938 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700939 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800940 fi
941 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800942 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800943 fi
944}
945
946function mmma()
947{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800948 local T=$(gettop)
949 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800950 if [ "$T" ]; then
951 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
952 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
953 local MY_PWD=`PWD= /bin/pwd`
954 if [ "$MY_PWD" = "$T" ]; then
955 MY_PWD=
956 else
957 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
958 fi
959 local DIR=
960 local MODULE_PATHS=
961 local ARGS=
962 for DIR in $DIRS ; do
963 if [ -d $DIR ]; then
964 if [ "$MY_PWD" = "" ]; then
965 MODULE_PATHS="$MODULE_PATHS $DIR"
966 else
967 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
968 fi
969 else
970 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100971 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800972 *) echo "Couldn't find directory $DIR"; return 1;;
973 esac
974 fi
975 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800976 $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 -0800977 else
978 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700979 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800980 fi
981}
982
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700983function croot()
984{
985 T=$(gettop)
986 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800987 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988 else
989 echo "Couldn't locate the top of the tree. Try setting TOP."
990 fi
991}
992
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700993function cproj()
994{
995 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700996 local HERE=$PWD
997 T=
998 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
999 T=$PWD
1000 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001001 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001002 return
1003 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001004 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001005 done
Ying Wang9cd17642012-12-13 10:52:07 -08001006 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001007 echo "can't find Android.mk"
1008}
1009
Daniel Sandler47e0a882013-07-30 13:23:52 -04001010# simplified version of ps; output in the form
1011# <pid> <procname>
1012function qpid() {
1013 local prepend=''
1014 local append=''
1015 if [ "$1" = "--exact" ]; then
1016 prepend=' '
1017 append='$'
1018 shift
1019 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1020 echo "usage: qpid [[--exact] <process name|pid>"
1021 return 255
1022 fi
1023
1024 local EXE="$1"
1025 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001026 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001027 else
1028 adb shell ps \
1029 | tr -d '\r' \
1030 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1031 fi
1032}
1033
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001034function pid()
1035{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001036 local prepend=''
1037 local append=''
1038 if [ "$1" = "--exact" ]; then
1039 prepend=' '
1040 append='$'
1041 shift
1042 fi
1043 local EXE="$1"
1044 if [ "$EXE" ] ; then
1045 local PID=`adb shell ps \
1046 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001047 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001048 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1049 echo "$PID"
1050 else
1051 echo "usage: pid [--exact] <process name>"
1052 return 255
1053 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001054}
1055
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001056# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001057# that has the core-file-size limit set correctly
1058#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001059# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001060# if its core-file-size limit is not set already.
1061# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1062
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001063function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001064{
1065 echo "Getting root...";
1066 adb root;
1067 adb wait-for-device;
1068
1069 echo "Remounting root parition read-write...";
1070 adb shell mount -w -o remount -t rootfs rootfs;
1071 sleep 1;
1072 adb wait-for-device;
1073 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001074 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075 adb shell chmod 0777 /cores;
1076
1077 echo "Granting SELinux permission to dump in /cores...";
1078 adb shell restorecon -R /cores;
1079
1080 echo "Set core pattern.";
1081 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1082
1083 echo "Done."
1084}
1085
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001086# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001087# $1 = PID of process (e.g., $(pid mediaserver))
1088#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001089# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001090# dump to actually be generated.
1091
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001092function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001093{
1094 local PID=$1;
1095 if [ -z "$PID" ]; then
1096 printf "Expecting a PID!\n";
1097 return;
1098 fi;
1099 echo "Setting core limit for $PID to infinite...";
1100 adb shell prlimit $PID 4 -1 -1
1101}
1102
1103# core - send SIGV and pull the core for process
1104# $1 = PID of process (e.g., $(pid mediaserver))
1105#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001106# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001107# enabled globally.
1108
1109function core()
1110{
1111 local PID=$1;
1112
1113 if [ -z "$PID" ]; then
1114 printf "Expecting a PID!\n";
1115 return;
1116 fi;
1117
1118 local CORENAME=core.$PID;
1119 local COREPATH=/cores/$CORENAME;
1120 local SIG=SEGV;
1121
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001122 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001123
1124 local done=0;
1125 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1126 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1127 adb shell kill -$SIG $PID;
1128 sleep 1;
1129 done;
1130
1131 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1132 echo "Done: core is under $COREPATH on device.";
1133}
1134
Christopher Tate744ee802009-11-12 15:33:08 -08001135# systemstack - dump the current stack trace of all threads in the system process
1136# to the usual ANR traces file
1137function systemstack()
1138{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001139 stacks system_server
1140}
1141
1142function stacks()
1143{
1144 if [[ $1 =~ ^[0-9]+$ ]] ; then
1145 local PID="$1"
1146 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001147 local PIDLIST="$(pid $1)"
1148 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1149 local PID="$PIDLIST"
1150 elif [ "$PIDLIST" ] ; then
1151 echo "more than one process: $1"
1152 else
1153 echo "no such process: $1"
1154 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001155 else
1156 echo "usage: stacks [pid|process name]"
1157 fi
1158
1159 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001160 # Determine whether the process is native
1161 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1162 # Dump stacks of Dalvik process
1163 local TRACES=/data/anr/traces.txt
1164 local ORIG=/data/anr/traces.orig
1165 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001166
Jeff Brownb12c2e52013-08-19 15:14:16 -07001167 # Keep original traces to avoid clobbering
1168 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001169
Jeff Brownb12c2e52013-08-19 15:14:16 -07001170 # Make sure we have a usable file
1171 adb shell touch $TRACES
1172 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001173
Jeff Brownb12c2e52013-08-19 15:14:16 -07001174 # Dump stacks and wait for dump to finish
1175 adb shell kill -3 $PID
1176 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001177
Jeff Brownb12c2e52013-08-19 15:14:16 -07001178 # Restore original stacks, and show current output
1179 adb shell mv $TRACES $TMP
1180 adb shell mv $ORIG $TRACES
1181 adb shell cat $TMP
1182 else
1183 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001184 local USE64BIT="$(is64bit $PID)"
1185 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001186 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001187 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001188}
1189
Michael Wrightaeed7212014-06-19 19:58:12 -07001190# Read the ELF header from /proc/$PID/exe to determine if the process is
1191# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001192function is64bit()
1193{
1194 local PID="$1"
1195 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001196 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001197 echo "64"
1198 else
1199 echo ""
1200 fi
1201 else
1202 echo ""
1203 fi
1204}
1205
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001206case `uname -s` in
1207 Darwin)
1208 function sgrep()
1209 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001210 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 -07001211 }
1212
1213 ;;
1214 *)
1215 function sgrep()
1216 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001217 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 -07001218 }
1219 ;;
1220esac
1221
Raghu Gandham8da43102012-07-25 19:57:22 -07001222function gettargetarch
1223{
1224 get_build_var TARGET_ARCH
1225}
1226
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001227function ggrep()
1228{
1229 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1230}
1231
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001232function jgrep()
1233{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001234 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 -07001235}
1236
1237function cgrep()
1238{
Dan Albert01961192014-11-22 10:16:01 -08001239 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 -07001240}
1241
1242function resgrep()
1243{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001244 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 -07001245}
1246
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001247function mangrep()
1248{
1249 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1250}
1251
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001252function sepgrep()
1253{
1254 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 "$@"
1255}
1256
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001257function rcgrep()
1258{
1259 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1260}
1261
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001262case `uname -s` in
1263 Darwin)
1264 function mgrep()
1265 {
Ying Wang324c2b22012-08-17 15:03:20 -07001266 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 -07001267 }
1268
1269 function treegrep()
1270 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001271 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 -07001272 }
1273
1274 ;;
1275 *)
1276 function mgrep()
1277 {
Ying Wang324c2b22012-08-17 15:03:20 -07001278 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 -07001279 }
1280
1281 function treegrep()
1282 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001283 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 -07001284 }
1285
1286 ;;
1287esac
1288
1289function getprebuilt
1290{
1291 get_abs_build_var ANDROID_PREBUILTS
1292}
1293
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001294function tracedmdump()
1295{
1296 T=$(gettop)
1297 if [ ! "$T" ]; then
1298 echo "Couldn't locate the top of the tree. Try setting TOP."
1299 return
1300 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001301 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001302 local arch=$(gettargetarch)
1303 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001304
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001305 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001306 if [ ! "$TRACE" ] ; then
1307 echo "usage: tracedmdump tracename"
1308 return
1309 fi
1310
Jack Veenstra60116fc2009-04-09 18:12:34 -07001311 if [ ! -r "$KERNEL" ] ; then
1312 echo "Error: cannot find kernel: '$KERNEL'"
1313 return
1314 fi
1315
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001316 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001317 if [ "$BASETRACE" = "$TRACE" ] ; then
1318 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1319 fi
1320
1321 echo "post-processing traces..."
1322 rm -f $TRACE/qtrace.dexlist
1323 post_trace $TRACE
1324 if [ $? -ne 0 ]; then
1325 echo "***"
1326 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1327 echo "***"
1328 return
1329 fi
1330 echo "generating dexlist output..."
1331 /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
1332 echo "generating dmtrace data..."
1333 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1334 echo "generating html file..."
1335 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1336 echo "done, see $TRACE/dmtrace.html for details"
1337 echo "or run:"
1338 echo " traceview $TRACE/dmtrace"
1339}
1340
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001341# communicate with a running device or emulator, set up necessary state,
1342# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001343function runhat()
1344{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001345 # process standard adb options
1346 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001347 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001348 adbTarget=$1
1349 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001350 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001351 adbTarget="$1 $2"
1352 shift 2
1353 fi
1354 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001355 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001356
1357 # runhat options
1358 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001359
1360 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001361 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001362 return
1363 fi
1364
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001365 # confirm hat is available
1366 if [ -z $(which hat) ]; then
1367 echo "hat is not available in this configuration."
1368 return
1369 fi
1370
Andy McFaddenb6289852010-07-12 08:00:19 -07001371 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001372 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001373 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001374 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001375 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001376 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377 echo -n "> "
1378 read
1379
The Android Open Source Project88b60792009-03-03 19:28:42 -08001380 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001381
The Android Open Source Project88b60792009-03-03 19:28:42 -08001382 echo "Retrieving file $devFile..."
1383 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001384
The Android Open Source Project88b60792009-03-03 19:28:42 -08001385 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001386
The Android Open Source Project88b60792009-03-03 19:28:42 -08001387 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001388 echo "View the output by pointing your browser at http://localhost:7000/"
1389 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001390 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001391}
1392
1393function getbugreports()
1394{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001395 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001396
1397 if [ ! "$reports" ]; then
1398 echo "Could not locate any bugreports."
1399 return
1400 fi
1401
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001402 local report
1403 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001404 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001405 echo "/sdcard/bugreports/${report}"
1406 adb pull /sdcard/bugreports/${report} ${report}
1407 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001408 done
1409}
1410
Victoria Lease1b296b42012-08-21 15:44:06 -07001411function getsdcardpath()
1412{
1413 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1414}
1415
1416function getscreenshotpath()
1417{
1418 echo "$(getsdcardpath)/Pictures/Screenshots"
1419}
1420
1421function getlastscreenshot()
1422{
1423 local screenshot_path=$(getscreenshotpath)
1424 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1425 if [ "$screenshot" = "" ]; then
1426 echo "No screenshots found."
1427 return
1428 fi
1429 echo "${screenshot}"
1430 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1431}
1432
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001433function startviewserver()
1434{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001435 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001436 if [ $# -gt 0 ]; then
1437 port=$1
1438 fi
1439 adb shell service call window 1 i32 $port
1440}
1441
1442function stopviewserver()
1443{
1444 adb shell service call window 2
1445}
1446
1447function isviewserverstarted()
1448{
1449 adb shell service call window 3
1450}
1451
Romain Guyb84049a2010-10-04 16:56:11 -07001452function key_home()
1453{
1454 adb shell input keyevent 3
1455}
1456
1457function key_back()
1458{
1459 adb shell input keyevent 4
1460}
1461
1462function key_menu()
1463{
1464 adb shell input keyevent 82
1465}
1466
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001467function smoketest()
1468{
1469 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1470 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1471 return
1472 fi
1473 T=$(gettop)
1474 if [ ! "$T" ]; then
1475 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1476 return
1477 fi
1478
Ying Wang9cd17642012-12-13 10:52:07 -08001479 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001480 adb uninstall com.android.smoketest > /dev/null &&
1481 adb uninstall com.android.smoketest.tests > /dev/null &&
1482 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1483 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1484 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1485}
1486
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001487# simple shortcut to the runtest command
1488function runtest()
1489{
1490 T=$(gettop)
1491 if [ ! "$T" ]; then
1492 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1493 return
1494 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001495 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001496}
1497
The Android Open Source Project88b60792009-03-03 19:28:42 -08001498function godir () {
1499 if [[ -z "$1" ]]; then
1500 echo "Usage: godir <regex>"
1501 return
1502 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001503 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001504 if [[ ! -f $T/filelist ]]; then
1505 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001506 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001507 echo " Done"
1508 echo ""
1509 fi
1510 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001511 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001512 if [[ ${#lines[@]} = 0 ]]; then
1513 echo "Not found"
1514 return
1515 fi
1516 local pathname
1517 local choice
1518 if [[ ${#lines[@]} > 1 ]]; then
1519 while [[ -z "$pathname" ]]; do
1520 local index=1
1521 local line
1522 for line in ${lines[@]}; do
1523 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001524 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001525 done
1526 echo
1527 echo -n "Select one: "
1528 unset choice
1529 read choice
1530 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1531 echo "Invalid choice"
1532 continue
1533 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001534 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001535 done
1536 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001537 pathname=${lines[0]}
1538 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001539 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001540}
1541
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001542function cmremote()
1543{
1544 git remote rm cmremote 2> /dev/null
1545 if [ ! -d .git ]
1546 then
1547 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1548 fi
1549 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1550 if [ -z "$GERRIT_REMOTE" ]
1551 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001552 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1553 if [ -z "$GERRIT_REMOTE" ]
1554 then
1555 echo Unable to set up the git remote, are you in the root of the repo?
1556 return 0
1557 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001558 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001559 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001560 if [ -z "$CMUSER" ]
1561 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001562 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001563 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001564 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001565 fi
1566 echo You can now push to "cmremote".
1567}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001568export -f cmremote
1569
Steve Kondik873fa562012-09-17 11:33:18 -07001570function aospremote()
1571{
1572 git remote rm aosp 2> /dev/null
1573 if [ ! -d .git ]
1574 then
1575 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1576 fi
1577 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1578 if (echo $PROJECT | grep -qv "^device")
1579 then
1580 PFX="platform/"
1581 fi
1582 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1583 echo "Remote 'aosp' created"
1584}
1585export -f aospremote
1586
Steve Kondikf00e7d92012-09-23 23:46:55 -07001587function installboot()
1588{
1589 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1590 then
1591 echo "No recovery.fstab found. Build recovery first."
1592 return 1
1593 fi
1594 if [ ! -e "$OUT/boot.img" ];
1595 then
1596 echo "No boot.img found. Run make bootimage first."
1597 return 1
1598 fi
1599 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1600 if [ -z "$PARTITION" ];
1601 then
1602 echo "Unable to determine boot partition."
1603 return 1
1604 fi
1605 adb start-server
1606 adb root
1607 sleep 1
1608 adb wait-for-device
1609 adb remount
1610 adb wait-for-device
1611 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1612 then
1613 adb push $OUT/boot.img /cache/
1614 for i in $OUT/system/lib/modules/*;
1615 do
1616 adb push $i /system/lib/modules/
1617 done
1618 adb shell dd if=/cache/boot.img of=$PARTITION
1619 adb shell chmod 644 /system/lib/modules/*
1620 echo "Installation complete."
1621 else
1622 echo "The connected device does not appear to be $CM_BUILD, run away!"
1623 fi
1624}
1625
Steve Kondik83c03d52012-10-24 16:40:42 -07001626function installrecovery()
1627{
1628 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1629 then
1630 echo "No recovery.fstab found. Build recovery first."
1631 return 1
1632 fi
1633 if [ ! -e "$OUT/recovery.img" ];
1634 then
1635 echo "No recovery.img found. Run make recoveryimage first."
1636 return 1
1637 fi
1638 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1639 if [ -z "$PARTITION" ];
1640 then
1641 echo "Unable to determine recovery partition."
1642 return 1
1643 fi
1644 adb start-server
1645 adb root
1646 sleep 1
1647 adb wait-for-device
1648 adb remount
1649 adb wait-for-device
1650 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1651 then
1652 adb push $OUT/recovery.img /cache/
1653 adb shell dd if=/cache/recovery.img of=$PARTITION
1654 echo "Installation complete."
1655 else
1656 echo "The connected device does not appear to be $CM_BUILD, run away!"
1657 fi
1658}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001659
Koushik Duttab55f13a2012-05-14 16:14:36 -07001660function makerecipe() {
1661 if [ -z "$1" ]
1662 then
1663 echo "No branch name provided."
1664 return 1
1665 fi
1666 cd android
1667 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1668 git commit -a -m "$1"
1669 cd ..
1670
1671 repo forall -c '
1672
1673 if [ "$REPO_REMOTE" == "github" ]
1674 then
1675 pwd
1676 cmremote
1677 git push cmremote HEAD:refs/heads/'$1'
1678 fi
1679 '
1680}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001681
1682function cmgerrit() {
1683 if [ $# -eq 0 ]; then
1684 $FUNCNAME help
1685 return 1
1686 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001687 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001688 local review=`git config --get remote.github.review`
1689 local project=`git config --get remote.github.projectname`
1690 local command=$1
1691 shift
1692 case $command in
1693 help)
1694 if [ $# -eq 0 ]; then
1695 cat <<EOF
1696Usage:
1697 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1698
1699Commands:
1700 fetch Just fetch the change as FETCH_HEAD
1701 help Show this help, or for a specific command
1702 pull Pull a change into current branch
1703 push Push HEAD or a local branch to Gerrit for a specific branch
1704
1705Any other Git commands that support refname would work as:
1706 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1707
1708See '$FUNCNAME help COMMAND' for more information on a specific command.
1709
1710Example:
1711 $FUNCNAME checkout -b topic 1234/5
1712works as:
1713 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1714 && git checkout -b topic FETCH_HEAD
1715will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1716Patch-set 1 will be fetched if omitted.
1717EOF
1718 return
1719 fi
1720 case $1 in
1721 __cmg_*) echo "For internal use only." ;;
1722 changes|for)
1723 if [ "$FUNCNAME" = "cmgerrit" ]; then
1724 echo "'$FUNCNAME $1' is deprecated."
1725 fi
1726 ;;
1727 help) $FUNCNAME help ;;
1728 fetch|pull) cat <<EOF
1729usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1730
1731works as:
1732 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1733 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1734
1735Example:
1736 $FUNCNAME $1 1234
1737will $1 patch-set 1 of change 1234
1738EOF
1739 ;;
1740 push) cat <<EOF
1741usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1742
1743works as:
1744 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1745 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1746
1747Example:
1748 $FUNCNAME push fix6789:gingerbread
1749will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1750HEAD will be pushed from local if omitted.
1751EOF
1752 ;;
1753 *)
1754 $FUNCNAME __cmg_err_not_supported $1 && return
1755 cat <<EOF
1756usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1757
1758works as:
1759 git fetch http://DOMAIN/p/PROJECT \\
1760 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1761 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1762EOF
1763 ;;
1764 esac
1765 ;;
1766 __cmg_get_ref)
1767 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1768 local change_id patchset_id hash
1769 case $1 in
1770 */*)
1771 change_id=${1%%/*}
1772 patchset_id=${1#*/}
1773 ;;
1774 *)
1775 change_id=$1
1776 patchset_id=1
1777 ;;
1778 esac
1779 hash=$(($change_id % 100))
1780 case $hash in
1781 [0-9]) hash="0$hash" ;;
1782 esac
1783 echo "refs/changes/$hash/$change_id/$patchset_id"
1784 ;;
1785 fetch|pull)
1786 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1787 $FUNCNAME __cmg_err_not_repo && return 1
1788 local change=$1
1789 shift
1790 git $command $@ http://$review/p/$project \
1791 $($FUNCNAME __cmg_get_ref $change) || return 1
1792 ;;
1793 push)
1794 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1795 $FUNCNAME __cmg_err_not_repo && return 1
1796 if [ -z "$user" ]; then
1797 echo >&2 "Gerrit username not found."
1798 return 1
1799 fi
1800 local local_branch remote_branch
1801 case $1 in
1802 *:*)
1803 local_branch=${1%:*}
1804 remote_branch=${1##*:}
1805 ;;
1806 *)
1807 local_branch=HEAD
1808 remote_branch=$1
1809 ;;
1810 esac
1811 shift
1812 git push $@ ssh://$user@$review:29418/$project \
1813 $local_branch:refs/for/$remote_branch || return 1
1814 ;;
1815 changes|for)
1816 if [ "$FUNCNAME" = "cmgerrit" ]; then
1817 echo >&2 "'$FUNCNAME $command' is deprecated."
1818 fi
1819 ;;
1820 __cmg_err_no_arg)
1821 if [ $# -lt 2 ]; then
1822 echo >&2 "'$FUNCNAME $command' missing argument."
1823 elif [ $2 -eq 0 ]; then
1824 if [ -n "$3" ]; then
1825 $FUNCNAME help $1
1826 else
1827 echo >&2 "'$FUNCNAME $1' missing argument."
1828 fi
1829 else
1830 return 1
1831 fi
1832 ;;
1833 __cmg_err_not_repo)
1834 if [ -z "$review" -o -z "$project" ]; then
1835 echo >&2 "Not currently in any reviewable repository."
1836 else
1837 return 1
1838 fi
1839 ;;
1840 __cmg_err_not_supported)
1841 $FUNCNAME __cmg_err_no_arg $command $# && return
1842 case $1 in
1843 #TODO: filter more git commands that don't use refname
1844 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1845 echo >&2 "'$FUNCNAME $1' is not supported."
1846 ;;
1847 *) return 1 ;;
1848 esac
1849 ;;
1850 #TODO: other special cases?
1851 *)
1852 $FUNCNAME __cmg_err_not_supported $command && return 1
1853 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1854 $FUNCNAME __cmg_err_not_repo && return 1
1855 local args="$@"
1856 local change pre_args refs_arg post_args
1857 case "$args" in
1858 *--\ *)
1859 pre_args=${args%%-- *}
1860 post_args="-- ${args#*-- }"
1861 ;;
1862 *) pre_args="$args" ;;
1863 esac
1864 args=($pre_args)
1865 pre_args=
1866 if [ ${#args[@]} -gt 0 ]; then
1867 change=${args[${#args[@]}-1]}
1868 fi
1869 if [ ${#args[@]} -gt 1 ]; then
1870 pre_args=${args[0]}
1871 for ((i=1; i<${#args[@]}-1; i++)); do
1872 pre_args="$pre_args ${args[$i]}"
1873 done
1874 fi
1875 while ((1)); do
1876 case $change in
1877 ""|--)
1878 $FUNCNAME help $command
1879 return 1
1880 ;;
1881 *@*)
1882 if [ -z "$refs_arg" ]; then
1883 refs_arg="@${change#*@}"
1884 change=${change%%@*}
1885 fi
1886 ;;
1887 *~*)
1888 if [ -z "$refs_arg" ]; then
1889 refs_arg="~${change#*~}"
1890 change=${change%%~*}
1891 fi
1892 ;;
1893 *^*)
1894 if [ -z "$refs_arg" ]; then
1895 refs_arg="^${change#*^}"
1896 change=${change%%^*}
1897 fi
1898 ;;
1899 *:*)
1900 if [ -z "$refs_arg" ]; then
1901 refs_arg=":${change#*:}"
1902 change=${change%%:*}
1903 fi
1904 ;;
1905 *) break ;;
1906 esac
1907 done
1908 $FUNCNAME fetch $change \
1909 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1910 || return 1
1911 ;;
1912 esac
1913}
1914
1915function cmrebase() {
1916 local repo=$1
1917 local refs=$2
1918 local pwd="$(pwd)"
1919 local dir="$(gettop)/$repo"
1920
1921 if [ -z $repo ] || [ -z $refs ]; then
1922 echo "CyanogenMod Gerrit Rebase Usage: "
1923 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1924 echo " The patch IDs appear on the Gerrit commands that are offered."
1925 echo " They consist on a series of numbers and slashes, after the text"
1926 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1927 echo ""
1928 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1929 echo ""
1930 return
1931 fi
1932
1933 if [ ! -d $dir ]; then
1934 echo "Directory $dir doesn't exist in tree."
1935 return
1936 fi
1937 cd $dir
1938 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1939 echo "Starting branch..."
1940 repo start tmprebase .
1941 echo "Bringing it up to date..."
1942 repo sync .
1943 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001944 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001945 if [ "$?" != "0" ]; then
1946 echo "Error cherry-picking. Not uploading!"
1947 return
1948 fi
1949 echo "Uploading..."
1950 repo upload .
1951 echo "Cleaning up..."
1952 repo abandon tmprebase .
1953 cd $pwd
1954}
1955
1956function mka() {
1957 case `uname -s` in
1958 Darwin)
1959 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1960 ;;
1961 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001962 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001963 ;;
1964 esac
1965}
1966
1967function reposync() {
1968 case `uname -s` in
1969 Darwin)
1970 repo sync -j 4 "$@"
1971 ;;
1972 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001973 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001974 ;;
1975 esac
1976}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001977
1978function repodiff() {
1979 if [ -z "$*" ]; then
1980 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1981 return
1982 fi
1983 diffopts=$* repo forall -c \
1984 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1985}
1986
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301987# Credit for color strip sed: http://goo.gl/BoIcm
1988function dopush()
1989{
1990 local func=$1
1991 shift
1992
1993 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1994 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
1995 echo "No device is online. Waiting for one..."
1996 echo "Please connect USB and/or enable USB debugging"
1997 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
1998 sleep 1
1999 done
2000 echo "Device Found."
2001 fi
2002
Chirayu Desai6dadb572012-12-26 10:53:58 +05302003 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2004 then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302005 adb root &> /dev/null
2006 sleep 0.3
2007 adb wait-for-device &> /dev/null
2008 sleep 0.3
2009 adb remount &> /dev/null
2010
2011 $func $* | tee $OUT/.log
2012
2013 # Install: <file>
2014 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)
2015
2016 # Copy: <file>
2017 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)
2018
2019 for FILE in $LOC; do
2020 # Get target file name (i.e. system/bin/adb)
2021 TARGET=$(echo $FILE | sed "s#$OUT/##")
2022
2023 # Don't send files that are not in /system.
2024 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2025 continue
2026 else
2027 case $TARGET in
2028 system/app/SystemUI.apk|system/framework/*)
2029 stop_n_start=true
2030 ;;
2031 *)
2032 stop_n_start=false
2033 ;;
2034 esac
2035 if $stop_n_start ; then adb shell stop ; fi
2036 echo "Pushing: $TARGET"
2037 adb push $FILE $TARGET
2038 if $stop_n_start ; then adb shell start ; fi
2039 fi
2040 done
2041 rm -f $OUT/.log
2042 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302043 else
2044 echo "The connected device does not appear to be $CM_BUILD, run away!"
2045 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302046}
2047
2048alias mmp='dopush mm'
2049alias mmmp='dopush mmm'
2050alias mkap='dopush mka'
2051alias cmkap='dopush cmka'
2052
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002053# 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 +00002054#
2055# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2056# For some reason, installing the JDK doesn't make it show up in the
2057# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002058function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002059 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002060 # we can reset it later, depending on the version of java the build
2061 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002062 #
2063 # If we don't do this, the JAVA_HOME value set by the first call to
2064 # build/envsetup.sh will persist forever.
2065 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2066 export JAVA_HOME=""
2067 fi
2068
Andy McFaddenbd960942010-06-24 12:52:51 -07002069 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002070 case `uname -s` in
2071 Darwin)
2072 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2073 ;;
2074 *)
2075 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2076 ;;
2077 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002078
2079 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2080 # we can change it on the next envsetup.sh, if required.
2081 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002082 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002083}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002084
Alex Rayf0d08eb2013-03-08 15:15:06 -08002085# Print colored exit condition
2086function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002087 "$@"
2088 local retval=$?
2089 if [ $retval -ne 0 ]
2090 then
2091 echo -e "\e[0;31mFAILURE\e[00m"
2092 else
2093 echo -e "\e[0;32mSUCCESS\e[00m"
2094 fi
2095 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002096}
2097
Ying Wanged21d4c2014-08-24 22:14:19 -07002098function get_make_command()
2099{
2100 echo command make
2101}
2102
Ed Heylcc6be0a2014-06-18 14:55:58 -07002103function make()
2104{
2105 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002106 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002107 local ret=$?
2108 local end_time=$(date +"%s")
2109 local tdiff=$(($end_time-$start_time))
2110 local hours=$(($tdiff / 3600 ))
2111 local mins=$((($tdiff % 3600) / 60))
2112 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002113 local ncolors=$(tput colors 2>/dev/null)
2114 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2115 color_failed="\e[0;31m"
2116 color_success="\e[0;32m"
2117 color_reset="\e[00m"
2118 else
2119 color_failed=""
2120 color_success=""
2121 color_reset=""
2122 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002123 echo
2124 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002125 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002126 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002127 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002128 fi
2129 if [ $hours -gt 0 ] ; then
2130 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2131 elif [ $mins -gt 0 ] ; then
2132 printf "(%02g:%02g (mm:ss))" $mins $secs
2133 elif [ $secs -gt 0 ] ; then
2134 printf "(%s seconds)" $secs
2135 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002136 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002137 echo
2138 return $ret
2139}
2140
Raphael Moll70a86b02011-06-20 16:03:14 -07002141if [ "x$SHELL" != "x/bin/bash" ]; then
2142 case `ps -o command -p $$` in
2143 *bash*)
2144 ;;
2145 *)
2146 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2147 ;;
2148 esac
2149fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002150
2151# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002152for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2153 `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 -08002154do
2155 echo "including $f"
2156 . $f
2157done
2158unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002159
2160addcompletions