blob: cc41c2d03e8e25cc0c18184652fe18307e11278b [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
JustArchif70c7e62014-06-22 14:37:30 +0200554 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000555 CM_DEVICES_ONLY="true"
556 unset LUNCH_MENU_CHOICES
557 add_lunch_combo full-eng
558 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
559 do
560 echo "including $f"
561 . $f
562 done
563 unset f
564
565 if [ $# -eq 0 ]; then
566 # No arguments, so let's have the full menu
567 lunch
568 else
569 echo "z$target" | grep -q "-"
570 if [ $? -eq 0 ]; then
571 # A buildtype was specified, assume a full device name
572 lunch $target
573 else
574 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200575 if [ -z "$variant" ]; then
576 variant="userdebug"
577 fi
578 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000579 fi
580 fi
581 return $?
582}
583
584alias bib=breakfast
585
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586function lunch()
587{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 local answer
589
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800591 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 else
593 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700594 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 fi
597
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 local selection=
599
600 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700602 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
604 then
605 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
606 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800607 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800608 fi
609 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
610 then
611 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700612 fi
613
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800614 if [ -z "$selection" ]
615 then
616 echo
617 echo "Invalid lunch combo: $answer"
618 return 1
619 fi
620
Joe Onoratoda12daf2010-06-09 18:18:31 -0700621 export TARGET_BUILD_APPS=
622
Jeff Browne33ba4c2011-07-11 22:11:46 -0700623 local product=$(echo -n $selection | sed -e "s/-.*$//")
624 check_product $product
625 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800627 # if we can't find a product, try to grab it off the CM github
628 T=$(gettop)
629 pushd $T > /dev/null
630 build/tools/roomservice.py $product
631 popd > /dev/null
632 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000633 else
634 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800635 fi
636 if [ $? -ne 0 ]
637 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700638 echo
639 echo "** Don't have a product spec for: '$product'"
640 echo "** Do you have the right repo manifest?"
641 product=
642 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643
Jeff Browne33ba4c2011-07-11 22:11:46 -0700644 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
645 check_variant $variant
646 if [ $? -ne 0 ]
647 then
648 echo
649 echo "** Invalid variant: '$variant'"
650 echo "** Must be one of ${VARIANT_CHOICES[@]}"
651 variant=
652 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800653
Jeff Browne33ba4c2011-07-11 22:11:46 -0700654 if [ -z "$product" -o -z "$variant" ]
655 then
656 echo
657 return 1
658 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659
Jeff Browne33ba4c2011-07-11 22:11:46 -0700660 export TARGET_PRODUCT=$product
661 export TARGET_BUILD_VARIANT=$variant
662 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663
664 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800665
Chirayu Desaib89b3242013-06-30 10:04:25 +0530666 fixup_common_out_dir
667
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800669 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670}
671
Jeff Davidson513d7a42010-08-02 10:00:44 -0700672# Tab completion for lunch.
673function _lunch()
674{
675 local cur prev opts
676 COMPREPLY=()
677 cur="${COMP_WORDS[COMP_CWORD]}"
678 prev="${COMP_WORDS[COMP_CWORD-1]}"
679
680 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
681 return 0
682}
Emilio López9ad6eea2013-11-03 13:02:13 -0300683complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700684
Joe Onoratoda12daf2010-06-09 18:18:31 -0700685# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700686# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700687function tapas()
688{
Ying Wangb541ab62014-05-29 17:57:40 -0700689 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 -0700690 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700691 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
692 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 -0700693
Ying Wang67f02922012-08-22 10:25:20 -0700694 if [ $(echo $arch | wc -w) -gt 1 ]; then
695 echo "tapas: Error: Multiple build archs supplied: $arch"
696 return
697 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700698 if [ $(echo $variant | wc -w) -gt 1 ]; then
699 echo "tapas: Error: Multiple build variants supplied: $variant"
700 return
701 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700702 if [ $(echo $density | wc -w) -gt 1 ]; then
703 echo "tapas: Error: Multiple densities supplied: $density"
704 return
705 fi
Ying Wang67f02922012-08-22 10:25:20 -0700706
707 local product=full
708 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700709 x86) product=full_x86;;
710 mips) product=full_mips;;
711 armv5) product=generic_armv5;;
712 arm64) product=aosp_arm64;;
713 x86_64) product=aosp_x86_64;;
714 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700715 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700716 if [ -z "$variant" ]; then
717 variant=eng
718 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700719 if [ -z "$apps" ]; then
720 apps=all
721 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600722 if [ -z "$density" ]; then
723 density=alldpi
724 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700725
Ying Wang67f02922012-08-22 10:25:20 -0700726 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700727 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700728 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700729 export TARGET_BUILD_TYPE=release
730 export TARGET_BUILD_APPS=$apps
731
732 set_stuff_for_environment
733 printconfig
734}
735
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100736function eat()
737{
738 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530739 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100740 ZIPFILE=cm-$MODVERSION.zip
741 ZIPPATH=$OUT/$ZIPFILE
742 if [ ! -f $ZIPPATH ] ; then
743 echo "Nothing to eat"
744 return 1
745 fi
746 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
747 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
748 echo "No device is online. Waiting for one..."
749 echo "Please connect USB and/or enable USB debugging"
750 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
751 sleep 1
752 done
753 echo "Device Found.."
754 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530755 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
756 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100757 # if adbd isn't root we can't write to /cache/recovery/
758 adb root
759 sleep 1
760 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700761 cat << EOF > /tmp/command
762--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100763EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700764 if adb push /tmp/command /cache/recovery/ ; then
765 echo "Rebooting into recovery for sideload installation"
766 adb reboot recovery
767 adb wait-for-sideload
768 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100769 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700770 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100771 else
772 echo "Nothing to eat"
773 return 1
774 fi
775 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530776 else
777 echo "The connected device does not appear to be $CM_BUILD, run away!"
778 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100779}
780
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000781function omnom
782{
783 brunch $*
784 eat
785}
786
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787function gettop
788{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800789 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700791 # The following circumlocution ensures we remove symlinks from TOP.
792 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 else
794 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800795 # The following circumlocution (repeated below as well) ensures
796 # that we record the true directory name and not one that is
797 # faked up with symlink names.
798 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800800 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 T=
802 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800803 \cd ..
synergyb112a402013-07-05 19:47:47 -0700804 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700805 done
Ying Wang9cd17642012-12-13 10:52:07 -0800806 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700807 if [ -f "$T/$TOPFILE" ]; then
808 echo $T
809 fi
810 fi
811 fi
812}
813
Andrew Hsieh906cb782013-09-10 17:37:14 +0800814# Return driver for "make", if any (eg. static analyzer)
815function getdriver()
816{
817 local T="$1"
818 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
819 if [ -n "$WITH_STATIC_ANALYZER" ]; then
820 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800821$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
822--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800823--status-bugs \
824--top=$T"
825 fi
826}
827
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700828function m()
829{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800830 local T=$(gettop)
831 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700832 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800833 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834 else
835 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700836 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700837 fi
838}
839
840function findmakefile()
841{
842 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800843 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844 T=
845 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700846 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847 if [ -f "$T/Android.mk" ]; then
848 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800849 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850 return
851 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800852 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700853 done
Ying Wang9cd17642012-12-13 10:52:07 -0800854 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855}
856
857function mm()
858{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800859 local T=$(gettop)
860 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700861 # If we're sitting in the root of the build tree, just do a
862 # normal make.
863 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800864 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700865 else
866 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800867 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700868 local MODULES=
869 local GET_INSTALL_PATH=
870 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700871 # Remove the path to top as the makefilepath needs to be relative
872 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873 if [ ! "$T" ]; then
874 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700875 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700876 elif [ ! "$M" ]; then
877 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700878 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700879 else
Ying Wanga7deb082013-08-16 13:24:47 -0700880 for ARG in $@; do
881 case $ARG in
882 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
883 esac
884 done
885 if [ -n "$GET_INSTALL_PATH" ]; then
886 MODULES=
887 ARGS=GET-INSTALL-PATH
888 else
889 MODULES=all_modules
890 ARGS=$@
891 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700892 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 -0700893 fi
894 fi
895}
896
897function mmm()
898{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800899 local T=$(gettop)
900 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700901 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800902 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800903 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800904 local ARGS=
905 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700906 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800907 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
908 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
909 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800910 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
911 if [ "$MODULES" = "" ]; then
912 MODULES=all_modules
913 fi
914 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700916 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
917 local TO_CHOP=`expr $TO_CHOP + 1`
918 local START=`PWD= /bin/pwd`
919 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700920 if [ "$MFILE" = "" ] ; then
921 MFILE=$DIR/Android.mk
922 else
923 MFILE=$MFILE/$DIR/Android.mk
924 fi
925 MAKEFILE="$MAKEFILE $MFILE"
926 else
Ying Wanga7deb082013-08-16 13:24:47 -0700927 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100928 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700929 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
930 *) echo "No Android.mk in $DIR."; return 1;;
931 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 fi
933 done
Ying Wanga7deb082013-08-16 13:24:47 -0700934 if [ -n "$GET_INSTALL_PATH" ]; then
935 ARGS=$GET_INSTALL_PATH
936 MODULES=
937 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800938 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 -0700939 else
940 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700941 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942 fi
943}
944
Ying Wangb607f7b2013-02-08 18:01:04 -0800945function mma()
946{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800947 local T=$(gettop)
948 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800949 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800950 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800951 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800952 if [ ! "$T" ]; then
953 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700954 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800955 fi
956 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800957 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800958 fi
959}
960
961function mmma()
962{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800963 local T=$(gettop)
964 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800965 if [ "$T" ]; then
966 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
967 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
968 local MY_PWD=`PWD= /bin/pwd`
969 if [ "$MY_PWD" = "$T" ]; then
970 MY_PWD=
971 else
972 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
973 fi
974 local DIR=
975 local MODULE_PATHS=
976 local ARGS=
977 for DIR in $DIRS ; do
978 if [ -d $DIR ]; then
979 if [ "$MY_PWD" = "" ]; then
980 MODULE_PATHS="$MODULE_PATHS $DIR"
981 else
982 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
983 fi
984 else
985 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100986 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800987 *) echo "Couldn't find directory $DIR"; return 1;;
988 esac
989 fi
990 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800991 $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 -0800992 else
993 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700994 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800995 fi
996}
997
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998function croot()
999{
1000 T=$(gettop)
1001 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001002 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001003 else
1004 echo "Couldn't locate the top of the tree. Try setting TOP."
1005 fi
1006}
1007
nebkatfb67a1e2012-12-28 10:40:45 +00001008function cout()
1009{
1010 if [ "$OUT" ]; then
1011 cd $OUT
1012 else
1013 echo "Couldn't locate out directory. Try setting OUT."
1014 fi
1015}
1016
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001017function cproj()
1018{
1019 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 local HERE=$PWD
1021 T=
1022 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1023 T=$PWD
1024 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001025 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001026 return
1027 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001028 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001029 done
Ying Wang9cd17642012-12-13 10:52:07 -08001030 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001031 echo "can't find Android.mk"
1032}
1033
Daniel Sandler47e0a882013-07-30 13:23:52 -04001034# simplified version of ps; output in the form
1035# <pid> <procname>
1036function qpid() {
1037 local prepend=''
1038 local append=''
1039 if [ "$1" = "--exact" ]; then
1040 prepend=' '
1041 append='$'
1042 shift
1043 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1044 echo "usage: qpid [[--exact] <process name|pid>"
1045 return 255
1046 fi
1047
1048 local EXE="$1"
1049 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001050 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001051 else
1052 adb shell ps \
1053 | tr -d '\r' \
1054 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1055 fi
1056}
1057
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001058function pid()
1059{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001060 local prepend=''
1061 local append=''
1062 if [ "$1" = "--exact" ]; then
1063 prepend=' '
1064 append='$'
1065 shift
1066 fi
1067 local EXE="$1"
1068 if [ "$EXE" ] ; then
1069 local PID=`adb shell ps \
1070 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001071 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001072 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1073 echo "$PID"
1074 else
1075 echo "usage: pid [--exact] <process name>"
1076 return 255
1077 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001078}
1079
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001080# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001081# that has the core-file-size limit set correctly
1082#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001083# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001084# if its core-file-size limit is not set already.
1085# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1086
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001087function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088{
1089 echo "Getting root...";
1090 adb root;
1091 adb wait-for-device;
1092
1093 echo "Remounting root parition read-write...";
1094 adb shell mount -w -o remount -t rootfs rootfs;
1095 sleep 1;
1096 adb wait-for-device;
1097 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001098 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001099 adb shell chmod 0777 /cores;
1100
1101 echo "Granting SELinux permission to dump in /cores...";
1102 adb shell restorecon -R /cores;
1103
1104 echo "Set core pattern.";
1105 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1106
1107 echo "Done."
1108}
1109
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001110# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001111# $1 = PID of process (e.g., $(pid mediaserver))
1112#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001113# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001114# dump to actually be generated.
1115
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001116function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001117{
1118 local PID=$1;
1119 if [ -z "$PID" ]; then
1120 printf "Expecting a PID!\n";
1121 return;
1122 fi;
1123 echo "Setting core limit for $PID to infinite...";
1124 adb shell prlimit $PID 4 -1 -1
1125}
1126
1127# core - send SIGV and pull the core for process
1128# $1 = PID of process (e.g., $(pid mediaserver))
1129#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001130# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001131# enabled globally.
1132
1133function core()
1134{
1135 local PID=$1;
1136
1137 if [ -z "$PID" ]; then
1138 printf "Expecting a PID!\n";
1139 return;
1140 fi;
1141
1142 local CORENAME=core.$PID;
1143 local COREPATH=/cores/$CORENAME;
1144 local SIG=SEGV;
1145
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001146 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001147
1148 local done=0;
1149 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1150 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1151 adb shell kill -$SIG $PID;
1152 sleep 1;
1153 done;
1154
1155 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1156 echo "Done: core is under $COREPATH on device.";
1157}
1158
Christopher Tate744ee802009-11-12 15:33:08 -08001159# systemstack - dump the current stack trace of all threads in the system process
1160# to the usual ANR traces file
1161function systemstack()
1162{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001163 stacks system_server
1164}
1165
1166function stacks()
1167{
1168 if [[ $1 =~ ^[0-9]+$ ]] ; then
1169 local PID="$1"
1170 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001171 local PIDLIST="$(pid $1)"
1172 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1173 local PID="$PIDLIST"
1174 elif [ "$PIDLIST" ] ; then
1175 echo "more than one process: $1"
1176 else
1177 echo "no such process: $1"
1178 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001179 else
1180 echo "usage: stacks [pid|process name]"
1181 fi
1182
1183 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001184 # Determine whether the process is native
1185 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1186 # Dump stacks of Dalvik process
1187 local TRACES=/data/anr/traces.txt
1188 local ORIG=/data/anr/traces.orig
1189 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001190
Jeff Brownb12c2e52013-08-19 15:14:16 -07001191 # Keep original traces to avoid clobbering
1192 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001193
Jeff Brownb12c2e52013-08-19 15:14:16 -07001194 # Make sure we have a usable file
1195 adb shell touch $TRACES
1196 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001197
Jeff Brownb12c2e52013-08-19 15:14:16 -07001198 # Dump stacks and wait for dump to finish
1199 adb shell kill -3 $PID
1200 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001201
Jeff Brownb12c2e52013-08-19 15:14:16 -07001202 # Restore original stacks, and show current output
1203 adb shell mv $TRACES $TMP
1204 adb shell mv $ORIG $TRACES
1205 adb shell cat $TMP
1206 else
1207 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001208 local USE64BIT="$(is64bit $PID)"
1209 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001210 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001211 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001212}
1213
Michael Wrightaeed7212014-06-19 19:58:12 -07001214# Read the ELF header from /proc/$PID/exe to determine if the process is
1215# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001216function is64bit()
1217{
1218 local PID="$1"
1219 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001220 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001221 echo "64"
1222 else
1223 echo ""
1224 fi
1225 else
1226 echo ""
1227 fi
1228}
1229
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001230case `uname -s` in
1231 Darwin)
1232 function sgrep()
1233 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001234 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 -07001235 }
1236
1237 ;;
1238 *)
1239 function sgrep()
1240 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001241 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 -07001242 }
1243 ;;
1244esac
1245
Raghu Gandham8da43102012-07-25 19:57:22 -07001246function gettargetarch
1247{
1248 get_build_var TARGET_ARCH
1249}
1250
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001251function ggrep()
1252{
1253 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1254}
1255
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001256function jgrep()
1257{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001258 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 -07001259}
1260
1261function cgrep()
1262{
Dan Albert01961192014-11-22 10:16:01 -08001263 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 -07001264}
1265
1266function resgrep()
1267{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001268 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 -07001269}
1270
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001271function mangrep()
1272{
1273 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1274}
1275
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001276function sepgrep()
1277{
1278 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 "$@"
1279}
1280
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001281function rcgrep()
1282{
1283 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1284}
1285
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001286case `uname -s` in
1287 Darwin)
1288 function mgrep()
1289 {
Ying Wang324c2b22012-08-17 15:03:20 -07001290 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 -07001291 }
1292
1293 function treegrep()
1294 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001295 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 -07001296 }
1297
1298 ;;
1299 *)
1300 function mgrep()
1301 {
Ying Wang324c2b22012-08-17 15:03:20 -07001302 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 -07001303 }
1304
1305 function treegrep()
1306 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001307 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 -07001308 }
1309
1310 ;;
1311esac
1312
1313function getprebuilt
1314{
1315 get_abs_build_var ANDROID_PREBUILTS
1316}
1317
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001318function tracedmdump()
1319{
1320 T=$(gettop)
1321 if [ ! "$T" ]; then
1322 echo "Couldn't locate the top of the tree. Try setting TOP."
1323 return
1324 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001325 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001326 local arch=$(gettargetarch)
1327 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001328
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001329 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001330 if [ ! "$TRACE" ] ; then
1331 echo "usage: tracedmdump tracename"
1332 return
1333 fi
1334
Jack Veenstra60116fc2009-04-09 18:12:34 -07001335 if [ ! -r "$KERNEL" ] ; then
1336 echo "Error: cannot find kernel: '$KERNEL'"
1337 return
1338 fi
1339
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001340 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001341 if [ "$BASETRACE" = "$TRACE" ] ; then
1342 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1343 fi
1344
1345 echo "post-processing traces..."
1346 rm -f $TRACE/qtrace.dexlist
1347 post_trace $TRACE
1348 if [ $? -ne 0 ]; then
1349 echo "***"
1350 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1351 echo "***"
1352 return
1353 fi
1354 echo "generating dexlist output..."
1355 /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
1356 echo "generating dmtrace data..."
1357 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1358 echo "generating html file..."
1359 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1360 echo "done, see $TRACE/dmtrace.html for details"
1361 echo "or run:"
1362 echo " traceview $TRACE/dmtrace"
1363}
1364
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001365# communicate with a running device or emulator, set up necessary state,
1366# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001367function runhat()
1368{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001369 # process standard adb options
1370 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001371 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001372 adbTarget=$1
1373 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001374 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001375 adbTarget="$1 $2"
1376 shift 2
1377 fi
1378 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001379 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380
1381 # runhat options
1382 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001383
1384 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001385 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001386 return
1387 fi
1388
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001389 # confirm hat is available
1390 if [ -z $(which hat) ]; then
1391 echo "hat is not available in this configuration."
1392 return
1393 fi
1394
Andy McFaddenb6289852010-07-12 08:00:19 -07001395 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001396 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001398 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001399 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401 echo -n "> "
1402 read
1403
The Android Open Source Project88b60792009-03-03 19:28:42 -08001404 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001405
The Android Open Source Project88b60792009-03-03 19:28:42 -08001406 echo "Retrieving file $devFile..."
1407 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001408
The Android Open Source Project88b60792009-03-03 19:28:42 -08001409 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001410
The Android Open Source Project88b60792009-03-03 19:28:42 -08001411 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001412 echo "View the output by pointing your browser at http://localhost:7000/"
1413 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001414 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001415}
1416
1417function getbugreports()
1418{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001419 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420
1421 if [ ! "$reports" ]; then
1422 echo "Could not locate any bugreports."
1423 return
1424 fi
1425
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001426 local report
1427 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001428 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001429 echo "/sdcard/bugreports/${report}"
1430 adb pull /sdcard/bugreports/${report} ${report}
1431 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001432 done
1433}
1434
Victoria Lease1b296b42012-08-21 15:44:06 -07001435function getsdcardpath()
1436{
1437 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1438}
1439
1440function getscreenshotpath()
1441{
1442 echo "$(getsdcardpath)/Pictures/Screenshots"
1443}
1444
1445function getlastscreenshot()
1446{
1447 local screenshot_path=$(getscreenshotpath)
1448 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1449 if [ "$screenshot" = "" ]; then
1450 echo "No screenshots found."
1451 return
1452 fi
1453 echo "${screenshot}"
1454 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1455}
1456
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001457function startviewserver()
1458{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001459 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001460 if [ $# -gt 0 ]; then
1461 port=$1
1462 fi
1463 adb shell service call window 1 i32 $port
1464}
1465
1466function stopviewserver()
1467{
1468 adb shell service call window 2
1469}
1470
1471function isviewserverstarted()
1472{
1473 adb shell service call window 3
1474}
1475
Romain Guyb84049a2010-10-04 16:56:11 -07001476function key_home()
1477{
1478 adb shell input keyevent 3
1479}
1480
1481function key_back()
1482{
1483 adb shell input keyevent 4
1484}
1485
1486function key_menu()
1487{
1488 adb shell input keyevent 82
1489}
1490
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001491function smoketest()
1492{
1493 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1494 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1495 return
1496 fi
1497 T=$(gettop)
1498 if [ ! "$T" ]; then
1499 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1500 return
1501 fi
1502
Ying Wang9cd17642012-12-13 10:52:07 -08001503 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001504 adb uninstall com.android.smoketest > /dev/null &&
1505 adb uninstall com.android.smoketest.tests > /dev/null &&
1506 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1507 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1508 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1509}
1510
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001511# simple shortcut to the runtest command
1512function runtest()
1513{
1514 T=$(gettop)
1515 if [ ! "$T" ]; then
1516 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1517 return
1518 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001519 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001520}
1521
The Android Open Source Project88b60792009-03-03 19:28:42 -08001522function godir () {
1523 if [[ -z "$1" ]]; then
1524 echo "Usage: godir <regex>"
1525 return
1526 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001527 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001528 if [[ ! -f $T/filelist ]]; then
1529 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001530 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001531 echo " Done"
1532 echo ""
1533 fi
1534 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001535 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001536 if [[ ${#lines[@]} = 0 ]]; then
1537 echo "Not found"
1538 return
1539 fi
1540 local pathname
1541 local choice
1542 if [[ ${#lines[@]} > 1 ]]; then
1543 while [[ -z "$pathname" ]]; do
1544 local index=1
1545 local line
1546 for line in ${lines[@]}; do
1547 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001548 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001549 done
1550 echo
1551 echo -n "Select one: "
1552 unset choice
1553 read choice
1554 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1555 echo "Invalid choice"
1556 continue
1557 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001558 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001559 done
1560 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001561 pathname=${lines[0]}
1562 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001563 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001564}
1565
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001566function cmremote()
1567{
1568 git remote rm cmremote 2> /dev/null
1569 if [ ! -d .git ]
1570 then
1571 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1572 fi
1573 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1574 if [ -z "$GERRIT_REMOTE" ]
1575 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001576 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1577 if [ -z "$GERRIT_REMOTE" ]
1578 then
1579 echo Unable to set up the git remote, are you in the root of the repo?
1580 return 0
1581 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001582 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001583 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001584 if [ -z "$CMUSER" ]
1585 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001586 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001587 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001588 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001589 fi
1590 echo You can now push to "cmremote".
1591}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001592
Steve Kondik873fa562012-09-17 11:33:18 -07001593function aospremote()
1594{
1595 git remote rm aosp 2> /dev/null
1596 if [ ! -d .git ]
1597 then
1598 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1599 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001600 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001601 if (echo $PROJECT | grep -qv "^device")
1602 then
1603 PFX="platform/"
1604 fi
1605 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1606 echo "Remote 'aosp' created"
1607}
Steve Kondik873fa562012-09-17 11:33:18 -07001608
Steve Kondik20c21d22013-10-27 13:34:36 -07001609function cafremote()
1610{
1611 git remote rm caf 2> /dev/null
1612 if [ ! -d .git ]
1613 then
1614 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1615 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001616 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001617 if (echo $PROJECT | grep -qv "^device")
1618 then
1619 PFX="platform/"
1620 fi
1621 git remote add caf git://codeaurora.org/$PFX$PROJECT
1622 echo "Remote 'caf' created"
1623}
Steve Kondik20c21d22013-10-27 13:34:36 -07001624
Steve Kondikf00e7d92012-09-23 23:46:55 -07001625function installboot()
1626{
1627 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1628 then
1629 echo "No recovery.fstab found. Build recovery first."
1630 return 1
1631 fi
1632 if [ ! -e "$OUT/boot.img" ];
1633 then
1634 echo "No boot.img found. Run make bootimage first."
1635 return 1
1636 fi
1637 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1638 if [ -z "$PARTITION" ];
1639 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001640 # Try for RECOVERY_FSTAB_VERSION = 2
1641 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1642 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1643 if [ -z "$PARTITION" ];
1644 then
1645 echo "Unable to determine boot partition."
1646 return 1
1647 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001648 fi
1649 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001650 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001651 adb root
1652 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001653 adb wait-for-online shell mount /system 2>&1 > /dev/null
1654 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001655 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1656 then
1657 adb push $OUT/boot.img /cache/
1658 for i in $OUT/system/lib/modules/*;
1659 do
1660 adb push $i /system/lib/modules/
1661 done
1662 adb shell dd if=/cache/boot.img of=$PARTITION
1663 adb shell chmod 644 /system/lib/modules/*
1664 echo "Installation complete."
1665 else
1666 echo "The connected device does not appear to be $CM_BUILD, run away!"
1667 fi
1668}
1669
Steve Kondik83c03d52012-10-24 16:40:42 -07001670function installrecovery()
1671{
1672 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1673 then
1674 echo "No recovery.fstab found. Build recovery first."
1675 return 1
1676 fi
1677 if [ ! -e "$OUT/recovery.img" ];
1678 then
1679 echo "No recovery.img found. Run make recoveryimage first."
1680 return 1
1681 fi
1682 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1683 if [ -z "$PARTITION" ];
1684 then
Steve Kondik75f10762013-08-09 21:03:42 -07001685 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001686 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1687 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001688 if [ -z "$PARTITION" ];
1689 then
1690 echo "Unable to determine recovery partition."
1691 return 1
1692 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001693 fi
1694 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001695 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001696 adb root
1697 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001698 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1699 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001700 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1701 then
1702 adb push $OUT/recovery.img /cache/
1703 adb shell dd if=/cache/recovery.img of=$PARTITION
1704 echo "Installation complete."
1705 else
1706 echo "The connected device does not appear to be $CM_BUILD, run away!"
1707 fi
1708}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001709
Koushik Duttab55f13a2012-05-14 16:14:36 -07001710function makerecipe() {
1711 if [ -z "$1" ]
1712 then
1713 echo "No branch name provided."
1714 return 1
1715 fi
1716 cd android
1717 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1718 git commit -a -m "$1"
1719 cd ..
1720
1721 repo forall -c '
1722
1723 if [ "$REPO_REMOTE" == "github" ]
1724 then
1725 pwd
1726 cmremote
1727 git push cmremote HEAD:refs/heads/'$1'
1728 fi
1729 '
1730}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001731
1732function cmgerrit() {
1733 if [ $# -eq 0 ]; then
1734 $FUNCNAME help
1735 return 1
1736 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001737 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001738 local review=`git config --get remote.github.review`
1739 local project=`git config --get remote.github.projectname`
1740 local command=$1
1741 shift
1742 case $command in
1743 help)
1744 if [ $# -eq 0 ]; then
1745 cat <<EOF
1746Usage:
1747 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1748
1749Commands:
1750 fetch Just fetch the change as FETCH_HEAD
1751 help Show this help, or for a specific command
1752 pull Pull a change into current branch
1753 push Push HEAD or a local branch to Gerrit for a specific branch
1754
1755Any other Git commands that support refname would work as:
1756 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1757
1758See '$FUNCNAME help COMMAND' for more information on a specific command.
1759
1760Example:
1761 $FUNCNAME checkout -b topic 1234/5
1762works as:
1763 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1764 && git checkout -b topic FETCH_HEAD
1765will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1766Patch-set 1 will be fetched if omitted.
1767EOF
1768 return
1769 fi
1770 case $1 in
1771 __cmg_*) echo "For internal use only." ;;
1772 changes|for)
1773 if [ "$FUNCNAME" = "cmgerrit" ]; then
1774 echo "'$FUNCNAME $1' is deprecated."
1775 fi
1776 ;;
1777 help) $FUNCNAME help ;;
1778 fetch|pull) cat <<EOF
1779usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1780
1781works as:
1782 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1783 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1784
1785Example:
1786 $FUNCNAME $1 1234
1787will $1 patch-set 1 of change 1234
1788EOF
1789 ;;
1790 push) cat <<EOF
1791usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1792
1793works as:
1794 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1795 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1796
1797Example:
1798 $FUNCNAME push fix6789:gingerbread
1799will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1800HEAD will be pushed from local if omitted.
1801EOF
1802 ;;
1803 *)
1804 $FUNCNAME __cmg_err_not_supported $1 && return
1805 cat <<EOF
1806usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1807
1808works as:
1809 git fetch http://DOMAIN/p/PROJECT \\
1810 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1811 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1812EOF
1813 ;;
1814 esac
1815 ;;
1816 __cmg_get_ref)
1817 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1818 local change_id patchset_id hash
1819 case $1 in
1820 */*)
1821 change_id=${1%%/*}
1822 patchset_id=${1#*/}
1823 ;;
1824 *)
1825 change_id=$1
1826 patchset_id=1
1827 ;;
1828 esac
1829 hash=$(($change_id % 100))
1830 case $hash in
1831 [0-9]) hash="0$hash" ;;
1832 esac
1833 echo "refs/changes/$hash/$change_id/$patchset_id"
1834 ;;
1835 fetch|pull)
1836 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1837 $FUNCNAME __cmg_err_not_repo && return 1
1838 local change=$1
1839 shift
1840 git $command $@ http://$review/p/$project \
1841 $($FUNCNAME __cmg_get_ref $change) || return 1
1842 ;;
1843 push)
1844 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1845 $FUNCNAME __cmg_err_not_repo && return 1
1846 if [ -z "$user" ]; then
1847 echo >&2 "Gerrit username not found."
1848 return 1
1849 fi
1850 local local_branch remote_branch
1851 case $1 in
1852 *:*)
1853 local_branch=${1%:*}
1854 remote_branch=${1##*:}
1855 ;;
1856 *)
1857 local_branch=HEAD
1858 remote_branch=$1
1859 ;;
1860 esac
1861 shift
1862 git push $@ ssh://$user@$review:29418/$project \
1863 $local_branch:refs/for/$remote_branch || return 1
1864 ;;
1865 changes|for)
1866 if [ "$FUNCNAME" = "cmgerrit" ]; then
1867 echo >&2 "'$FUNCNAME $command' is deprecated."
1868 fi
1869 ;;
1870 __cmg_err_no_arg)
1871 if [ $# -lt 2 ]; then
1872 echo >&2 "'$FUNCNAME $command' missing argument."
1873 elif [ $2 -eq 0 ]; then
1874 if [ -n "$3" ]; then
1875 $FUNCNAME help $1
1876 else
1877 echo >&2 "'$FUNCNAME $1' missing argument."
1878 fi
1879 else
1880 return 1
1881 fi
1882 ;;
1883 __cmg_err_not_repo)
1884 if [ -z "$review" -o -z "$project" ]; then
1885 echo >&2 "Not currently in any reviewable repository."
1886 else
1887 return 1
1888 fi
1889 ;;
1890 __cmg_err_not_supported)
1891 $FUNCNAME __cmg_err_no_arg $command $# && return
1892 case $1 in
1893 #TODO: filter more git commands that don't use refname
1894 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1895 echo >&2 "'$FUNCNAME $1' is not supported."
1896 ;;
1897 *) return 1 ;;
1898 esac
1899 ;;
1900 #TODO: other special cases?
1901 *)
1902 $FUNCNAME __cmg_err_not_supported $command && return 1
1903 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1904 $FUNCNAME __cmg_err_not_repo && return 1
1905 local args="$@"
1906 local change pre_args refs_arg post_args
1907 case "$args" in
1908 *--\ *)
1909 pre_args=${args%%-- *}
1910 post_args="-- ${args#*-- }"
1911 ;;
1912 *) pre_args="$args" ;;
1913 esac
1914 args=($pre_args)
1915 pre_args=
1916 if [ ${#args[@]} -gt 0 ]; then
1917 change=${args[${#args[@]}-1]}
1918 fi
1919 if [ ${#args[@]} -gt 1 ]; then
1920 pre_args=${args[0]}
1921 for ((i=1; i<${#args[@]}-1; i++)); do
1922 pre_args="$pre_args ${args[$i]}"
1923 done
1924 fi
1925 while ((1)); do
1926 case $change in
1927 ""|--)
1928 $FUNCNAME help $command
1929 return 1
1930 ;;
1931 *@*)
1932 if [ -z "$refs_arg" ]; then
1933 refs_arg="@${change#*@}"
1934 change=${change%%@*}
1935 fi
1936 ;;
1937 *~*)
1938 if [ -z "$refs_arg" ]; then
1939 refs_arg="~${change#*~}"
1940 change=${change%%~*}
1941 fi
1942 ;;
1943 *^*)
1944 if [ -z "$refs_arg" ]; then
1945 refs_arg="^${change#*^}"
1946 change=${change%%^*}
1947 fi
1948 ;;
1949 *:*)
1950 if [ -z "$refs_arg" ]; then
1951 refs_arg=":${change#*:}"
1952 change=${change%%:*}
1953 fi
1954 ;;
1955 *) break ;;
1956 esac
1957 done
1958 $FUNCNAME fetch $change \
1959 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1960 || return 1
1961 ;;
1962 esac
1963}
1964
1965function cmrebase() {
1966 local repo=$1
1967 local refs=$2
1968 local pwd="$(pwd)"
1969 local dir="$(gettop)/$repo"
1970
1971 if [ -z $repo ] || [ -z $refs ]; then
1972 echo "CyanogenMod Gerrit Rebase Usage: "
1973 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1974 echo " The patch IDs appear on the Gerrit commands that are offered."
1975 echo " They consist on a series of numbers and slashes, after the text"
1976 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1977 echo ""
1978 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1979 echo ""
1980 return
1981 fi
1982
1983 if [ ! -d $dir ]; then
1984 echo "Directory $dir doesn't exist in tree."
1985 return
1986 fi
1987 cd $dir
1988 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1989 echo "Starting branch..."
1990 repo start tmprebase .
1991 echo "Bringing it up to date..."
1992 repo sync .
1993 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001994 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001995 if [ "$?" != "0" ]; then
1996 echo "Error cherry-picking. Not uploading!"
1997 return
1998 fi
1999 echo "Uploading..."
2000 repo upload .
2001 echo "Cleaning up..."
2002 repo abandon tmprebase .
2003 cd $pwd
2004}
2005
2006function mka() {
2007 case `uname -s` in
2008 Darwin)
2009 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2010 ;;
2011 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07002012 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002013 ;;
2014 esac
2015}
2016
2017function reposync() {
2018 case `uname -s` in
2019 Darwin)
2020 repo sync -j 4 "$@"
2021 ;;
2022 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002023 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002024 ;;
2025 esac
2026}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002027
2028function repodiff() {
2029 if [ -z "$*" ]; then
2030 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2031 return
2032 fi
2033 diffopts=$* repo forall -c \
2034 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2035}
2036
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302037# Credit for color strip sed: http://goo.gl/BoIcm
2038function dopush()
2039{
2040 local func=$1
2041 shift
2042
2043 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2044 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2045 echo "No device is online. Waiting for one..."
2046 echo "Please connect USB and/or enable USB debugging"
2047 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2048 sleep 1
2049 done
2050 echo "Device Found."
2051 fi
2052
Chirayu Desai6dadb572012-12-26 10:53:58 +05302053 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2054 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002055 # retrieve IP and PORT info if we're using a TCP connection
2056 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2057 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302058 adb root &> /dev/null
2059 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002060 if [ -n "$TCPIPPORT" ]
2061 then
2062 # adb root just killed our connection
2063 # so reconnect...
2064 adb connect "$TCPIPPORT"
2065 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302066 adb wait-for-device &> /dev/null
2067 sleep 0.3
2068 adb remount &> /dev/null
2069
Matt Mower668ea262014-05-20 02:52:23 -05002070 mkdir -p $OUT
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302071 $func $* | tee $OUT/.log
2072
2073 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002074 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)"
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302075
2076 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002077 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)"
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302078
Matt Mower668ea262014-05-20 02:52:23 -05002079 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302080 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002081 # Make sure file is in $OUT/system
2082 case $FILE in
2083 $OUT/system/*)
2084 # Get target file name (i.e. /system/bin/adb)
2085 TARGET=$(echo $FILE | sed "s#$OUT##")
2086 ;;
2087 *) continue ;;
2088 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302089
Matt Mower668ea262014-05-20 02:52:23 -05002090 case $TARGET in
2091 /system/priv-app/SystemUI.apk|/system/framework/*)
2092 # Only need to stop services once
2093 if ! $stop_n_start; then
2094 adb shell stop
2095 stop_n_start=true
2096 fi
2097 echo "Pushing: $TARGET"
2098 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302099 ;;
2100 *)
Matt Mower668ea262014-05-20 02:52:23 -05002101 echo "Pushing: $TARGET"
2102 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302103 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002104 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302105 done
Matt Mower668ea262014-05-20 02:52:23 -05002106 if $stop_n_start; then
2107 adb shell start
2108 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302109 rm -f $OUT/.log
2110 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302111 else
2112 echo "The connected device does not appear to be $CM_BUILD, run away!"
2113 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302114}
2115
2116alias mmp='dopush mm'
2117alias mmmp='dopush mmm'
2118alias mkap='dopush mka'
2119alias cmkap='dopush cmka'
2120
Chirayu Desai4a319b82013-06-05 20:14:33 +05302121function repopick() {
2122 T=$(gettop)
2123 $T/build/tools/repopick.py $@
2124}
2125
Chirayu Desaib89b3242013-06-30 10:04:25 +05302126function fixup_common_out_dir() {
2127 common_out_dir=$(get_build_var OUT_DIR)/target/common
2128 target_device=$(get_build_var TARGET_DEVICE)
2129 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2130 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2131 mv ${common_out_dir} ${common_out_dir}-${target_device}
2132 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2133 else
2134 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2135 mkdir -p ${common_out_dir}-${target_device}
2136 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2137 fi
2138 else
2139 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2140 mkdir -p ${common_out_dir}
2141 fi
2142}
2143
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002144# 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 +00002145#
2146# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2147# For some reason, installing the JDK doesn't make it show up in the
2148# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002149function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002150 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002151 # we can reset it later, depending on the version of java the build
2152 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002153 #
2154 # If we don't do this, the JAVA_HOME value set by the first call to
2155 # build/envsetup.sh will persist forever.
2156 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2157 export JAVA_HOME=""
2158 fi
2159
Andy McFaddenbd960942010-06-24 12:52:51 -07002160 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002161 case `uname -s` in
2162 Darwin)
2163 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2164 ;;
2165 *)
2166 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2167 ;;
2168 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002169
2170 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2171 # we can change it on the next envsetup.sh, if required.
2172 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002173 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002174}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002175
Alex Rayf0d08eb2013-03-08 15:15:06 -08002176# Print colored exit condition
2177function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002178 "$@"
2179 local retval=$?
2180 if [ $retval -ne 0 ]
2181 then
2182 echo -e "\e[0;31mFAILURE\e[00m"
2183 else
2184 echo -e "\e[0;32mSUCCESS\e[00m"
2185 fi
2186 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002187}
2188
Ying Wanged21d4c2014-08-24 22:14:19 -07002189function get_make_command()
2190{
2191 echo command make
2192}
2193
Ed Heylcc6be0a2014-06-18 14:55:58 -07002194function make()
2195{
2196 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002197 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002198 local ret=$?
2199 local end_time=$(date +"%s")
2200 local tdiff=$(($end_time-$start_time))
2201 local hours=$(($tdiff / 3600 ))
2202 local mins=$((($tdiff % 3600) / 60))
2203 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002204 local ncolors=$(tput colors 2>/dev/null)
2205 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2206 color_failed="\e[0;31m"
2207 color_success="\e[0;32m"
2208 color_reset="\e[00m"
2209 else
2210 color_failed=""
2211 color_success=""
2212 color_reset=""
2213 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002214 echo
2215 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002216 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002217 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002218 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002219 fi
2220 if [ $hours -gt 0 ] ; then
2221 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2222 elif [ $mins -gt 0 ] ; then
2223 printf "(%02g:%02g (mm:ss))" $mins $secs
2224 elif [ $secs -gt 0 ] ; then
2225 printf "(%s seconds)" $secs
2226 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002227 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002228 echo
2229 return $ret
2230}
2231
Raphael Moll70a86b02011-06-20 16:03:14 -07002232if [ "x$SHELL" != "x/bin/bash" ]; then
2233 case `ps -o command -p $$` in
2234 *bash*)
2235 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002236 *zsh*)
2237 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002238 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002239 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002240 ;;
2241 esac
2242fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002243
2244# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002245for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2246 `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 -08002247do
2248 echo "including $f"
2249 . $f
2250done
2251unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002252
2253addcompletions