blob: fcb8ec6fd12eda57727f94c3271406ff9c2ddccf [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
Steve Kondikd6fba552012-12-27 15:28:34 -0800274 if [ -z "$PROMPT_COMMAND" ]; then
275 # No prompts
276 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
277 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
278 # Prompts exist, but no hardstatus
279 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700280 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800281 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
282 PROMPT_COMMAND=$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')
283 fi
284
285 if [ -z "$apps" ]; then
286 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
287 else
288 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
289 fi
290 export ANDROID_PROMPT_PREFIX
291
292 # Inject build data into hardstatus
293 export PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/\\033]0;\(.*\)\\007/\\033]0;$ANDROID_PROMPT_PREFIX \1\\007/g')"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800294 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700295}
296
Kenny Root52aa81c2011-07-15 11:07:06 -0700297function addcompletions()
298{
299 local T dir f
300
301 # Keep us from trying to run in something that isn't bash.
302 if [ -z "${BASH_VERSION}" ]; then
303 return
304 fi
305
306 # Keep us from trying to run in bash that's too old.
307 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
308 return
309 fi
310
311 dir="sdk/bash_completion"
312 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700313 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700314 echo "including $f"
315 . $f
316 done
317 fi
318}
319
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700320function choosetype()
321{
322 echo "Build type choices are:"
323 echo " 1. release"
324 echo " 2. debug"
325 echo
326
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700328 DEFAULT_NUM=1
329 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 export TARGET_BUILD_TYPE=
332 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333 while [ -z $TARGET_BUILD_TYPE ]
334 do
335 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 if [ -z "$1" ] ; then
337 read ANSWER
338 else
339 echo $1
340 ANSWER=$1
341 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 case $ANSWER in
343 "")
344 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
345 ;;
346 1)
347 export TARGET_BUILD_TYPE=release
348 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349 release)
350 export TARGET_BUILD_TYPE=release
351 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700352 2)
353 export TARGET_BUILD_TYPE=debug
354 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800355 debug)
356 export TARGET_BUILD_TYPE=debug
357 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700358 *)
359 echo
360 echo "I didn't understand your response. Please try again."
361 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 ;;
363 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800364 if [ -n "$1" ] ; then
365 break
366 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367 done
368
369 set_stuff_for_environment
370}
371
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800372#
373# This function isn't really right: It chooses a TARGET_PRODUCT
374# based on the list of boards. Usually, that gets you something
375# that kinda works with a generic product, but really, you should
376# pick a product by name.
377#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378function chooseproduct()
379{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700380 if [ "x$TARGET_PRODUCT" != x ] ; then
381 default_value=$TARGET_PRODUCT
382 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700383 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384 fi
385
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800386 export TARGET_PRODUCT=
387 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700388 while [ -z "$TARGET_PRODUCT" ]
389 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700390 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800391 if [ -z "$1" ] ; then
392 read ANSWER
393 else
394 echo $1
395 ANSWER=$1
396 fi
397
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700398 if [ -z "$ANSWER" ] ; then
399 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800400 else
401 if check_product $ANSWER
402 then
403 export TARGET_PRODUCT=$ANSWER
404 else
405 echo "** Not a valid product: $ANSWER"
406 fi
407 fi
408 if [ -n "$1" ] ; then
409 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700410 fi
411 done
412
413 set_stuff_for_environment
414}
415
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800416function choosevariant()
417{
418 echo "Variant choices are:"
419 local index=1
420 local v
421 for v in ${VARIANT_CHOICES[@]}
422 do
423 # The product name is the name of the directory containing
424 # the makefile we found, above.
425 echo " $index. $v"
426 index=$(($index+1))
427 done
428
429 local default_value=eng
430 local ANSWER
431
432 export TARGET_BUILD_VARIANT=
433 while [ -z "$TARGET_BUILD_VARIANT" ]
434 do
435 echo -n "Which would you like? [$default_value] "
436 if [ -z "$1" ] ; then
437 read ANSWER
438 else
439 echo $1
440 ANSWER=$1
441 fi
442
443 if [ -z "$ANSWER" ] ; then
444 export TARGET_BUILD_VARIANT=$default_value
445 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
446 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800447 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448 fi
449 else
450 if check_variant $ANSWER
451 then
452 export TARGET_BUILD_VARIANT=$ANSWER
453 else
454 echo "** Not a valid variant: $ANSWER"
455 fi
456 fi
457 if [ -n "$1" ] ; then
458 break
459 fi
460 done
461}
462
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463function choosecombo()
464{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700465 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466
467 echo
468 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700469 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470
471 echo
472 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700473 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800474
475 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478}
479
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480# Clear this variable. It will be built up again when the vendorsetup.sh
481# files are included at the end of this file.
482unset LUNCH_MENU_CHOICES
483function add_lunch_combo()
484{
485 local new_combo=$1
486 local c
487 for c in ${LUNCH_MENU_CHOICES[@]} ; do
488 if [ "$new_combo" = "$c" ] ; then
489 return
490 fi
491 done
492 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
493}
494
495# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700496add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800497add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000498add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800499add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000500add_lunch_combo aosp_x86-eng
501add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503function print_lunch_menu()
504{
505 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 echo
507 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000508 if [ "$(uname)" = "Darwin" ] ; then
509 echo " (ohai, koush!)"
510 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700511 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000512 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
513 echo "Breakfast menu... pick a combo:"
514 else
515 echo "Lunch menu... pick a combo:"
516 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517
518 local i=1
519 local choice
520 for choice in ${LUNCH_MENU_CHOICES[@]}
521 do
522 echo " $i. $choice"
523 i=$(($i+1))
524 done
525
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000526 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
527 echo "... and don't forget the bacon!"
528 fi
529
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700530 echo
531}
532
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000533function brunch()
534{
535 breakfast $*
536 if [ $? -eq 0 ]; then
537 mka bacon
538 else
539 echo "No such item in brunch menu. Try 'breakfast'"
540 return 1
541 fi
542 return $?
543}
544
545function breakfast()
546{
547 target=$1
548 CM_DEVICES_ONLY="true"
549 unset LUNCH_MENU_CHOICES
550 add_lunch_combo full-eng
551 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
552 do
553 echo "including $f"
554 . $f
555 done
556 unset f
557
558 if [ $# -eq 0 ]; then
559 # No arguments, so let's have the full menu
560 lunch
561 else
562 echo "z$target" | grep -q "-"
563 if [ $? -eq 0 ]; then
564 # A buildtype was specified, assume a full device name
565 lunch $target
566 else
567 # This is probably just the CM model name
568 lunch cm_$target-userdebug
569 fi
570 fi
571 return $?
572}
573
574alias bib=breakfast
575
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700576function lunch()
577{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578 local answer
579
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 else
583 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700584 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800585 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586 fi
587
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 local selection=
589
590 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700592 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
594 then
595 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
596 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800597 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 fi
599 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
600 then
601 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700602 fi
603
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800604 if [ -z "$selection" ]
605 then
606 echo
607 echo "Invalid lunch combo: $answer"
608 return 1
609 fi
610
Joe Onoratoda12daf2010-06-09 18:18:31 -0700611 export TARGET_BUILD_APPS=
612
Jeff Browne33ba4c2011-07-11 22:11:46 -0700613 local product=$(echo -n $selection | sed -e "s/-.*$//")
614 check_product $product
615 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800616 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800617 # if we can't find a product, try to grab it off the CM github
618 T=$(gettop)
619 pushd $T > /dev/null
620 build/tools/roomservice.py $product
621 popd > /dev/null
622 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000623 else
624 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800625 fi
626 if [ $? -ne 0 ]
627 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700628 echo
629 echo "** Don't have a product spec for: '$product'"
630 echo "** Do you have the right repo manifest?"
631 product=
632 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800633
Jeff Browne33ba4c2011-07-11 22:11:46 -0700634 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
635 check_variant $variant
636 if [ $? -ne 0 ]
637 then
638 echo
639 echo "** Invalid variant: '$variant'"
640 echo "** Must be one of ${VARIANT_CHOICES[@]}"
641 variant=
642 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643
Jeff Browne33ba4c2011-07-11 22:11:46 -0700644 if [ -z "$product" -o -z "$variant" ]
645 then
646 echo
647 return 1
648 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800649
Jeff Browne33ba4c2011-07-11 22:11:46 -0700650 export TARGET_PRODUCT=$product
651 export TARGET_BUILD_VARIANT=$variant
652 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653
654 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800655
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700656 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800657 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658}
659
Jeff Davidson513d7a42010-08-02 10:00:44 -0700660# Tab completion for lunch.
661function _lunch()
662{
663 local cur prev opts
664 COMPREPLY=()
665 cur="${COMP_WORDS[COMP_CWORD]}"
666 prev="${COMP_WORDS[COMP_CWORD-1]}"
667
668 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
669 return 0
670}
671complete -F _lunch lunch
672
Joe Onoratoda12daf2010-06-09 18:18:31 -0700673# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700674# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700675function tapas()
676{
Ying Wangb541ab62014-05-29 17:57:40 -0700677 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 -0700678 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700679 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
680 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 -0700681
Ying Wang67f02922012-08-22 10:25:20 -0700682 if [ $(echo $arch | wc -w) -gt 1 ]; then
683 echo "tapas: Error: Multiple build archs supplied: $arch"
684 return
685 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700686 if [ $(echo $variant | wc -w) -gt 1 ]; then
687 echo "tapas: Error: Multiple build variants supplied: $variant"
688 return
689 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700690 if [ $(echo $density | wc -w) -gt 1 ]; then
691 echo "tapas: Error: Multiple densities supplied: $density"
692 return
693 fi
Ying Wang67f02922012-08-22 10:25:20 -0700694
695 local product=full
696 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700697 x86) product=full_x86;;
698 mips) product=full_mips;;
699 armv5) product=generic_armv5;;
700 arm64) product=aosp_arm64;;
701 x86_64) product=aosp_x86_64;;
702 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700703 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700704 if [ -z "$variant" ]; then
705 variant=eng
706 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700707 if [ -z "$apps" ]; then
708 apps=all
709 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600710 if [ -z "$density" ]; then
711 density=alldpi
712 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700713
Ying Wang67f02922012-08-22 10:25:20 -0700714 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700715 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700716 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700717 export TARGET_BUILD_TYPE=release
718 export TARGET_BUILD_APPS=$apps
719
720 set_stuff_for_environment
721 printconfig
722}
723
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100724function eat()
725{
726 if [ "$OUT" ] ; then
727 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
728 ZIPFILE=cm-$MODVERSION.zip
729 ZIPPATH=$OUT/$ZIPFILE
730 if [ ! -f $ZIPPATH ] ; then
731 echo "Nothing to eat"
732 return 1
733 fi
734 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
735 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
736 echo "No device is online. Waiting for one..."
737 echo "Please connect USB and/or enable USB debugging"
738 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
739 sleep 1
740 done
741 echo "Device Found.."
742 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530743 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
744 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100745 # if adbd isn't root we can't write to /cache/recovery/
746 adb root
747 sleep 1
748 adb wait-for-device
749 SZ=`stat -c %s $ZIPPATH`
750 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
751 if [ $CACHESIZE -gt $SZ ];
752 then
753 PUSHDIR=/cache/
754 DIR=cache
755 else
756 PUSHDIR=/storage/sdcard0/
757 # Optional path for sdcard0 in recovery
758 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
759 fi
760 echo "Pushing $ZIPFILE to $PUSHDIR"
761 if adb push $ZIPPATH $PUSHDIR ; then
762 cat << EOF > /tmp/command
763--update_package=/$DIR/$ZIPFILE
764EOF
765 if adb push /tmp/command /cache/recovery/ ; then
766 echo "Rebooting into recovery for installation"
767 adb reboot recovery
768 fi
769 rm /tmp/command
770 fi
771 else
772 echo "Nothing to eat"
773 return 1
774 fi
775 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530776 else
777 echo "The connected device does not appear to be $CM_BUILD, run away!"
778 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100779}
780
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000781function omnom
782{
783 brunch $*
784 eat
785}
786
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787function gettop
788{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800789 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700791 # The following circumlocution ensures we remove symlinks from TOP.
792 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 else
794 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800795 # The following circumlocution (repeated below as well) ensures
796 # that we record the true directory name and not one that is
797 # faked up with symlink names.
798 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800800 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 T=
802 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800803 \cd ..
synergyb112a402013-07-05 19:47:47 -0700804 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700805 done
Ying Wang9cd17642012-12-13 10:52:07 -0800806 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700807 if [ -f "$T/$TOPFILE" ]; then
808 echo $T
809 fi
810 fi
811 fi
812}
813
Andrew Hsieh906cb782013-09-10 17:37:14 +0800814# Return driver for "make", if any (eg. static analyzer)
815function getdriver()
816{
817 local T="$1"
818 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
819 if [ -n "$WITH_STATIC_ANALYZER" ]; then
820 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800821$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
822--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800823--status-bugs \
824--top=$T"
825 fi
826}
827
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700828function m()
829{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800830 local T=$(gettop)
831 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700832 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800833 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834 else
835 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700836 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700837 fi
838}
839
840function findmakefile()
841{
842 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800843 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844 T=
845 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700846 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847 if [ -f "$T/Android.mk" ]; then
848 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800849 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850 return
851 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800852 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700853 done
Ying Wang9cd17642012-12-13 10:52:07 -0800854 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855}
856
857function mm()
858{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800859 local T=$(gettop)
860 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861 # If we're sitting in the root of the build tree, just do a
862 # normal make.
863 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800864 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700865 else
866 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800867 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700868 local MODULES=
869 local GET_INSTALL_PATH=
870 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700871 # Remove the path to top as the makefilepath needs to be relative
872 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873 if [ ! "$T" ]; then
874 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700875 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700876 elif [ ! "$M" ]; then
877 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700878 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700879 else
Ying Wanga7deb082013-08-16 13:24:47 -0700880 for ARG in $@; do
881 case $ARG in
882 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
883 esac
884 done
885 if [ -n "$GET_INSTALL_PATH" ]; then
886 MODULES=
887 ARGS=GET-INSTALL-PATH
888 else
889 MODULES=all_modules
890 ARGS=$@
891 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700892 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 -0700893 fi
894 fi
895}
896
897function mmm()
898{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800899 local T=$(gettop)
900 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700901 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800902 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800903 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800904 local ARGS=
905 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700906 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800907 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
908 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
909 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800910 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
911 if [ "$MODULES" = "" ]; then
912 MODULES=all_modules
913 fi
914 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700916 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
917 local TO_CHOP=`expr $TO_CHOP + 1`
918 local START=`PWD= /bin/pwd`
919 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700920 if [ "$MFILE" = "" ] ; then
921 MFILE=$DIR/Android.mk
922 else
923 MFILE=$MFILE/$DIR/Android.mk
924 fi
925 MAKEFILE="$MAKEFILE $MFILE"
926 else
Ying Wanga7deb082013-08-16 13:24:47 -0700927 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100928 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700929 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
930 *) echo "No Android.mk in $DIR."; return 1;;
931 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 fi
933 done
Ying Wanga7deb082013-08-16 13:24:47 -0700934 if [ -n "$GET_INSTALL_PATH" ]; then
935 ARGS=$GET_INSTALL_PATH
936 MODULES=
937 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800938 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 -0700939 else
940 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700941 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942 fi
943}
944
Ying Wangb607f7b2013-02-08 18:01:04 -0800945function mma()
946{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800947 local T=$(gettop)
948 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800949 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800950 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800951 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800952 if [ ! "$T" ]; then
953 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700954 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800955 fi
956 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800957 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800958 fi
959}
960
961function mmma()
962{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800963 local T=$(gettop)
964 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800965 if [ "$T" ]; then
966 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
967 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
968 local MY_PWD=`PWD= /bin/pwd`
969 if [ "$MY_PWD" = "$T" ]; then
970 MY_PWD=
971 else
972 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
973 fi
974 local DIR=
975 local MODULE_PATHS=
976 local ARGS=
977 for DIR in $DIRS ; do
978 if [ -d $DIR ]; then
979 if [ "$MY_PWD" = "" ]; then
980 MODULE_PATHS="$MODULE_PATHS $DIR"
981 else
982 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
983 fi
984 else
985 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100986 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800987 *) echo "Couldn't find directory $DIR"; return 1;;
988 esac
989 fi
990 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800991 $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 -0800992 else
993 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700994 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800995 fi
996}
997
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998function croot()
999{
1000 T=$(gettop)
1001 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001002 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001003 else
1004 echo "Couldn't locate the top of the tree. Try setting TOP."
1005 fi
1006}
1007
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001008function cproj()
1009{
1010 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001011 local HERE=$PWD
1012 T=
1013 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1014 T=$PWD
1015 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001016 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001017 return
1018 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001019 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 done
Ying Wang9cd17642012-12-13 10:52:07 -08001021 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001022 echo "can't find Android.mk"
1023}
1024
Daniel Sandler47e0a882013-07-30 13:23:52 -04001025# simplified version of ps; output in the form
1026# <pid> <procname>
1027function qpid() {
1028 local prepend=''
1029 local append=''
1030 if [ "$1" = "--exact" ]; then
1031 prepend=' '
1032 append='$'
1033 shift
1034 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1035 echo "usage: qpid [[--exact] <process name|pid>"
1036 return 255
1037 fi
1038
1039 local EXE="$1"
1040 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001041 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001042 else
1043 adb shell ps \
1044 | tr -d '\r' \
1045 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1046 fi
1047}
1048
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001049function pid()
1050{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001051 local prepend=''
1052 local append=''
1053 if [ "$1" = "--exact" ]; then
1054 prepend=' '
1055 append='$'
1056 shift
1057 fi
1058 local EXE="$1"
1059 if [ "$EXE" ] ; then
1060 local PID=`adb shell ps \
1061 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001062 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001063 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1064 echo "$PID"
1065 else
1066 echo "usage: pid [--exact] <process name>"
1067 return 255
1068 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001069}
1070
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001071# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001072# that has the core-file-size limit set correctly
1073#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001074# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075# if its core-file-size limit is not set already.
1076# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1077
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001078function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001079{
1080 echo "Getting root...";
1081 adb root;
1082 adb wait-for-device;
1083
1084 echo "Remounting root parition read-write...";
1085 adb shell mount -w -o remount -t rootfs rootfs;
1086 sleep 1;
1087 adb wait-for-device;
1088 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001089 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001090 adb shell chmod 0777 /cores;
1091
1092 echo "Granting SELinux permission to dump in /cores...";
1093 adb shell restorecon -R /cores;
1094
1095 echo "Set core pattern.";
1096 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1097
1098 echo "Done."
1099}
1100
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001101# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001102# $1 = PID of process (e.g., $(pid mediaserver))
1103#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001104# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001105# dump to actually be generated.
1106
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001107function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001108{
1109 local PID=$1;
1110 if [ -z "$PID" ]; then
1111 printf "Expecting a PID!\n";
1112 return;
1113 fi;
1114 echo "Setting core limit for $PID to infinite...";
1115 adb shell prlimit $PID 4 -1 -1
1116}
1117
1118# core - send SIGV and pull the core for process
1119# $1 = PID of process (e.g., $(pid mediaserver))
1120#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001121# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001122# enabled globally.
1123
1124function core()
1125{
1126 local PID=$1;
1127
1128 if [ -z "$PID" ]; then
1129 printf "Expecting a PID!\n";
1130 return;
1131 fi;
1132
1133 local CORENAME=core.$PID;
1134 local COREPATH=/cores/$CORENAME;
1135 local SIG=SEGV;
1136
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001137 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001138
1139 local done=0;
1140 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1141 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1142 adb shell kill -$SIG $PID;
1143 sleep 1;
1144 done;
1145
1146 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1147 echo "Done: core is under $COREPATH on device.";
1148}
1149
Christopher Tate744ee802009-11-12 15:33:08 -08001150# systemstack - dump the current stack trace of all threads in the system process
1151# to the usual ANR traces file
1152function systemstack()
1153{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001154 stacks system_server
1155}
1156
1157function stacks()
1158{
1159 if [[ $1 =~ ^[0-9]+$ ]] ; then
1160 local PID="$1"
1161 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001162 local PIDLIST="$(pid $1)"
1163 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1164 local PID="$PIDLIST"
1165 elif [ "$PIDLIST" ] ; then
1166 echo "more than one process: $1"
1167 else
1168 echo "no such process: $1"
1169 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001170 else
1171 echo "usage: stacks [pid|process name]"
1172 fi
1173
1174 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001175 # Determine whether the process is native
1176 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1177 # Dump stacks of Dalvik process
1178 local TRACES=/data/anr/traces.txt
1179 local ORIG=/data/anr/traces.orig
1180 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001181
Jeff Brownb12c2e52013-08-19 15:14:16 -07001182 # Keep original traces to avoid clobbering
1183 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001184
Jeff Brownb12c2e52013-08-19 15:14:16 -07001185 # Make sure we have a usable file
1186 adb shell touch $TRACES
1187 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001188
Jeff Brownb12c2e52013-08-19 15:14:16 -07001189 # Dump stacks and wait for dump to finish
1190 adb shell kill -3 $PID
1191 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001192
Jeff Brownb12c2e52013-08-19 15:14:16 -07001193 # Restore original stacks, and show current output
1194 adb shell mv $TRACES $TMP
1195 adb shell mv $ORIG $TRACES
1196 adb shell cat $TMP
1197 else
1198 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001199 local USE64BIT="$(is64bit $PID)"
1200 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001201 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001202 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001203}
1204
Michael Wrightaeed7212014-06-19 19:58:12 -07001205# Read the ELF header from /proc/$PID/exe to determine if the process is
1206# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001207function is64bit()
1208{
1209 local PID="$1"
1210 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001211 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001212 echo "64"
1213 else
1214 echo ""
1215 fi
1216 else
1217 echo ""
1218 fi
1219}
1220
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001221case `uname -s` in
1222 Darwin)
1223 function sgrep()
1224 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001225 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 -07001226 }
1227
1228 ;;
1229 *)
1230 function sgrep()
1231 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001232 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 -07001233 }
1234 ;;
1235esac
1236
Raghu Gandham8da43102012-07-25 19:57:22 -07001237function gettargetarch
1238{
1239 get_build_var TARGET_ARCH
1240}
1241
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001242function ggrep()
1243{
1244 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1245}
1246
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001247function jgrep()
1248{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001249 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 -07001250}
1251
1252function cgrep()
1253{
Dan Albert01961192014-11-22 10:16:01 -08001254 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 -07001255}
1256
1257function resgrep()
1258{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001259 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 -07001260}
1261
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001262function mangrep()
1263{
1264 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1265}
1266
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001267function sepgrep()
1268{
1269 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 "$@"
1270}
1271
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001272function rcgrep()
1273{
1274 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1275}
1276
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001277case `uname -s` in
1278 Darwin)
1279 function mgrep()
1280 {
Ying Wang324c2b22012-08-17 15:03:20 -07001281 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 -07001282 }
1283
1284 function treegrep()
1285 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001286 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 -07001287 }
1288
1289 ;;
1290 *)
1291 function mgrep()
1292 {
Ying Wang324c2b22012-08-17 15:03:20 -07001293 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 -07001294 }
1295
1296 function treegrep()
1297 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001298 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 -07001299 }
1300
1301 ;;
1302esac
1303
1304function getprebuilt
1305{
1306 get_abs_build_var ANDROID_PREBUILTS
1307}
1308
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309function tracedmdump()
1310{
1311 T=$(gettop)
1312 if [ ! "$T" ]; then
1313 echo "Couldn't locate the top of the tree. Try setting TOP."
1314 return
1315 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001316 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001317 local arch=$(gettargetarch)
1318 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001319
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001320 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001321 if [ ! "$TRACE" ] ; then
1322 echo "usage: tracedmdump tracename"
1323 return
1324 fi
1325
Jack Veenstra60116fc2009-04-09 18:12:34 -07001326 if [ ! -r "$KERNEL" ] ; then
1327 echo "Error: cannot find kernel: '$KERNEL'"
1328 return
1329 fi
1330
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001331 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001332 if [ "$BASETRACE" = "$TRACE" ] ; then
1333 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1334 fi
1335
1336 echo "post-processing traces..."
1337 rm -f $TRACE/qtrace.dexlist
1338 post_trace $TRACE
1339 if [ $? -ne 0 ]; then
1340 echo "***"
1341 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1342 echo "***"
1343 return
1344 fi
1345 echo "generating dexlist output..."
1346 /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
1347 echo "generating dmtrace data..."
1348 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1349 echo "generating html file..."
1350 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1351 echo "done, see $TRACE/dmtrace.html for details"
1352 echo "or run:"
1353 echo " traceview $TRACE/dmtrace"
1354}
1355
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001356# communicate with a running device or emulator, set up necessary state,
1357# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001358function runhat()
1359{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001360 # process standard adb options
1361 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001362 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001363 adbTarget=$1
1364 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001365 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001366 adbTarget="$1 $2"
1367 shift 2
1368 fi
1369 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001370 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001371
1372 # runhat options
1373 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001374
1375 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001376 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377 return
1378 fi
1379
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380 # confirm hat is available
1381 if [ -z $(which hat) ]; then
1382 echo "hat is not available in this configuration."
1383 return
1384 fi
1385
Andy McFaddenb6289852010-07-12 08:00:19 -07001386 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001387 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001388 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001389 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001390 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001391 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001392 echo -n "> "
1393 read
1394
The Android Open Source Project88b60792009-03-03 19:28:42 -08001395 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001396
The Android Open Source Project88b60792009-03-03 19:28:42 -08001397 echo "Retrieving file $devFile..."
1398 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001399
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401
The Android Open Source Project88b60792009-03-03 19:28:42 -08001402 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001403 echo "View the output by pointing your browser at http://localhost:7000/"
1404 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001405 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001406}
1407
1408function getbugreports()
1409{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001410 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001411
1412 if [ ! "$reports" ]; then
1413 echo "Could not locate any bugreports."
1414 return
1415 fi
1416
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001417 local report
1418 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001419 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001420 echo "/sdcard/bugreports/${report}"
1421 adb pull /sdcard/bugreports/${report} ${report}
1422 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001423 done
1424}
1425
Victoria Lease1b296b42012-08-21 15:44:06 -07001426function getsdcardpath()
1427{
1428 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1429}
1430
1431function getscreenshotpath()
1432{
1433 echo "$(getsdcardpath)/Pictures/Screenshots"
1434}
1435
1436function getlastscreenshot()
1437{
1438 local screenshot_path=$(getscreenshotpath)
1439 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1440 if [ "$screenshot" = "" ]; then
1441 echo "No screenshots found."
1442 return
1443 fi
1444 echo "${screenshot}"
1445 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1446}
1447
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001448function startviewserver()
1449{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001450 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001451 if [ $# -gt 0 ]; then
1452 port=$1
1453 fi
1454 adb shell service call window 1 i32 $port
1455}
1456
1457function stopviewserver()
1458{
1459 adb shell service call window 2
1460}
1461
1462function isviewserverstarted()
1463{
1464 adb shell service call window 3
1465}
1466
Romain Guyb84049a2010-10-04 16:56:11 -07001467function key_home()
1468{
1469 adb shell input keyevent 3
1470}
1471
1472function key_back()
1473{
1474 adb shell input keyevent 4
1475}
1476
1477function key_menu()
1478{
1479 adb shell input keyevent 82
1480}
1481
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001482function smoketest()
1483{
1484 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1485 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1486 return
1487 fi
1488 T=$(gettop)
1489 if [ ! "$T" ]; then
1490 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1491 return
1492 fi
1493
Ying Wang9cd17642012-12-13 10:52:07 -08001494 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001495 adb uninstall com.android.smoketest > /dev/null &&
1496 adb uninstall com.android.smoketest.tests > /dev/null &&
1497 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1498 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1499 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1500}
1501
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001502# simple shortcut to the runtest command
1503function runtest()
1504{
1505 T=$(gettop)
1506 if [ ! "$T" ]; then
1507 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1508 return
1509 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001510 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001511}
1512
The Android Open Source Project88b60792009-03-03 19:28:42 -08001513function godir () {
1514 if [[ -z "$1" ]]; then
1515 echo "Usage: godir <regex>"
1516 return
1517 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001518 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001519 if [[ ! -f $T/filelist ]]; then
1520 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001521 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001522 echo " Done"
1523 echo ""
1524 fi
1525 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001526 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527 if [[ ${#lines[@]} = 0 ]]; then
1528 echo "Not found"
1529 return
1530 fi
1531 local pathname
1532 local choice
1533 if [[ ${#lines[@]} > 1 ]]; then
1534 while [[ -z "$pathname" ]]; do
1535 local index=1
1536 local line
1537 for line in ${lines[@]}; do
1538 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001539 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001540 done
1541 echo
1542 echo -n "Select one: "
1543 unset choice
1544 read choice
1545 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1546 echo "Invalid choice"
1547 continue
1548 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001549 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001550 done
1551 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001552 pathname=${lines[0]}
1553 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001554 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001555}
1556
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001557function cmremote()
1558{
1559 git remote rm cmremote 2> /dev/null
1560 if [ ! -d .git ]
1561 then
1562 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1563 fi
1564 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1565 if [ -z "$GERRIT_REMOTE" ]
1566 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001567 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1568 if [ -z "$GERRIT_REMOTE" ]
1569 then
1570 echo Unable to set up the git remote, are you in the root of the repo?
1571 return 0
1572 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001573 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001574 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001575 if [ -z "$CMUSER" ]
1576 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001577 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001578 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001579 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001580 fi
1581 echo You can now push to "cmremote".
1582}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001583export -f cmremote
1584
Steve Kondik873fa562012-09-17 11:33:18 -07001585function aospremote()
1586{
1587 git remote rm aosp 2> /dev/null
1588 if [ ! -d .git ]
1589 then
1590 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1591 fi
1592 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1593 if (echo $PROJECT | grep -qv "^device")
1594 then
1595 PFX="platform/"
1596 fi
1597 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1598 echo "Remote 'aosp' created"
1599}
1600export -f aospremote
1601
Steve Kondikf00e7d92012-09-23 23:46:55 -07001602function installboot()
1603{
1604 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1605 then
1606 echo "No recovery.fstab found. Build recovery first."
1607 return 1
1608 fi
1609 if [ ! -e "$OUT/boot.img" ];
1610 then
1611 echo "No boot.img found. Run make bootimage first."
1612 return 1
1613 fi
1614 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1615 if [ -z "$PARTITION" ];
1616 then
1617 echo "Unable to determine boot partition."
1618 return 1
1619 fi
1620 adb start-server
1621 adb root
1622 sleep 1
1623 adb wait-for-device
1624 adb remount
1625 adb wait-for-device
1626 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1627 then
1628 adb push $OUT/boot.img /cache/
1629 for i in $OUT/system/lib/modules/*;
1630 do
1631 adb push $i /system/lib/modules/
1632 done
1633 adb shell dd if=/cache/boot.img of=$PARTITION
1634 adb shell chmod 644 /system/lib/modules/*
1635 echo "Installation complete."
1636 else
1637 echo "The connected device does not appear to be $CM_BUILD, run away!"
1638 fi
1639}
1640
Steve Kondik83c03d52012-10-24 16:40:42 -07001641function installrecovery()
1642{
1643 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1644 then
1645 echo "No recovery.fstab found. Build recovery first."
1646 return 1
1647 fi
1648 if [ ! -e "$OUT/recovery.img" ];
1649 then
1650 echo "No recovery.img found. Run make recoveryimage first."
1651 return 1
1652 fi
1653 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1654 if [ -z "$PARTITION" ];
1655 then
1656 echo "Unable to determine recovery partition."
1657 return 1
1658 fi
1659 adb start-server
1660 adb root
1661 sleep 1
1662 adb wait-for-device
1663 adb remount
1664 adb wait-for-device
1665 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1666 then
1667 adb push $OUT/recovery.img /cache/
1668 adb shell dd if=/cache/recovery.img of=$PARTITION
1669 echo "Installation complete."
1670 else
1671 echo "The connected device does not appear to be $CM_BUILD, run away!"
1672 fi
1673}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001674
Koushik Duttab55f13a2012-05-14 16:14:36 -07001675function makerecipe() {
1676 if [ -z "$1" ]
1677 then
1678 echo "No branch name provided."
1679 return 1
1680 fi
1681 cd android
1682 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1683 git commit -a -m "$1"
1684 cd ..
1685
1686 repo forall -c '
1687
1688 if [ "$REPO_REMOTE" == "github" ]
1689 then
1690 pwd
1691 cmremote
1692 git push cmremote HEAD:refs/heads/'$1'
1693 fi
1694 '
1695}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001696
1697function cmgerrit() {
1698 if [ $# -eq 0 ]; then
1699 $FUNCNAME help
1700 return 1
1701 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001702 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001703 local review=`git config --get remote.github.review`
1704 local project=`git config --get remote.github.projectname`
1705 local command=$1
1706 shift
1707 case $command in
1708 help)
1709 if [ $# -eq 0 ]; then
1710 cat <<EOF
1711Usage:
1712 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1713
1714Commands:
1715 fetch Just fetch the change as FETCH_HEAD
1716 help Show this help, or for a specific command
1717 pull Pull a change into current branch
1718 push Push HEAD or a local branch to Gerrit for a specific branch
1719
1720Any other Git commands that support refname would work as:
1721 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1722
1723See '$FUNCNAME help COMMAND' for more information on a specific command.
1724
1725Example:
1726 $FUNCNAME checkout -b topic 1234/5
1727works as:
1728 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1729 && git checkout -b topic FETCH_HEAD
1730will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1731Patch-set 1 will be fetched if omitted.
1732EOF
1733 return
1734 fi
1735 case $1 in
1736 __cmg_*) echo "For internal use only." ;;
1737 changes|for)
1738 if [ "$FUNCNAME" = "cmgerrit" ]; then
1739 echo "'$FUNCNAME $1' is deprecated."
1740 fi
1741 ;;
1742 help) $FUNCNAME help ;;
1743 fetch|pull) cat <<EOF
1744usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1745
1746works as:
1747 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1748 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1749
1750Example:
1751 $FUNCNAME $1 1234
1752will $1 patch-set 1 of change 1234
1753EOF
1754 ;;
1755 push) cat <<EOF
1756usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1757
1758works as:
1759 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1760 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1761
1762Example:
1763 $FUNCNAME push fix6789:gingerbread
1764will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1765HEAD will be pushed from local if omitted.
1766EOF
1767 ;;
1768 *)
1769 $FUNCNAME __cmg_err_not_supported $1 && return
1770 cat <<EOF
1771usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1772
1773works as:
1774 git fetch http://DOMAIN/p/PROJECT \\
1775 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1776 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1777EOF
1778 ;;
1779 esac
1780 ;;
1781 __cmg_get_ref)
1782 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1783 local change_id patchset_id hash
1784 case $1 in
1785 */*)
1786 change_id=${1%%/*}
1787 patchset_id=${1#*/}
1788 ;;
1789 *)
1790 change_id=$1
1791 patchset_id=1
1792 ;;
1793 esac
1794 hash=$(($change_id % 100))
1795 case $hash in
1796 [0-9]) hash="0$hash" ;;
1797 esac
1798 echo "refs/changes/$hash/$change_id/$patchset_id"
1799 ;;
1800 fetch|pull)
1801 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1802 $FUNCNAME __cmg_err_not_repo && return 1
1803 local change=$1
1804 shift
1805 git $command $@ http://$review/p/$project \
1806 $($FUNCNAME __cmg_get_ref $change) || return 1
1807 ;;
1808 push)
1809 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1810 $FUNCNAME __cmg_err_not_repo && return 1
1811 if [ -z "$user" ]; then
1812 echo >&2 "Gerrit username not found."
1813 return 1
1814 fi
1815 local local_branch remote_branch
1816 case $1 in
1817 *:*)
1818 local_branch=${1%:*}
1819 remote_branch=${1##*:}
1820 ;;
1821 *)
1822 local_branch=HEAD
1823 remote_branch=$1
1824 ;;
1825 esac
1826 shift
1827 git push $@ ssh://$user@$review:29418/$project \
1828 $local_branch:refs/for/$remote_branch || return 1
1829 ;;
1830 changes|for)
1831 if [ "$FUNCNAME" = "cmgerrit" ]; then
1832 echo >&2 "'$FUNCNAME $command' is deprecated."
1833 fi
1834 ;;
1835 __cmg_err_no_arg)
1836 if [ $# -lt 2 ]; then
1837 echo >&2 "'$FUNCNAME $command' missing argument."
1838 elif [ $2 -eq 0 ]; then
1839 if [ -n "$3" ]; then
1840 $FUNCNAME help $1
1841 else
1842 echo >&2 "'$FUNCNAME $1' missing argument."
1843 fi
1844 else
1845 return 1
1846 fi
1847 ;;
1848 __cmg_err_not_repo)
1849 if [ -z "$review" -o -z "$project" ]; then
1850 echo >&2 "Not currently in any reviewable repository."
1851 else
1852 return 1
1853 fi
1854 ;;
1855 __cmg_err_not_supported)
1856 $FUNCNAME __cmg_err_no_arg $command $# && return
1857 case $1 in
1858 #TODO: filter more git commands that don't use refname
1859 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1860 echo >&2 "'$FUNCNAME $1' is not supported."
1861 ;;
1862 *) return 1 ;;
1863 esac
1864 ;;
1865 #TODO: other special cases?
1866 *)
1867 $FUNCNAME __cmg_err_not_supported $command && return 1
1868 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1869 $FUNCNAME __cmg_err_not_repo && return 1
1870 local args="$@"
1871 local change pre_args refs_arg post_args
1872 case "$args" in
1873 *--\ *)
1874 pre_args=${args%%-- *}
1875 post_args="-- ${args#*-- }"
1876 ;;
1877 *) pre_args="$args" ;;
1878 esac
1879 args=($pre_args)
1880 pre_args=
1881 if [ ${#args[@]} -gt 0 ]; then
1882 change=${args[${#args[@]}-1]}
1883 fi
1884 if [ ${#args[@]} -gt 1 ]; then
1885 pre_args=${args[0]}
1886 for ((i=1; i<${#args[@]}-1; i++)); do
1887 pre_args="$pre_args ${args[$i]}"
1888 done
1889 fi
1890 while ((1)); do
1891 case $change in
1892 ""|--)
1893 $FUNCNAME help $command
1894 return 1
1895 ;;
1896 *@*)
1897 if [ -z "$refs_arg" ]; then
1898 refs_arg="@${change#*@}"
1899 change=${change%%@*}
1900 fi
1901 ;;
1902 *~*)
1903 if [ -z "$refs_arg" ]; then
1904 refs_arg="~${change#*~}"
1905 change=${change%%~*}
1906 fi
1907 ;;
1908 *^*)
1909 if [ -z "$refs_arg" ]; then
1910 refs_arg="^${change#*^}"
1911 change=${change%%^*}
1912 fi
1913 ;;
1914 *:*)
1915 if [ -z "$refs_arg" ]; then
1916 refs_arg=":${change#*:}"
1917 change=${change%%:*}
1918 fi
1919 ;;
1920 *) break ;;
1921 esac
1922 done
1923 $FUNCNAME fetch $change \
1924 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1925 || return 1
1926 ;;
1927 esac
1928}
1929
1930function cmrebase() {
1931 local repo=$1
1932 local refs=$2
1933 local pwd="$(pwd)"
1934 local dir="$(gettop)/$repo"
1935
1936 if [ -z $repo ] || [ -z $refs ]; then
1937 echo "CyanogenMod Gerrit Rebase Usage: "
1938 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1939 echo " The patch IDs appear on the Gerrit commands that are offered."
1940 echo " They consist on a series of numbers and slashes, after the text"
1941 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1942 echo ""
1943 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1944 echo ""
1945 return
1946 fi
1947
1948 if [ ! -d $dir ]; then
1949 echo "Directory $dir doesn't exist in tree."
1950 return
1951 fi
1952 cd $dir
1953 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1954 echo "Starting branch..."
1955 repo start tmprebase .
1956 echo "Bringing it up to date..."
1957 repo sync .
1958 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001959 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001960 if [ "$?" != "0" ]; then
1961 echo "Error cherry-picking. Not uploading!"
1962 return
1963 fi
1964 echo "Uploading..."
1965 repo upload .
1966 echo "Cleaning up..."
1967 repo abandon tmprebase .
1968 cd $pwd
1969}
1970
1971function mka() {
1972 case `uname -s` in
1973 Darwin)
1974 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1975 ;;
1976 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001977 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001978 ;;
1979 esac
1980}
1981
1982function reposync() {
1983 case `uname -s` in
1984 Darwin)
1985 repo sync -j 4 "$@"
1986 ;;
1987 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001988 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001989 ;;
1990 esac
1991}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001992
1993function repodiff() {
1994 if [ -z "$*" ]; then
1995 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1996 return
1997 fi
1998 diffopts=$* repo forall -c \
1999 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2000}
2001
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302002# Credit for color strip sed: http://goo.gl/BoIcm
2003function dopush()
2004{
2005 local func=$1
2006 shift
2007
2008 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2009 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2010 echo "No device is online. Waiting for one..."
2011 echo "Please connect USB and/or enable USB debugging"
2012 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2013 sleep 1
2014 done
2015 echo "Device Found."
2016 fi
2017
Chirayu Desai6dadb572012-12-26 10:53:58 +05302018 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2019 then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302020 adb root &> /dev/null
2021 sleep 0.3
2022 adb wait-for-device &> /dev/null
2023 sleep 0.3
2024 adb remount &> /dev/null
2025
2026 $func $* | tee $OUT/.log
2027
2028 # Install: <file>
2029 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)
2030
2031 # Copy: <file>
2032 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)
2033
2034 for FILE in $LOC; do
2035 # Get target file name (i.e. system/bin/adb)
2036 TARGET=$(echo $FILE | sed "s#$OUT/##")
2037
2038 # Don't send files that are not in /system.
2039 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2040 continue
2041 else
2042 case $TARGET in
2043 system/app/SystemUI.apk|system/framework/*)
2044 stop_n_start=true
2045 ;;
2046 *)
2047 stop_n_start=false
2048 ;;
2049 esac
2050 if $stop_n_start ; then adb shell stop ; fi
2051 echo "Pushing: $TARGET"
2052 adb push $FILE $TARGET
2053 if $stop_n_start ; then adb shell start ; fi
2054 fi
2055 done
2056 rm -f $OUT/.log
2057 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302058 else
2059 echo "The connected device does not appear to be $CM_BUILD, run away!"
2060 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302061}
2062
2063alias mmp='dopush mm'
2064alias mmmp='dopush mmm'
2065alias mkap='dopush mka'
2066alias cmkap='dopush cmka'
2067
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002068# 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 +00002069#
2070# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2071# For some reason, installing the JDK doesn't make it show up in the
2072# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002073function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002074 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002075 # we can reset it later, depending on the version of java the build
2076 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002077 #
2078 # If we don't do this, the JAVA_HOME value set by the first call to
2079 # build/envsetup.sh will persist forever.
2080 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2081 export JAVA_HOME=""
2082 fi
2083
Andy McFaddenbd960942010-06-24 12:52:51 -07002084 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002085 case `uname -s` in
2086 Darwin)
2087 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2088 ;;
2089 *)
2090 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2091 ;;
2092 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002093
2094 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2095 # we can change it on the next envsetup.sh, if required.
2096 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002097 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002098}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002099
Alex Rayf0d08eb2013-03-08 15:15:06 -08002100# Print colored exit condition
2101function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002102 "$@"
2103 local retval=$?
2104 if [ $retval -ne 0 ]
2105 then
2106 echo -e "\e[0;31mFAILURE\e[00m"
2107 else
2108 echo -e "\e[0;32mSUCCESS\e[00m"
2109 fi
2110 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002111}
2112
Ying Wanged21d4c2014-08-24 22:14:19 -07002113function get_make_command()
2114{
2115 echo command make
2116}
2117
Ed Heylcc6be0a2014-06-18 14:55:58 -07002118function make()
2119{
2120 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002121 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002122 local ret=$?
2123 local end_time=$(date +"%s")
2124 local tdiff=$(($end_time-$start_time))
2125 local hours=$(($tdiff / 3600 ))
2126 local mins=$((($tdiff % 3600) / 60))
2127 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002128 local ncolors=$(tput colors 2>/dev/null)
2129 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2130 color_failed="\e[0;31m"
2131 color_success="\e[0;32m"
2132 color_reset="\e[00m"
2133 else
2134 color_failed=""
2135 color_success=""
2136 color_reset=""
2137 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002138 echo
2139 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002140 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002141 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002142 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002143 fi
2144 if [ $hours -gt 0 ] ; then
2145 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2146 elif [ $mins -gt 0 ] ; then
2147 printf "(%02g:%02g (mm:ss))" $mins $secs
2148 elif [ $secs -gt 0 ] ; then
2149 printf "(%s seconds)" $secs
2150 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002151 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002152 echo
2153 return $ret
2154}
2155
Raphael Moll70a86b02011-06-20 16:03:14 -07002156if [ "x$SHELL" != "x/bin/bash" ]; then
2157 case `ps -o command -p $$` in
2158 *bash*)
2159 ;;
2160 *)
2161 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2162 ;;
2163 esac
2164fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002165
2166# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002167for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2168 `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 -08002169do
2170 echo "including $f"
2171 . $f
2172done
2173unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002174
2175addcompletions