blob: c572c16bdf394b362f04b0d379c4337cd48538eb [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
Christopher Laisfa8d9352013-06-03 15:15:39 -0500284 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800285 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
cybojenixa5dd6ce2013-06-28 20:30:00 +0100526 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800527 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100528 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529
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
Chirayu Desaib89b3242013-06-30 10:04:25 +0530660 fixup_common_out_dir
661
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800663 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664}
665
Jeff Davidson513d7a42010-08-02 10:00:44 -0700666# Tab completion for lunch.
667function _lunch()
668{
669 local cur prev opts
670 COMPREPLY=()
671 cur="${COMP_WORDS[COMP_CWORD]}"
672 prev="${COMP_WORDS[COMP_CWORD-1]}"
673
674 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
675 return 0
676}
677complete -F _lunch lunch
678
Joe Onoratoda12daf2010-06-09 18:18:31 -0700679# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700680# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700681function tapas()
682{
Ying Wangb541ab62014-05-29 17:57:40 -0700683 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 -0700684 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700685 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
686 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 -0700687
Ying Wang67f02922012-08-22 10:25:20 -0700688 if [ $(echo $arch | wc -w) -gt 1 ]; then
689 echo "tapas: Error: Multiple build archs supplied: $arch"
690 return
691 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700692 if [ $(echo $variant | wc -w) -gt 1 ]; then
693 echo "tapas: Error: Multiple build variants supplied: $variant"
694 return
695 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700696 if [ $(echo $density | wc -w) -gt 1 ]; then
697 echo "tapas: Error: Multiple densities supplied: $density"
698 return
699 fi
Ying Wang67f02922012-08-22 10:25:20 -0700700
701 local product=full
702 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700703 x86) product=full_x86;;
704 mips) product=full_mips;;
705 armv5) product=generic_armv5;;
706 arm64) product=aosp_arm64;;
707 x86_64) product=aosp_x86_64;;
708 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700709 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700710 if [ -z "$variant" ]; then
711 variant=eng
712 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700713 if [ -z "$apps" ]; then
714 apps=all
715 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600716 if [ -z "$density" ]; then
717 density=alldpi
718 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700719
Ying Wang67f02922012-08-22 10:25:20 -0700720 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700721 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700722 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700723 export TARGET_BUILD_TYPE=release
724 export TARGET_BUILD_APPS=$apps
725
726 set_stuff_for_environment
727 printconfig
728}
729
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100730function eat()
731{
732 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530733 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100734 ZIPFILE=cm-$MODVERSION.zip
735 ZIPPATH=$OUT/$ZIPFILE
736 if [ ! -f $ZIPPATH ] ; then
737 echo "Nothing to eat"
738 return 1
739 fi
740 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
741 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
742 echo "No device is online. Waiting for one..."
743 echo "Please connect USB and/or enable USB debugging"
744 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
745 sleep 1
746 done
747 echo "Device Found.."
748 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530749 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
750 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100751 # if adbd isn't root we can't write to /cache/recovery/
752 adb root
753 sleep 1
754 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700755 cat << EOF > /tmp/command
756--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100757EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700758 if adb push /tmp/command /cache/recovery/ ; then
759 echo "Rebooting into recovery for sideload installation"
760 adb reboot recovery
761 adb wait-for-sideload
762 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100763 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700764 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100765 else
766 echo "Nothing to eat"
767 return 1
768 fi
769 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530770 else
771 echo "The connected device does not appear to be $CM_BUILD, run away!"
772 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100773}
774
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000775function omnom
776{
777 brunch $*
778 eat
779}
780
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781function gettop
782{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800783 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700785 # The following circumlocution ensures we remove symlinks from TOP.
786 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787 else
788 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800789 # The following circumlocution (repeated below as well) ensures
790 # that we record the true directory name and not one that is
791 # faked up with symlink names.
792 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800794 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700795 T=
796 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800797 \cd ..
synergyb112a402013-07-05 19:47:47 -0700798 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799 done
Ying Wang9cd17642012-12-13 10:52:07 -0800800 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 if [ -f "$T/$TOPFILE" ]; then
802 echo $T
803 fi
804 fi
805 fi
806}
807
Andrew Hsieh906cb782013-09-10 17:37:14 +0800808# Return driver for "make", if any (eg. static analyzer)
809function getdriver()
810{
811 local T="$1"
812 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
813 if [ -n "$WITH_STATIC_ANALYZER" ]; then
814 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800815$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
816--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800817--status-bugs \
818--top=$T"
819 fi
820}
821
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822function m()
823{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800824 local T=$(gettop)
825 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700826 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800827 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700828 else
829 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700830 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831 fi
832}
833
834function findmakefile()
835{
836 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800837 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838 T=
839 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700840 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700841 if [ -f "$T/Android.mk" ]; then
842 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800843 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844 return
845 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800846 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847 done
Ying Wang9cd17642012-12-13 10:52:07 -0800848 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700849}
850
851function mm()
852{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800853 local T=$(gettop)
854 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855 # If we're sitting in the root of the build tree, just do a
856 # normal make.
857 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800858 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700859 else
860 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800861 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700862 local MODULES=
863 local GET_INSTALL_PATH=
864 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700865 # Remove the path to top as the makefilepath needs to be relative
866 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867 if [ ! "$T" ]; then
868 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700869 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870 elif [ ! "$M" ]; then
871 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700872 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873 else
Ying Wanga7deb082013-08-16 13:24:47 -0700874 for ARG in $@; do
875 case $ARG in
876 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
877 esac
878 done
879 if [ -n "$GET_INSTALL_PATH" ]; then
880 MODULES=
881 ARGS=GET-INSTALL-PATH
882 else
883 MODULES=all_modules
884 ARGS=$@
885 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700886 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 -0700887 fi
888 fi
889}
890
891function mmm()
892{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800893 local T=$(gettop)
894 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700895 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800896 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800897 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800898 local ARGS=
899 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700900 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800901 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
902 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
903 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800904 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
905 if [ "$MODULES" = "" ]; then
906 MODULES=all_modules
907 fi
908 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700910 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
911 local TO_CHOP=`expr $TO_CHOP + 1`
912 local START=`PWD= /bin/pwd`
913 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700914 if [ "$MFILE" = "" ] ; then
915 MFILE=$DIR/Android.mk
916 else
917 MFILE=$MFILE/$DIR/Android.mk
918 fi
919 MAKEFILE="$MAKEFILE $MFILE"
920 else
Ying Wanga7deb082013-08-16 13:24:47 -0700921 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100922 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700923 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
924 *) echo "No Android.mk in $DIR."; return 1;;
925 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700926 fi
927 done
Ying Wanga7deb082013-08-16 13:24:47 -0700928 if [ -n "$GET_INSTALL_PATH" ]; then
929 ARGS=$GET_INSTALL_PATH
930 MODULES=
931 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800932 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 -0700933 else
934 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700935 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700936 fi
937}
938
Ying Wangb607f7b2013-02-08 18:01:04 -0800939function mma()
940{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800941 local T=$(gettop)
942 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800943 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800944 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800945 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800946 if [ ! "$T" ]; then
947 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700948 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800949 fi
950 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800951 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800952 fi
953}
954
955function mmma()
956{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800957 local T=$(gettop)
958 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800959 if [ "$T" ]; then
960 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
961 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
962 local MY_PWD=`PWD= /bin/pwd`
963 if [ "$MY_PWD" = "$T" ]; then
964 MY_PWD=
965 else
966 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
967 fi
968 local DIR=
969 local MODULE_PATHS=
970 local ARGS=
971 for DIR in $DIRS ; do
972 if [ -d $DIR ]; then
973 if [ "$MY_PWD" = "" ]; then
974 MODULE_PATHS="$MODULE_PATHS $DIR"
975 else
976 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
977 fi
978 else
979 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100980 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800981 *) echo "Couldn't find directory $DIR"; return 1;;
982 esac
983 fi
984 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800985 $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 -0800986 else
987 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700988 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800989 fi
990}
991
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992function croot()
993{
994 T=$(gettop)
995 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800996 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700997 else
998 echo "Couldn't locate the top of the tree. Try setting TOP."
999 fi
1000}
1001
nebkatfb67a1e2012-12-28 10:40:45 +00001002function cout()
1003{
1004 if [ "$OUT" ]; then
1005 cd $OUT
1006 else
1007 echo "Couldn't locate out directory. Try setting OUT."
1008 fi
1009}
1010
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001011function cproj()
1012{
1013 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001014 local HERE=$PWD
1015 T=
1016 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1017 T=$PWD
1018 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001019 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 return
1021 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001022 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001023 done
Ying Wang9cd17642012-12-13 10:52:07 -08001024 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001025 echo "can't find Android.mk"
1026}
1027
Daniel Sandler47e0a882013-07-30 13:23:52 -04001028# simplified version of ps; output in the form
1029# <pid> <procname>
1030function qpid() {
1031 local prepend=''
1032 local append=''
1033 if [ "$1" = "--exact" ]; then
1034 prepend=' '
1035 append='$'
1036 shift
1037 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1038 echo "usage: qpid [[--exact] <process name|pid>"
1039 return 255
1040 fi
1041
1042 local EXE="$1"
1043 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001044 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001045 else
1046 adb shell ps \
1047 | tr -d '\r' \
1048 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1049 fi
1050}
1051
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001052function pid()
1053{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001054 local prepend=''
1055 local append=''
1056 if [ "$1" = "--exact" ]; then
1057 prepend=' '
1058 append='$'
1059 shift
1060 fi
1061 local EXE="$1"
1062 if [ "$EXE" ] ; then
1063 local PID=`adb shell ps \
1064 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001065 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001066 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1067 echo "$PID"
1068 else
1069 echo "usage: pid [--exact] <process name>"
1070 return 255
1071 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001072}
1073
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001074# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075# that has the core-file-size limit set correctly
1076#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001077# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001078# if its core-file-size limit is not set already.
1079# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1080
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001081function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001082{
1083 echo "Getting root...";
1084 adb root;
1085 adb wait-for-device;
1086
1087 echo "Remounting root parition read-write...";
1088 adb shell mount -w -o remount -t rootfs rootfs;
1089 sleep 1;
1090 adb wait-for-device;
1091 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001092 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001093 adb shell chmod 0777 /cores;
1094
1095 echo "Granting SELinux permission to dump in /cores...";
1096 adb shell restorecon -R /cores;
1097
1098 echo "Set core pattern.";
1099 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1100
1101 echo "Done."
1102}
1103
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001104# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001105# $1 = PID of process (e.g., $(pid mediaserver))
1106#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001107# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001108# dump to actually be generated.
1109
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001110function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001111{
1112 local PID=$1;
1113 if [ -z "$PID" ]; then
1114 printf "Expecting a PID!\n";
1115 return;
1116 fi;
1117 echo "Setting core limit for $PID to infinite...";
1118 adb shell prlimit $PID 4 -1 -1
1119}
1120
1121# core - send SIGV and pull the core for process
1122# $1 = PID of process (e.g., $(pid mediaserver))
1123#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001124# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001125# enabled globally.
1126
1127function core()
1128{
1129 local PID=$1;
1130
1131 if [ -z "$PID" ]; then
1132 printf "Expecting a PID!\n";
1133 return;
1134 fi;
1135
1136 local CORENAME=core.$PID;
1137 local COREPATH=/cores/$CORENAME;
1138 local SIG=SEGV;
1139
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001140 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001141
1142 local done=0;
1143 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1144 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1145 adb shell kill -$SIG $PID;
1146 sleep 1;
1147 done;
1148
1149 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1150 echo "Done: core is under $COREPATH on device.";
1151}
1152
Christopher Tate744ee802009-11-12 15:33:08 -08001153# systemstack - dump the current stack trace of all threads in the system process
1154# to the usual ANR traces file
1155function systemstack()
1156{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001157 stacks system_server
1158}
1159
1160function stacks()
1161{
1162 if [[ $1 =~ ^[0-9]+$ ]] ; then
1163 local PID="$1"
1164 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001165 local PIDLIST="$(pid $1)"
1166 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1167 local PID="$PIDLIST"
1168 elif [ "$PIDLIST" ] ; then
1169 echo "more than one process: $1"
1170 else
1171 echo "no such process: $1"
1172 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001173 else
1174 echo "usage: stacks [pid|process name]"
1175 fi
1176
1177 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001178 # Determine whether the process is native
1179 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1180 # Dump stacks of Dalvik process
1181 local TRACES=/data/anr/traces.txt
1182 local ORIG=/data/anr/traces.orig
1183 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001184
Jeff Brownb12c2e52013-08-19 15:14:16 -07001185 # Keep original traces to avoid clobbering
1186 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001187
Jeff Brownb12c2e52013-08-19 15:14:16 -07001188 # Make sure we have a usable file
1189 adb shell touch $TRACES
1190 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001191
Jeff Brownb12c2e52013-08-19 15:14:16 -07001192 # Dump stacks and wait for dump to finish
1193 adb shell kill -3 $PID
1194 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001195
Jeff Brownb12c2e52013-08-19 15:14:16 -07001196 # Restore original stacks, and show current output
1197 adb shell mv $TRACES $TMP
1198 adb shell mv $ORIG $TRACES
1199 adb shell cat $TMP
1200 else
1201 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001202 local USE64BIT="$(is64bit $PID)"
1203 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001204 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001205 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001206}
1207
Michael Wrightaeed7212014-06-19 19:58:12 -07001208# Read the ELF header from /proc/$PID/exe to determine if the process is
1209# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001210function is64bit()
1211{
1212 local PID="$1"
1213 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001214 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001215 echo "64"
1216 else
1217 echo ""
1218 fi
1219 else
1220 echo ""
1221 fi
1222}
1223
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001224case `uname -s` in
1225 Darwin)
1226 function sgrep()
1227 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001228 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 -07001229 }
1230
1231 ;;
1232 *)
1233 function sgrep()
1234 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001235 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 -07001236 }
1237 ;;
1238esac
1239
Raghu Gandham8da43102012-07-25 19:57:22 -07001240function gettargetarch
1241{
1242 get_build_var TARGET_ARCH
1243}
1244
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001245function ggrep()
1246{
1247 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1248}
1249
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001250function jgrep()
1251{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001252 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 -07001253}
1254
1255function cgrep()
1256{
Dan Albert01961192014-11-22 10:16:01 -08001257 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 -07001258}
1259
1260function resgrep()
1261{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001262 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 -07001263}
1264
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001265function mangrep()
1266{
1267 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1268}
1269
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001270function sepgrep()
1271{
1272 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 "$@"
1273}
1274
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001275function rcgrep()
1276{
1277 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1278}
1279
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001280case `uname -s` in
1281 Darwin)
1282 function mgrep()
1283 {
Ying Wang324c2b22012-08-17 15:03:20 -07001284 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 -07001285 }
1286
1287 function treegrep()
1288 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001289 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 -07001290 }
1291
1292 ;;
1293 *)
1294 function mgrep()
1295 {
Ying Wang324c2b22012-08-17 15:03:20 -07001296 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 -07001297 }
1298
1299 function treegrep()
1300 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001301 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 -07001302 }
1303
1304 ;;
1305esac
1306
1307function getprebuilt
1308{
1309 get_abs_build_var ANDROID_PREBUILTS
1310}
1311
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001312function tracedmdump()
1313{
1314 T=$(gettop)
1315 if [ ! "$T" ]; then
1316 echo "Couldn't locate the top of the tree. Try setting TOP."
1317 return
1318 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001319 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001320 local arch=$(gettargetarch)
1321 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001323 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001324 if [ ! "$TRACE" ] ; then
1325 echo "usage: tracedmdump tracename"
1326 return
1327 fi
1328
Jack Veenstra60116fc2009-04-09 18:12:34 -07001329 if [ ! -r "$KERNEL" ] ; then
1330 echo "Error: cannot find kernel: '$KERNEL'"
1331 return
1332 fi
1333
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001334 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001335 if [ "$BASETRACE" = "$TRACE" ] ; then
1336 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1337 fi
1338
1339 echo "post-processing traces..."
1340 rm -f $TRACE/qtrace.dexlist
1341 post_trace $TRACE
1342 if [ $? -ne 0 ]; then
1343 echo "***"
1344 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1345 echo "***"
1346 return
1347 fi
1348 echo "generating dexlist output..."
1349 /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
1350 echo "generating dmtrace data..."
1351 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1352 echo "generating html file..."
1353 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1354 echo "done, see $TRACE/dmtrace.html for details"
1355 echo "or run:"
1356 echo " traceview $TRACE/dmtrace"
1357}
1358
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001359# communicate with a running device or emulator, set up necessary state,
1360# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001361function runhat()
1362{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001363 # process standard adb options
1364 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001365 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001366 adbTarget=$1
1367 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001368 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001369 adbTarget="$1 $2"
1370 shift 2
1371 fi
1372 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001373 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001374
1375 # runhat options
1376 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377
1378 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001379 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380 return
1381 fi
1382
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001383 # confirm hat is available
1384 if [ -z $(which hat) ]; then
1385 echo "hat is not available in this configuration."
1386 return
1387 fi
1388
Andy McFaddenb6289852010-07-12 08:00:19 -07001389 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001390 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001391 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001392 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001393 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001394 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001395 echo -n "> "
1396 read
1397
The Android Open Source Project88b60792009-03-03 19:28:42 -08001398 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001399
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400 echo "Retrieving file $devFile..."
1401 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001402
The Android Open Source Project88b60792009-03-03 19:28:42 -08001403 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001404
The Android Open Source Project88b60792009-03-03 19:28:42 -08001405 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001406 echo "View the output by pointing your browser at http://localhost:7000/"
1407 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001408 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001409}
1410
1411function getbugreports()
1412{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001413 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001414
1415 if [ ! "$reports" ]; then
1416 echo "Could not locate any bugreports."
1417 return
1418 fi
1419
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001420 local report
1421 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001422 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001423 echo "/sdcard/bugreports/${report}"
1424 adb pull /sdcard/bugreports/${report} ${report}
1425 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001426 done
1427}
1428
Victoria Lease1b296b42012-08-21 15:44:06 -07001429function getsdcardpath()
1430{
1431 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1432}
1433
1434function getscreenshotpath()
1435{
1436 echo "$(getsdcardpath)/Pictures/Screenshots"
1437}
1438
1439function getlastscreenshot()
1440{
1441 local screenshot_path=$(getscreenshotpath)
1442 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1443 if [ "$screenshot" = "" ]; then
1444 echo "No screenshots found."
1445 return
1446 fi
1447 echo "${screenshot}"
1448 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1449}
1450
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001451function startviewserver()
1452{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001453 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001454 if [ $# -gt 0 ]; then
1455 port=$1
1456 fi
1457 adb shell service call window 1 i32 $port
1458}
1459
1460function stopviewserver()
1461{
1462 adb shell service call window 2
1463}
1464
1465function isviewserverstarted()
1466{
1467 adb shell service call window 3
1468}
1469
Romain Guyb84049a2010-10-04 16:56:11 -07001470function key_home()
1471{
1472 adb shell input keyevent 3
1473}
1474
1475function key_back()
1476{
1477 adb shell input keyevent 4
1478}
1479
1480function key_menu()
1481{
1482 adb shell input keyevent 82
1483}
1484
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001485function smoketest()
1486{
1487 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1488 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1489 return
1490 fi
1491 T=$(gettop)
1492 if [ ! "$T" ]; then
1493 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1494 return
1495 fi
1496
Ying Wang9cd17642012-12-13 10:52:07 -08001497 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001498 adb uninstall com.android.smoketest > /dev/null &&
1499 adb uninstall com.android.smoketest.tests > /dev/null &&
1500 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1501 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1502 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1503}
1504
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001505# simple shortcut to the runtest command
1506function runtest()
1507{
1508 T=$(gettop)
1509 if [ ! "$T" ]; then
1510 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1511 return
1512 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001513 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001514}
1515
The Android Open Source Project88b60792009-03-03 19:28:42 -08001516function godir () {
1517 if [[ -z "$1" ]]; then
1518 echo "Usage: godir <regex>"
1519 return
1520 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001521 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001522 if [[ ! -f $T/filelist ]]; then
1523 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001524 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001525 echo " Done"
1526 echo ""
1527 fi
1528 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001529 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001530 if [[ ${#lines[@]} = 0 ]]; then
1531 echo "Not found"
1532 return
1533 fi
1534 local pathname
1535 local choice
1536 if [[ ${#lines[@]} > 1 ]]; then
1537 while [[ -z "$pathname" ]]; do
1538 local index=1
1539 local line
1540 for line in ${lines[@]}; do
1541 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001542 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001543 done
1544 echo
1545 echo -n "Select one: "
1546 unset choice
1547 read choice
1548 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1549 echo "Invalid choice"
1550 continue
1551 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001552 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001553 done
1554 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001555 pathname=${lines[0]}
1556 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001557 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001558}
1559
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001560function cmremote()
1561{
1562 git remote rm cmremote 2> /dev/null
1563 if [ ! -d .git ]
1564 then
1565 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1566 fi
1567 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1568 if [ -z "$GERRIT_REMOTE" ]
1569 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001570 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1571 if [ -z "$GERRIT_REMOTE" ]
1572 then
1573 echo Unable to set up the git remote, are you in the root of the repo?
1574 return 0
1575 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001576 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001577 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001578 if [ -z "$CMUSER" ]
1579 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001580 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001581 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001582 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001583 fi
1584 echo You can now push to "cmremote".
1585}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001586export -f cmremote
1587
Steve Kondik873fa562012-09-17 11:33:18 -07001588function aospremote()
1589{
1590 git remote rm aosp 2> /dev/null
1591 if [ ! -d .git ]
1592 then
1593 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1594 fi
1595 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1596 if (echo $PROJECT | grep -qv "^device")
1597 then
1598 PFX="platform/"
1599 fi
1600 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1601 echo "Remote 'aosp' created"
1602}
1603export -f aospremote
1604
Steve Kondikf00e7d92012-09-23 23:46:55 -07001605function installboot()
1606{
1607 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1608 then
1609 echo "No recovery.fstab found. Build recovery first."
1610 return 1
1611 fi
1612 if [ ! -e "$OUT/boot.img" ];
1613 then
1614 echo "No boot.img found. Run make bootimage first."
1615 return 1
1616 fi
1617 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1618 if [ -z "$PARTITION" ];
1619 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001620 # Try for RECOVERY_FSTAB_VERSION = 2
1621 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1622 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1623 if [ -z "$PARTITION" ];
1624 then
1625 echo "Unable to determine boot partition."
1626 return 1
1627 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001628 fi
1629 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001630 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001631 adb root
1632 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001633 adb wait-for-online shell mount /system 2>&1 > /dev/null
1634 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001635 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1636 then
1637 adb push $OUT/boot.img /cache/
1638 for i in $OUT/system/lib/modules/*;
1639 do
1640 adb push $i /system/lib/modules/
1641 done
1642 adb shell dd if=/cache/boot.img of=$PARTITION
1643 adb shell chmod 644 /system/lib/modules/*
1644 echo "Installation complete."
1645 else
1646 echo "The connected device does not appear to be $CM_BUILD, run away!"
1647 fi
1648}
1649
Steve Kondik83c03d52012-10-24 16:40:42 -07001650function installrecovery()
1651{
1652 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1653 then
1654 echo "No recovery.fstab found. Build recovery first."
1655 return 1
1656 fi
1657 if [ ! -e "$OUT/recovery.img" ];
1658 then
1659 echo "No recovery.img found. Run make recoveryimage first."
1660 return 1
1661 fi
1662 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1663 if [ -z "$PARTITION" ];
1664 then
Steve Kondik75f10762013-08-09 21:03:42 -07001665 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001666 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1667 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001668 if [ -z "$PARTITION" ];
1669 then
1670 echo "Unable to determine recovery partition."
1671 return 1
1672 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001673 fi
1674 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001675 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001676 adb root
1677 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001678 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1679 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001680 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1681 then
1682 adb push $OUT/recovery.img /cache/
1683 adb shell dd if=/cache/recovery.img of=$PARTITION
1684 echo "Installation complete."
1685 else
1686 echo "The connected device does not appear to be $CM_BUILD, run away!"
1687 fi
1688}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001689
Koushik Duttab55f13a2012-05-14 16:14:36 -07001690function makerecipe() {
1691 if [ -z "$1" ]
1692 then
1693 echo "No branch name provided."
1694 return 1
1695 fi
1696 cd android
1697 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1698 git commit -a -m "$1"
1699 cd ..
1700
1701 repo forall -c '
1702
1703 if [ "$REPO_REMOTE" == "github" ]
1704 then
1705 pwd
1706 cmremote
1707 git push cmremote HEAD:refs/heads/'$1'
1708 fi
1709 '
1710}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001711
1712function cmgerrit() {
1713 if [ $# -eq 0 ]; then
1714 $FUNCNAME help
1715 return 1
1716 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001717 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001718 local review=`git config --get remote.github.review`
1719 local project=`git config --get remote.github.projectname`
1720 local command=$1
1721 shift
1722 case $command in
1723 help)
1724 if [ $# -eq 0 ]; then
1725 cat <<EOF
1726Usage:
1727 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1728
1729Commands:
1730 fetch Just fetch the change as FETCH_HEAD
1731 help Show this help, or for a specific command
1732 pull Pull a change into current branch
1733 push Push HEAD or a local branch to Gerrit for a specific branch
1734
1735Any other Git commands that support refname would work as:
1736 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1737
1738See '$FUNCNAME help COMMAND' for more information on a specific command.
1739
1740Example:
1741 $FUNCNAME checkout -b topic 1234/5
1742works as:
1743 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1744 && git checkout -b topic FETCH_HEAD
1745will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1746Patch-set 1 will be fetched if omitted.
1747EOF
1748 return
1749 fi
1750 case $1 in
1751 __cmg_*) echo "For internal use only." ;;
1752 changes|for)
1753 if [ "$FUNCNAME" = "cmgerrit" ]; then
1754 echo "'$FUNCNAME $1' is deprecated."
1755 fi
1756 ;;
1757 help) $FUNCNAME help ;;
1758 fetch|pull) cat <<EOF
1759usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1760
1761works as:
1762 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1763 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1764
1765Example:
1766 $FUNCNAME $1 1234
1767will $1 patch-set 1 of change 1234
1768EOF
1769 ;;
1770 push) cat <<EOF
1771usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1772
1773works as:
1774 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1775 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1776
1777Example:
1778 $FUNCNAME push fix6789:gingerbread
1779will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1780HEAD will be pushed from local if omitted.
1781EOF
1782 ;;
1783 *)
1784 $FUNCNAME __cmg_err_not_supported $1 && return
1785 cat <<EOF
1786usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1787
1788works as:
1789 git fetch http://DOMAIN/p/PROJECT \\
1790 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1791 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1792EOF
1793 ;;
1794 esac
1795 ;;
1796 __cmg_get_ref)
1797 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1798 local change_id patchset_id hash
1799 case $1 in
1800 */*)
1801 change_id=${1%%/*}
1802 patchset_id=${1#*/}
1803 ;;
1804 *)
1805 change_id=$1
1806 patchset_id=1
1807 ;;
1808 esac
1809 hash=$(($change_id % 100))
1810 case $hash in
1811 [0-9]) hash="0$hash" ;;
1812 esac
1813 echo "refs/changes/$hash/$change_id/$patchset_id"
1814 ;;
1815 fetch|pull)
1816 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1817 $FUNCNAME __cmg_err_not_repo && return 1
1818 local change=$1
1819 shift
1820 git $command $@ http://$review/p/$project \
1821 $($FUNCNAME __cmg_get_ref $change) || return 1
1822 ;;
1823 push)
1824 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1825 $FUNCNAME __cmg_err_not_repo && return 1
1826 if [ -z "$user" ]; then
1827 echo >&2 "Gerrit username not found."
1828 return 1
1829 fi
1830 local local_branch remote_branch
1831 case $1 in
1832 *:*)
1833 local_branch=${1%:*}
1834 remote_branch=${1##*:}
1835 ;;
1836 *)
1837 local_branch=HEAD
1838 remote_branch=$1
1839 ;;
1840 esac
1841 shift
1842 git push $@ ssh://$user@$review:29418/$project \
1843 $local_branch:refs/for/$remote_branch || return 1
1844 ;;
1845 changes|for)
1846 if [ "$FUNCNAME" = "cmgerrit" ]; then
1847 echo >&2 "'$FUNCNAME $command' is deprecated."
1848 fi
1849 ;;
1850 __cmg_err_no_arg)
1851 if [ $# -lt 2 ]; then
1852 echo >&2 "'$FUNCNAME $command' missing argument."
1853 elif [ $2 -eq 0 ]; then
1854 if [ -n "$3" ]; then
1855 $FUNCNAME help $1
1856 else
1857 echo >&2 "'$FUNCNAME $1' missing argument."
1858 fi
1859 else
1860 return 1
1861 fi
1862 ;;
1863 __cmg_err_not_repo)
1864 if [ -z "$review" -o -z "$project" ]; then
1865 echo >&2 "Not currently in any reviewable repository."
1866 else
1867 return 1
1868 fi
1869 ;;
1870 __cmg_err_not_supported)
1871 $FUNCNAME __cmg_err_no_arg $command $# && return
1872 case $1 in
1873 #TODO: filter more git commands that don't use refname
1874 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1875 echo >&2 "'$FUNCNAME $1' is not supported."
1876 ;;
1877 *) return 1 ;;
1878 esac
1879 ;;
1880 #TODO: other special cases?
1881 *)
1882 $FUNCNAME __cmg_err_not_supported $command && return 1
1883 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1884 $FUNCNAME __cmg_err_not_repo && return 1
1885 local args="$@"
1886 local change pre_args refs_arg post_args
1887 case "$args" in
1888 *--\ *)
1889 pre_args=${args%%-- *}
1890 post_args="-- ${args#*-- }"
1891 ;;
1892 *) pre_args="$args" ;;
1893 esac
1894 args=($pre_args)
1895 pre_args=
1896 if [ ${#args[@]} -gt 0 ]; then
1897 change=${args[${#args[@]}-1]}
1898 fi
1899 if [ ${#args[@]} -gt 1 ]; then
1900 pre_args=${args[0]}
1901 for ((i=1; i<${#args[@]}-1; i++)); do
1902 pre_args="$pre_args ${args[$i]}"
1903 done
1904 fi
1905 while ((1)); do
1906 case $change in
1907 ""|--)
1908 $FUNCNAME help $command
1909 return 1
1910 ;;
1911 *@*)
1912 if [ -z "$refs_arg" ]; then
1913 refs_arg="@${change#*@}"
1914 change=${change%%@*}
1915 fi
1916 ;;
1917 *~*)
1918 if [ -z "$refs_arg" ]; then
1919 refs_arg="~${change#*~}"
1920 change=${change%%~*}
1921 fi
1922 ;;
1923 *^*)
1924 if [ -z "$refs_arg" ]; then
1925 refs_arg="^${change#*^}"
1926 change=${change%%^*}
1927 fi
1928 ;;
1929 *:*)
1930 if [ -z "$refs_arg" ]; then
1931 refs_arg=":${change#*:}"
1932 change=${change%%:*}
1933 fi
1934 ;;
1935 *) break ;;
1936 esac
1937 done
1938 $FUNCNAME fetch $change \
1939 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1940 || return 1
1941 ;;
1942 esac
1943}
1944
1945function cmrebase() {
1946 local repo=$1
1947 local refs=$2
1948 local pwd="$(pwd)"
1949 local dir="$(gettop)/$repo"
1950
1951 if [ -z $repo ] || [ -z $refs ]; then
1952 echo "CyanogenMod Gerrit Rebase Usage: "
1953 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1954 echo " The patch IDs appear on the Gerrit commands that are offered."
1955 echo " They consist on a series of numbers and slashes, after the text"
1956 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1957 echo ""
1958 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1959 echo ""
1960 return
1961 fi
1962
1963 if [ ! -d $dir ]; then
1964 echo "Directory $dir doesn't exist in tree."
1965 return
1966 fi
1967 cd $dir
1968 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1969 echo "Starting branch..."
1970 repo start tmprebase .
1971 echo "Bringing it up to date..."
1972 repo sync .
1973 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001974 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001975 if [ "$?" != "0" ]; then
1976 echo "Error cherry-picking. Not uploading!"
1977 return
1978 fi
1979 echo "Uploading..."
1980 repo upload .
1981 echo "Cleaning up..."
1982 repo abandon tmprebase .
1983 cd $pwd
1984}
1985
1986function mka() {
1987 case `uname -s` in
1988 Darwin)
1989 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1990 ;;
1991 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001992 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001993 ;;
1994 esac
1995}
1996
1997function reposync() {
1998 case `uname -s` in
1999 Darwin)
2000 repo sync -j 4 "$@"
2001 ;;
2002 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002003 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002004 ;;
2005 esac
2006}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002007
2008function repodiff() {
2009 if [ -z "$*" ]; then
2010 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2011 return
2012 fi
2013 diffopts=$* repo forall -c \
2014 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2015}
2016
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302017# Credit for color strip sed: http://goo.gl/BoIcm
2018function dopush()
2019{
2020 local func=$1
2021 shift
2022
2023 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2024 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2025 echo "No device is online. Waiting for one..."
2026 echo "Please connect USB and/or enable USB debugging"
2027 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2028 sleep 1
2029 done
2030 echo "Device Found."
2031 fi
2032
Chirayu Desai6dadb572012-12-26 10:53:58 +05302033 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2034 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002035 # retrieve IP and PORT info if we're using a TCP connection
2036 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2037 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302038 adb root &> /dev/null
2039 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002040 if [ -n "$TCPIPPORT" ]
2041 then
2042 # adb root just killed our connection
2043 # so reconnect...
2044 adb connect "$TCPIPPORT"
2045 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302046 adb wait-for-device &> /dev/null
2047 sleep 0.3
2048 adb remount &> /dev/null
2049
2050 $func $* | tee $OUT/.log
2051
2052 # Install: <file>
2053 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)
2054
2055 # Copy: <file>
2056 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)
2057
2058 for FILE in $LOC; do
2059 # Get target file name (i.e. system/bin/adb)
2060 TARGET=$(echo $FILE | sed "s#$OUT/##")
2061
Chirayu Desai894076f2013-05-19 19:54:32 +05302062 # Don't send files that are not under /system or /data
2063 if [ ! "echo $TARGET | egrep '^system\/' > /dev/null" -o \
2064 "echo $TARGET | egrep '^data\/' > /dev/null" ] ; then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302065 continue
2066 else
2067 case $TARGET in
2068 system/app/SystemUI.apk|system/framework/*)
2069 stop_n_start=true
2070 ;;
2071 *)
2072 stop_n_start=false
2073 ;;
2074 esac
2075 if $stop_n_start ; then adb shell stop ; fi
2076 echo "Pushing: $TARGET"
2077 adb push $FILE $TARGET
2078 if $stop_n_start ; then adb shell start ; fi
2079 fi
2080 done
2081 rm -f $OUT/.log
2082 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302083 else
2084 echo "The connected device does not appear to be $CM_BUILD, run away!"
2085 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302086}
2087
2088alias mmp='dopush mm'
2089alias mmmp='dopush mmm'
2090alias mkap='dopush mka'
2091alias cmkap='dopush cmka'
2092
Chirayu Desai4a319b82013-06-05 20:14:33 +05302093function repopick() {
2094 T=$(gettop)
2095 $T/build/tools/repopick.py $@
2096}
2097
Chirayu Desaib89b3242013-06-30 10:04:25 +05302098function fixup_common_out_dir() {
2099 common_out_dir=$(get_build_var OUT_DIR)/target/common
2100 target_device=$(get_build_var TARGET_DEVICE)
2101 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2102 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2103 mv ${common_out_dir} ${common_out_dir}-${target_device}
2104 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2105 else
2106 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2107 mkdir -p ${common_out_dir}-${target_device}
2108 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2109 fi
2110 else
2111 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2112 mkdir -p ${common_out_dir}
2113 fi
2114}
2115
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002116# 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 +00002117#
2118# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2119# For some reason, installing the JDK doesn't make it show up in the
2120# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002121function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002122 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002123 # we can reset it later, depending on the version of java the build
2124 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002125 #
2126 # If we don't do this, the JAVA_HOME value set by the first call to
2127 # build/envsetup.sh will persist forever.
2128 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2129 export JAVA_HOME=""
2130 fi
2131
Andy McFaddenbd960942010-06-24 12:52:51 -07002132 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002133 case `uname -s` in
2134 Darwin)
2135 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2136 ;;
2137 *)
2138 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2139 ;;
2140 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002141
2142 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2143 # we can change it on the next envsetup.sh, if required.
2144 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002145 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002146}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002147
Alex Rayf0d08eb2013-03-08 15:15:06 -08002148# Print colored exit condition
2149function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002150 "$@"
2151 local retval=$?
2152 if [ $retval -ne 0 ]
2153 then
2154 echo -e "\e[0;31mFAILURE\e[00m"
2155 else
2156 echo -e "\e[0;32mSUCCESS\e[00m"
2157 fi
2158 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002159}
2160
Ying Wanged21d4c2014-08-24 22:14:19 -07002161function get_make_command()
2162{
2163 echo command make
2164}
2165
Ed Heylcc6be0a2014-06-18 14:55:58 -07002166function make()
2167{
2168 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002169 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002170 local ret=$?
2171 local end_time=$(date +"%s")
2172 local tdiff=$(($end_time-$start_time))
2173 local hours=$(($tdiff / 3600 ))
2174 local mins=$((($tdiff % 3600) / 60))
2175 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002176 local ncolors=$(tput colors 2>/dev/null)
2177 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2178 color_failed="\e[0;31m"
2179 color_success="\e[0;32m"
2180 color_reset="\e[00m"
2181 else
2182 color_failed=""
2183 color_success=""
2184 color_reset=""
2185 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002186 echo
2187 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002188 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002189 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002190 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002191 fi
2192 if [ $hours -gt 0 ] ; then
2193 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2194 elif [ $mins -gt 0 ] ; then
2195 printf "(%02g:%02g (mm:ss))" $mins $secs
2196 elif [ $secs -gt 0 ] ; then
2197 printf "(%s seconds)" $secs
2198 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002199 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002200 echo
2201 return $ret
2202}
2203
Raphael Moll70a86b02011-06-20 16:03:14 -07002204if [ "x$SHELL" != "x/bin/bash" ]; then
2205 case `ps -o command -p $$` in
2206 *bash*)
2207 ;;
2208 *)
2209 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2210 ;;
2211 esac
2212fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002213
2214# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002215for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2216 `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 -08002217do
2218 echo "including $f"
2219 . $f
2220done
2221unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002222
2223addcompletions