blob: e0b2c62a35e30da71729b383c96721cf1b7f485b [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.
nebkatfb67a1e2012-12-28 10:40:45 +00007- cout: Changes directory to out.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07008- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08009- mm: Builds all of the modules in the current directory, but not their dependencies.
10- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000011 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080012- mma: Builds all of the modules in the current directory, and their dependencies.
Daniel Bateman22185ba2012-08-04 03:48:09 -050013- mmp: Builds all of the modules in the current directory and pushes them to the device.
14- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080015- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070016- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070017- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070018- jgrep: Greps on all local Java files.
19- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000020- mangrep: Greps on all local AndroidManifest.xml files.
21- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070022- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080023- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060024- cmremote: Add git remote for CM Gerrit Review
25- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
26- cmrebase: Rebase a Gerrit change and push it again
Steve Kondik873fa562012-09-17 11:33:18 -070027- aospremote: Add git remote for matching AOSP repository
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060028- mka: Builds using SCHED_BATCH on all processors
29- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053030- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070031- installboot: Installs a boot.img to the connected device.
32- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070033
Dan Albert4ae5d4b2014-10-31 16:23:08 -070034Environemnt options:
35- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
36 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
37 build is leak-check clean.
38
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070039Look at the source to view more functions. The complete list is:
40EOF
41 T=$(gettop)
42 local A
43 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070044 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 -070045 A="$A $i"
46 done
47 echo $A
48}
49
50# Get the value of a build variable as an absolute path.
51function get_abs_build_var()
52{
53 T=$(gettop)
54 if [ ! "$T" ]; then
55 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
56 return
57 fi
Ying Wang9cd17642012-12-13 10:52:07 -080058 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070059 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070060}
61
62# Get the exact value of a build variable.
63function get_build_var()
64{
65 T=$(gettop)
66 if [ ! "$T" ]; then
67 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
68 return
69 fi
Andrew Boie6905e212013-12-19 13:21:46 -080070 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070071 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080072}
73
74# check to see if the supplied product is one we can build
75function check_product()
76{
77 T=$(gettop)
78 if [ ! "$T" ]; then
79 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
80 return
81 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000082
83 if (echo -n $1 | grep -q -e "^cm_") ; then
84 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
Ricardo Cerqueira34ae3232013-09-26 00:10:20 +010085 export BUILD_NUMBER=$((date +%s%N ; echo $CM_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10)
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000086 else
87 CM_BUILD=
88 fi
89 export CM_BUILD
90
Jeff Browne33ba4c2011-07-11 22:11:46 -070091 TARGET_PRODUCT=$1 \
92 TARGET_BUILD_VARIANT= \
93 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070094 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080095 get_build_var TARGET_DEVICE > /dev/null
96 # hide successful answers, but allow the errors to show
97}
98
99VARIANT_CHOICES=(user userdebug eng)
100
101# check to see if the supplied variant is valid
102function check_variant()
103{
104 for v in ${VARIANT_CHOICES[@]}
105 do
106 if [ "$v" = "$1" ]
107 then
108 return 0
109 fi
110 done
111 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700112}
113
114function setpaths()
115{
116 T=$(gettop)
117 if [ ! "$T" ]; then
118 echo "Couldn't locate the top of the tree. Try setting TOP."
119 return
120 fi
121
122 ##################################################################
123 # #
124 # Read me before you modify this code #
125 # #
126 # This function sets ANDROID_BUILD_PATHS to what it is adding #
127 # to PATH, and the next time it is run, it removes that from #
128 # PATH. This is required so lunch can be run more than once #
129 # and still have working paths. #
130 # #
131 ##################################################################
132
Raphael Mollc639c782011-06-20 17:25:01 -0700133 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
134 # due to "C:\Program Files" being in the path.
135
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700136 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700137 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700138 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
139 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700140 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700141 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800142 # strip leading ':', if any
143 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500144 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700145
146 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700147 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700148 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700149
Ben Cheng8bc4c432012-11-16 13:29:13 -0800150 # defined in core/config.mk
151 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700152 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800153 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800154
Raphael Mollc639c782011-06-20 17:25:01 -0700155 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800156 export ANDROID_TOOLCHAIN=
157 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200158 local ARCH=$(get_build_var TARGET_ARCH)
159 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400160 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700161 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400162 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
163 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800164 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200165 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800166 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700167 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700168 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700169 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000170 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200171 *)
172 echo "Can't find toolchain for unknown architecture: $ARCH"
173 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700174 ;;
175 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700176 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800177 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700178 fi
Raphael732936d2011-06-22 14:35:32 -0700179
Ben Chengfba67bf2014-02-25 10:27:07 -0800180 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
181 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
182 fi
183
184 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700185 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700186 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800187 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800188 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700189 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100190 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
191 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700192 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700193 ;;
194 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700195 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700196 ;;
197 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700198
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700199 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700200 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 +0200201
202 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
203 # to ensure that the corresponding 'emulator' binaries are used.
204 case $(uname -s) in
205 Darwin)
206 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
207 ;;
208 Linux)
209 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
210 ;;
211 *)
212 ANDROID_EMULATOR_PREBUILTS=
213 ;;
214 esac
215 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700216 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200217 export ANDROID_EMULATOR_PREBUILTS
218 fi
219
Ying Wangaa1c9b52012-11-26 20:51:59 -0800220 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800221
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500222 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900223 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500224 if [ -n "$JAVA_HOME" ]; then
225 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900226 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
227 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500228 fi
229
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800230 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700231 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
232 export OUT=$ANDROID_PRODUCT_OUT
233
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700234 unset ANDROID_HOST_OUT
235 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
236
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800237 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700238 # TODO: fix the path
239 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
240}
241
242function printconfig()
243{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800244 T=$(gettop)
245 if [ ! "$T" ]; then
246 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
247 return
248 fi
249 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250}
251
252function set_stuff_for_environment()
253{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800254 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500255 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256 setpaths
257 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700258
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800259 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700260 # With this environment variable new GCC can apply colors to warnings/errors
261 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 -0700262 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263}
264
265function set_sequence_number()
266{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700267 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268}
269
270function settitle()
271{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800272 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700273 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700274 local product=$TARGET_PRODUCT
275 local variant=$TARGET_BUILD_VARIANT
276 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800277 if [ -z "$PROMPT_COMMAND" ]; then
278 # No prompts
279 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
280 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
281 # Prompts exist, but no hardstatus
282 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700283 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800284 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500285 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800286 fi
287
288 if [ -z "$apps" ]; then
289 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
290 else
291 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
292 fi
293 export ANDROID_PROMPT_PREFIX
294
295 # Inject build data into hardstatus
296 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 -0800297 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298}
299
Kenny Root52aa81c2011-07-15 11:07:06 -0700300function addcompletions()
301{
302 local T dir f
303
304 # Keep us from trying to run in something that isn't bash.
305 if [ -z "${BASH_VERSION}" ]; then
306 return
307 fi
308
309 # Keep us from trying to run in bash that's too old.
310 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
311 return
312 fi
313
Chirayu Desai20a61372013-03-16 20:00:17 +0530314 dirs="sdk/bash_completion vendor/cm/bash_completion"
315 for dir in $dirs; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700316 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700317 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700318 echo "including $f"
319 . $f
320 done
321 fi
Chirayu Desai20a61372013-03-16 20:00:17 +0530322 done
Kenny Root52aa81c2011-07-15 11:07:06 -0700323}
324
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325function choosetype()
326{
327 echo "Build type choices are:"
328 echo " 1. release"
329 echo " 2. debug"
330 echo
331
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700333 DEFAULT_NUM=1
334 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 export TARGET_BUILD_TYPE=
337 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 while [ -z $TARGET_BUILD_TYPE ]
339 do
340 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 if [ -z "$1" ] ; then
342 read ANSWER
343 else
344 echo $1
345 ANSWER=$1
346 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 case $ANSWER in
348 "")
349 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
350 ;;
351 1)
352 export TARGET_BUILD_TYPE=release
353 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800354 release)
355 export TARGET_BUILD_TYPE=release
356 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357 2)
358 export TARGET_BUILD_TYPE=debug
359 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800360 debug)
361 export TARGET_BUILD_TYPE=debug
362 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700363 *)
364 echo
365 echo "I didn't understand your response. Please try again."
366 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367 ;;
368 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800369 if [ -n "$1" ] ; then
370 break
371 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700372 done
373
374 set_stuff_for_environment
375}
376
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800377#
378# This function isn't really right: It chooses a TARGET_PRODUCT
379# based on the list of boards. Usually, that gets you something
380# that kinda works with a generic product, but really, you should
381# pick a product by name.
382#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383function chooseproduct()
384{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700385 if [ "x$TARGET_PRODUCT" != x ] ; then
386 default_value=$TARGET_PRODUCT
387 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700388 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700389 fi
390
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800391 export TARGET_PRODUCT=
392 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700393 while [ -z "$TARGET_PRODUCT" ]
394 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700395 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800396 if [ -z "$1" ] ; then
397 read ANSWER
398 else
399 echo $1
400 ANSWER=$1
401 fi
402
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700403 if [ -z "$ANSWER" ] ; then
404 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800405 else
406 if check_product $ANSWER
407 then
408 export TARGET_PRODUCT=$ANSWER
409 else
410 echo "** Not a valid product: $ANSWER"
411 fi
412 fi
413 if [ -n "$1" ] ; then
414 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700415 fi
416 done
417
418 set_stuff_for_environment
419}
420
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421function choosevariant()
422{
423 echo "Variant choices are:"
424 local index=1
425 local v
426 for v in ${VARIANT_CHOICES[@]}
427 do
428 # The product name is the name of the directory containing
429 # the makefile we found, above.
430 echo " $index. $v"
431 index=$(($index+1))
432 done
433
434 local default_value=eng
435 local ANSWER
436
437 export TARGET_BUILD_VARIANT=
438 while [ -z "$TARGET_BUILD_VARIANT" ]
439 do
440 echo -n "Which would you like? [$default_value] "
441 if [ -z "$1" ] ; then
442 read ANSWER
443 else
444 echo $1
445 ANSWER=$1
446 fi
447
448 if [ -z "$ANSWER" ] ; then
449 export TARGET_BUILD_VARIANT=$default_value
450 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
451 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800452 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453 fi
454 else
455 if check_variant $ANSWER
456 then
457 export TARGET_BUILD_VARIANT=$ANSWER
458 else
459 echo "** Not a valid variant: $ANSWER"
460 fi
461 fi
462 if [ -n "$1" ] ; then
463 break
464 fi
465 done
466}
467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468function choosecombo()
469{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700470 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471
472 echo
473 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700474 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475
476 echo
477 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700478 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479
480 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700481 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483}
484
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485# Clear this variable. It will be built up again when the vendorsetup.sh
486# files are included at the end of this file.
487unset LUNCH_MENU_CHOICES
488function add_lunch_combo()
489{
490 local new_combo=$1
491 local c
492 for c in ${LUNCH_MENU_CHOICES[@]} ; do
493 if [ "$new_combo" = "$c" ] ; then
494 return
495 fi
496 done
497 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
498}
499
500# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700501add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800502add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000503add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800504add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000505add_lunch_combo aosp_x86-eng
506add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508function print_lunch_menu()
509{
510 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700511 echo
512 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000513 if [ "$(uname)" = "Darwin" ] ; then
514 echo " (ohai, koush!)"
515 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000517 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
518 echo "Breakfast menu... pick a combo:"
519 else
520 echo "Lunch menu... pick a combo:"
521 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522
523 local i=1
524 local choice
525 for choice in ${LUNCH_MENU_CHOICES[@]}
526 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100527 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800528 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100529 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000531 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
532 echo "... and don't forget the bacon!"
533 fi
534
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535 echo
536}
537
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000538function brunch()
539{
540 breakfast $*
541 if [ $? -eq 0 ]; then
542 mka bacon
543 else
544 echo "No such item in brunch menu. Try 'breakfast'"
545 return 1
546 fi
547 return $?
548}
549
550function breakfast()
551{
552 target=$1
553 CM_DEVICES_ONLY="true"
554 unset LUNCH_MENU_CHOICES
555 add_lunch_combo full-eng
556 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
557 do
558 echo "including $f"
559 . $f
560 done
561 unset f
562
563 if [ $# -eq 0 ]; then
564 # No arguments, so let's have the full menu
565 lunch
566 else
567 echo "z$target" | grep -q "-"
568 if [ $? -eq 0 ]; then
569 # A buildtype was specified, assume a full device name
570 lunch $target
571 else
572 # This is probably just the CM model name
573 lunch cm_$target-userdebug
574 fi
575 fi
576 return $?
577}
578
579alias bib=breakfast
580
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581function lunch()
582{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583 local answer
584
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587 else
588 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700589 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 fi
592
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 local selection=
594
595 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700597 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
599 then
600 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
601 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800602 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 fi
604 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
605 then
606 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700607 fi
608
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800609 if [ -z "$selection" ]
610 then
611 echo
612 echo "Invalid lunch combo: $answer"
613 return 1
614 fi
615
Joe Onoratoda12daf2010-06-09 18:18:31 -0700616 export TARGET_BUILD_APPS=
617
Jeff Browne33ba4c2011-07-11 22:11:46 -0700618 local product=$(echo -n $selection | sed -e "s/-.*$//")
619 check_product $product
620 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800621 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800622 # if we can't find a product, try to grab it off the CM github
623 T=$(gettop)
624 pushd $T > /dev/null
625 build/tools/roomservice.py $product
626 popd > /dev/null
627 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000628 else
629 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800630 fi
631 if [ $? -ne 0 ]
632 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700633 echo
634 echo "** Don't have a product spec for: '$product'"
635 echo "** Do you have the right repo manifest?"
636 product=
637 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800638
Jeff Browne33ba4c2011-07-11 22:11:46 -0700639 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
640 check_variant $variant
641 if [ $? -ne 0 ]
642 then
643 echo
644 echo "** Invalid variant: '$variant'"
645 echo "** Must be one of ${VARIANT_CHOICES[@]}"
646 variant=
647 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800648
Jeff Browne33ba4c2011-07-11 22:11:46 -0700649 if [ -z "$product" -o -z "$variant" ]
650 then
651 echo
652 return 1
653 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654
Jeff Browne33ba4c2011-07-11 22:11:46 -0700655 export TARGET_PRODUCT=$product
656 export TARGET_BUILD_VARIANT=$variant
657 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658
659 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800660
Chirayu Desaib89b3242013-06-30 10:04:25 +0530661 fixup_common_out_dir
662
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800664 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700665}
666
Jeff Davidson513d7a42010-08-02 10:00:44 -0700667# Tab completion for lunch.
668function _lunch()
669{
670 local cur prev opts
671 COMPREPLY=()
672 cur="${COMP_WORDS[COMP_CWORD]}"
673 prev="${COMP_WORDS[COMP_CWORD-1]}"
674
675 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
676 return 0
677}
678complete -F _lunch lunch
679
Joe Onoratoda12daf2010-06-09 18:18:31 -0700680# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700681# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700682function tapas()
683{
Ying Wangb541ab62014-05-29 17:57:40 -0700684 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 -0700685 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700686 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
687 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 -0700688
Ying Wang67f02922012-08-22 10:25:20 -0700689 if [ $(echo $arch | wc -w) -gt 1 ]; then
690 echo "tapas: Error: Multiple build archs supplied: $arch"
691 return
692 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700693 if [ $(echo $variant | wc -w) -gt 1 ]; then
694 echo "tapas: Error: Multiple build variants supplied: $variant"
695 return
696 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700697 if [ $(echo $density | wc -w) -gt 1 ]; then
698 echo "tapas: Error: Multiple densities supplied: $density"
699 return
700 fi
Ying Wang67f02922012-08-22 10:25:20 -0700701
702 local product=full
703 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700704 x86) product=full_x86;;
705 mips) product=full_mips;;
706 armv5) product=generic_armv5;;
707 arm64) product=aosp_arm64;;
708 x86_64) product=aosp_x86_64;;
709 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700710 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700711 if [ -z "$variant" ]; then
712 variant=eng
713 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700714 if [ -z "$apps" ]; then
715 apps=all
716 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600717 if [ -z "$density" ]; then
718 density=alldpi
719 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700720
Ying Wang67f02922012-08-22 10:25:20 -0700721 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700722 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700723 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700724 export TARGET_BUILD_TYPE=release
725 export TARGET_BUILD_APPS=$apps
726
727 set_stuff_for_environment
728 printconfig
729}
730
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100731function eat()
732{
733 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530734 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100735 ZIPFILE=cm-$MODVERSION.zip
736 ZIPPATH=$OUT/$ZIPFILE
737 if [ ! -f $ZIPPATH ] ; then
738 echo "Nothing to eat"
739 return 1
740 fi
741 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
742 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
743 echo "No device is online. Waiting for one..."
744 echo "Please connect USB and/or enable USB debugging"
745 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
746 sleep 1
747 done
748 echo "Device Found.."
749 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530750 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
751 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100752 # if adbd isn't root we can't write to /cache/recovery/
753 adb root
754 sleep 1
755 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700756 cat << EOF > /tmp/command
757--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100758EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700759 if adb push /tmp/command /cache/recovery/ ; then
760 echo "Rebooting into recovery for sideload installation"
761 adb reboot recovery
762 adb wait-for-sideload
763 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100764 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700765 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100766 else
767 echo "Nothing to eat"
768 return 1
769 fi
770 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530771 else
772 echo "The connected device does not appear to be $CM_BUILD, run away!"
773 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100774}
775
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000776function omnom
777{
778 brunch $*
779 eat
780}
781
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782function gettop
783{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800784 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700786 # The following circumlocution ensures we remove symlinks from TOP.
787 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788 else
789 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800790 # The following circumlocution (repeated below as well) ensures
791 # that we record the true directory name and not one that is
792 # faked up with symlink names.
793 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800795 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 T=
797 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800798 \cd ..
synergyb112a402013-07-05 19:47:47 -0700799 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700800 done
Ying Wang9cd17642012-12-13 10:52:07 -0800801 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802 if [ -f "$T/$TOPFILE" ]; then
803 echo $T
804 fi
805 fi
806 fi
807}
808
Andrew Hsieh906cb782013-09-10 17:37:14 +0800809# Return driver for "make", if any (eg. static analyzer)
810function getdriver()
811{
812 local T="$1"
813 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
814 if [ -n "$WITH_STATIC_ANALYZER" ]; then
815 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800816$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
817--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800818--status-bugs \
819--top=$T"
820 fi
821}
822
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823function m()
824{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800825 local T=$(gettop)
826 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800828 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829 else
830 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700831 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700832 fi
833}
834
835function findmakefile()
836{
837 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800838 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 T=
840 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700841 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842 if [ -f "$T/Android.mk" ]; then
843 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800844 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 return
846 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800847 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848 done
Ying Wang9cd17642012-12-13 10:52:07 -0800849 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850}
851
852function mm()
853{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800854 local T=$(gettop)
855 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700856 # If we're sitting in the root of the build tree, just do a
857 # normal make.
858 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800859 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700860 else
861 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800862 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700863 local MODULES=
864 local GET_INSTALL_PATH=
865 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700866 # Remove the path to top as the makefilepath needs to be relative
867 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868 if [ ! "$T" ]; then
869 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700870 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871 elif [ ! "$M" ]; then
872 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700873 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700874 else
Ying Wanga7deb082013-08-16 13:24:47 -0700875 for ARG in $@; do
876 case $ARG in
877 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
878 esac
879 done
880 if [ -n "$GET_INSTALL_PATH" ]; then
881 MODULES=
882 ARGS=GET-INSTALL-PATH
883 else
884 MODULES=all_modules
885 ARGS=$@
886 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700887 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 -0700888 fi
889 fi
890}
891
892function mmm()
893{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800894 local T=$(gettop)
895 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700896 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800897 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800898 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800899 local ARGS=
900 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700901 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800902 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
903 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
904 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800905 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
906 if [ "$MODULES" = "" ]; then
907 MODULES=all_modules
908 fi
909 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700910 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700911 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
912 local TO_CHOP=`expr $TO_CHOP + 1`
913 local START=`PWD= /bin/pwd`
914 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915 if [ "$MFILE" = "" ] ; then
916 MFILE=$DIR/Android.mk
917 else
918 MFILE=$MFILE/$DIR/Android.mk
919 fi
920 MAKEFILE="$MAKEFILE $MFILE"
921 else
Ying Wanga7deb082013-08-16 13:24:47 -0700922 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100923 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700924 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
925 *) echo "No Android.mk in $DIR."; return 1;;
926 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700927 fi
928 done
Ying Wanga7deb082013-08-16 13:24:47 -0700929 if [ -n "$GET_INSTALL_PATH" ]; then
930 ARGS=$GET_INSTALL_PATH
931 MODULES=
932 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800933 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 -0700934 else
935 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700936 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700937 fi
938}
939
Ying Wangb607f7b2013-02-08 18:01:04 -0800940function mma()
941{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800942 local T=$(gettop)
943 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800945 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800946 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800947 if [ ! "$T" ]; then
948 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700949 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800950 fi
951 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800952 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800953 fi
954}
955
956function mmma()
957{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800958 local T=$(gettop)
959 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800960 if [ "$T" ]; then
961 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
962 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
963 local MY_PWD=`PWD= /bin/pwd`
964 if [ "$MY_PWD" = "$T" ]; then
965 MY_PWD=
966 else
967 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
968 fi
969 local DIR=
970 local MODULE_PATHS=
971 local ARGS=
972 for DIR in $DIRS ; do
973 if [ -d $DIR ]; then
974 if [ "$MY_PWD" = "" ]; then
975 MODULE_PATHS="$MODULE_PATHS $DIR"
976 else
977 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
978 fi
979 else
980 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100981 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800982 *) echo "Couldn't find directory $DIR"; return 1;;
983 esac
984 fi
985 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800986 $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 -0800987 else
988 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700989 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800990 fi
991}
992
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700993function croot()
994{
995 T=$(gettop)
996 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800997 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998 else
999 echo "Couldn't locate the top of the tree. Try setting TOP."
1000 fi
1001}
1002
nebkatfb67a1e2012-12-28 10:40:45 +00001003function cout()
1004{
1005 if [ "$OUT" ]; then
1006 cd $OUT
1007 else
1008 echo "Couldn't locate out directory. Try setting OUT."
1009 fi
1010}
1011
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001012function cproj()
1013{
1014 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001015 local HERE=$PWD
1016 T=
1017 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1018 T=$PWD
1019 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001020 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001021 return
1022 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001023 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001024 done
Ying Wang9cd17642012-12-13 10:52:07 -08001025 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001026 echo "can't find Android.mk"
1027}
1028
Daniel Sandler47e0a882013-07-30 13:23:52 -04001029# simplified version of ps; output in the form
1030# <pid> <procname>
1031function qpid() {
1032 local prepend=''
1033 local append=''
1034 if [ "$1" = "--exact" ]; then
1035 prepend=' '
1036 append='$'
1037 shift
1038 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1039 echo "usage: qpid [[--exact] <process name|pid>"
1040 return 255
1041 fi
1042
1043 local EXE="$1"
1044 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001045 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001046 else
1047 adb shell ps \
1048 | tr -d '\r' \
1049 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1050 fi
1051}
1052
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001053function pid()
1054{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001055 local prepend=''
1056 local append=''
1057 if [ "$1" = "--exact" ]; then
1058 prepend=' '
1059 append='$'
1060 shift
1061 fi
1062 local EXE="$1"
1063 if [ "$EXE" ] ; then
1064 local PID=`adb shell ps \
1065 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001066 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001067 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1068 echo "$PID"
1069 else
1070 echo "usage: pid [--exact] <process name>"
1071 return 255
1072 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001073}
1074
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001075# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001076# that has the core-file-size limit set correctly
1077#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001078# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001079# if its core-file-size limit is not set already.
1080# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1081
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001082function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001083{
1084 echo "Getting root...";
1085 adb root;
1086 adb wait-for-device;
1087
1088 echo "Remounting root parition read-write...";
1089 adb shell mount -w -o remount -t rootfs rootfs;
1090 sleep 1;
1091 adb wait-for-device;
1092 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001093 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094 adb shell chmod 0777 /cores;
1095
1096 echo "Granting SELinux permission to dump in /cores...";
1097 adb shell restorecon -R /cores;
1098
1099 echo "Set core pattern.";
1100 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1101
1102 echo "Done."
1103}
1104
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001105# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001106# $1 = PID of process (e.g., $(pid mediaserver))
1107#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001108# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001109# dump to actually be generated.
1110
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001111function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001112{
1113 local PID=$1;
1114 if [ -z "$PID" ]; then
1115 printf "Expecting a PID!\n";
1116 return;
1117 fi;
1118 echo "Setting core limit for $PID to infinite...";
1119 adb shell prlimit $PID 4 -1 -1
1120}
1121
1122# core - send SIGV and pull the core for process
1123# $1 = PID of process (e.g., $(pid mediaserver))
1124#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001125# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001126# enabled globally.
1127
1128function core()
1129{
1130 local PID=$1;
1131
1132 if [ -z "$PID" ]; then
1133 printf "Expecting a PID!\n";
1134 return;
1135 fi;
1136
1137 local CORENAME=core.$PID;
1138 local COREPATH=/cores/$CORENAME;
1139 local SIG=SEGV;
1140
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001141 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001142
1143 local done=0;
1144 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1145 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1146 adb shell kill -$SIG $PID;
1147 sleep 1;
1148 done;
1149
1150 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1151 echo "Done: core is under $COREPATH on device.";
1152}
1153
Christopher Tate744ee802009-11-12 15:33:08 -08001154# systemstack - dump the current stack trace of all threads in the system process
1155# to the usual ANR traces file
1156function systemstack()
1157{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001158 stacks system_server
1159}
1160
1161function stacks()
1162{
1163 if [[ $1 =~ ^[0-9]+$ ]] ; then
1164 local PID="$1"
1165 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001166 local PIDLIST="$(pid $1)"
1167 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1168 local PID="$PIDLIST"
1169 elif [ "$PIDLIST" ] ; then
1170 echo "more than one process: $1"
1171 else
1172 echo "no such process: $1"
1173 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001174 else
1175 echo "usage: stacks [pid|process name]"
1176 fi
1177
1178 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001179 # Determine whether the process is native
1180 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1181 # Dump stacks of Dalvik process
1182 local TRACES=/data/anr/traces.txt
1183 local ORIG=/data/anr/traces.orig
1184 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001185
Jeff Brownb12c2e52013-08-19 15:14:16 -07001186 # Keep original traces to avoid clobbering
1187 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001188
Jeff Brownb12c2e52013-08-19 15:14:16 -07001189 # Make sure we have a usable file
1190 adb shell touch $TRACES
1191 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001192
Jeff Brownb12c2e52013-08-19 15:14:16 -07001193 # Dump stacks and wait for dump to finish
1194 adb shell kill -3 $PID
1195 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001196
Jeff Brownb12c2e52013-08-19 15:14:16 -07001197 # Restore original stacks, and show current output
1198 adb shell mv $TRACES $TMP
1199 adb shell mv $ORIG $TRACES
1200 adb shell cat $TMP
1201 else
1202 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001203 local USE64BIT="$(is64bit $PID)"
1204 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001205 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001206 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001207}
1208
Michael Wrightaeed7212014-06-19 19:58:12 -07001209# Read the ELF header from /proc/$PID/exe to determine if the process is
1210# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001211function is64bit()
1212{
1213 local PID="$1"
1214 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001215 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001216 echo "64"
1217 else
1218 echo ""
1219 fi
1220 else
1221 echo ""
1222 fi
1223}
1224
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001225case `uname -s` in
1226 Darwin)
1227 function sgrep()
1228 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001229 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 -07001230 }
1231
1232 ;;
1233 *)
1234 function sgrep()
1235 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001236 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 -07001237 }
1238 ;;
1239esac
1240
Raghu Gandham8da43102012-07-25 19:57:22 -07001241function gettargetarch
1242{
1243 get_build_var TARGET_ARCH
1244}
1245
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001246function ggrep()
1247{
1248 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1249}
1250
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001251function jgrep()
1252{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001253 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 -07001254}
1255
1256function cgrep()
1257{
Dan Albert01961192014-11-22 10:16:01 -08001258 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 -07001259}
1260
1261function resgrep()
1262{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001263 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 -07001264}
1265
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001266function mangrep()
1267{
1268 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1269}
1270
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001271function sepgrep()
1272{
1273 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 "$@"
1274}
1275
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001276function rcgrep()
1277{
1278 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1279}
1280
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001281case `uname -s` in
1282 Darwin)
1283 function mgrep()
1284 {
Ying Wang324c2b22012-08-17 15:03:20 -07001285 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 -07001286 }
1287
1288 function treegrep()
1289 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001290 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 -07001291 }
1292
1293 ;;
1294 *)
1295 function mgrep()
1296 {
Ying Wang324c2b22012-08-17 15:03:20 -07001297 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 -07001298 }
1299
1300 function treegrep()
1301 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001302 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 -07001303 }
1304
1305 ;;
1306esac
1307
1308function getprebuilt
1309{
1310 get_abs_build_var ANDROID_PREBUILTS
1311}
1312
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001313function tracedmdump()
1314{
1315 T=$(gettop)
1316 if [ ! "$T" ]; then
1317 echo "Couldn't locate the top of the tree. Try setting TOP."
1318 return
1319 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001320 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001321 local arch=$(gettargetarch)
1322 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001323
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001324 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001325 if [ ! "$TRACE" ] ; then
1326 echo "usage: tracedmdump tracename"
1327 return
1328 fi
1329
Jack Veenstra60116fc2009-04-09 18:12:34 -07001330 if [ ! -r "$KERNEL" ] ; then
1331 echo "Error: cannot find kernel: '$KERNEL'"
1332 return
1333 fi
1334
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001335 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001336 if [ "$BASETRACE" = "$TRACE" ] ; then
1337 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1338 fi
1339
1340 echo "post-processing traces..."
1341 rm -f $TRACE/qtrace.dexlist
1342 post_trace $TRACE
1343 if [ $? -ne 0 ]; then
1344 echo "***"
1345 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1346 echo "***"
1347 return
1348 fi
1349 echo "generating dexlist output..."
1350 /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
1351 echo "generating dmtrace data..."
1352 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1353 echo "generating html file..."
1354 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1355 echo "done, see $TRACE/dmtrace.html for details"
1356 echo "or run:"
1357 echo " traceview $TRACE/dmtrace"
1358}
1359
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001360# communicate with a running device or emulator, set up necessary state,
1361# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001362function runhat()
1363{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001364 # process standard adb options
1365 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001366 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001367 adbTarget=$1
1368 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001369 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001370 adbTarget="$1 $2"
1371 shift 2
1372 fi
1373 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001374 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001375
1376 # runhat options
1377 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001378
1379 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001380 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001381 return
1382 fi
1383
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001384 # confirm hat is available
1385 if [ -z $(which hat) ]; then
1386 echo "hat is not available in this configuration."
1387 return
1388 fi
1389
Andy McFaddenb6289852010-07-12 08:00:19 -07001390 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001391 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001392 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001393 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001394 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001395 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001396 echo -n "> "
1397 read
1398
The Android Open Source Project88b60792009-03-03 19:28:42 -08001399 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001400
The Android Open Source Project88b60792009-03-03 19:28:42 -08001401 echo "Retrieving file $devFile..."
1402 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001403
The Android Open Source Project88b60792009-03-03 19:28:42 -08001404 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001405
The Android Open Source Project88b60792009-03-03 19:28:42 -08001406 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001407 echo "View the output by pointing your browser at http://localhost:7000/"
1408 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001409 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001410}
1411
1412function getbugreports()
1413{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001414 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001415
1416 if [ ! "$reports" ]; then
1417 echo "Could not locate any bugreports."
1418 return
1419 fi
1420
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001421 local report
1422 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001423 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001424 echo "/sdcard/bugreports/${report}"
1425 adb pull /sdcard/bugreports/${report} ${report}
1426 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001427 done
1428}
1429
Victoria Lease1b296b42012-08-21 15:44:06 -07001430function getsdcardpath()
1431{
1432 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1433}
1434
1435function getscreenshotpath()
1436{
1437 echo "$(getsdcardpath)/Pictures/Screenshots"
1438}
1439
1440function getlastscreenshot()
1441{
1442 local screenshot_path=$(getscreenshotpath)
1443 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1444 if [ "$screenshot" = "" ]; then
1445 echo "No screenshots found."
1446 return
1447 fi
1448 echo "${screenshot}"
1449 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1450}
1451
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001452function startviewserver()
1453{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001454 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001455 if [ $# -gt 0 ]; then
1456 port=$1
1457 fi
1458 adb shell service call window 1 i32 $port
1459}
1460
1461function stopviewserver()
1462{
1463 adb shell service call window 2
1464}
1465
1466function isviewserverstarted()
1467{
1468 adb shell service call window 3
1469}
1470
Romain Guyb84049a2010-10-04 16:56:11 -07001471function key_home()
1472{
1473 adb shell input keyevent 3
1474}
1475
1476function key_back()
1477{
1478 adb shell input keyevent 4
1479}
1480
1481function key_menu()
1482{
1483 adb shell input keyevent 82
1484}
1485
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001486function smoketest()
1487{
1488 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1489 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1490 return
1491 fi
1492 T=$(gettop)
1493 if [ ! "$T" ]; then
1494 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1495 return
1496 fi
1497
Ying Wang9cd17642012-12-13 10:52:07 -08001498 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001499 adb uninstall com.android.smoketest > /dev/null &&
1500 adb uninstall com.android.smoketest.tests > /dev/null &&
1501 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1502 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1503 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1504}
1505
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001506# simple shortcut to the runtest command
1507function runtest()
1508{
1509 T=$(gettop)
1510 if [ ! "$T" ]; then
1511 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1512 return
1513 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001514 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001515}
1516
The Android Open Source Project88b60792009-03-03 19:28:42 -08001517function godir () {
1518 if [[ -z "$1" ]]; then
1519 echo "Usage: godir <regex>"
1520 return
1521 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001522 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001523 if [[ ! -f $T/filelist ]]; then
1524 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001525 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001526 echo " Done"
1527 echo ""
1528 fi
1529 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001530 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001531 if [[ ${#lines[@]} = 0 ]]; then
1532 echo "Not found"
1533 return
1534 fi
1535 local pathname
1536 local choice
1537 if [[ ${#lines[@]} > 1 ]]; then
1538 while [[ -z "$pathname" ]]; do
1539 local index=1
1540 local line
1541 for line in ${lines[@]}; do
1542 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001543 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001544 done
1545 echo
1546 echo -n "Select one: "
1547 unset choice
1548 read choice
1549 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1550 echo "Invalid choice"
1551 continue
1552 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001553 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001554 done
1555 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001556 pathname=${lines[0]}
1557 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001558 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001559}
1560
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001561function cmremote()
1562{
1563 git remote rm cmremote 2> /dev/null
1564 if [ ! -d .git ]
1565 then
1566 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1567 fi
1568 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1569 if [ -z "$GERRIT_REMOTE" ]
1570 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001571 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1572 if [ -z "$GERRIT_REMOTE" ]
1573 then
1574 echo Unable to set up the git remote, are you in the root of the repo?
1575 return 0
1576 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001577 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001578 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001579 if [ -z "$CMUSER" ]
1580 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001581 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001582 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001583 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001584 fi
1585 echo You can now push to "cmremote".
1586}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001587export -f cmremote
1588
Steve Kondik873fa562012-09-17 11:33:18 -07001589function aospremote()
1590{
1591 git remote rm aosp 2> /dev/null
1592 if [ ! -d .git ]
1593 then
1594 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1595 fi
1596 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1597 if (echo $PROJECT | grep -qv "^device")
1598 then
1599 PFX="platform/"
1600 fi
1601 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1602 echo "Remote 'aosp' created"
1603}
1604export -f aospremote
1605
Steve Kondikf00e7d92012-09-23 23:46:55 -07001606function installboot()
1607{
1608 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1609 then
1610 echo "No recovery.fstab found. Build recovery first."
1611 return 1
1612 fi
1613 if [ ! -e "$OUT/boot.img" ];
1614 then
1615 echo "No boot.img found. Run make bootimage first."
1616 return 1
1617 fi
1618 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1619 if [ -z "$PARTITION" ];
1620 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001621 # Try for RECOVERY_FSTAB_VERSION = 2
1622 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1623 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1624 if [ -z "$PARTITION" ];
1625 then
1626 echo "Unable to determine boot partition."
1627 return 1
1628 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001629 fi
1630 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001631 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001632 adb root
1633 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001634 adb wait-for-online shell mount /system 2>&1 > /dev/null
1635 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001636 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1637 then
1638 adb push $OUT/boot.img /cache/
1639 for i in $OUT/system/lib/modules/*;
1640 do
1641 adb push $i /system/lib/modules/
1642 done
1643 adb shell dd if=/cache/boot.img of=$PARTITION
1644 adb shell chmod 644 /system/lib/modules/*
1645 echo "Installation complete."
1646 else
1647 echo "The connected device does not appear to be $CM_BUILD, run away!"
1648 fi
1649}
1650
Steve Kondik83c03d52012-10-24 16:40:42 -07001651function installrecovery()
1652{
1653 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1654 then
1655 echo "No recovery.fstab found. Build recovery first."
1656 return 1
1657 fi
1658 if [ ! -e "$OUT/recovery.img" ];
1659 then
1660 echo "No recovery.img found. Run make recoveryimage first."
1661 return 1
1662 fi
1663 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1664 if [ -z "$PARTITION" ];
1665 then
Steve Kondik75f10762013-08-09 21:03:42 -07001666 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001667 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1668 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001669 if [ -z "$PARTITION" ];
1670 then
1671 echo "Unable to determine recovery partition."
1672 return 1
1673 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001674 fi
1675 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001676 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001677 adb root
1678 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001679 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1680 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001681 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1682 then
1683 adb push $OUT/recovery.img /cache/
1684 adb shell dd if=/cache/recovery.img of=$PARTITION
1685 echo "Installation complete."
1686 else
1687 echo "The connected device does not appear to be $CM_BUILD, run away!"
1688 fi
1689}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001690
Koushik Duttab55f13a2012-05-14 16:14:36 -07001691function makerecipe() {
1692 if [ -z "$1" ]
1693 then
1694 echo "No branch name provided."
1695 return 1
1696 fi
1697 cd android
1698 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1699 git commit -a -m "$1"
1700 cd ..
1701
1702 repo forall -c '
1703
1704 if [ "$REPO_REMOTE" == "github" ]
1705 then
1706 pwd
1707 cmremote
1708 git push cmremote HEAD:refs/heads/'$1'
1709 fi
1710 '
1711}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001712
1713function cmgerrit() {
1714 if [ $# -eq 0 ]; then
1715 $FUNCNAME help
1716 return 1
1717 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001718 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001719 local review=`git config --get remote.github.review`
1720 local project=`git config --get remote.github.projectname`
1721 local command=$1
1722 shift
1723 case $command in
1724 help)
1725 if [ $# -eq 0 ]; then
1726 cat <<EOF
1727Usage:
1728 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1729
1730Commands:
1731 fetch Just fetch the change as FETCH_HEAD
1732 help Show this help, or for a specific command
1733 pull Pull a change into current branch
1734 push Push HEAD or a local branch to Gerrit for a specific branch
1735
1736Any other Git commands that support refname would work as:
1737 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1738
1739See '$FUNCNAME help COMMAND' for more information on a specific command.
1740
1741Example:
1742 $FUNCNAME checkout -b topic 1234/5
1743works as:
1744 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1745 && git checkout -b topic FETCH_HEAD
1746will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1747Patch-set 1 will be fetched if omitted.
1748EOF
1749 return
1750 fi
1751 case $1 in
1752 __cmg_*) echo "For internal use only." ;;
1753 changes|for)
1754 if [ "$FUNCNAME" = "cmgerrit" ]; then
1755 echo "'$FUNCNAME $1' is deprecated."
1756 fi
1757 ;;
1758 help) $FUNCNAME help ;;
1759 fetch|pull) cat <<EOF
1760usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1761
1762works as:
1763 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1764 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1765
1766Example:
1767 $FUNCNAME $1 1234
1768will $1 patch-set 1 of change 1234
1769EOF
1770 ;;
1771 push) cat <<EOF
1772usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1773
1774works as:
1775 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1776 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1777
1778Example:
1779 $FUNCNAME push fix6789:gingerbread
1780will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1781HEAD will be pushed from local if omitted.
1782EOF
1783 ;;
1784 *)
1785 $FUNCNAME __cmg_err_not_supported $1 && return
1786 cat <<EOF
1787usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1788
1789works as:
1790 git fetch http://DOMAIN/p/PROJECT \\
1791 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1792 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1793EOF
1794 ;;
1795 esac
1796 ;;
1797 __cmg_get_ref)
1798 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1799 local change_id patchset_id hash
1800 case $1 in
1801 */*)
1802 change_id=${1%%/*}
1803 patchset_id=${1#*/}
1804 ;;
1805 *)
1806 change_id=$1
1807 patchset_id=1
1808 ;;
1809 esac
1810 hash=$(($change_id % 100))
1811 case $hash in
1812 [0-9]) hash="0$hash" ;;
1813 esac
1814 echo "refs/changes/$hash/$change_id/$patchset_id"
1815 ;;
1816 fetch|pull)
1817 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1818 $FUNCNAME __cmg_err_not_repo && return 1
1819 local change=$1
1820 shift
1821 git $command $@ http://$review/p/$project \
1822 $($FUNCNAME __cmg_get_ref $change) || return 1
1823 ;;
1824 push)
1825 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1826 $FUNCNAME __cmg_err_not_repo && return 1
1827 if [ -z "$user" ]; then
1828 echo >&2 "Gerrit username not found."
1829 return 1
1830 fi
1831 local local_branch remote_branch
1832 case $1 in
1833 *:*)
1834 local_branch=${1%:*}
1835 remote_branch=${1##*:}
1836 ;;
1837 *)
1838 local_branch=HEAD
1839 remote_branch=$1
1840 ;;
1841 esac
1842 shift
1843 git push $@ ssh://$user@$review:29418/$project \
1844 $local_branch:refs/for/$remote_branch || return 1
1845 ;;
1846 changes|for)
1847 if [ "$FUNCNAME" = "cmgerrit" ]; then
1848 echo >&2 "'$FUNCNAME $command' is deprecated."
1849 fi
1850 ;;
1851 __cmg_err_no_arg)
1852 if [ $# -lt 2 ]; then
1853 echo >&2 "'$FUNCNAME $command' missing argument."
1854 elif [ $2 -eq 0 ]; then
1855 if [ -n "$3" ]; then
1856 $FUNCNAME help $1
1857 else
1858 echo >&2 "'$FUNCNAME $1' missing argument."
1859 fi
1860 else
1861 return 1
1862 fi
1863 ;;
1864 __cmg_err_not_repo)
1865 if [ -z "$review" -o -z "$project" ]; then
1866 echo >&2 "Not currently in any reviewable repository."
1867 else
1868 return 1
1869 fi
1870 ;;
1871 __cmg_err_not_supported)
1872 $FUNCNAME __cmg_err_no_arg $command $# && return
1873 case $1 in
1874 #TODO: filter more git commands that don't use refname
1875 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1876 echo >&2 "'$FUNCNAME $1' is not supported."
1877 ;;
1878 *) return 1 ;;
1879 esac
1880 ;;
1881 #TODO: other special cases?
1882 *)
1883 $FUNCNAME __cmg_err_not_supported $command && return 1
1884 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1885 $FUNCNAME __cmg_err_not_repo && return 1
1886 local args="$@"
1887 local change pre_args refs_arg post_args
1888 case "$args" in
1889 *--\ *)
1890 pre_args=${args%%-- *}
1891 post_args="-- ${args#*-- }"
1892 ;;
1893 *) pre_args="$args" ;;
1894 esac
1895 args=($pre_args)
1896 pre_args=
1897 if [ ${#args[@]} -gt 0 ]; then
1898 change=${args[${#args[@]}-1]}
1899 fi
1900 if [ ${#args[@]} -gt 1 ]; then
1901 pre_args=${args[0]}
1902 for ((i=1; i<${#args[@]}-1; i++)); do
1903 pre_args="$pre_args ${args[$i]}"
1904 done
1905 fi
1906 while ((1)); do
1907 case $change in
1908 ""|--)
1909 $FUNCNAME help $command
1910 return 1
1911 ;;
1912 *@*)
1913 if [ -z "$refs_arg" ]; then
1914 refs_arg="@${change#*@}"
1915 change=${change%%@*}
1916 fi
1917 ;;
1918 *~*)
1919 if [ -z "$refs_arg" ]; then
1920 refs_arg="~${change#*~}"
1921 change=${change%%~*}
1922 fi
1923 ;;
1924 *^*)
1925 if [ -z "$refs_arg" ]; then
1926 refs_arg="^${change#*^}"
1927 change=${change%%^*}
1928 fi
1929 ;;
1930 *:*)
1931 if [ -z "$refs_arg" ]; then
1932 refs_arg=":${change#*:}"
1933 change=${change%%:*}
1934 fi
1935 ;;
1936 *) break ;;
1937 esac
1938 done
1939 $FUNCNAME fetch $change \
1940 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1941 || return 1
1942 ;;
1943 esac
1944}
1945
1946function cmrebase() {
1947 local repo=$1
1948 local refs=$2
1949 local pwd="$(pwd)"
1950 local dir="$(gettop)/$repo"
1951
1952 if [ -z $repo ] || [ -z $refs ]; then
1953 echo "CyanogenMod Gerrit Rebase Usage: "
1954 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1955 echo " The patch IDs appear on the Gerrit commands that are offered."
1956 echo " They consist on a series of numbers and slashes, after the text"
1957 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1958 echo ""
1959 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1960 echo ""
1961 return
1962 fi
1963
1964 if [ ! -d $dir ]; then
1965 echo "Directory $dir doesn't exist in tree."
1966 return
1967 fi
1968 cd $dir
1969 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1970 echo "Starting branch..."
1971 repo start tmprebase .
1972 echo "Bringing it up to date..."
1973 repo sync .
1974 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001975 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001976 if [ "$?" != "0" ]; then
1977 echo "Error cherry-picking. Not uploading!"
1978 return
1979 fi
1980 echo "Uploading..."
1981 repo upload .
1982 echo "Cleaning up..."
1983 repo abandon tmprebase .
1984 cd $pwd
1985}
1986
1987function mka() {
1988 case `uname -s` in
1989 Darwin)
1990 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1991 ;;
1992 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001993 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001994 ;;
1995 esac
1996}
1997
1998function reposync() {
1999 case `uname -s` in
2000 Darwin)
2001 repo sync -j 4 "$@"
2002 ;;
2003 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002004 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002005 ;;
2006 esac
2007}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002008
2009function repodiff() {
2010 if [ -z "$*" ]; then
2011 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2012 return
2013 fi
2014 diffopts=$* repo forall -c \
2015 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2016}
2017
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302018# Credit for color strip sed: http://goo.gl/BoIcm
2019function dopush()
2020{
2021 local func=$1
2022 shift
2023
2024 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2025 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2026 echo "No device is online. Waiting for one..."
2027 echo "Please connect USB and/or enable USB debugging"
2028 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2029 sleep 1
2030 done
2031 echo "Device Found."
2032 fi
2033
Chirayu Desai6dadb572012-12-26 10:53:58 +05302034 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2035 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002036 # retrieve IP and PORT info if we're using a TCP connection
2037 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2038 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302039 adb root &> /dev/null
2040 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002041 if [ -n "$TCPIPPORT" ]
2042 then
2043 # adb root just killed our connection
2044 # so reconnect...
2045 adb connect "$TCPIPPORT"
2046 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302047 adb wait-for-device &> /dev/null
2048 sleep 0.3
2049 adb remount &> /dev/null
2050
2051 $func $* | tee $OUT/.log
2052
2053 # Install: <file>
2054 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)
2055
2056 # Copy: <file>
2057 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)
2058
2059 for FILE in $LOC; do
2060 # Get target file name (i.e. system/bin/adb)
2061 TARGET=$(echo $FILE | sed "s#$OUT/##")
2062
Chirayu Desai894076f2013-05-19 19:54:32 +05302063 # Don't send files that are not under /system or /data
2064 if [ ! "echo $TARGET | egrep '^system\/' > /dev/null" -o \
2065 "echo $TARGET | egrep '^data\/' > /dev/null" ] ; then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302066 continue
2067 else
2068 case $TARGET in
2069 system/app/SystemUI.apk|system/framework/*)
2070 stop_n_start=true
2071 ;;
2072 *)
2073 stop_n_start=false
2074 ;;
2075 esac
2076 if $stop_n_start ; then adb shell stop ; fi
2077 echo "Pushing: $TARGET"
2078 adb push $FILE $TARGET
2079 if $stop_n_start ; then adb shell start ; fi
2080 fi
2081 done
2082 rm -f $OUT/.log
2083 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302084 else
2085 echo "The connected device does not appear to be $CM_BUILD, run away!"
2086 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302087}
2088
2089alias mmp='dopush mm'
2090alias mmmp='dopush mmm'
2091alias mkap='dopush mka'
2092alias cmkap='dopush cmka'
2093
Chirayu Desai4a319b82013-06-05 20:14:33 +05302094function repopick() {
2095 T=$(gettop)
2096 $T/build/tools/repopick.py $@
2097}
2098
Chirayu Desaib89b3242013-06-30 10:04:25 +05302099function fixup_common_out_dir() {
2100 common_out_dir=$(get_build_var OUT_DIR)/target/common
2101 target_device=$(get_build_var TARGET_DEVICE)
2102 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2103 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2104 mv ${common_out_dir} ${common_out_dir}-${target_device}
2105 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2106 else
2107 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2108 mkdir -p ${common_out_dir}-${target_device}
2109 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2110 fi
2111 else
2112 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2113 mkdir -p ${common_out_dir}
2114 fi
2115}
2116
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002117# 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 +00002118#
2119# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2120# For some reason, installing the JDK doesn't make it show up in the
2121# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002122function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002123 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002124 # we can reset it later, depending on the version of java the build
2125 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002126 #
2127 # If we don't do this, the JAVA_HOME value set by the first call to
2128 # build/envsetup.sh will persist forever.
2129 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2130 export JAVA_HOME=""
2131 fi
2132
Andy McFaddenbd960942010-06-24 12:52:51 -07002133 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002134 case `uname -s` in
2135 Darwin)
2136 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2137 ;;
2138 *)
2139 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2140 ;;
2141 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002142
2143 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2144 # we can change it on the next envsetup.sh, if required.
2145 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002146 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002147}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002148
Alex Rayf0d08eb2013-03-08 15:15:06 -08002149# Print colored exit condition
2150function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002151 "$@"
2152 local retval=$?
2153 if [ $retval -ne 0 ]
2154 then
2155 echo -e "\e[0;31mFAILURE\e[00m"
2156 else
2157 echo -e "\e[0;32mSUCCESS\e[00m"
2158 fi
2159 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002160}
2161
Ying Wanged21d4c2014-08-24 22:14:19 -07002162function get_make_command()
2163{
2164 echo command make
2165}
2166
Ed Heylcc6be0a2014-06-18 14:55:58 -07002167function make()
2168{
2169 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002170 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002171 local ret=$?
2172 local end_time=$(date +"%s")
2173 local tdiff=$(($end_time-$start_time))
2174 local hours=$(($tdiff / 3600 ))
2175 local mins=$((($tdiff % 3600) / 60))
2176 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002177 local ncolors=$(tput colors 2>/dev/null)
2178 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2179 color_failed="\e[0;31m"
2180 color_success="\e[0;32m"
2181 color_reset="\e[00m"
2182 else
2183 color_failed=""
2184 color_success=""
2185 color_reset=""
2186 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002187 echo
2188 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002189 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002190 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002191 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002192 fi
2193 if [ $hours -gt 0 ] ; then
2194 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2195 elif [ $mins -gt 0 ] ; then
2196 printf "(%02g:%02g (mm:ss))" $mins $secs
2197 elif [ $secs -gt 0 ] ; then
2198 printf "(%s seconds)" $secs
2199 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002200 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002201 echo
2202 return $ret
2203}
2204
Raphael Moll70a86b02011-06-20 16:03:14 -07002205if [ "x$SHELL" != "x/bin/bash" ]; then
2206 case `ps -o command -p $$` in
2207 *bash*)
2208 ;;
2209 *)
2210 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2211 ;;
2212 esac
2213fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002214
2215# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002216for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2217 `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 -08002218do
2219 echo "including $f"
2220 . $f
2221done
2222unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002223
2224addcompletions