blob: 05035bec3014ce4f2ee8b96954091411f344d26f [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
Chirayu Desai20a61372013-03-16 20:00:17 +0530311 dirs="sdk/bash_completion vendor/cm/bash_completion"
312 for dir in $dirs; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700313 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700314 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700315 echo "including $f"
316 . $f
317 done
318 fi
Chirayu Desai20a61372013-03-16 20:00:17 +0530319 done
Kenny Root52aa81c2011-07-15 11:07:06 -0700320}
321
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322function choosetype()
323{
324 echo "Build type choices are:"
325 echo " 1. release"
326 echo " 2. debug"
327 echo
328
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800329 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700330 DEFAULT_NUM=1
331 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 export TARGET_BUILD_TYPE=
334 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335 while [ -z $TARGET_BUILD_TYPE ]
336 do
337 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800338 if [ -z "$1" ] ; then
339 read ANSWER
340 else
341 echo $1
342 ANSWER=$1
343 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700344 case $ANSWER in
345 "")
346 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
347 ;;
348 1)
349 export TARGET_BUILD_TYPE=release
350 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800351 release)
352 export TARGET_BUILD_TYPE=release
353 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700354 2)
355 export TARGET_BUILD_TYPE=debug
356 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800357 debug)
358 export TARGET_BUILD_TYPE=debug
359 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700360 *)
361 echo
362 echo "I didn't understand your response. Please try again."
363 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 ;;
365 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800366 if [ -n "$1" ] ; then
367 break
368 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700369 done
370
371 set_stuff_for_environment
372}
373
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800374#
375# This function isn't really right: It chooses a TARGET_PRODUCT
376# based on the list of boards. Usually, that gets you something
377# that kinda works with a generic product, but really, you should
378# pick a product by name.
379#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700380function chooseproduct()
381{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700382 if [ "x$TARGET_PRODUCT" != x ] ; then
383 default_value=$TARGET_PRODUCT
384 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700385 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700386 fi
387
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800388 export TARGET_PRODUCT=
389 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700390 while [ -z "$TARGET_PRODUCT" ]
391 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700392 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800393 if [ -z "$1" ] ; then
394 read ANSWER
395 else
396 echo $1
397 ANSWER=$1
398 fi
399
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700400 if [ -z "$ANSWER" ] ; then
401 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800402 else
403 if check_product $ANSWER
404 then
405 export TARGET_PRODUCT=$ANSWER
406 else
407 echo "** Not a valid product: $ANSWER"
408 fi
409 fi
410 if [ -n "$1" ] ; then
411 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700412 fi
413 done
414
415 set_stuff_for_environment
416}
417
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800418function choosevariant()
419{
420 echo "Variant choices are:"
421 local index=1
422 local v
423 for v in ${VARIANT_CHOICES[@]}
424 do
425 # The product name is the name of the directory containing
426 # the makefile we found, above.
427 echo " $index. $v"
428 index=$(($index+1))
429 done
430
431 local default_value=eng
432 local ANSWER
433
434 export TARGET_BUILD_VARIANT=
435 while [ -z "$TARGET_BUILD_VARIANT" ]
436 do
437 echo -n "Which would you like? [$default_value] "
438 if [ -z "$1" ] ; then
439 read ANSWER
440 else
441 echo $1
442 ANSWER=$1
443 fi
444
445 if [ -z "$ANSWER" ] ; then
446 export TARGET_BUILD_VARIANT=$default_value
447 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
448 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800449 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800450 fi
451 else
452 if check_variant $ANSWER
453 then
454 export TARGET_BUILD_VARIANT=$ANSWER
455 else
456 echo "** Not a valid variant: $ANSWER"
457 fi
458 fi
459 if [ -n "$1" ] ; then
460 break
461 fi
462 done
463}
464
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465function choosecombo()
466{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700467 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468
469 echo
470 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700471 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700472
473 echo
474 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700475 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476
477 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480}
481
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482# Clear this variable. It will be built up again when the vendorsetup.sh
483# files are included at the end of this file.
484unset LUNCH_MENU_CHOICES
485function add_lunch_combo()
486{
487 local new_combo=$1
488 local c
489 for c in ${LUNCH_MENU_CHOICES[@]} ; do
490 if [ "$new_combo" = "$c" ] ; then
491 return
492 fi
493 done
494 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
495}
496
497# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700498add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800499add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000500add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800501add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000502add_lunch_combo aosp_x86-eng
503add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505function print_lunch_menu()
506{
507 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 echo
509 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000510 if [ "$(uname)" = "Darwin" ] ; then
511 echo " (ohai, koush!)"
512 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700513 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000514 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
515 echo "Breakfast menu... pick a combo:"
516 else
517 echo "Lunch menu... pick a combo:"
518 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519
520 local i=1
521 local choice
522 for choice in ${LUNCH_MENU_CHOICES[@]}
523 do
524 echo " $i. $choice"
525 i=$(($i+1))
526 done
527
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000528 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
529 echo "... and don't forget the bacon!"
530 fi
531
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700532 echo
533}
534
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000535function brunch()
536{
537 breakfast $*
538 if [ $? -eq 0 ]; then
539 mka bacon
540 else
541 echo "No such item in brunch menu. Try 'breakfast'"
542 return 1
543 fi
544 return $?
545}
546
547function breakfast()
548{
549 target=$1
550 CM_DEVICES_ONLY="true"
551 unset LUNCH_MENU_CHOICES
552 add_lunch_combo full-eng
553 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
554 do
555 echo "including $f"
556 . $f
557 done
558 unset f
559
560 if [ $# -eq 0 ]; then
561 # No arguments, so let's have the full menu
562 lunch
563 else
564 echo "z$target" | grep -q "-"
565 if [ $? -eq 0 ]; then
566 # A buildtype was specified, assume a full device name
567 lunch $target
568 else
569 # This is probably just the CM model name
570 lunch cm_$target-userdebug
571 fi
572 fi
573 return $?
574}
575
576alias bib=breakfast
577
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578function lunch()
579{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 local answer
581
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584 else
585 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700586 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588 fi
589
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 local selection=
591
592 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700593 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700594 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
596 then
597 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
598 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800599 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800600 fi
601 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
602 then
603 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 fi
605
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 if [ -z "$selection" ]
607 then
608 echo
609 echo "Invalid lunch combo: $answer"
610 return 1
611 fi
612
Joe Onoratoda12daf2010-06-09 18:18:31 -0700613 export TARGET_BUILD_APPS=
614
Jeff Browne33ba4c2011-07-11 22:11:46 -0700615 local product=$(echo -n $selection | sed -e "s/-.*$//")
616 check_product $product
617 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800619 # if we can't find a product, try to grab it off the CM github
620 T=$(gettop)
621 pushd $T > /dev/null
622 build/tools/roomservice.py $product
623 popd > /dev/null
624 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000625 else
626 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800627 fi
628 if [ $? -ne 0 ]
629 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700630 echo
631 echo "** Don't have a product spec for: '$product'"
632 echo "** Do you have the right repo manifest?"
633 product=
634 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800635
Jeff Browne33ba4c2011-07-11 22:11:46 -0700636 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
637 check_variant $variant
638 if [ $? -ne 0 ]
639 then
640 echo
641 echo "** Invalid variant: '$variant'"
642 echo "** Must be one of ${VARIANT_CHOICES[@]}"
643 variant=
644 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645
Jeff Browne33ba4c2011-07-11 22:11:46 -0700646 if [ -z "$product" -o -z "$variant" ]
647 then
648 echo
649 return 1
650 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800651
Jeff Browne33ba4c2011-07-11 22:11:46 -0700652 export TARGET_PRODUCT=$product
653 export TARGET_BUILD_VARIANT=$variant
654 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655
656 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800657
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660}
661
Jeff Davidson513d7a42010-08-02 10:00:44 -0700662# Tab completion for lunch.
663function _lunch()
664{
665 local cur prev opts
666 COMPREPLY=()
667 cur="${COMP_WORDS[COMP_CWORD]}"
668 prev="${COMP_WORDS[COMP_CWORD-1]}"
669
670 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
671 return 0
672}
673complete -F _lunch lunch
674
Joe Onoratoda12daf2010-06-09 18:18:31 -0700675# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700676# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677function tapas()
678{
Ying Wangb541ab62014-05-29 17:57:40 -0700679 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 -0700680 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700681 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
682 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 -0700683
Ying Wang67f02922012-08-22 10:25:20 -0700684 if [ $(echo $arch | wc -w) -gt 1 ]; then
685 echo "tapas: Error: Multiple build archs supplied: $arch"
686 return
687 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700688 if [ $(echo $variant | wc -w) -gt 1 ]; then
689 echo "tapas: Error: Multiple build variants supplied: $variant"
690 return
691 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700692 if [ $(echo $density | wc -w) -gt 1 ]; then
693 echo "tapas: Error: Multiple densities supplied: $density"
694 return
695 fi
Ying Wang67f02922012-08-22 10:25:20 -0700696
697 local product=full
698 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700699 x86) product=full_x86;;
700 mips) product=full_mips;;
701 armv5) product=generic_armv5;;
702 arm64) product=aosp_arm64;;
703 x86_64) product=aosp_x86_64;;
704 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700705 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700706 if [ -z "$variant" ]; then
707 variant=eng
708 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700709 if [ -z "$apps" ]; then
710 apps=all
711 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600712 if [ -z "$density" ]; then
713 density=alldpi
714 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700715
Ying Wang67f02922012-08-22 10:25:20 -0700716 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700717 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700718 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700719 export TARGET_BUILD_TYPE=release
720 export TARGET_BUILD_APPS=$apps
721
722 set_stuff_for_environment
723 printconfig
724}
725
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100726function eat()
727{
728 if [ "$OUT" ] ; then
729 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
730 ZIPFILE=cm-$MODVERSION.zip
731 ZIPPATH=$OUT/$ZIPFILE
732 if [ ! -f $ZIPPATH ] ; then
733 echo "Nothing to eat"
734 return 1
735 fi
736 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
737 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
738 echo "No device is online. Waiting for one..."
739 echo "Please connect USB and/or enable USB debugging"
740 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
741 sleep 1
742 done
743 echo "Device Found.."
744 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530745 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
746 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100747 # if adbd isn't root we can't write to /cache/recovery/
748 adb root
749 sleep 1
750 adb wait-for-device
751 SZ=`stat -c %s $ZIPPATH`
752 CACHESIZE=`adb shell busybox df -PB1 /cache | grep /cache | tr -s ' ' | cut -d ' ' -f 4`
753 if [ $CACHESIZE -gt $SZ ];
754 then
755 PUSHDIR=/cache/
756 DIR=cache
757 else
758 PUSHDIR=/storage/sdcard0/
759 # Optional path for sdcard0 in recovery
760 [ -z "$1" ] && DIR=sdcard/0 || DIR=$1
761 fi
762 echo "Pushing $ZIPFILE to $PUSHDIR"
763 if adb push $ZIPPATH $PUSHDIR ; then
764 cat << EOF > /tmp/command
765--update_package=/$DIR/$ZIPFILE
766EOF
767 if adb push /tmp/command /cache/recovery/ ; then
768 echo "Rebooting into recovery for installation"
769 adb reboot recovery
770 fi
771 rm /tmp/command
772 fi
773 else
774 echo "Nothing to eat"
775 return 1
776 fi
777 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530778 else
779 echo "The connected device does not appear to be $CM_BUILD, run away!"
780 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100781}
782
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000783function omnom
784{
785 brunch $*
786 eat
787}
788
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789function gettop
790{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800791 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700793 # The following circumlocution ensures we remove symlinks from TOP.
794 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700795 else
796 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800797 # The following circumlocution (repeated below as well) ensures
798 # that we record the true directory name and not one that is
799 # faked up with symlink names.
800 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800802 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 T=
804 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800805 \cd ..
synergyb112a402013-07-05 19:47:47 -0700806 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700807 done
Ying Wang9cd17642012-12-13 10:52:07 -0800808 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700809 if [ -f "$T/$TOPFILE" ]; then
810 echo $T
811 fi
812 fi
813 fi
814}
815
Andrew Hsieh906cb782013-09-10 17:37:14 +0800816# Return driver for "make", if any (eg. static analyzer)
817function getdriver()
818{
819 local T="$1"
820 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
821 if [ -n "$WITH_STATIC_ANALYZER" ]; then
822 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800823$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
824--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800825--status-bugs \
826--top=$T"
827 fi
828}
829
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700830function m()
831{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800832 local T=$(gettop)
833 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800835 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 else
837 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700838 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 fi
840}
841
842function findmakefile()
843{
844 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800845 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846 T=
847 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700848 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700849 if [ -f "$T/Android.mk" ]; then
850 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800851 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700852 return
853 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800854 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855 done
Ying Wang9cd17642012-12-13 10:52:07 -0800856 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700857}
858
859function mm()
860{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800861 local T=$(gettop)
862 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700863 # If we're sitting in the root of the build tree, just do a
864 # normal make.
865 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800866 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867 else
868 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800869 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700870 local MODULES=
871 local GET_INSTALL_PATH=
872 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700873 # Remove the path to top as the makefilepath needs to be relative
874 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700875 if [ ! "$T" ]; then
876 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700877 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700878 elif [ ! "$M" ]; then
879 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700880 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700881 else
Ying Wanga7deb082013-08-16 13:24:47 -0700882 for ARG in $@; do
883 case $ARG in
884 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
885 esac
886 done
887 if [ -n "$GET_INSTALL_PATH" ]; then
888 MODULES=
889 ARGS=GET-INSTALL-PATH
890 else
891 MODULES=all_modules
892 ARGS=$@
893 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700894 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 -0700895 fi
896 fi
897}
898
899function mmm()
900{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800901 local T=$(gettop)
902 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700903 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800904 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800905 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800906 local ARGS=
907 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700908 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800909 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
910 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
911 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800912 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
913 if [ "$MODULES" = "" ]; then
914 MODULES=all_modules
915 fi
916 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700917 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700918 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
919 local TO_CHOP=`expr $TO_CHOP + 1`
920 local START=`PWD= /bin/pwd`
921 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922 if [ "$MFILE" = "" ] ; then
923 MFILE=$DIR/Android.mk
924 else
925 MFILE=$MFILE/$DIR/Android.mk
926 fi
927 MAKEFILE="$MAKEFILE $MFILE"
928 else
Ying Wanga7deb082013-08-16 13:24:47 -0700929 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100930 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700931 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
932 *) echo "No Android.mk in $DIR."; return 1;;
933 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700934 fi
935 done
Ying Wanga7deb082013-08-16 13:24:47 -0700936 if [ -n "$GET_INSTALL_PATH" ]; then
937 ARGS=$GET_INSTALL_PATH
938 MODULES=
939 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800940 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 -0700941 else
942 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700943 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700944 fi
945}
946
Ying Wangb607f7b2013-02-08 18:01:04 -0800947function mma()
948{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800949 local T=$(gettop)
950 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800951 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800952 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800953 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800954 if [ ! "$T" ]; then
955 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700956 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800957 fi
958 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800959 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800960 fi
961}
962
963function mmma()
964{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800965 local T=$(gettop)
966 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800967 if [ "$T" ]; then
968 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
969 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
970 local MY_PWD=`PWD= /bin/pwd`
971 if [ "$MY_PWD" = "$T" ]; then
972 MY_PWD=
973 else
974 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
975 fi
976 local DIR=
977 local MODULE_PATHS=
978 local ARGS=
979 for DIR in $DIRS ; do
980 if [ -d $DIR ]; then
981 if [ "$MY_PWD" = "" ]; then
982 MODULE_PATHS="$MODULE_PATHS $DIR"
983 else
984 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
985 fi
986 else
987 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100988 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800989 *) echo "Couldn't find directory $DIR"; return 1;;
990 esac
991 fi
992 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800993 $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 -0800994 else
995 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700996 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800997 fi
998}
999
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001000function croot()
1001{
1002 T=$(gettop)
1003 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001004 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001005 else
1006 echo "Couldn't locate the top of the tree. Try setting TOP."
1007 fi
1008}
1009
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001010function cproj()
1011{
1012 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001013 local HERE=$PWD
1014 T=
1015 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1016 T=$PWD
1017 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001018 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001019 return
1020 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001021 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001022 done
Ying Wang9cd17642012-12-13 10:52:07 -08001023 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001024 echo "can't find Android.mk"
1025}
1026
Daniel Sandler47e0a882013-07-30 13:23:52 -04001027# simplified version of ps; output in the form
1028# <pid> <procname>
1029function qpid() {
1030 local prepend=''
1031 local append=''
1032 if [ "$1" = "--exact" ]; then
1033 prepend=' '
1034 append='$'
1035 shift
1036 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1037 echo "usage: qpid [[--exact] <process name|pid>"
1038 return 255
1039 fi
1040
1041 local EXE="$1"
1042 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001043 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001044 else
1045 adb shell ps \
1046 | tr -d '\r' \
1047 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1048 fi
1049}
1050
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001051function pid()
1052{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001053 local prepend=''
1054 local append=''
1055 if [ "$1" = "--exact" ]; then
1056 prepend=' '
1057 append='$'
1058 shift
1059 fi
1060 local EXE="$1"
1061 if [ "$EXE" ] ; then
1062 local PID=`adb shell ps \
1063 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001064 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001065 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1066 echo "$PID"
1067 else
1068 echo "usage: pid [--exact] <process name>"
1069 return 255
1070 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001071}
1072
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001073# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001074# that has the core-file-size limit set correctly
1075#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001076# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077# if its core-file-size limit is not set already.
1078# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1079
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001080function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001081{
1082 echo "Getting root...";
1083 adb root;
1084 adb wait-for-device;
1085
1086 echo "Remounting root parition read-write...";
1087 adb shell mount -w -o remount -t rootfs rootfs;
1088 sleep 1;
1089 adb wait-for-device;
1090 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001091 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001092 adb shell chmod 0777 /cores;
1093
1094 echo "Granting SELinux permission to dump in /cores...";
1095 adb shell restorecon -R /cores;
1096
1097 echo "Set core pattern.";
1098 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1099
1100 echo "Done."
1101}
1102
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001103# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001104# $1 = PID of process (e.g., $(pid mediaserver))
1105#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001106# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001107# dump to actually be generated.
1108
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001109function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001110{
1111 local PID=$1;
1112 if [ -z "$PID" ]; then
1113 printf "Expecting a PID!\n";
1114 return;
1115 fi;
1116 echo "Setting core limit for $PID to infinite...";
1117 adb shell prlimit $PID 4 -1 -1
1118}
1119
1120# core - send SIGV and pull the core for process
1121# $1 = PID of process (e.g., $(pid mediaserver))
1122#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001123# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001124# enabled globally.
1125
1126function core()
1127{
1128 local PID=$1;
1129
1130 if [ -z "$PID" ]; then
1131 printf "Expecting a PID!\n";
1132 return;
1133 fi;
1134
1135 local CORENAME=core.$PID;
1136 local COREPATH=/cores/$CORENAME;
1137 local SIG=SEGV;
1138
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001139 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001140
1141 local done=0;
1142 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1143 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1144 adb shell kill -$SIG $PID;
1145 sleep 1;
1146 done;
1147
1148 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1149 echo "Done: core is under $COREPATH on device.";
1150}
1151
Christopher Tate744ee802009-11-12 15:33:08 -08001152# systemstack - dump the current stack trace of all threads in the system process
1153# to the usual ANR traces file
1154function systemstack()
1155{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001156 stacks system_server
1157}
1158
1159function stacks()
1160{
1161 if [[ $1 =~ ^[0-9]+$ ]] ; then
1162 local PID="$1"
1163 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001164 local PIDLIST="$(pid $1)"
1165 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1166 local PID="$PIDLIST"
1167 elif [ "$PIDLIST" ] ; then
1168 echo "more than one process: $1"
1169 else
1170 echo "no such process: $1"
1171 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001172 else
1173 echo "usage: stacks [pid|process name]"
1174 fi
1175
1176 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001177 # Determine whether the process is native
1178 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1179 # Dump stacks of Dalvik process
1180 local TRACES=/data/anr/traces.txt
1181 local ORIG=/data/anr/traces.orig
1182 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001183
Jeff Brownb12c2e52013-08-19 15:14:16 -07001184 # Keep original traces to avoid clobbering
1185 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001186
Jeff Brownb12c2e52013-08-19 15:14:16 -07001187 # Make sure we have a usable file
1188 adb shell touch $TRACES
1189 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001190
Jeff Brownb12c2e52013-08-19 15:14:16 -07001191 # Dump stacks and wait for dump to finish
1192 adb shell kill -3 $PID
1193 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001194
Jeff Brownb12c2e52013-08-19 15:14:16 -07001195 # Restore original stacks, and show current output
1196 adb shell mv $TRACES $TMP
1197 adb shell mv $ORIG $TRACES
1198 adb shell cat $TMP
1199 else
1200 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001201 local USE64BIT="$(is64bit $PID)"
1202 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001203 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001204 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001205}
1206
Michael Wrightaeed7212014-06-19 19:58:12 -07001207# Read the ELF header from /proc/$PID/exe to determine if the process is
1208# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001209function is64bit()
1210{
1211 local PID="$1"
1212 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001213 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001214 echo "64"
1215 else
1216 echo ""
1217 fi
1218 else
1219 echo ""
1220 fi
1221}
1222
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001223case `uname -s` in
1224 Darwin)
1225 function sgrep()
1226 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001227 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 -07001228 }
1229
1230 ;;
1231 *)
1232 function sgrep()
1233 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001234 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 -07001235 }
1236 ;;
1237esac
1238
Raghu Gandham8da43102012-07-25 19:57:22 -07001239function gettargetarch
1240{
1241 get_build_var TARGET_ARCH
1242}
1243
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001244function ggrep()
1245{
1246 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1247}
1248
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001249function jgrep()
1250{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001251 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 -07001252}
1253
1254function cgrep()
1255{
Dan Albert01961192014-11-22 10:16:01 -08001256 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 -07001257}
1258
1259function resgrep()
1260{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001261 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 -07001262}
1263
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001264function mangrep()
1265{
1266 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1267}
1268
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001269function sepgrep()
1270{
1271 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 "$@"
1272}
1273
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001274function rcgrep()
1275{
1276 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1277}
1278
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001279case `uname -s` in
1280 Darwin)
1281 function mgrep()
1282 {
Ying Wang324c2b22012-08-17 15:03:20 -07001283 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 -07001284 }
1285
1286 function treegrep()
1287 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001288 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 -07001289 }
1290
1291 ;;
1292 *)
1293 function mgrep()
1294 {
Ying Wang324c2b22012-08-17 15:03:20 -07001295 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 -07001296 }
1297
1298 function treegrep()
1299 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001300 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 -07001301 }
1302
1303 ;;
1304esac
1305
1306function getprebuilt
1307{
1308 get_abs_build_var ANDROID_PREBUILTS
1309}
1310
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001311function tracedmdump()
1312{
1313 T=$(gettop)
1314 if [ ! "$T" ]; then
1315 echo "Couldn't locate the top of the tree. Try setting TOP."
1316 return
1317 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001318 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001319 local arch=$(gettargetarch)
1320 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001321
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001322 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001323 if [ ! "$TRACE" ] ; then
1324 echo "usage: tracedmdump tracename"
1325 return
1326 fi
1327
Jack Veenstra60116fc2009-04-09 18:12:34 -07001328 if [ ! -r "$KERNEL" ] ; then
1329 echo "Error: cannot find kernel: '$KERNEL'"
1330 return
1331 fi
1332
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001333 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001334 if [ "$BASETRACE" = "$TRACE" ] ; then
1335 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1336 fi
1337
1338 echo "post-processing traces..."
1339 rm -f $TRACE/qtrace.dexlist
1340 post_trace $TRACE
1341 if [ $? -ne 0 ]; then
1342 echo "***"
1343 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1344 echo "***"
1345 return
1346 fi
1347 echo "generating dexlist output..."
1348 /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
1349 echo "generating dmtrace data..."
1350 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1351 echo "generating html file..."
1352 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1353 echo "done, see $TRACE/dmtrace.html for details"
1354 echo "or run:"
1355 echo " traceview $TRACE/dmtrace"
1356}
1357
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001358# communicate with a running device or emulator, set up necessary state,
1359# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001360function runhat()
1361{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001362 # process standard adb options
1363 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001364 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001365 adbTarget=$1
1366 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001367 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001368 adbTarget="$1 $2"
1369 shift 2
1370 fi
1371 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001372 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001373
1374 # runhat options
1375 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001376
1377 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001378 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001379 return
1380 fi
1381
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001382 # confirm hat is available
1383 if [ -z $(which hat) ]; then
1384 echo "hat is not available in this configuration."
1385 return
1386 fi
1387
Andy McFaddenb6289852010-07-12 08:00:19 -07001388 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001389 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001390 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001391 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001392 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001393 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001394 echo -n "> "
1395 read
1396
The Android Open Source Project88b60792009-03-03 19:28:42 -08001397 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001398
The Android Open Source Project88b60792009-03-03 19:28:42 -08001399 echo "Retrieving file $devFile..."
1400 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401
The Android Open Source Project88b60792009-03-03 19:28:42 -08001402 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001403
The Android Open Source Project88b60792009-03-03 19:28:42 -08001404 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001405 echo "View the output by pointing your browser at http://localhost:7000/"
1406 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001407 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001408}
1409
1410function getbugreports()
1411{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001412 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001413
1414 if [ ! "$reports" ]; then
1415 echo "Could not locate any bugreports."
1416 return
1417 fi
1418
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001419 local report
1420 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001421 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001422 echo "/sdcard/bugreports/${report}"
1423 adb pull /sdcard/bugreports/${report} ${report}
1424 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001425 done
1426}
1427
Victoria Lease1b296b42012-08-21 15:44:06 -07001428function getsdcardpath()
1429{
1430 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1431}
1432
1433function getscreenshotpath()
1434{
1435 echo "$(getsdcardpath)/Pictures/Screenshots"
1436}
1437
1438function getlastscreenshot()
1439{
1440 local screenshot_path=$(getscreenshotpath)
1441 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1442 if [ "$screenshot" = "" ]; then
1443 echo "No screenshots found."
1444 return
1445 fi
1446 echo "${screenshot}"
1447 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1448}
1449
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001450function startviewserver()
1451{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001452 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001453 if [ $# -gt 0 ]; then
1454 port=$1
1455 fi
1456 adb shell service call window 1 i32 $port
1457}
1458
1459function stopviewserver()
1460{
1461 adb shell service call window 2
1462}
1463
1464function isviewserverstarted()
1465{
1466 adb shell service call window 3
1467}
1468
Romain Guyb84049a2010-10-04 16:56:11 -07001469function key_home()
1470{
1471 adb shell input keyevent 3
1472}
1473
1474function key_back()
1475{
1476 adb shell input keyevent 4
1477}
1478
1479function key_menu()
1480{
1481 adb shell input keyevent 82
1482}
1483
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001484function smoketest()
1485{
1486 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1487 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1488 return
1489 fi
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
1495
Ying Wang9cd17642012-12-13 10:52:07 -08001496 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001497 adb uninstall com.android.smoketest > /dev/null &&
1498 adb uninstall com.android.smoketest.tests > /dev/null &&
1499 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1500 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1501 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1502}
1503
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001504# simple shortcut to the runtest command
1505function runtest()
1506{
1507 T=$(gettop)
1508 if [ ! "$T" ]; then
1509 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1510 return
1511 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001512 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001513}
1514
The Android Open Source Project88b60792009-03-03 19:28:42 -08001515function godir () {
1516 if [[ -z "$1" ]]; then
1517 echo "Usage: godir <regex>"
1518 return
1519 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001520 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001521 if [[ ! -f $T/filelist ]]; then
1522 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001523 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001524 echo " Done"
1525 echo ""
1526 fi
1527 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001528 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001529 if [[ ${#lines[@]} = 0 ]]; then
1530 echo "Not found"
1531 return
1532 fi
1533 local pathname
1534 local choice
1535 if [[ ${#lines[@]} > 1 ]]; then
1536 while [[ -z "$pathname" ]]; do
1537 local index=1
1538 local line
1539 for line in ${lines[@]}; do
1540 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001541 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001542 done
1543 echo
1544 echo -n "Select one: "
1545 unset choice
1546 read choice
1547 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1548 echo "Invalid choice"
1549 continue
1550 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001551 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001552 done
1553 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001554 pathname=${lines[0]}
1555 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001556 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001557}
1558
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001559function cmremote()
1560{
1561 git remote rm cmremote 2> /dev/null
1562 if [ ! -d .git ]
1563 then
1564 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1565 fi
1566 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1567 if [ -z "$GERRIT_REMOTE" ]
1568 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001569 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1570 if [ -z "$GERRIT_REMOTE" ]
1571 then
1572 echo Unable to set up the git remote, are you in the root of the repo?
1573 return 0
1574 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001575 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001576 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001577 if [ -z "$CMUSER" ]
1578 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001579 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001580 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001581 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001582 fi
1583 echo You can now push to "cmremote".
1584}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001585export -f cmremote
1586
Steve Kondik873fa562012-09-17 11:33:18 -07001587function aospremote()
1588{
1589 git remote rm aosp 2> /dev/null
1590 if [ ! -d .git ]
1591 then
1592 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1593 fi
1594 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1595 if (echo $PROJECT | grep -qv "^device")
1596 then
1597 PFX="platform/"
1598 fi
1599 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1600 echo "Remote 'aosp' created"
1601}
1602export -f aospremote
1603
Steve Kondikf00e7d92012-09-23 23:46:55 -07001604function installboot()
1605{
1606 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1607 then
1608 echo "No recovery.fstab found. Build recovery first."
1609 return 1
1610 fi
1611 if [ ! -e "$OUT/boot.img" ];
1612 then
1613 echo "No boot.img found. Run make bootimage first."
1614 return 1
1615 fi
1616 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1617 if [ -z "$PARTITION" ];
1618 then
1619 echo "Unable to determine boot partition."
1620 return 1
1621 fi
1622 adb start-server
1623 adb root
1624 sleep 1
1625 adb wait-for-device
1626 adb remount
1627 adb wait-for-device
1628 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1629 then
1630 adb push $OUT/boot.img /cache/
1631 for i in $OUT/system/lib/modules/*;
1632 do
1633 adb push $i /system/lib/modules/
1634 done
1635 adb shell dd if=/cache/boot.img of=$PARTITION
1636 adb shell chmod 644 /system/lib/modules/*
1637 echo "Installation complete."
1638 else
1639 echo "The connected device does not appear to be $CM_BUILD, run away!"
1640 fi
1641}
1642
Steve Kondik83c03d52012-10-24 16:40:42 -07001643function installrecovery()
1644{
1645 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1646 then
1647 echo "No recovery.fstab found. Build recovery first."
1648 return 1
1649 fi
1650 if [ ! -e "$OUT/recovery.img" ];
1651 then
1652 echo "No recovery.img found. Run make recoveryimage first."
1653 return 1
1654 fi
1655 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1656 if [ -z "$PARTITION" ];
1657 then
1658 echo "Unable to determine recovery partition."
1659 return 1
1660 fi
1661 adb start-server
1662 adb root
1663 sleep 1
1664 adb wait-for-device
1665 adb remount
1666 adb wait-for-device
1667 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1668 then
1669 adb push $OUT/recovery.img /cache/
1670 adb shell dd if=/cache/recovery.img of=$PARTITION
1671 echo "Installation complete."
1672 else
1673 echo "The connected device does not appear to be $CM_BUILD, run away!"
1674 fi
1675}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001676
Koushik Duttab55f13a2012-05-14 16:14:36 -07001677function makerecipe() {
1678 if [ -z "$1" ]
1679 then
1680 echo "No branch name provided."
1681 return 1
1682 fi
1683 cd android
1684 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1685 git commit -a -m "$1"
1686 cd ..
1687
1688 repo forall -c '
1689
1690 if [ "$REPO_REMOTE" == "github" ]
1691 then
1692 pwd
1693 cmremote
1694 git push cmremote HEAD:refs/heads/'$1'
1695 fi
1696 '
1697}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001698
1699function cmgerrit() {
1700 if [ $# -eq 0 ]; then
1701 $FUNCNAME help
1702 return 1
1703 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001704 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001705 local review=`git config --get remote.github.review`
1706 local project=`git config --get remote.github.projectname`
1707 local command=$1
1708 shift
1709 case $command in
1710 help)
1711 if [ $# -eq 0 ]; then
1712 cat <<EOF
1713Usage:
1714 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1715
1716Commands:
1717 fetch Just fetch the change as FETCH_HEAD
1718 help Show this help, or for a specific command
1719 pull Pull a change into current branch
1720 push Push HEAD or a local branch to Gerrit for a specific branch
1721
1722Any other Git commands that support refname would work as:
1723 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1724
1725See '$FUNCNAME help COMMAND' for more information on a specific command.
1726
1727Example:
1728 $FUNCNAME checkout -b topic 1234/5
1729works as:
1730 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1731 && git checkout -b topic FETCH_HEAD
1732will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1733Patch-set 1 will be fetched if omitted.
1734EOF
1735 return
1736 fi
1737 case $1 in
1738 __cmg_*) echo "For internal use only." ;;
1739 changes|for)
1740 if [ "$FUNCNAME" = "cmgerrit" ]; then
1741 echo "'$FUNCNAME $1' is deprecated."
1742 fi
1743 ;;
1744 help) $FUNCNAME help ;;
1745 fetch|pull) cat <<EOF
1746usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1747
1748works as:
1749 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1750 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1751
1752Example:
1753 $FUNCNAME $1 1234
1754will $1 patch-set 1 of change 1234
1755EOF
1756 ;;
1757 push) cat <<EOF
1758usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1759
1760works as:
1761 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1762 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1763
1764Example:
1765 $FUNCNAME push fix6789:gingerbread
1766will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1767HEAD will be pushed from local if omitted.
1768EOF
1769 ;;
1770 *)
1771 $FUNCNAME __cmg_err_not_supported $1 && return
1772 cat <<EOF
1773usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1774
1775works as:
1776 git fetch http://DOMAIN/p/PROJECT \\
1777 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1778 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1779EOF
1780 ;;
1781 esac
1782 ;;
1783 __cmg_get_ref)
1784 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1785 local change_id patchset_id hash
1786 case $1 in
1787 */*)
1788 change_id=${1%%/*}
1789 patchset_id=${1#*/}
1790 ;;
1791 *)
1792 change_id=$1
1793 patchset_id=1
1794 ;;
1795 esac
1796 hash=$(($change_id % 100))
1797 case $hash in
1798 [0-9]) hash="0$hash" ;;
1799 esac
1800 echo "refs/changes/$hash/$change_id/$patchset_id"
1801 ;;
1802 fetch|pull)
1803 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1804 $FUNCNAME __cmg_err_not_repo && return 1
1805 local change=$1
1806 shift
1807 git $command $@ http://$review/p/$project \
1808 $($FUNCNAME __cmg_get_ref $change) || return 1
1809 ;;
1810 push)
1811 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1812 $FUNCNAME __cmg_err_not_repo && return 1
1813 if [ -z "$user" ]; then
1814 echo >&2 "Gerrit username not found."
1815 return 1
1816 fi
1817 local local_branch remote_branch
1818 case $1 in
1819 *:*)
1820 local_branch=${1%:*}
1821 remote_branch=${1##*:}
1822 ;;
1823 *)
1824 local_branch=HEAD
1825 remote_branch=$1
1826 ;;
1827 esac
1828 shift
1829 git push $@ ssh://$user@$review:29418/$project \
1830 $local_branch:refs/for/$remote_branch || return 1
1831 ;;
1832 changes|for)
1833 if [ "$FUNCNAME" = "cmgerrit" ]; then
1834 echo >&2 "'$FUNCNAME $command' is deprecated."
1835 fi
1836 ;;
1837 __cmg_err_no_arg)
1838 if [ $# -lt 2 ]; then
1839 echo >&2 "'$FUNCNAME $command' missing argument."
1840 elif [ $2 -eq 0 ]; then
1841 if [ -n "$3" ]; then
1842 $FUNCNAME help $1
1843 else
1844 echo >&2 "'$FUNCNAME $1' missing argument."
1845 fi
1846 else
1847 return 1
1848 fi
1849 ;;
1850 __cmg_err_not_repo)
1851 if [ -z "$review" -o -z "$project" ]; then
1852 echo >&2 "Not currently in any reviewable repository."
1853 else
1854 return 1
1855 fi
1856 ;;
1857 __cmg_err_not_supported)
1858 $FUNCNAME __cmg_err_no_arg $command $# && return
1859 case $1 in
1860 #TODO: filter more git commands that don't use refname
1861 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1862 echo >&2 "'$FUNCNAME $1' is not supported."
1863 ;;
1864 *) return 1 ;;
1865 esac
1866 ;;
1867 #TODO: other special cases?
1868 *)
1869 $FUNCNAME __cmg_err_not_supported $command && return 1
1870 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1871 $FUNCNAME __cmg_err_not_repo && return 1
1872 local args="$@"
1873 local change pre_args refs_arg post_args
1874 case "$args" in
1875 *--\ *)
1876 pre_args=${args%%-- *}
1877 post_args="-- ${args#*-- }"
1878 ;;
1879 *) pre_args="$args" ;;
1880 esac
1881 args=($pre_args)
1882 pre_args=
1883 if [ ${#args[@]} -gt 0 ]; then
1884 change=${args[${#args[@]}-1]}
1885 fi
1886 if [ ${#args[@]} -gt 1 ]; then
1887 pre_args=${args[0]}
1888 for ((i=1; i<${#args[@]}-1; i++)); do
1889 pre_args="$pre_args ${args[$i]}"
1890 done
1891 fi
1892 while ((1)); do
1893 case $change in
1894 ""|--)
1895 $FUNCNAME help $command
1896 return 1
1897 ;;
1898 *@*)
1899 if [ -z "$refs_arg" ]; then
1900 refs_arg="@${change#*@}"
1901 change=${change%%@*}
1902 fi
1903 ;;
1904 *~*)
1905 if [ -z "$refs_arg" ]; then
1906 refs_arg="~${change#*~}"
1907 change=${change%%~*}
1908 fi
1909 ;;
1910 *^*)
1911 if [ -z "$refs_arg" ]; then
1912 refs_arg="^${change#*^}"
1913 change=${change%%^*}
1914 fi
1915 ;;
1916 *:*)
1917 if [ -z "$refs_arg" ]; then
1918 refs_arg=":${change#*:}"
1919 change=${change%%:*}
1920 fi
1921 ;;
1922 *) break ;;
1923 esac
1924 done
1925 $FUNCNAME fetch $change \
1926 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1927 || return 1
1928 ;;
1929 esac
1930}
1931
1932function cmrebase() {
1933 local repo=$1
1934 local refs=$2
1935 local pwd="$(pwd)"
1936 local dir="$(gettop)/$repo"
1937
1938 if [ -z $repo ] || [ -z $refs ]; then
1939 echo "CyanogenMod Gerrit Rebase Usage: "
1940 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1941 echo " The patch IDs appear on the Gerrit commands that are offered."
1942 echo " They consist on a series of numbers and slashes, after the text"
1943 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1944 echo ""
1945 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1946 echo ""
1947 return
1948 fi
1949
1950 if [ ! -d $dir ]; then
1951 echo "Directory $dir doesn't exist in tree."
1952 return
1953 fi
1954 cd $dir
1955 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1956 echo "Starting branch..."
1957 repo start tmprebase .
1958 echo "Bringing it up to date..."
1959 repo sync .
1960 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001961 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001962 if [ "$?" != "0" ]; then
1963 echo "Error cherry-picking. Not uploading!"
1964 return
1965 fi
1966 echo "Uploading..."
1967 repo upload .
1968 echo "Cleaning up..."
1969 repo abandon tmprebase .
1970 cd $pwd
1971}
1972
1973function mka() {
1974 case `uname -s` in
1975 Darwin)
1976 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1977 ;;
1978 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001979 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001980 ;;
1981 esac
1982}
1983
1984function reposync() {
1985 case `uname -s` in
1986 Darwin)
1987 repo sync -j 4 "$@"
1988 ;;
1989 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001990 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001991 ;;
1992 esac
1993}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001994
1995function repodiff() {
1996 if [ -z "$*" ]; then
1997 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1998 return
1999 fi
2000 diffopts=$* repo forall -c \
2001 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2002}
2003
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302004# Credit for color strip sed: http://goo.gl/BoIcm
2005function dopush()
2006{
2007 local func=$1
2008 shift
2009
2010 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2011 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2012 echo "No device is online. Waiting for one..."
2013 echo "Please connect USB and/or enable USB debugging"
2014 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2015 sleep 1
2016 done
2017 echo "Device Found."
2018 fi
2019
Chirayu Desai6dadb572012-12-26 10:53:58 +05302020 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2021 then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302022 adb root &> /dev/null
2023 sleep 0.3
2024 adb wait-for-device &> /dev/null
2025 sleep 0.3
2026 adb remount &> /dev/null
2027
2028 $func $* | tee $OUT/.log
2029
2030 # Install: <file>
2031 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)
2032
2033 # Copy: <file>
2034 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)
2035
2036 for FILE in $LOC; do
2037 # Get target file name (i.e. system/bin/adb)
2038 TARGET=$(echo $FILE | sed "s#$OUT/##")
2039
2040 # Don't send files that are not in /system.
2041 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2042 continue
2043 else
2044 case $TARGET in
2045 system/app/SystemUI.apk|system/framework/*)
2046 stop_n_start=true
2047 ;;
2048 *)
2049 stop_n_start=false
2050 ;;
2051 esac
2052 if $stop_n_start ; then adb shell stop ; fi
2053 echo "Pushing: $TARGET"
2054 adb push $FILE $TARGET
2055 if $stop_n_start ; then adb shell start ; fi
2056 fi
2057 done
2058 rm -f $OUT/.log
2059 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302060 else
2061 echo "The connected device does not appear to be $CM_BUILD, run away!"
2062 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302063}
2064
2065alias mmp='dopush mm'
2066alias mmmp='dopush mmm'
2067alias mkap='dopush mka'
2068alias cmkap='dopush cmka'
2069
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002070# 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 +00002071#
2072# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2073# For some reason, installing the JDK doesn't make it show up in the
2074# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002075function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002076 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002077 # we can reset it later, depending on the version of java the build
2078 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002079 #
2080 # If we don't do this, the JAVA_HOME value set by the first call to
2081 # build/envsetup.sh will persist forever.
2082 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2083 export JAVA_HOME=""
2084 fi
2085
Andy McFaddenbd960942010-06-24 12:52:51 -07002086 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002087 case `uname -s` in
2088 Darwin)
2089 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2090 ;;
2091 *)
2092 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2093 ;;
2094 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002095
2096 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2097 # we can change it on the next envsetup.sh, if required.
2098 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002099 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002100}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002101
Alex Rayf0d08eb2013-03-08 15:15:06 -08002102# Print colored exit condition
2103function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002104 "$@"
2105 local retval=$?
2106 if [ $retval -ne 0 ]
2107 then
2108 echo -e "\e[0;31mFAILURE\e[00m"
2109 else
2110 echo -e "\e[0;32mSUCCESS\e[00m"
2111 fi
2112 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002113}
2114
Ying Wanged21d4c2014-08-24 22:14:19 -07002115function get_make_command()
2116{
2117 echo command make
2118}
2119
Ed Heylcc6be0a2014-06-18 14:55:58 -07002120function make()
2121{
2122 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002123 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002124 local ret=$?
2125 local end_time=$(date +"%s")
2126 local tdiff=$(($end_time-$start_time))
2127 local hours=$(($tdiff / 3600 ))
2128 local mins=$((($tdiff % 3600) / 60))
2129 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002130 local ncolors=$(tput colors 2>/dev/null)
2131 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2132 color_failed="\e[0;31m"
2133 color_success="\e[0;32m"
2134 color_reset="\e[00m"
2135 else
2136 color_failed=""
2137 color_success=""
2138 color_reset=""
2139 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002140 echo
2141 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002142 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002143 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002144 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002145 fi
2146 if [ $hours -gt 0 ] ; then
2147 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2148 elif [ $mins -gt 0 ] ; then
2149 printf "(%02g:%02g (mm:ss))" $mins $secs
2150 elif [ $secs -gt 0 ] ; then
2151 printf "(%s seconds)" $secs
2152 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002153 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002154 echo
2155 return $ret
2156}
2157
Raphael Moll70a86b02011-06-20 16:03:14 -07002158if [ "x$SHELL" != "x/bin/bash" ]; then
2159 case `ps -o command -p $$` in
2160 *bash*)
2161 ;;
2162 *)
2163 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2164 ;;
2165 esac
2166fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002167
2168# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002169for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2170 `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 -08002171do
2172 echo "including $f"
2173 . $f
2174done
2175unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002176
2177addcompletions