blob: 5d3ab3e246a8be469321c8067867913b7b01fb7f [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
Steve Kondik20c21d22013-10-27 13:34:36 -070028- cafremote: Add git remote for matching CodeAurora repository.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060029- mka: Builds using SCHED_BATCH on all processors
30- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053031- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070032- installboot: Installs a boot.img to the connected device.
33- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070034
Dan Albert4ae5d4b2014-10-31 16:23:08 -070035Environemnt options:
36- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
37 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
38 build is leak-check clean.
39
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070040Look at the source to view more functions. The complete list is:
41EOF
42 T=$(gettop)
43 local A
44 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070045 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 -070046 A="$A $i"
47 done
48 echo $A
49}
50
51# Get the value of a build variable as an absolute path.
52function get_abs_build_var()
53{
54 T=$(gettop)
55 if [ ! "$T" ]; then
56 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
57 return
58 fi
Ying Wang9cd17642012-12-13 10:52:07 -080059 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070060 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070061}
62
63# Get the exact value of a build variable.
64function get_build_var()
65{
66 T=$(gettop)
67 if [ ! "$T" ]; then
68 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
69 return
70 fi
Andrew Boie6905e212013-12-19 13:21:46 -080071 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070072 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080073}
74
75# check to see if the supplied product is one we can build
76function check_product()
77{
78 T=$(gettop)
79 if [ ! "$T" ]; then
80 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
81 return
82 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000083
84 if (echo -n $1 | grep -q -e "^cm_") ; then
85 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
Ricardo Cerqueira34ae3232013-09-26 00:10:20 +010086 export BUILD_NUMBER=$((date +%s%N ; echo $CM_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10)
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000087 else
88 CM_BUILD=
89 fi
90 export CM_BUILD
91
Jeff Browne33ba4c2011-07-11 22:11:46 -070092 TARGET_PRODUCT=$1 \
93 TARGET_BUILD_VARIANT= \
94 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070095 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080096 get_build_var TARGET_DEVICE > /dev/null
97 # hide successful answers, but allow the errors to show
98}
99
100VARIANT_CHOICES=(user userdebug eng)
101
102# check to see if the supplied variant is valid
103function check_variant()
104{
105 for v in ${VARIANT_CHOICES[@]}
106 do
107 if [ "$v" = "$1" ]
108 then
109 return 0
110 fi
111 done
112 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700113}
114
115function setpaths()
116{
117 T=$(gettop)
118 if [ ! "$T" ]; then
119 echo "Couldn't locate the top of the tree. Try setting TOP."
120 return
121 fi
122
123 ##################################################################
124 # #
125 # Read me before you modify this code #
126 # #
127 # This function sets ANDROID_BUILD_PATHS to what it is adding #
128 # to PATH, and the next time it is run, it removes that from #
129 # PATH. This is required so lunch can be run more than once #
130 # and still have working paths. #
131 # #
132 ##################################################################
133
Raphael Mollc639c782011-06-20 17:25:01 -0700134 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
135 # due to "C:\Program Files" being in the path.
136
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700138 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700139 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
140 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700141 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700142 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800143 # strip leading ':', if any
144 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500145 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700146
147 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700148 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700149 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700150
Ben Cheng8bc4c432012-11-16 13:29:13 -0800151 # defined in core/config.mk
152 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700153 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800154 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800155
Raphael Mollc639c782011-06-20 17:25:01 -0700156 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800157 export ANDROID_TOOLCHAIN=
158 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200159 local ARCH=$(get_build_var TARGET_ARCH)
160 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400161 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700162 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400163 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
164 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800165 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200166 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800167 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700168 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700169 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700170 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000171 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200172 *)
173 echo "Can't find toolchain for unknown architecture: $ARCH"
174 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700175 ;;
176 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700177 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800178 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700179 fi
Raphael732936d2011-06-22 14:35:32 -0700180
Ben Chengfba67bf2014-02-25 10:27:07 -0800181 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
182 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
183 fi
184
185 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700186 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700187 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800188 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800189 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700190 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100191 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
192 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700193 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700194 ;;
195 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700196 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700197 ;;
198 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700199
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700200 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700201 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 +0200202
203 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
204 # to ensure that the corresponding 'emulator' binaries are used.
205 case $(uname -s) in
206 Darwin)
207 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
208 ;;
209 Linux)
210 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
211 ;;
212 *)
213 ANDROID_EMULATOR_PREBUILTS=
214 ;;
215 esac
216 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700217 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200218 export ANDROID_EMULATOR_PREBUILTS
219 fi
220
Ying Wangaa1c9b52012-11-26 20:51:59 -0800221 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800222
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500223 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900224 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500225 if [ -n "$JAVA_HOME" ]; then
226 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900227 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
228 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500229 fi
230
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800231 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700232 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
233 export OUT=$ANDROID_PRODUCT_OUT
234
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700235 unset ANDROID_HOST_OUT
236 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
237
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239 # TODO: fix the path
240 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
241}
242
243function printconfig()
244{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800245 T=$(gettop)
246 if [ ! "$T" ]; then
247 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
248 return
249 fi
250 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700251}
252
253function set_stuff_for_environment()
254{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800255 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500256 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800257 setpaths
258 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700259
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800260 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700261 # With this environment variable new GCC can apply colors to warnings/errors
262 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 -0700263 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700264}
265
266function set_sequence_number()
267{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700268 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700269}
270
271function settitle()
272{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800273 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700274 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700275 local product=$TARGET_PRODUCT
276 local variant=$TARGET_BUILD_VARIANT
277 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800278 if [ -z "$PROMPT_COMMAND" ]; then
279 # No prompts
280 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
281 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
282 # Prompts exist, but no hardstatus
283 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700284 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800285 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500286 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800287 fi
288
289 if [ -z "$apps" ]; then
290 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
291 else
292 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
293 fi
294 export ANDROID_PROMPT_PREFIX
295
296 # Inject build data into hardstatus
297 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 -0800298 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700299}
300
Kenny Root52aa81c2011-07-15 11:07:06 -0700301function addcompletions()
302{
303 local T dir f
304
305 # Keep us from trying to run in something that isn't bash.
306 if [ -z "${BASH_VERSION}" ]; then
307 return
308 fi
309
310 # Keep us from trying to run in bash that's too old.
311 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
312 return
313 fi
314
Chirayu Desai20a61372013-03-16 20:00:17 +0530315 dirs="sdk/bash_completion vendor/cm/bash_completion"
316 for dir in $dirs; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700317 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700318 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700319 echo "including $f"
320 . $f
321 done
322 fi
Chirayu Desai20a61372013-03-16 20:00:17 +0530323 done
Kenny Root52aa81c2011-07-15 11:07:06 -0700324}
325
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700326function choosetype()
327{
328 echo "Build type choices are:"
329 echo " 1. release"
330 echo " 2. debug"
331 echo
332
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700334 DEFAULT_NUM=1
335 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700336
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800337 export TARGET_BUILD_TYPE=
338 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 while [ -z $TARGET_BUILD_TYPE ]
340 do
341 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800342 if [ -z "$1" ] ; then
343 read ANSWER
344 else
345 echo $1
346 ANSWER=$1
347 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700348 case $ANSWER in
349 "")
350 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
351 ;;
352 1)
353 export TARGET_BUILD_TYPE=release
354 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800355 release)
356 export TARGET_BUILD_TYPE=release
357 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700358 2)
359 export TARGET_BUILD_TYPE=debug
360 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800361 debug)
362 export TARGET_BUILD_TYPE=debug
363 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 *)
365 echo
366 echo "I didn't understand your response. Please try again."
367 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368 ;;
369 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800370 if [ -n "$1" ] ; then
371 break
372 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700373 done
374
375 set_stuff_for_environment
376}
377
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800378#
379# This function isn't really right: It chooses a TARGET_PRODUCT
380# based on the list of boards. Usually, that gets you something
381# that kinda works with a generic product, but really, you should
382# pick a product by name.
383#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384function chooseproduct()
385{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700386 if [ "x$TARGET_PRODUCT" != x ] ; then
387 default_value=$TARGET_PRODUCT
388 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700389 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700390 fi
391
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800392 export TARGET_PRODUCT=
393 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700394 while [ -z "$TARGET_PRODUCT" ]
395 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700396 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800397 if [ -z "$1" ] ; then
398 read ANSWER
399 else
400 echo $1
401 ANSWER=$1
402 fi
403
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700404 if [ -z "$ANSWER" ] ; then
405 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800406 else
407 if check_product $ANSWER
408 then
409 export TARGET_PRODUCT=$ANSWER
410 else
411 echo "** Not a valid product: $ANSWER"
412 fi
413 fi
414 if [ -n "$1" ] ; then
415 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700416 fi
417 done
418
419 set_stuff_for_environment
420}
421
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800422function choosevariant()
423{
424 echo "Variant choices are:"
425 local index=1
426 local v
427 for v in ${VARIANT_CHOICES[@]}
428 do
429 # The product name is the name of the directory containing
430 # the makefile we found, above.
431 echo " $index. $v"
432 index=$(($index+1))
433 done
434
435 local default_value=eng
436 local ANSWER
437
438 export TARGET_BUILD_VARIANT=
439 while [ -z "$TARGET_BUILD_VARIANT" ]
440 do
441 echo -n "Which would you like? [$default_value] "
442 if [ -z "$1" ] ; then
443 read ANSWER
444 else
445 echo $1
446 ANSWER=$1
447 fi
448
449 if [ -z "$ANSWER" ] ; then
450 export TARGET_BUILD_VARIANT=$default_value
451 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
452 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800453 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800454 fi
455 else
456 if check_variant $ANSWER
457 then
458 export TARGET_BUILD_VARIANT=$ANSWER
459 else
460 echo "** Not a valid variant: $ANSWER"
461 fi
462 fi
463 if [ -n "$1" ] ; then
464 break
465 fi
466 done
467}
468
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700469function choosecombo()
470{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700471 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700472
473 echo
474 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700475 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476
477 echo
478 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700479 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480
481 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700484}
485
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800486# Clear this variable. It will be built up again when the vendorsetup.sh
487# files are included at the end of this file.
488unset LUNCH_MENU_CHOICES
489function add_lunch_combo()
490{
491 local new_combo=$1
492 local c
493 for c in ${LUNCH_MENU_CHOICES[@]} ; do
494 if [ "$new_combo" = "$c" ] ; then
495 return
496 fi
497 done
498 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
499}
500
501# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700502add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800503add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000504add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800505add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000506add_lunch_combo aosp_x86-eng
507add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800508
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509function print_lunch_menu()
510{
511 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700512 echo
513 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000514 if [ "$(uname)" = "Darwin" ] ; then
515 echo " (ohai, koush!)"
516 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700517 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000518 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
519 echo "Breakfast menu... pick a combo:"
520 else
521 echo "Lunch menu... pick a combo:"
522 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800523
524 local i=1
525 local choice
526 for choice in ${LUNCH_MENU_CHOICES[@]}
527 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100528 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100530 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800531
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000532 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
533 echo "... and don't forget the bacon!"
534 fi
535
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700536 echo
537}
538
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000539function brunch()
540{
541 breakfast $*
542 if [ $? -eq 0 ]; then
543 mka bacon
544 else
545 echo "No such item in brunch menu. Try 'breakfast'"
546 return 1
547 fi
548 return $?
549}
550
551function breakfast()
552{
553 target=$1
554 CM_DEVICES_ONLY="true"
555 unset LUNCH_MENU_CHOICES
556 add_lunch_combo full-eng
557 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
558 do
559 echo "including $f"
560 . $f
561 done
562 unset f
563
564 if [ $# -eq 0 ]; then
565 # No arguments, so let's have the full menu
566 lunch
567 else
568 echo "z$target" | grep -q "-"
569 if [ $? -eq 0 ]; then
570 # A buildtype was specified, assume a full device name
571 lunch $target
572 else
573 # This is probably just the CM model name
574 lunch cm_$target-userdebug
575 fi
576 fi
577 return $?
578}
579
580alias bib=breakfast
581
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582function lunch()
583{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800584 local answer
585
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588 else
589 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700590 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800591 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 fi
593
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800594 local selection=
595
596 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700597 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700598 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800599 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
600 then
601 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
602 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800603 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800604 fi
605 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
606 then
607 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700608 fi
609
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800610 if [ -z "$selection" ]
611 then
612 echo
613 echo "Invalid lunch combo: $answer"
614 return 1
615 fi
616
Joe Onoratoda12daf2010-06-09 18:18:31 -0700617 export TARGET_BUILD_APPS=
618
Jeff Browne33ba4c2011-07-11 22:11:46 -0700619 local product=$(echo -n $selection | sed -e "s/-.*$//")
620 check_product $product
621 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800622 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800623 # if we can't find a product, try to grab it off the CM github
624 T=$(gettop)
625 pushd $T > /dev/null
626 build/tools/roomservice.py $product
627 popd > /dev/null
628 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000629 else
630 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800631 fi
632 if [ $? -ne 0 ]
633 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700634 echo
635 echo "** Don't have a product spec for: '$product'"
636 echo "** Do you have the right repo manifest?"
637 product=
638 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639
Jeff Browne33ba4c2011-07-11 22:11:46 -0700640 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
641 check_variant $variant
642 if [ $? -ne 0 ]
643 then
644 echo
645 echo "** Invalid variant: '$variant'"
646 echo "** Must be one of ${VARIANT_CHOICES[@]}"
647 variant=
648 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800649
Jeff Browne33ba4c2011-07-11 22:11:46 -0700650 if [ -z "$product" -o -z "$variant" ]
651 then
652 echo
653 return 1
654 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800655
Jeff Browne33ba4c2011-07-11 22:11:46 -0700656 export TARGET_PRODUCT=$product
657 export TARGET_BUILD_VARIANT=$variant
658 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659
660 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800661
Chirayu Desaib89b3242013-06-30 10:04:25 +0530662 fixup_common_out_dir
663
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800665 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700666}
667
Jeff Davidson513d7a42010-08-02 10:00:44 -0700668# Tab completion for lunch.
669function _lunch()
670{
671 local cur prev opts
672 COMPREPLY=()
673 cur="${COMP_WORDS[COMP_CWORD]}"
674 prev="${COMP_WORDS[COMP_CWORD-1]}"
675
676 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
677 return 0
678}
Emilio López9ad6eea2013-11-03 13:02:13 -0300679complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700680
Joe Onoratoda12daf2010-06-09 18:18:31 -0700681# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700682# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700683function tapas()
684{
Ying Wangb541ab62014-05-29 17:57:40 -0700685 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 -0700686 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700687 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
688 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 -0700689
Ying Wang67f02922012-08-22 10:25:20 -0700690 if [ $(echo $arch | wc -w) -gt 1 ]; then
691 echo "tapas: Error: Multiple build archs supplied: $arch"
692 return
693 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700694 if [ $(echo $variant | wc -w) -gt 1 ]; then
695 echo "tapas: Error: Multiple build variants supplied: $variant"
696 return
697 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700698 if [ $(echo $density | wc -w) -gt 1 ]; then
699 echo "tapas: Error: Multiple densities supplied: $density"
700 return
701 fi
Ying Wang67f02922012-08-22 10:25:20 -0700702
703 local product=full
704 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700705 x86) product=full_x86;;
706 mips) product=full_mips;;
707 armv5) product=generic_armv5;;
708 arm64) product=aosp_arm64;;
709 x86_64) product=aosp_x86_64;;
710 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700711 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700712 if [ -z "$variant" ]; then
713 variant=eng
714 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700715 if [ -z "$apps" ]; then
716 apps=all
717 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600718 if [ -z "$density" ]; then
719 density=alldpi
720 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700721
Ying Wang67f02922012-08-22 10:25:20 -0700722 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700723 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700724 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700725 export TARGET_BUILD_TYPE=release
726 export TARGET_BUILD_APPS=$apps
727
728 set_stuff_for_environment
729 printconfig
730}
731
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100732function eat()
733{
734 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530735 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100736 ZIPFILE=cm-$MODVERSION.zip
737 ZIPPATH=$OUT/$ZIPFILE
738 if [ ! -f $ZIPPATH ] ; then
739 echo "Nothing to eat"
740 return 1
741 fi
742 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
743 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
744 echo "No device is online. Waiting for one..."
745 echo "Please connect USB and/or enable USB debugging"
746 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
747 sleep 1
748 done
749 echo "Device Found.."
750 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530751 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
752 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100753 # if adbd isn't root we can't write to /cache/recovery/
754 adb root
755 sleep 1
756 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700757 cat << EOF > /tmp/command
758--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100759EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700760 if adb push /tmp/command /cache/recovery/ ; then
761 echo "Rebooting into recovery for sideload installation"
762 adb reboot recovery
763 adb wait-for-sideload
764 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100765 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700766 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100767 else
768 echo "Nothing to eat"
769 return 1
770 fi
771 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530772 else
773 echo "The connected device does not appear to be $CM_BUILD, run away!"
774 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100775}
776
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000777function omnom
778{
779 brunch $*
780 eat
781}
782
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700783function gettop
784{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800785 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700786 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700787 # The following circumlocution ensures we remove symlinks from TOP.
788 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789 else
790 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800791 # The following circumlocution (repeated below as well) ensures
792 # that we record the true directory name and not one that is
793 # faked up with symlink names.
794 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700795 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800796 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 T=
798 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800799 \cd ..
synergyb112a402013-07-05 19:47:47 -0700800 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 done
Ying Wang9cd17642012-12-13 10:52:07 -0800802 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 if [ -f "$T/$TOPFILE" ]; then
804 echo $T
805 fi
806 fi
807 fi
808}
809
Andrew Hsieh906cb782013-09-10 17:37:14 +0800810# Return driver for "make", if any (eg. static analyzer)
811function getdriver()
812{
813 local T="$1"
814 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
815 if [ -n "$WITH_STATIC_ANALYZER" ]; then
816 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800817$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
818--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800819--status-bugs \
820--top=$T"
821 fi
822}
823
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824function m()
825{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800826 local T=$(gettop)
827 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700828 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800829 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700830 else
831 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700832 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700833 fi
834}
835
836function findmakefile()
837{
838 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800839 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700840 T=
841 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700842 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700843 if [ -f "$T/Android.mk" ]; then
844 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800845 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846 return
847 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800848 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700849 done
Ying Wang9cd17642012-12-13 10:52:07 -0800850 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700851}
852
853function mm()
854{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800855 local T=$(gettop)
856 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700857 # If we're sitting in the root of the build tree, just do a
858 # normal make.
859 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800860 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861 else
862 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800863 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700864 local MODULES=
865 local GET_INSTALL_PATH=
866 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700867 # Remove the path to top as the makefilepath needs to be relative
868 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700869 if [ ! "$T" ]; then
870 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700871 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700872 elif [ ! "$M" ]; then
873 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700874 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700875 else
Ying Wanga7deb082013-08-16 13:24:47 -0700876 for ARG in $@; do
877 case $ARG in
878 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
879 esac
880 done
881 if [ -n "$GET_INSTALL_PATH" ]; then
882 MODULES=
883 ARGS=GET-INSTALL-PATH
884 else
885 MODULES=all_modules
886 ARGS=$@
887 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700888 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 -0700889 fi
890 fi
891}
892
893function mmm()
894{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800895 local T=$(gettop)
896 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700897 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800898 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800899 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800900 local ARGS=
901 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700902 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800903 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
904 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
905 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800906 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
907 if [ "$MODULES" = "" ]; then
908 MODULES=all_modules
909 fi
910 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700912 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
913 local TO_CHOP=`expr $TO_CHOP + 1`
914 local START=`PWD= /bin/pwd`
915 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700916 if [ "$MFILE" = "" ] ; then
917 MFILE=$DIR/Android.mk
918 else
919 MFILE=$MFILE/$DIR/Android.mk
920 fi
921 MAKEFILE="$MAKEFILE $MFILE"
922 else
Ying Wanga7deb082013-08-16 13:24:47 -0700923 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100924 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700925 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
926 *) echo "No Android.mk in $DIR."; return 1;;
927 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700928 fi
929 done
Ying Wanga7deb082013-08-16 13:24:47 -0700930 if [ -n "$GET_INSTALL_PATH" ]; then
931 ARGS=$GET_INSTALL_PATH
932 MODULES=
933 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800934 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 -0700935 else
936 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700937 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700938 fi
939}
940
Ying Wangb607f7b2013-02-08 18:01:04 -0800941function mma()
942{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800943 local T=$(gettop)
944 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800945 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800946 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800947 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800948 if [ ! "$T" ]; then
949 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700950 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800951 fi
952 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800953 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800954 fi
955}
956
957function mmma()
958{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800959 local T=$(gettop)
960 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800961 if [ "$T" ]; then
962 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
963 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
964 local MY_PWD=`PWD= /bin/pwd`
965 if [ "$MY_PWD" = "$T" ]; then
966 MY_PWD=
967 else
968 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
969 fi
970 local DIR=
971 local MODULE_PATHS=
972 local ARGS=
973 for DIR in $DIRS ; do
974 if [ -d $DIR ]; then
975 if [ "$MY_PWD" = "" ]; then
976 MODULE_PATHS="$MODULE_PATHS $DIR"
977 else
978 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
979 fi
980 else
981 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100982 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800983 *) echo "Couldn't find directory $DIR"; return 1;;
984 esac
985 fi
986 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800987 $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 -0800988 else
989 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700990 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800991 fi
992}
993
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700994function croot()
995{
996 T=$(gettop)
997 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800998 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700999 else
1000 echo "Couldn't locate the top of the tree. Try setting TOP."
1001 fi
1002}
1003
nebkatfb67a1e2012-12-28 10:40:45 +00001004function cout()
1005{
1006 if [ "$OUT" ]; then
1007 cd $OUT
1008 else
1009 echo "Couldn't locate out directory. Try setting OUT."
1010 fi
1011}
1012
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001013function cproj()
1014{
1015 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001016 local HERE=$PWD
1017 T=
1018 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1019 T=$PWD
1020 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001021 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001022 return
1023 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001024 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001025 done
Ying Wang9cd17642012-12-13 10:52:07 -08001026 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001027 echo "can't find Android.mk"
1028}
1029
Daniel Sandler47e0a882013-07-30 13:23:52 -04001030# simplified version of ps; output in the form
1031# <pid> <procname>
1032function qpid() {
1033 local prepend=''
1034 local append=''
1035 if [ "$1" = "--exact" ]; then
1036 prepend=' '
1037 append='$'
1038 shift
1039 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1040 echo "usage: qpid [[--exact] <process name|pid>"
1041 return 255
1042 fi
1043
1044 local EXE="$1"
1045 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001046 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001047 else
1048 adb shell ps \
1049 | tr -d '\r' \
1050 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1051 fi
1052}
1053
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001054function pid()
1055{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001056 local prepend=''
1057 local append=''
1058 if [ "$1" = "--exact" ]; then
1059 prepend=' '
1060 append='$'
1061 shift
1062 fi
1063 local EXE="$1"
1064 if [ "$EXE" ] ; then
1065 local PID=`adb shell ps \
1066 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001067 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001068 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1069 echo "$PID"
1070 else
1071 echo "usage: pid [--exact] <process name>"
1072 return 255
1073 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001074}
1075
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001076# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077# that has the core-file-size limit set correctly
1078#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001079# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080# if its core-file-size limit is not set already.
1081# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1082
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001083function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001084{
1085 echo "Getting root...";
1086 adb root;
1087 adb wait-for-device;
1088
1089 echo "Remounting root parition read-write...";
1090 adb shell mount -w -o remount -t rootfs rootfs;
1091 sleep 1;
1092 adb wait-for-device;
1093 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001094 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001095 adb shell chmod 0777 /cores;
1096
1097 echo "Granting SELinux permission to dump in /cores...";
1098 adb shell restorecon -R /cores;
1099
1100 echo "Set core pattern.";
1101 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1102
1103 echo "Done."
1104}
1105
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001106# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001107# $1 = PID of process (e.g., $(pid mediaserver))
1108#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001109# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001110# dump to actually be generated.
1111
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001112function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001113{
1114 local PID=$1;
1115 if [ -z "$PID" ]; then
1116 printf "Expecting a PID!\n";
1117 return;
1118 fi;
1119 echo "Setting core limit for $PID to infinite...";
1120 adb shell prlimit $PID 4 -1 -1
1121}
1122
1123# core - send SIGV and pull the core for process
1124# $1 = PID of process (e.g., $(pid mediaserver))
1125#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001126# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001127# enabled globally.
1128
1129function core()
1130{
1131 local PID=$1;
1132
1133 if [ -z "$PID" ]; then
1134 printf "Expecting a PID!\n";
1135 return;
1136 fi;
1137
1138 local CORENAME=core.$PID;
1139 local COREPATH=/cores/$CORENAME;
1140 local SIG=SEGV;
1141
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001142 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001143
1144 local done=0;
1145 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1146 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1147 adb shell kill -$SIG $PID;
1148 sleep 1;
1149 done;
1150
1151 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1152 echo "Done: core is under $COREPATH on device.";
1153}
1154
Christopher Tate744ee802009-11-12 15:33:08 -08001155# systemstack - dump the current stack trace of all threads in the system process
1156# to the usual ANR traces file
1157function systemstack()
1158{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001159 stacks system_server
1160}
1161
1162function stacks()
1163{
1164 if [[ $1 =~ ^[0-9]+$ ]] ; then
1165 local PID="$1"
1166 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001167 local PIDLIST="$(pid $1)"
1168 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1169 local PID="$PIDLIST"
1170 elif [ "$PIDLIST" ] ; then
1171 echo "more than one process: $1"
1172 else
1173 echo "no such process: $1"
1174 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001175 else
1176 echo "usage: stacks [pid|process name]"
1177 fi
1178
1179 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001180 # Determine whether the process is native
1181 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1182 # Dump stacks of Dalvik process
1183 local TRACES=/data/anr/traces.txt
1184 local ORIG=/data/anr/traces.orig
1185 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001186
Jeff Brownb12c2e52013-08-19 15:14:16 -07001187 # Keep original traces to avoid clobbering
1188 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001189
Jeff Brownb12c2e52013-08-19 15:14:16 -07001190 # Make sure we have a usable file
1191 adb shell touch $TRACES
1192 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001193
Jeff Brownb12c2e52013-08-19 15:14:16 -07001194 # Dump stacks and wait for dump to finish
1195 adb shell kill -3 $PID
1196 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001197
Jeff Brownb12c2e52013-08-19 15:14:16 -07001198 # Restore original stacks, and show current output
1199 adb shell mv $TRACES $TMP
1200 adb shell mv $ORIG $TRACES
1201 adb shell cat $TMP
1202 else
1203 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001204 local USE64BIT="$(is64bit $PID)"
1205 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001206 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001207 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001208}
1209
Michael Wrightaeed7212014-06-19 19:58:12 -07001210# Read the ELF header from /proc/$PID/exe to determine if the process is
1211# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001212function is64bit()
1213{
1214 local PID="$1"
1215 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001216 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001217 echo "64"
1218 else
1219 echo ""
1220 fi
1221 else
1222 echo ""
1223 fi
1224}
1225
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001226case `uname -s` in
1227 Darwin)
1228 function sgrep()
1229 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001230 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 -07001231 }
1232
1233 ;;
1234 *)
1235 function sgrep()
1236 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001237 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 -07001238 }
1239 ;;
1240esac
1241
Raghu Gandham8da43102012-07-25 19:57:22 -07001242function gettargetarch
1243{
1244 get_build_var TARGET_ARCH
1245}
1246
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001247function ggrep()
1248{
1249 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1250}
1251
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001252function jgrep()
1253{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001254 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 -07001255}
1256
1257function cgrep()
1258{
Dan Albert01961192014-11-22 10:16:01 -08001259 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 -07001260}
1261
1262function resgrep()
1263{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001264 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 -07001265}
1266
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001267function mangrep()
1268{
1269 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1270}
1271
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001272function sepgrep()
1273{
1274 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 "$@"
1275}
1276
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001277function rcgrep()
1278{
1279 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1280}
1281
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001282case `uname -s` in
1283 Darwin)
1284 function mgrep()
1285 {
Ying Wang324c2b22012-08-17 15:03:20 -07001286 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 -07001287 }
1288
1289 function treegrep()
1290 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001291 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 -07001292 }
1293
1294 ;;
1295 *)
1296 function mgrep()
1297 {
Ying Wang324c2b22012-08-17 15:03:20 -07001298 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 -07001299 }
1300
1301 function treegrep()
1302 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001303 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 -07001304 }
1305
1306 ;;
1307esac
1308
1309function getprebuilt
1310{
1311 get_abs_build_var ANDROID_PREBUILTS
1312}
1313
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001314function tracedmdump()
1315{
1316 T=$(gettop)
1317 if [ ! "$T" ]; then
1318 echo "Couldn't locate the top of the tree. Try setting TOP."
1319 return
1320 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001321 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001322 local arch=$(gettargetarch)
1323 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001324
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001325 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001326 if [ ! "$TRACE" ] ; then
1327 echo "usage: tracedmdump tracename"
1328 return
1329 fi
1330
Jack Veenstra60116fc2009-04-09 18:12:34 -07001331 if [ ! -r "$KERNEL" ] ; then
1332 echo "Error: cannot find kernel: '$KERNEL'"
1333 return
1334 fi
1335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001336 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001337 if [ "$BASETRACE" = "$TRACE" ] ; then
1338 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1339 fi
1340
1341 echo "post-processing traces..."
1342 rm -f $TRACE/qtrace.dexlist
1343 post_trace $TRACE
1344 if [ $? -ne 0 ]; then
1345 echo "***"
1346 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1347 echo "***"
1348 return
1349 fi
1350 echo "generating dexlist output..."
1351 /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
1352 echo "generating dmtrace data..."
1353 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1354 echo "generating html file..."
1355 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1356 echo "done, see $TRACE/dmtrace.html for details"
1357 echo "or run:"
1358 echo " traceview $TRACE/dmtrace"
1359}
1360
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001361# communicate with a running device or emulator, set up necessary state,
1362# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001363function runhat()
1364{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001365 # process standard adb options
1366 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001367 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001368 adbTarget=$1
1369 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001370 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001371 adbTarget="$1 $2"
1372 shift 2
1373 fi
1374 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001375 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001376
1377 # runhat options
1378 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001379
1380 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001381 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001382 return
1383 fi
1384
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001385 # confirm hat is available
1386 if [ -z $(which hat) ]; then
1387 echo "hat is not available in this configuration."
1388 return
1389 fi
1390
Andy McFaddenb6289852010-07-12 08:00:19 -07001391 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001392 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001393 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001394 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001395 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001396 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397 echo -n "> "
1398 read
1399
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401
The Android Open Source Project88b60792009-03-03 19:28:42 -08001402 echo "Retrieving file $devFile..."
1403 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001404
The Android Open Source Project88b60792009-03-03 19:28:42 -08001405 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001406
The Android Open Source Project88b60792009-03-03 19:28:42 -08001407 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001408 echo "View the output by pointing your browser at http://localhost:7000/"
1409 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001410 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001411}
1412
1413function getbugreports()
1414{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001415 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001416
1417 if [ ! "$reports" ]; then
1418 echo "Could not locate any bugreports."
1419 return
1420 fi
1421
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001422 local report
1423 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001424 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001425 echo "/sdcard/bugreports/${report}"
1426 adb pull /sdcard/bugreports/${report} ${report}
1427 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001428 done
1429}
1430
Victoria Lease1b296b42012-08-21 15:44:06 -07001431function getsdcardpath()
1432{
1433 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1434}
1435
1436function getscreenshotpath()
1437{
1438 echo "$(getsdcardpath)/Pictures/Screenshots"
1439}
1440
1441function getlastscreenshot()
1442{
1443 local screenshot_path=$(getscreenshotpath)
1444 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1445 if [ "$screenshot" = "" ]; then
1446 echo "No screenshots found."
1447 return
1448 fi
1449 echo "${screenshot}"
1450 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1451}
1452
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001453function startviewserver()
1454{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001455 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001456 if [ $# -gt 0 ]; then
1457 port=$1
1458 fi
1459 adb shell service call window 1 i32 $port
1460}
1461
1462function stopviewserver()
1463{
1464 adb shell service call window 2
1465}
1466
1467function isviewserverstarted()
1468{
1469 adb shell service call window 3
1470}
1471
Romain Guyb84049a2010-10-04 16:56:11 -07001472function key_home()
1473{
1474 adb shell input keyevent 3
1475}
1476
1477function key_back()
1478{
1479 adb shell input keyevent 4
1480}
1481
1482function key_menu()
1483{
1484 adb shell input keyevent 82
1485}
1486
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001487function smoketest()
1488{
1489 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1490 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1491 return
1492 fi
1493 T=$(gettop)
1494 if [ ! "$T" ]; then
1495 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1496 return
1497 fi
1498
Ying Wang9cd17642012-12-13 10:52:07 -08001499 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001500 adb uninstall com.android.smoketest > /dev/null &&
1501 adb uninstall com.android.smoketest.tests > /dev/null &&
1502 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1503 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1504 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1505}
1506
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001507# simple shortcut to the runtest command
1508function runtest()
1509{
1510 T=$(gettop)
1511 if [ ! "$T" ]; then
1512 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1513 return
1514 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001515 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001516}
1517
The Android Open Source Project88b60792009-03-03 19:28:42 -08001518function godir () {
1519 if [[ -z "$1" ]]; then
1520 echo "Usage: godir <regex>"
1521 return
1522 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001523 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001524 if [[ ! -f $T/filelist ]]; then
1525 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001526 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527 echo " Done"
1528 echo ""
1529 fi
1530 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001531 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001532 if [[ ${#lines[@]} = 0 ]]; then
1533 echo "Not found"
1534 return
1535 fi
1536 local pathname
1537 local choice
1538 if [[ ${#lines[@]} > 1 ]]; then
1539 while [[ -z "$pathname" ]]; do
1540 local index=1
1541 local line
1542 for line in ${lines[@]}; do
1543 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001544 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001545 done
1546 echo
1547 echo -n "Select one: "
1548 unset choice
1549 read choice
1550 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1551 echo "Invalid choice"
1552 continue
1553 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001554 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001555 done
1556 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001557 pathname=${lines[0]}
1558 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001559 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001560}
1561
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001562function cmremote()
1563{
1564 git remote rm cmremote 2> /dev/null
1565 if [ ! -d .git ]
1566 then
1567 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1568 fi
1569 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1570 if [ -z "$GERRIT_REMOTE" ]
1571 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001572 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1573 if [ -z "$GERRIT_REMOTE" ]
1574 then
1575 echo Unable to set up the git remote, are you in the root of the repo?
1576 return 0
1577 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001578 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001579 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001580 if [ -z "$CMUSER" ]
1581 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001582 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001583 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001584 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001585 fi
1586 echo You can now push to "cmremote".
1587}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001588
Steve Kondik873fa562012-09-17 11:33:18 -07001589function aospremote()
1590{
1591 git remote rm aosp 2> /dev/null
1592 if [ ! -d .git ]
1593 then
1594 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1595 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001596 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001597 if (echo $PROJECT | grep -qv "^device")
1598 then
1599 PFX="platform/"
1600 fi
1601 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1602 echo "Remote 'aosp' created"
1603}
Steve Kondik873fa562012-09-17 11:33:18 -07001604
Steve Kondik20c21d22013-10-27 13:34:36 -07001605function cafremote()
1606{
1607 git remote rm caf 2> /dev/null
1608 if [ ! -d .git ]
1609 then
1610 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1611 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001612 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001613 if (echo $PROJECT | grep -qv "^device")
1614 then
1615 PFX="platform/"
1616 fi
1617 git remote add caf git://codeaurora.org/$PFX$PROJECT
1618 echo "Remote 'caf' created"
1619}
Steve Kondik20c21d22013-10-27 13:34:36 -07001620
Steve Kondikf00e7d92012-09-23 23:46:55 -07001621function installboot()
1622{
1623 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1624 then
1625 echo "No recovery.fstab found. Build recovery first."
1626 return 1
1627 fi
1628 if [ ! -e "$OUT/boot.img" ];
1629 then
1630 echo "No boot.img found. Run make bootimage first."
1631 return 1
1632 fi
1633 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1634 if [ -z "$PARTITION" ];
1635 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001636 # Try for RECOVERY_FSTAB_VERSION = 2
1637 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1638 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1639 if [ -z "$PARTITION" ];
1640 then
1641 echo "Unable to determine boot partition."
1642 return 1
1643 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001644 fi
1645 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001646 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001647 adb root
1648 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001649 adb wait-for-online shell mount /system 2>&1 > /dev/null
1650 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001651 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1652 then
1653 adb push $OUT/boot.img /cache/
1654 for i in $OUT/system/lib/modules/*;
1655 do
1656 adb push $i /system/lib/modules/
1657 done
1658 adb shell dd if=/cache/boot.img of=$PARTITION
1659 adb shell chmod 644 /system/lib/modules/*
1660 echo "Installation complete."
1661 else
1662 echo "The connected device does not appear to be $CM_BUILD, run away!"
1663 fi
1664}
1665
Steve Kondik83c03d52012-10-24 16:40:42 -07001666function installrecovery()
1667{
1668 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1669 then
1670 echo "No recovery.fstab found. Build recovery first."
1671 return 1
1672 fi
1673 if [ ! -e "$OUT/recovery.img" ];
1674 then
1675 echo "No recovery.img found. Run make recoveryimage first."
1676 return 1
1677 fi
1678 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1679 if [ -z "$PARTITION" ];
1680 then
Steve Kondik75f10762013-08-09 21:03:42 -07001681 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001682 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1683 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001684 if [ -z "$PARTITION" ];
1685 then
1686 echo "Unable to determine recovery partition."
1687 return 1
1688 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001689 fi
1690 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001691 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001692 adb root
1693 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001694 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1695 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001696 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1697 then
1698 adb push $OUT/recovery.img /cache/
1699 adb shell dd if=/cache/recovery.img of=$PARTITION
1700 echo "Installation complete."
1701 else
1702 echo "The connected device does not appear to be $CM_BUILD, run away!"
1703 fi
1704}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001705
Koushik Duttab55f13a2012-05-14 16:14:36 -07001706function makerecipe() {
1707 if [ -z "$1" ]
1708 then
1709 echo "No branch name provided."
1710 return 1
1711 fi
1712 cd android
1713 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1714 git commit -a -m "$1"
1715 cd ..
1716
1717 repo forall -c '
1718
1719 if [ "$REPO_REMOTE" == "github" ]
1720 then
1721 pwd
1722 cmremote
1723 git push cmremote HEAD:refs/heads/'$1'
1724 fi
1725 '
1726}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001727
1728function cmgerrit() {
1729 if [ $# -eq 0 ]; then
1730 $FUNCNAME help
1731 return 1
1732 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001733 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001734 local review=`git config --get remote.github.review`
1735 local project=`git config --get remote.github.projectname`
1736 local command=$1
1737 shift
1738 case $command in
1739 help)
1740 if [ $# -eq 0 ]; then
1741 cat <<EOF
1742Usage:
1743 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1744
1745Commands:
1746 fetch Just fetch the change as FETCH_HEAD
1747 help Show this help, or for a specific command
1748 pull Pull a change into current branch
1749 push Push HEAD or a local branch to Gerrit for a specific branch
1750
1751Any other Git commands that support refname would work as:
1752 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1753
1754See '$FUNCNAME help COMMAND' for more information on a specific command.
1755
1756Example:
1757 $FUNCNAME checkout -b topic 1234/5
1758works as:
1759 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1760 && git checkout -b topic FETCH_HEAD
1761will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1762Patch-set 1 will be fetched if omitted.
1763EOF
1764 return
1765 fi
1766 case $1 in
1767 __cmg_*) echo "For internal use only." ;;
1768 changes|for)
1769 if [ "$FUNCNAME" = "cmgerrit" ]; then
1770 echo "'$FUNCNAME $1' is deprecated."
1771 fi
1772 ;;
1773 help) $FUNCNAME help ;;
1774 fetch|pull) cat <<EOF
1775usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1776
1777works as:
1778 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1779 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1780
1781Example:
1782 $FUNCNAME $1 1234
1783will $1 patch-set 1 of change 1234
1784EOF
1785 ;;
1786 push) cat <<EOF
1787usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1788
1789works as:
1790 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1791 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1792
1793Example:
1794 $FUNCNAME push fix6789:gingerbread
1795will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1796HEAD will be pushed from local if omitted.
1797EOF
1798 ;;
1799 *)
1800 $FUNCNAME __cmg_err_not_supported $1 && return
1801 cat <<EOF
1802usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1803
1804works as:
1805 git fetch http://DOMAIN/p/PROJECT \\
1806 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1807 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1808EOF
1809 ;;
1810 esac
1811 ;;
1812 __cmg_get_ref)
1813 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1814 local change_id patchset_id hash
1815 case $1 in
1816 */*)
1817 change_id=${1%%/*}
1818 patchset_id=${1#*/}
1819 ;;
1820 *)
1821 change_id=$1
1822 patchset_id=1
1823 ;;
1824 esac
1825 hash=$(($change_id % 100))
1826 case $hash in
1827 [0-9]) hash="0$hash" ;;
1828 esac
1829 echo "refs/changes/$hash/$change_id/$patchset_id"
1830 ;;
1831 fetch|pull)
1832 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1833 $FUNCNAME __cmg_err_not_repo && return 1
1834 local change=$1
1835 shift
1836 git $command $@ http://$review/p/$project \
1837 $($FUNCNAME __cmg_get_ref $change) || return 1
1838 ;;
1839 push)
1840 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1841 $FUNCNAME __cmg_err_not_repo && return 1
1842 if [ -z "$user" ]; then
1843 echo >&2 "Gerrit username not found."
1844 return 1
1845 fi
1846 local local_branch remote_branch
1847 case $1 in
1848 *:*)
1849 local_branch=${1%:*}
1850 remote_branch=${1##*:}
1851 ;;
1852 *)
1853 local_branch=HEAD
1854 remote_branch=$1
1855 ;;
1856 esac
1857 shift
1858 git push $@ ssh://$user@$review:29418/$project \
1859 $local_branch:refs/for/$remote_branch || return 1
1860 ;;
1861 changes|for)
1862 if [ "$FUNCNAME" = "cmgerrit" ]; then
1863 echo >&2 "'$FUNCNAME $command' is deprecated."
1864 fi
1865 ;;
1866 __cmg_err_no_arg)
1867 if [ $# -lt 2 ]; then
1868 echo >&2 "'$FUNCNAME $command' missing argument."
1869 elif [ $2 -eq 0 ]; then
1870 if [ -n "$3" ]; then
1871 $FUNCNAME help $1
1872 else
1873 echo >&2 "'$FUNCNAME $1' missing argument."
1874 fi
1875 else
1876 return 1
1877 fi
1878 ;;
1879 __cmg_err_not_repo)
1880 if [ -z "$review" -o -z "$project" ]; then
1881 echo >&2 "Not currently in any reviewable repository."
1882 else
1883 return 1
1884 fi
1885 ;;
1886 __cmg_err_not_supported)
1887 $FUNCNAME __cmg_err_no_arg $command $# && return
1888 case $1 in
1889 #TODO: filter more git commands that don't use refname
1890 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1891 echo >&2 "'$FUNCNAME $1' is not supported."
1892 ;;
1893 *) return 1 ;;
1894 esac
1895 ;;
1896 #TODO: other special cases?
1897 *)
1898 $FUNCNAME __cmg_err_not_supported $command && return 1
1899 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1900 $FUNCNAME __cmg_err_not_repo && return 1
1901 local args="$@"
1902 local change pre_args refs_arg post_args
1903 case "$args" in
1904 *--\ *)
1905 pre_args=${args%%-- *}
1906 post_args="-- ${args#*-- }"
1907 ;;
1908 *) pre_args="$args" ;;
1909 esac
1910 args=($pre_args)
1911 pre_args=
1912 if [ ${#args[@]} -gt 0 ]; then
1913 change=${args[${#args[@]}-1]}
1914 fi
1915 if [ ${#args[@]} -gt 1 ]; then
1916 pre_args=${args[0]}
1917 for ((i=1; i<${#args[@]}-1; i++)); do
1918 pre_args="$pre_args ${args[$i]}"
1919 done
1920 fi
1921 while ((1)); do
1922 case $change in
1923 ""|--)
1924 $FUNCNAME help $command
1925 return 1
1926 ;;
1927 *@*)
1928 if [ -z "$refs_arg" ]; then
1929 refs_arg="@${change#*@}"
1930 change=${change%%@*}
1931 fi
1932 ;;
1933 *~*)
1934 if [ -z "$refs_arg" ]; then
1935 refs_arg="~${change#*~}"
1936 change=${change%%~*}
1937 fi
1938 ;;
1939 *^*)
1940 if [ -z "$refs_arg" ]; then
1941 refs_arg="^${change#*^}"
1942 change=${change%%^*}
1943 fi
1944 ;;
1945 *:*)
1946 if [ -z "$refs_arg" ]; then
1947 refs_arg=":${change#*:}"
1948 change=${change%%:*}
1949 fi
1950 ;;
1951 *) break ;;
1952 esac
1953 done
1954 $FUNCNAME fetch $change \
1955 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1956 || return 1
1957 ;;
1958 esac
1959}
1960
1961function cmrebase() {
1962 local repo=$1
1963 local refs=$2
1964 local pwd="$(pwd)"
1965 local dir="$(gettop)/$repo"
1966
1967 if [ -z $repo ] || [ -z $refs ]; then
1968 echo "CyanogenMod Gerrit Rebase Usage: "
1969 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1970 echo " The patch IDs appear on the Gerrit commands that are offered."
1971 echo " They consist on a series of numbers and slashes, after the text"
1972 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1973 echo ""
1974 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1975 echo ""
1976 return
1977 fi
1978
1979 if [ ! -d $dir ]; then
1980 echo "Directory $dir doesn't exist in tree."
1981 return
1982 fi
1983 cd $dir
1984 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1985 echo "Starting branch..."
1986 repo start tmprebase .
1987 echo "Bringing it up to date..."
1988 repo sync .
1989 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001990 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001991 if [ "$?" != "0" ]; then
1992 echo "Error cherry-picking. Not uploading!"
1993 return
1994 fi
1995 echo "Uploading..."
1996 repo upload .
1997 echo "Cleaning up..."
1998 repo abandon tmprebase .
1999 cd $pwd
2000}
2001
2002function mka() {
2003 case `uname -s` in
2004 Darwin)
2005 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2006 ;;
2007 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07002008 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002009 ;;
2010 esac
2011}
2012
2013function reposync() {
2014 case `uname -s` in
2015 Darwin)
2016 repo sync -j 4 "$@"
2017 ;;
2018 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002019 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002020 ;;
2021 esac
2022}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002023
2024function repodiff() {
2025 if [ -z "$*" ]; then
2026 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2027 return
2028 fi
2029 diffopts=$* repo forall -c \
2030 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2031}
2032
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302033# Credit for color strip sed: http://goo.gl/BoIcm
2034function dopush()
2035{
2036 local func=$1
2037 shift
2038
2039 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2040 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2041 echo "No device is online. Waiting for one..."
2042 echo "Please connect USB and/or enable USB debugging"
2043 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2044 sleep 1
2045 done
2046 echo "Device Found."
2047 fi
2048
Chirayu Desai6dadb572012-12-26 10:53:58 +05302049 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2050 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002051 # retrieve IP and PORT info if we're using a TCP connection
2052 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2053 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302054 adb root &> /dev/null
2055 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002056 if [ -n "$TCPIPPORT" ]
2057 then
2058 # adb root just killed our connection
2059 # so reconnect...
2060 adb connect "$TCPIPPORT"
2061 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302062 adb wait-for-device &> /dev/null
2063 sleep 0.3
2064 adb remount &> /dev/null
2065
2066 $func $* | tee $OUT/.log
2067
2068 # Install: <file>
2069 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)
2070
2071 # Copy: <file>
2072 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)
2073
2074 for FILE in $LOC; do
2075 # Get target file name (i.e. system/bin/adb)
2076 TARGET=$(echo $FILE | sed "s#$OUT/##")
2077
Chirayu Desai894076f2013-05-19 19:54:32 +05302078 # Don't send files that are not under /system or /data
2079 if [ ! "echo $TARGET | egrep '^system\/' > /dev/null" -o \
2080 "echo $TARGET | egrep '^data\/' > /dev/null" ] ; then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302081 continue
2082 else
2083 case $TARGET in
2084 system/app/SystemUI.apk|system/framework/*)
2085 stop_n_start=true
2086 ;;
2087 *)
2088 stop_n_start=false
2089 ;;
2090 esac
2091 if $stop_n_start ; then adb shell stop ; fi
2092 echo "Pushing: $TARGET"
2093 adb push $FILE $TARGET
2094 if $stop_n_start ; then adb shell start ; fi
2095 fi
2096 done
2097 rm -f $OUT/.log
2098 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302099 else
2100 echo "The connected device does not appear to be $CM_BUILD, run away!"
2101 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302102}
2103
2104alias mmp='dopush mm'
2105alias mmmp='dopush mmm'
2106alias mkap='dopush mka'
2107alias cmkap='dopush cmka'
2108
Chirayu Desai4a319b82013-06-05 20:14:33 +05302109function repopick() {
2110 T=$(gettop)
2111 $T/build/tools/repopick.py $@
2112}
2113
Chirayu Desaib89b3242013-06-30 10:04:25 +05302114function fixup_common_out_dir() {
2115 common_out_dir=$(get_build_var OUT_DIR)/target/common
2116 target_device=$(get_build_var TARGET_DEVICE)
2117 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2118 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2119 mv ${common_out_dir} ${common_out_dir}-${target_device}
2120 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2121 else
2122 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2123 mkdir -p ${common_out_dir}-${target_device}
2124 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2125 fi
2126 else
2127 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2128 mkdir -p ${common_out_dir}
2129 fi
2130}
2131
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002132# 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 +00002133#
2134# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2135# For some reason, installing the JDK doesn't make it show up in the
2136# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002137function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002138 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002139 # we can reset it later, depending on the version of java the build
2140 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002141 #
2142 # If we don't do this, the JAVA_HOME value set by the first call to
2143 # build/envsetup.sh will persist forever.
2144 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2145 export JAVA_HOME=""
2146 fi
2147
Andy McFaddenbd960942010-06-24 12:52:51 -07002148 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002149 case `uname -s` in
2150 Darwin)
2151 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2152 ;;
2153 *)
2154 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2155 ;;
2156 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002157
2158 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2159 # we can change it on the next envsetup.sh, if required.
2160 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002161 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002162}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002163
Alex Rayf0d08eb2013-03-08 15:15:06 -08002164# Print colored exit condition
2165function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002166 "$@"
2167 local retval=$?
2168 if [ $retval -ne 0 ]
2169 then
2170 echo -e "\e[0;31mFAILURE\e[00m"
2171 else
2172 echo -e "\e[0;32mSUCCESS\e[00m"
2173 fi
2174 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002175}
2176
Ying Wanged21d4c2014-08-24 22:14:19 -07002177function get_make_command()
2178{
2179 echo command make
2180}
2181
Ed Heylcc6be0a2014-06-18 14:55:58 -07002182function make()
2183{
2184 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002185 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002186 local ret=$?
2187 local end_time=$(date +"%s")
2188 local tdiff=$(($end_time-$start_time))
2189 local hours=$(($tdiff / 3600 ))
2190 local mins=$((($tdiff % 3600) / 60))
2191 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002192 local ncolors=$(tput colors 2>/dev/null)
2193 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2194 color_failed="\e[0;31m"
2195 color_success="\e[0;32m"
2196 color_reset="\e[00m"
2197 else
2198 color_failed=""
2199 color_success=""
2200 color_reset=""
2201 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002202 echo
2203 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002204 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002205 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002206 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002207 fi
2208 if [ $hours -gt 0 ] ; then
2209 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2210 elif [ $mins -gt 0 ] ; then
2211 printf "(%02g:%02g (mm:ss))" $mins $secs
2212 elif [ $secs -gt 0 ] ; then
2213 printf "(%s seconds)" $secs
2214 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002215 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002216 echo
2217 return $ret
2218}
2219
Raphael Moll70a86b02011-06-20 16:03:14 -07002220if [ "x$SHELL" != "x/bin/bash" ]; then
2221 case `ps -o command -p $$` in
2222 *bash*)
2223 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002224 *zsh*)
2225 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002226 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002227 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002228 ;;
2229 esac
2230fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002231
2232# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002233for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2234 `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 -08002235do
2236 echo "including $f"
2237 . $f
2238done
2239unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002240
2241addcompletions