blob: d1f32ef5fbfc68646d443a49b5f2cd205de52e23 [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')
85 else
86 CM_BUILD=
87 fi
88 export CM_BUILD
89
Jeff Browne33ba4c2011-07-11 22:11:46 -070090 TARGET_PRODUCT=$1 \
91 TARGET_BUILD_VARIANT= \
92 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070093 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080094 get_build_var TARGET_DEVICE > /dev/null
95 # hide successful answers, but allow the errors to show
96}
97
98VARIANT_CHOICES=(user userdebug eng)
99
100# check to see if the supplied variant is valid
101function check_variant()
102{
103 for v in ${VARIANT_CHOICES[@]}
104 do
105 if [ "$v" = "$1" ]
106 then
107 return 0
108 fi
109 done
110 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700111}
112
113function setpaths()
114{
115 T=$(gettop)
116 if [ ! "$T" ]; then
117 echo "Couldn't locate the top of the tree. Try setting TOP."
118 return
119 fi
120
121 ##################################################################
122 # #
123 # Read me before you modify this code #
124 # #
125 # This function sets ANDROID_BUILD_PATHS to what it is adding #
126 # to PATH, and the next time it is run, it removes that from #
127 # PATH. This is required so lunch can be run more than once #
128 # and still have working paths. #
129 # #
130 ##################################################################
131
Raphael Mollc639c782011-06-20 17:25:01 -0700132 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
133 # due to "C:\Program Files" being in the path.
134
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700136 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
138 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700139 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700140 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800141 # strip leading ':', if any
142 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500143 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700144
145 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700146 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700147 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700148
Ben Cheng8bc4c432012-11-16 13:29:13 -0800149 # defined in core/config.mk
150 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700151 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800152 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800153
Raphael Mollc639c782011-06-20 17:25:01 -0700154 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800155 export ANDROID_TOOLCHAIN=
156 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200157 local ARCH=$(get_build_var TARGET_ARCH)
158 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400159 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700160 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400161 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
162 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800163 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200164 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800165 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700166 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700167 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700168 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000169 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200170 *)
171 echo "Can't find toolchain for unknown architecture: $ARCH"
172 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700173 ;;
174 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700175 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800176 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700177 fi
Raphael732936d2011-06-22 14:35:32 -0700178
Ben Chengfba67bf2014-02-25 10:27:07 -0800179 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
180 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
181 fi
182
183 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700184 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700185 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800186 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800187 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700188 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100189 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
190 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700191 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700192 ;;
193 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700194 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700195 ;;
196 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700197
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700198 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700199 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 +0200200
201 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
202 # to ensure that the corresponding 'emulator' binaries are used.
203 case $(uname -s) in
204 Darwin)
205 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
206 ;;
207 Linux)
208 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
209 ;;
210 *)
211 ANDROID_EMULATOR_PREBUILTS=
212 ;;
213 esac
214 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700215 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200216 export ANDROID_EMULATOR_PREBUILTS
217 fi
218
Ying Wangaa1c9b52012-11-26 20:51:59 -0800219 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800220
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500221 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900222 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500223 if [ -n "$JAVA_HOME" ]; then
224 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900225 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
226 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500227 fi
228
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800229 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700230 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
231 export OUT=$ANDROID_PRODUCT_OUT
232
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700233 unset ANDROID_HOST_OUT
234 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
235
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700237 # TODO: fix the path
238 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
239}
240
241function printconfig()
242{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800243 T=$(gettop)
244 if [ ! "$T" ]; then
245 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
246 return
247 fi
248 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700249}
250
251function set_stuff_for_environment()
252{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800253 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500254 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800255 setpaths
256 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700257
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800258 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700259 # With this environment variable new GCC can apply colors to warnings/errors
260 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 -0700261 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700262}
263
264function set_sequence_number()
265{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700266 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267}
268
269function settitle()
270{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800271 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700272 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700273 local product=$TARGET_PRODUCT
274 local variant=$TARGET_BUILD_VARIANT
275 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800276 if [ -z "$PROMPT_COMMAND" ]; then
277 # No prompts
278 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
279 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
280 # Prompts exist, but no hardstatus
281 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700282 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800283 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
284 PROMPT_COMMAND=$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')
285 fi
286
287 if [ -z "$apps" ]; then
288 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
289 else
290 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
291 fi
292 export ANDROID_PROMPT_PREFIX
293
294 # Inject build data into hardstatus
295 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 -0800296 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297}
298
Kenny Root52aa81c2011-07-15 11:07:06 -0700299function addcompletions()
300{
301 local T dir f
302
303 # Keep us from trying to run in something that isn't bash.
304 if [ -z "${BASH_VERSION}" ]; then
305 return
306 fi
307
308 # Keep us from trying to run in bash that's too old.
309 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
310 return
311 fi
312
Chirayu Desai20a61372013-03-16 20:00:17 +0530313 dirs="sdk/bash_completion vendor/cm/bash_completion"
314 for dir in $dirs; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700315 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700316 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700317 echo "including $f"
318 . $f
319 done
320 fi
Chirayu Desai20a61372013-03-16 20:00:17 +0530321 done
Kenny Root52aa81c2011-07-15 11:07:06 -0700322}
323
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324function choosetype()
325{
326 echo "Build type choices are:"
327 echo " 1. release"
328 echo " 2. debug"
329 echo
330
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700332 DEFAULT_NUM=1
333 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 export TARGET_BUILD_TYPE=
336 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 while [ -z $TARGET_BUILD_TYPE ]
338 do
339 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800340 if [ -z "$1" ] ; then
341 read ANSWER
342 else
343 echo $1
344 ANSWER=$1
345 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 case $ANSWER in
347 "")
348 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
349 ;;
350 1)
351 export TARGET_BUILD_TYPE=release
352 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353 release)
354 export TARGET_BUILD_TYPE=release
355 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700356 2)
357 export TARGET_BUILD_TYPE=debug
358 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800359 debug)
360 export TARGET_BUILD_TYPE=debug
361 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 *)
363 echo
364 echo "I didn't understand your response. Please try again."
365 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700366 ;;
367 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800368 if [ -n "$1" ] ; then
369 break
370 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700371 done
372
373 set_stuff_for_environment
374}
375
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800376#
377# This function isn't really right: It chooses a TARGET_PRODUCT
378# based on the list of boards. Usually, that gets you something
379# that kinda works with a generic product, but really, you should
380# pick a product by name.
381#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700382function chooseproduct()
383{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384 if [ "x$TARGET_PRODUCT" != x ] ; then
385 default_value=$TARGET_PRODUCT
386 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700387 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700388 fi
389
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800390 export TARGET_PRODUCT=
391 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700392 while [ -z "$TARGET_PRODUCT" ]
393 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700394 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395 if [ -z "$1" ] ; then
396 read ANSWER
397 else
398 echo $1
399 ANSWER=$1
400 fi
401
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700402 if [ -z "$ANSWER" ] ; then
403 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800404 else
405 if check_product $ANSWER
406 then
407 export TARGET_PRODUCT=$ANSWER
408 else
409 echo "** Not a valid product: $ANSWER"
410 fi
411 fi
412 if [ -n "$1" ] ; then
413 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700414 fi
415 done
416
417 set_stuff_for_environment
418}
419
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800420function choosevariant()
421{
422 echo "Variant choices are:"
423 local index=1
424 local v
425 for v in ${VARIANT_CHOICES[@]}
426 do
427 # The product name is the name of the directory containing
428 # the makefile we found, above.
429 echo " $index. $v"
430 index=$(($index+1))
431 done
432
433 local default_value=eng
434 local ANSWER
435
436 export TARGET_BUILD_VARIANT=
437 while [ -z "$TARGET_BUILD_VARIANT" ]
438 do
439 echo -n "Which would you like? [$default_value] "
440 if [ -z "$1" ] ; then
441 read ANSWER
442 else
443 echo $1
444 ANSWER=$1
445 fi
446
447 if [ -z "$ANSWER" ] ; then
448 export TARGET_BUILD_VARIANT=$default_value
449 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
450 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800451 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452 fi
453 else
454 if check_variant $ANSWER
455 then
456 export TARGET_BUILD_VARIANT=$ANSWER
457 else
458 echo "** Not a valid variant: $ANSWER"
459 fi
460 fi
461 if [ -n "$1" ] ; then
462 break
463 fi
464 done
465}
466
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467function choosecombo()
468{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700469 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470
471 echo
472 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700473 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474
475 echo
476 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700477 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800478
479 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482}
483
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484# Clear this variable. It will be built up again when the vendorsetup.sh
485# files are included at the end of this file.
486unset LUNCH_MENU_CHOICES
487function add_lunch_combo()
488{
489 local new_combo=$1
490 local c
491 for c in ${LUNCH_MENU_CHOICES[@]} ; do
492 if [ "$new_combo" = "$c" ] ; then
493 return
494 fi
495 done
496 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
497}
498
499# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700500add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800501add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000502add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800503add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000504add_lunch_combo aosp_x86-eng
505add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700507function print_lunch_menu()
508{
509 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510 echo
511 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000512 if [ "$(uname)" = "Darwin" ] ; then
513 echo " (ohai, koush!)"
514 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000516 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
517 echo "Breakfast menu... pick a combo:"
518 else
519 echo "Lunch menu... pick a combo:"
520 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521
522 local i=1
523 local choice
524 for choice in ${LUNCH_MENU_CHOICES[@]}
525 do
526 echo " $i. $choice"
527 i=$(($i+1))
528 done
529
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000530 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
531 echo "... and don't forget the bacon!"
532 fi
533
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700534 echo
535}
536
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000537function brunch()
538{
539 breakfast $*
540 if [ $? -eq 0 ]; then
541 mka bacon
542 else
543 echo "No such item in brunch menu. Try 'breakfast'"
544 return 1
545 fi
546 return $?
547}
548
549function breakfast()
550{
551 target=$1
552 CM_DEVICES_ONLY="true"
553 unset LUNCH_MENU_CHOICES
554 add_lunch_combo full-eng
555 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
556 do
557 echo "including $f"
558 . $f
559 done
560 unset f
561
562 if [ $# -eq 0 ]; then
563 # No arguments, so let's have the full menu
564 lunch
565 else
566 echo "z$target" | grep -q "-"
567 if [ $? -eq 0 ]; then
568 # A buildtype was specified, assume a full device name
569 lunch $target
570 else
571 # This is probably just the CM model name
572 lunch cm_$target-userdebug
573 fi
574 fi
575 return $?
576}
577
578alias bib=breakfast
579
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580function lunch()
581{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800582 local answer
583
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800585 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586 else
587 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700588 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 fi
591
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800592 local selection=
593
594 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700596 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
598 then
599 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
600 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800601 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602 fi
603 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
604 then
605 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606 fi
607
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800608 if [ -z "$selection" ]
609 then
610 echo
611 echo "Invalid lunch combo: $answer"
612 return 1
613 fi
614
Joe Onoratoda12daf2010-06-09 18:18:31 -0700615 export TARGET_BUILD_APPS=
616
Jeff Browne33ba4c2011-07-11 22:11:46 -0700617 local product=$(echo -n $selection | sed -e "s/-.*$//")
618 check_product $product
619 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800620 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800621 # if we can't find a product, try to grab it off the CM github
622 T=$(gettop)
623 pushd $T > /dev/null
624 build/tools/roomservice.py $product
625 popd > /dev/null
626 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000627 else
628 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800629 fi
630 if [ $? -ne 0 ]
631 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700632 echo
633 echo "** Don't have a product spec for: '$product'"
634 echo "** Do you have the right repo manifest?"
635 product=
636 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800637
Jeff Browne33ba4c2011-07-11 22:11:46 -0700638 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
639 check_variant $variant
640 if [ $? -ne 0 ]
641 then
642 echo
643 echo "** Invalid variant: '$variant'"
644 echo "** Must be one of ${VARIANT_CHOICES[@]}"
645 variant=
646 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800647
Jeff Browne33ba4c2011-07-11 22:11:46 -0700648 if [ -z "$product" -o -z "$variant" ]
649 then
650 echo
651 return 1
652 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800653
Jeff Browne33ba4c2011-07-11 22:11:46 -0700654 export TARGET_PRODUCT=$product
655 export TARGET_BUILD_VARIANT=$variant
656 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657
658 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800661 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662}
663
Jeff Davidson513d7a42010-08-02 10:00:44 -0700664# Tab completion for lunch.
665function _lunch()
666{
667 local cur prev opts
668 COMPREPLY=()
669 cur="${COMP_WORDS[COMP_CWORD]}"
670 prev="${COMP_WORDS[COMP_CWORD-1]}"
671
672 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
673 return 0
674}
675complete -F _lunch lunch
676
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700678# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700679function tapas()
680{
Ying Wangb541ab62014-05-29 17:57:40 -0700681 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 -0700682 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700683 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
684 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 -0700685
Ying Wang67f02922012-08-22 10:25:20 -0700686 if [ $(echo $arch | wc -w) -gt 1 ]; then
687 echo "tapas: Error: Multiple build archs supplied: $arch"
688 return
689 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700690 if [ $(echo $variant | wc -w) -gt 1 ]; then
691 echo "tapas: Error: Multiple build variants supplied: $variant"
692 return
693 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700694 if [ $(echo $density | wc -w) -gt 1 ]; then
695 echo "tapas: Error: Multiple densities supplied: $density"
696 return
697 fi
Ying Wang67f02922012-08-22 10:25:20 -0700698
699 local product=full
700 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700701 x86) product=full_x86;;
702 mips) product=full_mips;;
703 armv5) product=generic_armv5;;
704 arm64) product=aosp_arm64;;
705 x86_64) product=aosp_x86_64;;
706 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700707 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700708 if [ -z "$variant" ]; then
709 variant=eng
710 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700711 if [ -z "$apps" ]; then
712 apps=all
713 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600714 if [ -z "$density" ]; then
715 density=alldpi
716 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700717
Ying Wang67f02922012-08-22 10:25:20 -0700718 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700719 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700720 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700721 export TARGET_BUILD_TYPE=release
722 export TARGET_BUILD_APPS=$apps
723
724 set_stuff_for_environment
725 printconfig
726}
727
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100728function eat()
729{
730 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530731 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100732 ZIPFILE=cm-$MODVERSION.zip
733 ZIPPATH=$OUT/$ZIPFILE
734 if [ ! -f $ZIPPATH ] ; then
735 echo "Nothing to eat"
736 return 1
737 fi
738 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
739 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
740 echo "No device is online. Waiting for one..."
741 echo "Please connect USB and/or enable USB debugging"
742 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
743 sleep 1
744 done
745 echo "Device Found.."
746 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530747 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
748 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100749 # if adbd isn't root we can't write to /cache/recovery/
750 adb root
751 sleep 1
752 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700753 cat << EOF > /tmp/command
754--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100755EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700756 if adb push /tmp/command /cache/recovery/ ; then
757 echo "Rebooting into recovery for sideload installation"
758 adb reboot recovery
759 adb wait-for-sideload
760 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100761 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700762 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100763 else
764 echo "Nothing to eat"
765 return 1
766 fi
767 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530768 else
769 echo "The connected device does not appear to be $CM_BUILD, run away!"
770 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100771}
772
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000773function omnom
774{
775 brunch $*
776 eat
777}
778
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779function gettop
780{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800781 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700783 # The following circumlocution ensures we remove symlinks from TOP.
784 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 else
786 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800787 # The following circumlocution (repeated below as well) ensures
788 # that we record the true directory name and not one that is
789 # faked up with symlink names.
790 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800792 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 T=
794 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800795 \cd ..
synergyb112a402013-07-05 19:47:47 -0700796 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 done
Ying Wang9cd17642012-12-13 10:52:07 -0800798 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799 if [ -f "$T/$TOPFILE" ]; then
800 echo $T
801 fi
802 fi
803 fi
804}
805
Andrew Hsieh906cb782013-09-10 17:37:14 +0800806# Return driver for "make", if any (eg. static analyzer)
807function getdriver()
808{
809 local T="$1"
810 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
811 if [ -n "$WITH_STATIC_ANALYZER" ]; then
812 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800813$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
814--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800815--status-bugs \
816--top=$T"
817 fi
818}
819
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700820function m()
821{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800822 local T=$(gettop)
823 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800825 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700826 else
827 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700828 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829 fi
830}
831
832function findmakefile()
833{
834 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800835 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 T=
837 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700838 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 if [ -f "$T/Android.mk" ]; then
840 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800841 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842 return
843 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800844 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 done
Ying Wang9cd17642012-12-13 10:52:07 -0800846 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847}
848
849function mm()
850{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800851 local T=$(gettop)
852 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700853 # If we're sitting in the root of the build tree, just do a
854 # normal make.
855 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800856 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700857 else
858 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800859 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700860 local MODULES=
861 local GET_INSTALL_PATH=
862 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700863 # Remove the path to top as the makefilepath needs to be relative
864 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700865 if [ ! "$T" ]; then
866 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700867 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868 elif [ ! "$M" ]; then
869 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700870 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871 else
Ying Wanga7deb082013-08-16 13:24:47 -0700872 for ARG in $@; do
873 case $ARG in
874 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
875 esac
876 done
877 if [ -n "$GET_INSTALL_PATH" ]; then
878 MODULES=
879 ARGS=GET-INSTALL-PATH
880 else
881 MODULES=all_modules
882 ARGS=$@
883 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700884 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 -0700885 fi
886 fi
887}
888
889function mmm()
890{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800891 local T=$(gettop)
892 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700893 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800894 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800895 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800896 local ARGS=
897 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700898 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800899 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
900 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
901 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800902 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
903 if [ "$MODULES" = "" ]; then
904 MODULES=all_modules
905 fi
906 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700907 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700908 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
909 local TO_CHOP=`expr $TO_CHOP + 1`
910 local START=`PWD= /bin/pwd`
911 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700912 if [ "$MFILE" = "" ] ; then
913 MFILE=$DIR/Android.mk
914 else
915 MFILE=$MFILE/$DIR/Android.mk
916 fi
917 MAKEFILE="$MAKEFILE $MFILE"
918 else
Ying Wanga7deb082013-08-16 13:24:47 -0700919 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100920 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700921 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
922 *) echo "No Android.mk in $DIR."; return 1;;
923 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700924 fi
925 done
Ying Wanga7deb082013-08-16 13:24:47 -0700926 if [ -n "$GET_INSTALL_PATH" ]; then
927 ARGS=$GET_INSTALL_PATH
928 MODULES=
929 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800930 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 -0700931 else
932 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700933 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700934 fi
935}
936
Ying Wangb607f7b2013-02-08 18:01:04 -0800937function mma()
938{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800939 local T=$(gettop)
940 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800941 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800942 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800943 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 if [ ! "$T" ]; then
945 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700946 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800947 fi
948 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800949 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800950 fi
951}
952
953function mmma()
954{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800955 local T=$(gettop)
956 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800957 if [ "$T" ]; then
958 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
959 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
960 local MY_PWD=`PWD= /bin/pwd`
961 if [ "$MY_PWD" = "$T" ]; then
962 MY_PWD=
963 else
964 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
965 fi
966 local DIR=
967 local MODULE_PATHS=
968 local ARGS=
969 for DIR in $DIRS ; do
970 if [ -d $DIR ]; then
971 if [ "$MY_PWD" = "" ]; then
972 MODULE_PATHS="$MODULE_PATHS $DIR"
973 else
974 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
975 fi
976 else
977 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100978 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800979 *) echo "Couldn't find directory $DIR"; return 1;;
980 esac
981 fi
982 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800983 $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 -0800984 else
985 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700986 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800987 fi
988}
989
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700990function croot()
991{
992 T=$(gettop)
993 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800994 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700995 else
996 echo "Couldn't locate the top of the tree. Try setting TOP."
997 fi
998}
999
nebkatfb67a1e2012-12-28 10:40:45 +00001000function cout()
1001{
1002 if [ "$OUT" ]; then
1003 cd $OUT
1004 else
1005 echo "Couldn't locate out directory. Try setting OUT."
1006 fi
1007}
1008
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001009function cproj()
1010{
1011 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001012 local HERE=$PWD
1013 T=
1014 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1015 T=$PWD
1016 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001017 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001018 return
1019 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001020 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001021 done
Ying Wang9cd17642012-12-13 10:52:07 -08001022 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001023 echo "can't find Android.mk"
1024}
1025
Daniel Sandler47e0a882013-07-30 13:23:52 -04001026# simplified version of ps; output in the form
1027# <pid> <procname>
1028function qpid() {
1029 local prepend=''
1030 local append=''
1031 if [ "$1" = "--exact" ]; then
1032 prepend=' '
1033 append='$'
1034 shift
1035 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1036 echo "usage: qpid [[--exact] <process name|pid>"
1037 return 255
1038 fi
1039
1040 local EXE="$1"
1041 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001042 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001043 else
1044 adb shell ps \
1045 | tr -d '\r' \
1046 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1047 fi
1048}
1049
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001050function pid()
1051{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001052 local prepend=''
1053 local append=''
1054 if [ "$1" = "--exact" ]; then
1055 prepend=' '
1056 append='$'
1057 shift
1058 fi
1059 local EXE="$1"
1060 if [ "$EXE" ] ; then
1061 local PID=`adb shell ps \
1062 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001063 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001064 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1065 echo "$PID"
1066 else
1067 echo "usage: pid [--exact] <process name>"
1068 return 255
1069 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001070}
1071
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001072# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001073# that has the core-file-size limit set correctly
1074#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001075# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001076# if its core-file-size limit is not set already.
1077# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1078
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001079function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080{
1081 echo "Getting root...";
1082 adb root;
1083 adb wait-for-device;
1084
1085 echo "Remounting root parition read-write...";
1086 adb shell mount -w -o remount -t rootfs rootfs;
1087 sleep 1;
1088 adb wait-for-device;
1089 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001090 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001091 adb shell chmod 0777 /cores;
1092
1093 echo "Granting SELinux permission to dump in /cores...";
1094 adb shell restorecon -R /cores;
1095
1096 echo "Set core pattern.";
1097 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1098
1099 echo "Done."
1100}
1101
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001102# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103# $1 = PID of process (e.g., $(pid mediaserver))
1104#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001105# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001106# dump to actually be generated.
1107
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001108function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001109{
1110 local PID=$1;
1111 if [ -z "$PID" ]; then
1112 printf "Expecting a PID!\n";
1113 return;
1114 fi;
1115 echo "Setting core limit for $PID to infinite...";
1116 adb shell prlimit $PID 4 -1 -1
1117}
1118
1119# core - send SIGV and pull the core for process
1120# $1 = PID of process (e.g., $(pid mediaserver))
1121#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001122# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001123# enabled globally.
1124
1125function core()
1126{
1127 local PID=$1;
1128
1129 if [ -z "$PID" ]; then
1130 printf "Expecting a PID!\n";
1131 return;
1132 fi;
1133
1134 local CORENAME=core.$PID;
1135 local COREPATH=/cores/$CORENAME;
1136 local SIG=SEGV;
1137
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001138 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001139
1140 local done=0;
1141 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1142 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1143 adb shell kill -$SIG $PID;
1144 sleep 1;
1145 done;
1146
1147 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1148 echo "Done: core is under $COREPATH on device.";
1149}
1150
Christopher Tate744ee802009-11-12 15:33:08 -08001151# systemstack - dump the current stack trace of all threads in the system process
1152# to the usual ANR traces file
1153function systemstack()
1154{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001155 stacks system_server
1156}
1157
1158function stacks()
1159{
1160 if [[ $1 =~ ^[0-9]+$ ]] ; then
1161 local PID="$1"
1162 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001163 local PIDLIST="$(pid $1)"
1164 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1165 local PID="$PIDLIST"
1166 elif [ "$PIDLIST" ] ; then
1167 echo "more than one process: $1"
1168 else
1169 echo "no such process: $1"
1170 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001171 else
1172 echo "usage: stacks [pid|process name]"
1173 fi
1174
1175 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001176 # Determine whether the process is native
1177 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1178 # Dump stacks of Dalvik process
1179 local TRACES=/data/anr/traces.txt
1180 local ORIG=/data/anr/traces.orig
1181 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001182
Jeff Brownb12c2e52013-08-19 15:14:16 -07001183 # Keep original traces to avoid clobbering
1184 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001185
Jeff Brownb12c2e52013-08-19 15:14:16 -07001186 # Make sure we have a usable file
1187 adb shell touch $TRACES
1188 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001189
Jeff Brownb12c2e52013-08-19 15:14:16 -07001190 # Dump stacks and wait for dump to finish
1191 adb shell kill -3 $PID
1192 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001193
Jeff Brownb12c2e52013-08-19 15:14:16 -07001194 # Restore original stacks, and show current output
1195 adb shell mv $TRACES $TMP
1196 adb shell mv $ORIG $TRACES
1197 adb shell cat $TMP
1198 else
1199 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001200 local USE64BIT="$(is64bit $PID)"
1201 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001202 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001203 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001204}
1205
Michael Wrightaeed7212014-06-19 19:58:12 -07001206# Read the ELF header from /proc/$PID/exe to determine if the process is
1207# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001208function is64bit()
1209{
1210 local PID="$1"
1211 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001212 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001213 echo "64"
1214 else
1215 echo ""
1216 fi
1217 else
1218 echo ""
1219 fi
1220}
1221
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001222case `uname -s` in
1223 Darwin)
1224 function sgrep()
1225 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001226 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 -07001227 }
1228
1229 ;;
1230 *)
1231 function sgrep()
1232 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001233 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 -07001234 }
1235 ;;
1236esac
1237
Raghu Gandham8da43102012-07-25 19:57:22 -07001238function gettargetarch
1239{
1240 get_build_var TARGET_ARCH
1241}
1242
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001243function ggrep()
1244{
1245 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1246}
1247
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001248function jgrep()
1249{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001250 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 -07001251}
1252
1253function cgrep()
1254{
Dan Albert01961192014-11-22 10:16:01 -08001255 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 -07001256}
1257
1258function resgrep()
1259{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001260 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 -07001261}
1262
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001263function mangrep()
1264{
1265 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1266}
1267
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001268function sepgrep()
1269{
1270 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 "$@"
1271}
1272
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001273function rcgrep()
1274{
1275 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1276}
1277
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001278case `uname -s` in
1279 Darwin)
1280 function mgrep()
1281 {
Ying Wang324c2b22012-08-17 15:03:20 -07001282 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 -07001283 }
1284
1285 function treegrep()
1286 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001287 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 -07001288 }
1289
1290 ;;
1291 *)
1292 function mgrep()
1293 {
Ying Wang324c2b22012-08-17 15:03:20 -07001294 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 -07001295 }
1296
1297 function treegrep()
1298 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001299 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 -07001300 }
1301
1302 ;;
1303esac
1304
1305function getprebuilt
1306{
1307 get_abs_build_var ANDROID_PREBUILTS
1308}
1309
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001310function tracedmdump()
1311{
1312 T=$(gettop)
1313 if [ ! "$T" ]; then
1314 echo "Couldn't locate the top of the tree. Try setting TOP."
1315 return
1316 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001317 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001318 local arch=$(gettargetarch)
1319 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001320
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001321 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322 if [ ! "$TRACE" ] ; then
1323 echo "usage: tracedmdump tracename"
1324 return
1325 fi
1326
Jack Veenstra60116fc2009-04-09 18:12:34 -07001327 if [ ! -r "$KERNEL" ] ; then
1328 echo "Error: cannot find kernel: '$KERNEL'"
1329 return
1330 fi
1331
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001332 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001333 if [ "$BASETRACE" = "$TRACE" ] ; then
1334 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1335 fi
1336
1337 echo "post-processing traces..."
1338 rm -f $TRACE/qtrace.dexlist
1339 post_trace $TRACE
1340 if [ $? -ne 0 ]; then
1341 echo "***"
1342 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1343 echo "***"
1344 return
1345 fi
1346 echo "generating dexlist output..."
1347 /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
1348 echo "generating dmtrace data..."
1349 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1350 echo "generating html file..."
1351 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1352 echo "done, see $TRACE/dmtrace.html for details"
1353 echo "or run:"
1354 echo " traceview $TRACE/dmtrace"
1355}
1356
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001357# communicate with a running device or emulator, set up necessary state,
1358# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001359function runhat()
1360{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001361 # process standard adb options
1362 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001363 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001364 adbTarget=$1
1365 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001366 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001367 adbTarget="$1 $2"
1368 shift 2
1369 fi
1370 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001371 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001372
1373 # runhat options
1374 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001375
1376 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001377 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001378 return
1379 fi
1380
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001381 # confirm hat is available
1382 if [ -z $(which hat) ]; then
1383 echo "hat is not available in this configuration."
1384 return
1385 fi
1386
Andy McFaddenb6289852010-07-12 08:00:19 -07001387 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001388 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001389 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001390 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001391 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001392 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001393 echo -n "> "
1394 read
1395
The Android Open Source Project88b60792009-03-03 19:28:42 -08001396 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397
The Android Open Source Project88b60792009-03-03 19:28:42 -08001398 echo "Retrieving file $devFile..."
1399 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001400
The Android Open Source Project88b60792009-03-03 19:28:42 -08001401 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001402
The Android Open Source Project88b60792009-03-03 19:28:42 -08001403 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001404 echo "View the output by pointing your browser at http://localhost:7000/"
1405 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001406 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001407}
1408
1409function getbugreports()
1410{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001411 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001412
1413 if [ ! "$reports" ]; then
1414 echo "Could not locate any bugreports."
1415 return
1416 fi
1417
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001418 local report
1419 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001421 echo "/sdcard/bugreports/${report}"
1422 adb pull /sdcard/bugreports/${report} ${report}
1423 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001424 done
1425}
1426
Victoria Lease1b296b42012-08-21 15:44:06 -07001427function getsdcardpath()
1428{
1429 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1430}
1431
1432function getscreenshotpath()
1433{
1434 echo "$(getsdcardpath)/Pictures/Screenshots"
1435}
1436
1437function getlastscreenshot()
1438{
1439 local screenshot_path=$(getscreenshotpath)
1440 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1441 if [ "$screenshot" = "" ]; then
1442 echo "No screenshots found."
1443 return
1444 fi
1445 echo "${screenshot}"
1446 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1447}
1448
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001449function startviewserver()
1450{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001451 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001452 if [ $# -gt 0 ]; then
1453 port=$1
1454 fi
1455 adb shell service call window 1 i32 $port
1456}
1457
1458function stopviewserver()
1459{
1460 adb shell service call window 2
1461}
1462
1463function isviewserverstarted()
1464{
1465 adb shell service call window 3
1466}
1467
Romain Guyb84049a2010-10-04 16:56:11 -07001468function key_home()
1469{
1470 adb shell input keyevent 3
1471}
1472
1473function key_back()
1474{
1475 adb shell input keyevent 4
1476}
1477
1478function key_menu()
1479{
1480 adb shell input keyevent 82
1481}
1482
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001483function smoketest()
1484{
1485 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1486 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1487 return
1488 fi
1489 T=$(gettop)
1490 if [ ! "$T" ]; then
1491 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1492 return
1493 fi
1494
Ying Wang9cd17642012-12-13 10:52:07 -08001495 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001496 adb uninstall com.android.smoketest > /dev/null &&
1497 adb uninstall com.android.smoketest.tests > /dev/null &&
1498 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1499 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1500 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1501}
1502
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001503# simple shortcut to the runtest command
1504function runtest()
1505{
1506 T=$(gettop)
1507 if [ ! "$T" ]; then
1508 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1509 return
1510 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001511 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001512}
1513
The Android Open Source Project88b60792009-03-03 19:28:42 -08001514function godir () {
1515 if [[ -z "$1" ]]; then
1516 echo "Usage: godir <regex>"
1517 return
1518 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001519 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001520 if [[ ! -f $T/filelist ]]; then
1521 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001522 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001523 echo " Done"
1524 echo ""
1525 fi
1526 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001527 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001528 if [[ ${#lines[@]} = 0 ]]; then
1529 echo "Not found"
1530 return
1531 fi
1532 local pathname
1533 local choice
1534 if [[ ${#lines[@]} > 1 ]]; then
1535 while [[ -z "$pathname" ]]; do
1536 local index=1
1537 local line
1538 for line in ${lines[@]}; do
1539 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001540 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001541 done
1542 echo
1543 echo -n "Select one: "
1544 unset choice
1545 read choice
1546 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1547 echo "Invalid choice"
1548 continue
1549 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001550 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001551 done
1552 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001553 pathname=${lines[0]}
1554 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001555 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001556}
1557
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001558function cmremote()
1559{
1560 git remote rm cmremote 2> /dev/null
1561 if [ ! -d .git ]
1562 then
1563 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1564 fi
1565 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1566 if [ -z "$GERRIT_REMOTE" ]
1567 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001568 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1569 if [ -z "$GERRIT_REMOTE" ]
1570 then
1571 echo Unable to set up the git remote, are you in the root of the repo?
1572 return 0
1573 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001574 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001575 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001576 if [ -z "$CMUSER" ]
1577 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001578 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001579 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001580 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001581 fi
1582 echo You can now push to "cmremote".
1583}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001584export -f cmremote
1585
Steve Kondik873fa562012-09-17 11:33:18 -07001586function aospremote()
1587{
1588 git remote rm aosp 2> /dev/null
1589 if [ ! -d .git ]
1590 then
1591 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1592 fi
1593 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1594 if (echo $PROJECT | grep -qv "^device")
1595 then
1596 PFX="platform/"
1597 fi
1598 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1599 echo "Remote 'aosp' created"
1600}
1601export -f aospremote
1602
Steve Kondikf00e7d92012-09-23 23:46:55 -07001603function installboot()
1604{
1605 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1606 then
1607 echo "No recovery.fstab found. Build recovery first."
1608 return 1
1609 fi
1610 if [ ! -e "$OUT/boot.img" ];
1611 then
1612 echo "No boot.img found. Run make bootimage first."
1613 return 1
1614 fi
1615 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1616 if [ -z "$PARTITION" ];
1617 then
1618 echo "Unable to determine boot partition."
1619 return 1
1620 fi
1621 adb start-server
1622 adb root
1623 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001624 adb wait-for-online shell mount /system 2>&1 > /dev/null
1625 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001626 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1627 then
1628 adb push $OUT/boot.img /cache/
1629 for i in $OUT/system/lib/modules/*;
1630 do
1631 adb push $i /system/lib/modules/
1632 done
1633 adb shell dd if=/cache/boot.img of=$PARTITION
1634 adb shell chmod 644 /system/lib/modules/*
1635 echo "Installation complete."
1636 else
1637 echo "The connected device does not appear to be $CM_BUILD, run away!"
1638 fi
1639}
1640
Steve Kondik83c03d52012-10-24 16:40:42 -07001641function installrecovery()
1642{
1643 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1644 then
1645 echo "No recovery.fstab found. Build recovery first."
1646 return 1
1647 fi
1648 if [ ! -e "$OUT/recovery.img" ];
1649 then
1650 echo "No recovery.img found. Run make recoveryimage first."
1651 return 1
1652 fi
1653 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1654 if [ -z "$PARTITION" ];
1655 then
1656 echo "Unable to determine recovery partition."
1657 return 1
1658 fi
1659 adb start-server
1660 adb root
1661 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001662 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1663 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001664 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1665 then
1666 adb push $OUT/recovery.img /cache/
1667 adb shell dd if=/cache/recovery.img of=$PARTITION
1668 echo "Installation complete."
1669 else
1670 echo "The connected device does not appear to be $CM_BUILD, run away!"
1671 fi
1672}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001673
Koushik Duttab55f13a2012-05-14 16:14:36 -07001674function makerecipe() {
1675 if [ -z "$1" ]
1676 then
1677 echo "No branch name provided."
1678 return 1
1679 fi
1680 cd android
1681 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1682 git commit -a -m "$1"
1683 cd ..
1684
1685 repo forall -c '
1686
1687 if [ "$REPO_REMOTE" == "github" ]
1688 then
1689 pwd
1690 cmremote
1691 git push cmremote HEAD:refs/heads/'$1'
1692 fi
1693 '
1694}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001695
1696function cmgerrit() {
1697 if [ $# -eq 0 ]; then
1698 $FUNCNAME help
1699 return 1
1700 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001701 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001702 local review=`git config --get remote.github.review`
1703 local project=`git config --get remote.github.projectname`
1704 local command=$1
1705 shift
1706 case $command in
1707 help)
1708 if [ $# -eq 0 ]; then
1709 cat <<EOF
1710Usage:
1711 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1712
1713Commands:
1714 fetch Just fetch the change as FETCH_HEAD
1715 help Show this help, or for a specific command
1716 pull Pull a change into current branch
1717 push Push HEAD or a local branch to Gerrit for a specific branch
1718
1719Any other Git commands that support refname would work as:
1720 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1721
1722See '$FUNCNAME help COMMAND' for more information on a specific command.
1723
1724Example:
1725 $FUNCNAME checkout -b topic 1234/5
1726works as:
1727 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1728 && git checkout -b topic FETCH_HEAD
1729will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1730Patch-set 1 will be fetched if omitted.
1731EOF
1732 return
1733 fi
1734 case $1 in
1735 __cmg_*) echo "For internal use only." ;;
1736 changes|for)
1737 if [ "$FUNCNAME" = "cmgerrit" ]; then
1738 echo "'$FUNCNAME $1' is deprecated."
1739 fi
1740 ;;
1741 help) $FUNCNAME help ;;
1742 fetch|pull) cat <<EOF
1743usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1744
1745works as:
1746 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1747 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1748
1749Example:
1750 $FUNCNAME $1 1234
1751will $1 patch-set 1 of change 1234
1752EOF
1753 ;;
1754 push) cat <<EOF
1755usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1756
1757works as:
1758 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1759 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1760
1761Example:
1762 $FUNCNAME push fix6789:gingerbread
1763will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1764HEAD will be pushed from local if omitted.
1765EOF
1766 ;;
1767 *)
1768 $FUNCNAME __cmg_err_not_supported $1 && return
1769 cat <<EOF
1770usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1771
1772works as:
1773 git fetch http://DOMAIN/p/PROJECT \\
1774 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1775 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1776EOF
1777 ;;
1778 esac
1779 ;;
1780 __cmg_get_ref)
1781 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1782 local change_id patchset_id hash
1783 case $1 in
1784 */*)
1785 change_id=${1%%/*}
1786 patchset_id=${1#*/}
1787 ;;
1788 *)
1789 change_id=$1
1790 patchset_id=1
1791 ;;
1792 esac
1793 hash=$(($change_id % 100))
1794 case $hash in
1795 [0-9]) hash="0$hash" ;;
1796 esac
1797 echo "refs/changes/$hash/$change_id/$patchset_id"
1798 ;;
1799 fetch|pull)
1800 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1801 $FUNCNAME __cmg_err_not_repo && return 1
1802 local change=$1
1803 shift
1804 git $command $@ http://$review/p/$project \
1805 $($FUNCNAME __cmg_get_ref $change) || return 1
1806 ;;
1807 push)
1808 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1809 $FUNCNAME __cmg_err_not_repo && return 1
1810 if [ -z "$user" ]; then
1811 echo >&2 "Gerrit username not found."
1812 return 1
1813 fi
1814 local local_branch remote_branch
1815 case $1 in
1816 *:*)
1817 local_branch=${1%:*}
1818 remote_branch=${1##*:}
1819 ;;
1820 *)
1821 local_branch=HEAD
1822 remote_branch=$1
1823 ;;
1824 esac
1825 shift
1826 git push $@ ssh://$user@$review:29418/$project \
1827 $local_branch:refs/for/$remote_branch || return 1
1828 ;;
1829 changes|for)
1830 if [ "$FUNCNAME" = "cmgerrit" ]; then
1831 echo >&2 "'$FUNCNAME $command' is deprecated."
1832 fi
1833 ;;
1834 __cmg_err_no_arg)
1835 if [ $# -lt 2 ]; then
1836 echo >&2 "'$FUNCNAME $command' missing argument."
1837 elif [ $2 -eq 0 ]; then
1838 if [ -n "$3" ]; then
1839 $FUNCNAME help $1
1840 else
1841 echo >&2 "'$FUNCNAME $1' missing argument."
1842 fi
1843 else
1844 return 1
1845 fi
1846 ;;
1847 __cmg_err_not_repo)
1848 if [ -z "$review" -o -z "$project" ]; then
1849 echo >&2 "Not currently in any reviewable repository."
1850 else
1851 return 1
1852 fi
1853 ;;
1854 __cmg_err_not_supported)
1855 $FUNCNAME __cmg_err_no_arg $command $# && return
1856 case $1 in
1857 #TODO: filter more git commands that don't use refname
1858 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1859 echo >&2 "'$FUNCNAME $1' is not supported."
1860 ;;
1861 *) return 1 ;;
1862 esac
1863 ;;
1864 #TODO: other special cases?
1865 *)
1866 $FUNCNAME __cmg_err_not_supported $command && return 1
1867 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1868 $FUNCNAME __cmg_err_not_repo && return 1
1869 local args="$@"
1870 local change pre_args refs_arg post_args
1871 case "$args" in
1872 *--\ *)
1873 pre_args=${args%%-- *}
1874 post_args="-- ${args#*-- }"
1875 ;;
1876 *) pre_args="$args" ;;
1877 esac
1878 args=($pre_args)
1879 pre_args=
1880 if [ ${#args[@]} -gt 0 ]; then
1881 change=${args[${#args[@]}-1]}
1882 fi
1883 if [ ${#args[@]} -gt 1 ]; then
1884 pre_args=${args[0]}
1885 for ((i=1; i<${#args[@]}-1; i++)); do
1886 pre_args="$pre_args ${args[$i]}"
1887 done
1888 fi
1889 while ((1)); do
1890 case $change in
1891 ""|--)
1892 $FUNCNAME help $command
1893 return 1
1894 ;;
1895 *@*)
1896 if [ -z "$refs_arg" ]; then
1897 refs_arg="@${change#*@}"
1898 change=${change%%@*}
1899 fi
1900 ;;
1901 *~*)
1902 if [ -z "$refs_arg" ]; then
1903 refs_arg="~${change#*~}"
1904 change=${change%%~*}
1905 fi
1906 ;;
1907 *^*)
1908 if [ -z "$refs_arg" ]; then
1909 refs_arg="^${change#*^}"
1910 change=${change%%^*}
1911 fi
1912 ;;
1913 *:*)
1914 if [ -z "$refs_arg" ]; then
1915 refs_arg=":${change#*:}"
1916 change=${change%%:*}
1917 fi
1918 ;;
1919 *) break ;;
1920 esac
1921 done
1922 $FUNCNAME fetch $change \
1923 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1924 || return 1
1925 ;;
1926 esac
1927}
1928
1929function cmrebase() {
1930 local repo=$1
1931 local refs=$2
1932 local pwd="$(pwd)"
1933 local dir="$(gettop)/$repo"
1934
1935 if [ -z $repo ] || [ -z $refs ]; then
1936 echo "CyanogenMod Gerrit Rebase Usage: "
1937 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1938 echo " The patch IDs appear on the Gerrit commands that are offered."
1939 echo " They consist on a series of numbers and slashes, after the text"
1940 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1941 echo ""
1942 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1943 echo ""
1944 return
1945 fi
1946
1947 if [ ! -d $dir ]; then
1948 echo "Directory $dir doesn't exist in tree."
1949 return
1950 fi
1951 cd $dir
1952 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1953 echo "Starting branch..."
1954 repo start tmprebase .
1955 echo "Bringing it up to date..."
1956 repo sync .
1957 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001958 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001959 if [ "$?" != "0" ]; then
1960 echo "Error cherry-picking. Not uploading!"
1961 return
1962 fi
1963 echo "Uploading..."
1964 repo upload .
1965 echo "Cleaning up..."
1966 repo abandon tmprebase .
1967 cd $pwd
1968}
1969
1970function mka() {
1971 case `uname -s` in
1972 Darwin)
1973 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1974 ;;
1975 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001976 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001977 ;;
1978 esac
1979}
1980
1981function reposync() {
1982 case `uname -s` in
1983 Darwin)
1984 repo sync -j 4 "$@"
1985 ;;
1986 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001987 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001988 ;;
1989 esac
1990}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001991
1992function repodiff() {
1993 if [ -z "$*" ]; then
1994 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1995 return
1996 fi
1997 diffopts=$* repo forall -c \
1998 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1999}
2000
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302001# Credit for color strip sed: http://goo.gl/BoIcm
2002function dopush()
2003{
2004 local func=$1
2005 shift
2006
2007 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2008 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2009 echo "No device is online. Waiting for one..."
2010 echo "Please connect USB and/or enable USB debugging"
2011 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2012 sleep 1
2013 done
2014 echo "Device Found."
2015 fi
2016
Chirayu Desai6dadb572012-12-26 10:53:58 +05302017 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2018 then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302019 adb root &> /dev/null
2020 sleep 0.3
2021 adb wait-for-device &> /dev/null
2022 sleep 0.3
2023 adb remount &> /dev/null
2024
2025 $func $* | tee $OUT/.log
2026
2027 # Install: <file>
2028 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)
2029
2030 # Copy: <file>
2031 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)
2032
2033 for FILE in $LOC; do
2034 # Get target file name (i.e. system/bin/adb)
2035 TARGET=$(echo $FILE | sed "s#$OUT/##")
2036
2037 # Don't send files that are not in /system.
2038 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2039 continue
2040 else
2041 case $TARGET in
2042 system/app/SystemUI.apk|system/framework/*)
2043 stop_n_start=true
2044 ;;
2045 *)
2046 stop_n_start=false
2047 ;;
2048 esac
2049 if $stop_n_start ; then adb shell stop ; fi
2050 echo "Pushing: $TARGET"
2051 adb push $FILE $TARGET
2052 if $stop_n_start ; then adb shell start ; fi
2053 fi
2054 done
2055 rm -f $OUT/.log
2056 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302057 else
2058 echo "The connected device does not appear to be $CM_BUILD, run away!"
2059 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302060}
2061
2062alias mmp='dopush mm'
2063alias mmmp='dopush mmm'
2064alias mkap='dopush mka'
2065alias cmkap='dopush cmka'
2066
Chirayu Desai4a319b82013-06-05 20:14:33 +05302067function repopick() {
2068 T=$(gettop)
2069 $T/build/tools/repopick.py $@
2070}
2071
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002072# 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 +00002073#
2074# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2075# For some reason, installing the JDK doesn't make it show up in the
2076# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002077function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002078 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002079 # we can reset it later, depending on the version of java the build
2080 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002081 #
2082 # If we don't do this, the JAVA_HOME value set by the first call to
2083 # build/envsetup.sh will persist forever.
2084 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2085 export JAVA_HOME=""
2086 fi
2087
Andy McFaddenbd960942010-06-24 12:52:51 -07002088 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002089 case `uname -s` in
2090 Darwin)
2091 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2092 ;;
2093 *)
2094 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2095 ;;
2096 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002097
2098 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2099 # we can change it on the next envsetup.sh, if required.
2100 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002101 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002102}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002103
Alex Rayf0d08eb2013-03-08 15:15:06 -08002104# Print colored exit condition
2105function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002106 "$@"
2107 local retval=$?
2108 if [ $retval -ne 0 ]
2109 then
2110 echo -e "\e[0;31mFAILURE\e[00m"
2111 else
2112 echo -e "\e[0;32mSUCCESS\e[00m"
2113 fi
2114 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002115}
2116
Ying Wanged21d4c2014-08-24 22:14:19 -07002117function get_make_command()
2118{
2119 echo command make
2120}
2121
Ed Heylcc6be0a2014-06-18 14:55:58 -07002122function make()
2123{
2124 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002125 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002126 local ret=$?
2127 local end_time=$(date +"%s")
2128 local tdiff=$(($end_time-$start_time))
2129 local hours=$(($tdiff / 3600 ))
2130 local mins=$((($tdiff % 3600) / 60))
2131 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002132 local ncolors=$(tput colors 2>/dev/null)
2133 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2134 color_failed="\e[0;31m"
2135 color_success="\e[0;32m"
2136 color_reset="\e[00m"
2137 else
2138 color_failed=""
2139 color_success=""
2140 color_reset=""
2141 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002142 echo
2143 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002144 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002145 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002146 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002147 fi
2148 if [ $hours -gt 0 ] ; then
2149 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2150 elif [ $mins -gt 0 ] ; then
2151 printf "(%02g:%02g (mm:ss))" $mins $secs
2152 elif [ $secs -gt 0 ] ; then
2153 printf "(%s seconds)" $secs
2154 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002155 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002156 echo
2157 return $ret
2158}
2159
Raphael Moll70a86b02011-06-20 16:03:14 -07002160if [ "x$SHELL" != "x/bin/bash" ]; then
2161 case `ps -o command -p $$` in
2162 *bash*)
2163 ;;
2164 *)
2165 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2166 ;;
2167 esac
2168fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002169
2170# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002171for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2172 `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 -08002173do
2174 echo "including $f"
2175 . $f
2176done
2177unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002178
2179addcompletions