blob: 9a49eb342ae8bd51048db5b47b00649d35d9ec79 [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
Chirayu Desaicf2bdb62012-09-28 11:56:02 +053030- mkap: Builds the module(s) using mka and pushes them to the device.
31- cmka: Cleans and builds using mka.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060032- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053033- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070034- installboot: Installs a boot.img to the connected device.
35- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070036
Dan Albert4ae5d4b2014-10-31 16:23:08 -070037Environemnt options:
38- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
39 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
40 build is leak-check clean.
41
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070042Look at the source to view more functions. The complete list is:
43EOF
44 T=$(gettop)
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
Anthony King0780f2f2015-04-30 23:16:10 +010046 echo "$i"
47 done | column
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070048}
49
50# Get the value of a build variable as an absolute path.
51function get_abs_build_var()
52{
53 T=$(gettop)
54 if [ ! "$T" ]; then
55 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
56 return
57 fi
Ying Wang9cd17642012-12-13 10:52:07 -080058 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070059 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070060}
61
62# Get the exact value of a build variable.
63function get_build_var()
64{
65 T=$(gettop)
66 if [ ! "$T" ]; then
67 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
68 return
69 fi
Andrew Boie6905e212013-12-19 13:21:46 -080070 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070071 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080072}
73
74# check to see if the supplied product is one we can build
75function check_product()
76{
77 T=$(gettop)
78 if [ ! "$T" ]; then
79 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
80 return
81 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000082
83 if (echo -n $1 | grep -q -e "^cm_") ; then
84 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
Ricardo Cerqueira34ae3232013-09-26 00:10:20 +010085 export BUILD_NUMBER=$((date +%s%N ; echo $CM_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10)
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000086 else
87 CM_BUILD=
88 fi
89 export CM_BUILD
90
Jeff Browne33ba4c2011-07-11 22:11:46 -070091 TARGET_PRODUCT=$1 \
92 TARGET_BUILD_VARIANT= \
93 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070094 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080095 get_build_var TARGET_DEVICE > /dev/null
96 # hide successful answers, but allow the errors to show
97}
98
99VARIANT_CHOICES=(user userdebug eng)
100
101# check to see if the supplied variant is valid
102function check_variant()
103{
104 for v in ${VARIANT_CHOICES[@]}
105 do
106 if [ "$v" = "$1" ]
107 then
108 return 0
109 fi
110 done
111 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700112}
113
114function setpaths()
115{
116 T=$(gettop)
117 if [ ! "$T" ]; then
118 echo "Couldn't locate the top of the tree. Try setting TOP."
119 return
120 fi
121
122 ##################################################################
123 # #
124 # Read me before you modify this code #
125 # #
126 # This function sets ANDROID_BUILD_PATHS to what it is adding #
127 # to PATH, and the next time it is run, it removes that from #
128 # PATH. This is required so lunch can be run more than once #
129 # and still have working paths. #
130 # #
131 ##################################################################
132
Raphael Mollc639c782011-06-20 17:25:01 -0700133 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
134 # due to "C:\Program Files" being in the path.
135
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700136 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700137 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700138 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
139 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700140 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700141 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800142 # strip leading ':', if any
143 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500144 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700145
146 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700147 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700148 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700149
Ben Cheng8bc4c432012-11-16 13:29:13 -0800150 # defined in core/config.mk
151 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700152 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800153 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800154
Raphael Mollc639c782011-06-20 17:25:01 -0700155 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800156 export ANDROID_TOOLCHAIN=
157 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200158 local ARCH=$(get_build_var TARGET_ARCH)
159 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400160 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700161 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400162 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
163 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800164 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200165 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800166 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700167 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700168 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700169 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000170 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200171 *)
172 echo "Can't find toolchain for unknown architecture: $ARCH"
173 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700174 ;;
175 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700176 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800177 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700178 fi
Raphael732936d2011-06-22 14:35:32 -0700179
Ben Chengfba67bf2014-02-25 10:27:07 -0800180 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
181 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
182 fi
183
184 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700185 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700186 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800187 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800188 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700189 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100190 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
191 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700192 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700193 ;;
194 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700195 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700196 ;;
197 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700198
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700199 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700200 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200201
202 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
203 # to ensure that the corresponding 'emulator' binaries are used.
204 case $(uname -s) in
205 Darwin)
206 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
207 ;;
208 Linux)
209 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
210 ;;
211 *)
212 ANDROID_EMULATOR_PREBUILTS=
213 ;;
214 esac
215 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700216 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200217 export ANDROID_EMULATOR_PREBUILTS
218 fi
219
Ying Wangaa1c9b52012-11-26 20:51:59 -0800220 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800221
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500222 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900223 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500224 if [ -n "$JAVA_HOME" ]; then
225 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900226 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
227 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500228 fi
229
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800230 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700231 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
232 export OUT=$ANDROID_PRODUCT_OUT
233
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700234 unset ANDROID_HOST_OUT
235 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
236
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800237 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700238 # TODO: fix the path
239 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
240}
241
242function printconfig()
243{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800244 T=$(gettop)
245 if [ ! "$T" ]; then
246 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
247 return
248 fi
249 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250}
251
252function set_stuff_for_environment()
253{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800254 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500255 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256 setpaths
257 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700258
Ben Chengaac3f812013-08-13 14:38:15 -0700259 # With this environment variable new GCC can apply colors to warnings/errors
260 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700261 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700262}
263
264function set_sequence_number()
265{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700266 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267}
268
269function settitle()
270{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800271 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700272 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700273 local product=$TARGET_PRODUCT
274 local variant=$TARGET_BUILD_VARIANT
275 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800276 if [ -z "$PROMPT_COMMAND" ]; then
277 # No prompts
278 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
279 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
280 # Prompts exist, but no hardstatus
281 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700282 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800283 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500284 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800285 fi
286
287 if [ -z "$apps" ]; then
288 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
289 else
290 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
291 fi
292 export ANDROID_PROMPT_PREFIX
293
294 # Inject build data into hardstatus
295 export PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/\\033]0;\(.*\)\\007/\\033]0;$ANDROID_PROMPT_PREFIX \1\\007/g')"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800296 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700297}
298
Kyle Ladd031a0b62013-09-11 20:43:42 -0400299function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700300{
Kenny Root52aa81c2011-07-15 11:07:06 -0700301 # Keep us from trying to run in something that isn't bash.
302 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400303 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700304 fi
305
306 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200307 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400308 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700309 fi
310
Kyle Ladd031a0b62013-09-11 20:43:42 -0400311 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700312}
313
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700314function choosetype()
315{
316 echo "Build type choices are:"
317 echo " 1. release"
318 echo " 2. debug"
319 echo
320
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800321 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700322 DEFAULT_NUM=1
323 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800325 export TARGET_BUILD_TYPE=
326 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327 while [ -z $TARGET_BUILD_TYPE ]
328 do
329 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 if [ -z "$1" ] ; then
331 read ANSWER
332 else
333 echo $1
334 ANSWER=$1
335 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700336 case $ANSWER in
337 "")
338 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
339 ;;
340 1)
341 export TARGET_BUILD_TYPE=release
342 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800343 release)
344 export TARGET_BUILD_TYPE=release
345 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 2)
347 export TARGET_BUILD_TYPE=debug
348 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349 debug)
350 export TARGET_BUILD_TYPE=debug
351 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700352 *)
353 echo
354 echo "I didn't understand your response. Please try again."
355 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700356 ;;
357 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800358 if [ -n "$1" ] ; then
359 break
360 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361 done
362
363 set_stuff_for_environment
364}
365
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800366#
367# This function isn't really right: It chooses a TARGET_PRODUCT
368# based on the list of boards. Usually, that gets you something
369# that kinda works with a generic product, but really, you should
370# pick a product by name.
371#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700372function chooseproduct()
373{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700374 if [ "x$TARGET_PRODUCT" != x ] ; then
375 default_value=$TARGET_PRODUCT
376 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700377 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378 fi
379
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800380 export TARGET_PRODUCT=
381 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700382 while [ -z "$TARGET_PRODUCT" ]
383 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700384 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800385 if [ -z "$1" ] ; then
386 read ANSWER
387 else
388 echo $1
389 ANSWER=$1
390 fi
391
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700392 if [ -z "$ANSWER" ] ; then
393 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800394 else
395 if check_product $ANSWER
396 then
397 export TARGET_PRODUCT=$ANSWER
398 else
399 echo "** Not a valid product: $ANSWER"
400 fi
401 fi
402 if [ -n "$1" ] ; then
403 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700404 fi
405 done
406
407 set_stuff_for_environment
408}
409
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800410function choosevariant()
411{
412 echo "Variant choices are:"
413 local index=1
414 local v
415 for v in ${VARIANT_CHOICES[@]}
416 do
417 # The product name is the name of the directory containing
418 # the makefile we found, above.
419 echo " $index. $v"
420 index=$(($index+1))
421 done
422
423 local default_value=eng
424 local ANSWER
425
426 export TARGET_BUILD_VARIANT=
427 while [ -z "$TARGET_BUILD_VARIANT" ]
428 do
429 echo -n "Which would you like? [$default_value] "
430 if [ -z "$1" ] ; then
431 read ANSWER
432 else
433 echo $1
434 ANSWER=$1
435 fi
436
437 if [ -z "$ANSWER" ] ; then
438 export TARGET_BUILD_VARIANT=$default_value
439 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
440 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800441 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800442 fi
443 else
444 if check_variant $ANSWER
445 then
446 export TARGET_BUILD_VARIANT=$ANSWER
447 else
448 echo "** Not a valid variant: $ANSWER"
449 fi
450 fi
451 if [ -n "$1" ] ; then
452 break
453 fi
454 done
455}
456
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700457function choosecombo()
458{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700459 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460
461 echo
462 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700463 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464
465 echo
466 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700467 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468
469 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800471 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700472}
473
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800474# Clear this variable. It will be built up again when the vendorsetup.sh
475# files are included at the end of this file.
476unset LUNCH_MENU_CHOICES
477function add_lunch_combo()
478{
479 local new_combo=$1
480 local c
481 for c in ${LUNCH_MENU_CHOICES[@]} ; do
482 if [ "$new_combo" = "$c" ] ; then
483 return
484 fi
485 done
486 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
487}
488
489# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700490add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800491add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000492add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800493add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000494add_lunch_combo aosp_x86-eng
495add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800496
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700497function print_lunch_menu()
498{
499 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700500 echo
501 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000502 if [ "$(uname)" = "Darwin" ] ; then
503 echo " (ohai, koush!)"
504 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000506 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
507 echo "Breakfast menu... pick a combo:"
508 else
509 echo "Lunch menu... pick a combo:"
510 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800511
512 local i=1
513 local choice
514 for choice in ${LUNCH_MENU_CHOICES[@]}
515 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100516 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100518 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000520 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
521 echo "... and don't forget the bacon!"
522 fi
523
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700524 echo
525}
526
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000527function brunch()
528{
529 breakfast $*
530 if [ $? -eq 0 ]; then
531 mka bacon
532 else
533 echo "No such item in brunch menu. Try 'breakfast'"
534 return 1
535 fi
536 return $?
537}
538
539function breakfast()
540{
541 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200542 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000543 CM_DEVICES_ONLY="true"
544 unset LUNCH_MENU_CHOICES
545 add_lunch_combo full-eng
546 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
547 do
548 echo "including $f"
549 . $f
550 done
551 unset f
552
553 if [ $# -eq 0 ]; then
554 # No arguments, so let's have the full menu
555 lunch
556 else
557 echo "z$target" | grep -q "-"
558 if [ $? -eq 0 ]; then
559 # A buildtype was specified, assume a full device name
560 lunch $target
561 else
562 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200563 if [ -z "$variant" ]; then
564 variant="userdebug"
565 fi
566 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000567 fi
568 fi
569 return $?
570}
571
572alias bib=breakfast
573
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700574function lunch()
575{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800576 local answer
Anthony King850627c2015-04-30 22:57:08 +0100577 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 else
582 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700583 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800584 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 fi
586
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 local selection=
588
589 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700591 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800592 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
593 then
594 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
595 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800596 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 fi
598 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
599 then
600 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601 fi
602
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 if [ -z "$selection" ]
604 then
605 echo
606 echo "Invalid lunch combo: $answer"
607 return 1
608 fi
609
Joe Onoratoda12daf2010-06-09 18:18:31 -0700610 export TARGET_BUILD_APPS=
611
Jeff Browne33ba4c2011-07-11 22:11:46 -0700612 local product=$(echo -n $selection | sed -e "s/-.*$//")
613 check_product $product
614 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800616 # if we can't find a product, try to grab it off the CM github
617 T=$(gettop)
618 pushd $T > /dev/null
619 build/tools/roomservice.py $product
620 popd > /dev/null
621 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000622 else
623 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800624 fi
625 if [ $? -ne 0 ]
626 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700627 echo
628 echo "** Don't have a product spec for: '$product'"
629 echo "** Do you have the right repo manifest?"
630 product=
631 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800632
Jeff Browne33ba4c2011-07-11 22:11:46 -0700633 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
634 check_variant $variant
635 if [ $? -ne 0 ]
636 then
637 echo
638 echo "** Invalid variant: '$variant'"
639 echo "** Must be one of ${VARIANT_CHOICES[@]}"
640 variant=
641 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642
Jeff Browne33ba4c2011-07-11 22:11:46 -0700643 if [ -z "$product" -o -z "$variant" ]
644 then
645 echo
646 return 1
647 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800648
Jeff Browne33ba4c2011-07-11 22:11:46 -0700649 export TARGET_PRODUCT=$product
650 export TARGET_BUILD_VARIANT=$variant
651 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652
653 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654
Chirayu Desaib89b3242013-06-30 10:04:25 +0530655 fixup_common_out_dir
656
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800658 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659}
660
Jeff Davidson513d7a42010-08-02 10:00:44 -0700661# Tab completion for lunch.
662function _lunch()
663{
664 local cur prev opts
665 COMPREPLY=()
666 cur="${COMP_WORDS[COMP_CWORD]}"
667 prev="${COMP_WORDS[COMP_CWORD-1]}"
668
669 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
670 return 0
671}
Emilio López9ad6eea2013-11-03 13:02:13 -0300672complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700673
Joe Onoratoda12daf2010-06-09 18:18:31 -0700674# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700675# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700676function tapas()
677{
Ying Wangb541ab62014-05-29 17:57:40 -0700678 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 -0700679 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700680 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
681 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 -0700682
Ying Wang67f02922012-08-22 10:25:20 -0700683 if [ $(echo $arch | wc -w) -gt 1 ]; then
684 echo "tapas: Error: Multiple build archs supplied: $arch"
685 return
686 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700687 if [ $(echo $variant | wc -w) -gt 1 ]; then
688 echo "tapas: Error: Multiple build variants supplied: $variant"
689 return
690 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700691 if [ $(echo $density | wc -w) -gt 1 ]; then
692 echo "tapas: Error: Multiple densities supplied: $density"
693 return
694 fi
Ying Wang67f02922012-08-22 10:25:20 -0700695
696 local product=full
697 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700698 x86) product=full_x86;;
699 mips) product=full_mips;;
700 armv5) product=generic_armv5;;
701 arm64) product=aosp_arm64;;
702 x86_64) product=aosp_x86_64;;
703 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700704 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700705 if [ -z "$variant" ]; then
706 variant=eng
707 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700708 if [ -z "$apps" ]; then
709 apps=all
710 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600711 if [ -z "$density" ]; then
712 density=alldpi
713 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700714
Ying Wang67f02922012-08-22 10:25:20 -0700715 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700716 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700717 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700718 export TARGET_BUILD_TYPE=release
719 export TARGET_BUILD_APPS=$apps
720
721 set_stuff_for_environment
722 printconfig
723}
724
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100725function eat()
726{
727 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530728 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100729 ZIPFILE=cm-$MODVERSION.zip
730 ZIPPATH=$OUT/$ZIPFILE
731 if [ ! -f $ZIPPATH ] ; then
732 echo "Nothing to eat"
733 return 1
734 fi
735 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
736 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
737 echo "No device is online. Waiting for one..."
738 echo "Please connect USB and/or enable USB debugging"
739 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
740 sleep 1
741 done
742 echo "Device Found.."
743 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530744 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
745 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100746 # if adbd isn't root we can't write to /cache/recovery/
747 adb root
748 sleep 1
749 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700750 cat << EOF > /tmp/command
751--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100752EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700753 if adb push /tmp/command /cache/recovery/ ; then
754 echo "Rebooting into recovery for sideload installation"
755 adb reboot recovery
756 adb wait-for-sideload
757 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100758 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700759 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100760 else
761 echo "Nothing to eat"
762 return 1
763 fi
764 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530765 else
766 echo "The connected device does not appear to be $CM_BUILD, run away!"
767 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100768}
769
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000770function omnom
771{
772 brunch $*
773 eat
774}
775
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700776function gettop
777{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800778 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700780 # The following circumlocution ensures we remove symlinks from TOP.
781 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 else
783 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800784 # The following circumlocution (repeated below as well) ensures
785 # that we record the true directory name and not one that is
786 # faked up with symlink names.
787 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800789 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 T=
791 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800792 \cd ..
synergyb112a402013-07-05 19:47:47 -0700793 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 done
Ying Wang9cd17642012-12-13 10:52:07 -0800795 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 if [ -f "$T/$TOPFILE" ]; then
797 echo $T
798 fi
799 fi
800 fi
801}
802
Andrew Hsieh906cb782013-09-10 17:37:14 +0800803# Return driver for "make", if any (eg. static analyzer)
804function getdriver()
805{
806 local T="$1"
807 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
808 if [ -n "$WITH_STATIC_ANALYZER" ]; then
809 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800810$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
811--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800812--status-bugs \
813--top=$T"
814 fi
815}
816
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700817function m()
818{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800819 local T=$(gettop)
820 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700821 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800822 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823 else
824 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700825 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700826 fi
827}
828
829function findmakefile()
830{
831 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800832 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700833 T=
834 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700835 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 if [ -f "$T/Android.mk" ]; then
837 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800838 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 return
840 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800841 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842 done
Ying Wang9cd17642012-12-13 10:52:07 -0800843 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844}
845
846function mm()
847{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800848 local T=$(gettop)
849 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850 # If we're sitting in the root of the build tree, just do a
851 # normal make.
852 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800853 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700854 else
855 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800856 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700857 local MODULES=
858 local GET_INSTALL_PATH=
859 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700860 # Remove the path to top as the makefilepath needs to be relative
861 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700862 if [ ! "$T" ]; then
863 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700864 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700865 elif [ ! "$M" ]; then
866 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700867 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868 else
Ying Wanga7deb082013-08-16 13:24:47 -0700869 for ARG in $@; do
870 case $ARG in
871 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
872 esac
873 done
874 if [ -n "$GET_INSTALL_PATH" ]; then
875 MODULES=
876 ARGS=GET-INSTALL-PATH
877 else
878 MODULES=all_modules
879 ARGS=$@
880 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700881 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 -0700882 fi
883 fi
884}
885
886function mmm()
887{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800888 local T=$(gettop)
889 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700890 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800891 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800892 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800893 local ARGS=
894 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700895 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800896 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
897 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
898 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800899 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
900 if [ "$MODULES" = "" ]; then
901 MODULES=all_modules
902 fi
903 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700904 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700905 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
906 local TO_CHOP=`expr $TO_CHOP + 1`
907 local START=`PWD= /bin/pwd`
908 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 if [ "$MFILE" = "" ] ; then
910 MFILE=$DIR/Android.mk
911 else
912 MFILE=$MFILE/$DIR/Android.mk
913 fi
914 MAKEFILE="$MAKEFILE $MFILE"
915 else
Ying Wanga7deb082013-08-16 13:24:47 -0700916 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100917 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700918 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
919 *) echo "No Android.mk in $DIR."; return 1;;
920 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700921 fi
922 done
Ying Wanga7deb082013-08-16 13:24:47 -0700923 if [ -n "$GET_INSTALL_PATH" ]; then
924 ARGS=$GET_INSTALL_PATH
925 MODULES=
926 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800927 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 -0700928 else
929 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700930 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700931 fi
932}
933
Ying Wangb607f7b2013-02-08 18:01:04 -0800934function mma()
935{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800936 local T=$(gettop)
937 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800938 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800939 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800940 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800941 if [ ! "$T" ]; then
942 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700943 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 fi
945 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800946 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800947 fi
948}
949
950function mmma()
951{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800952 local T=$(gettop)
953 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800954 if [ "$T" ]; then
955 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
956 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
957 local MY_PWD=`PWD= /bin/pwd`
958 if [ "$MY_PWD" = "$T" ]; then
959 MY_PWD=
960 else
961 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
962 fi
963 local DIR=
964 local MODULE_PATHS=
965 local ARGS=
966 for DIR in $DIRS ; do
967 if [ -d $DIR ]; then
968 if [ "$MY_PWD" = "" ]; then
969 MODULE_PATHS="$MODULE_PATHS $DIR"
970 else
971 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
972 fi
973 else
974 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100975 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800976 *) echo "Couldn't find directory $DIR"; return 1;;
977 esac
978 fi
979 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800980 $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 -0800981 else
982 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700983 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800984 fi
985}
986
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700987function croot()
988{
989 T=$(gettop)
990 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800991 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992 else
993 echo "Couldn't locate the top of the tree. Try setting TOP."
994 fi
995}
996
nebkatfb67a1e2012-12-28 10:40:45 +0000997function cout()
998{
999 if [ "$OUT" ]; then
1000 cd $OUT
1001 else
1002 echo "Couldn't locate out directory. Try setting OUT."
1003 fi
1004}
1005
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001006function cproj()
1007{
1008 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001009 local HERE=$PWD
1010 T=
1011 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1012 T=$PWD
1013 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001014 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001015 return
1016 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001017 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001018 done
Ying Wang9cd17642012-12-13 10:52:07 -08001019 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 echo "can't find Android.mk"
1021}
1022
Daniel Sandler47e0a882013-07-30 13:23:52 -04001023# simplified version of ps; output in the form
1024# <pid> <procname>
1025function qpid() {
1026 local prepend=''
1027 local append=''
1028 if [ "$1" = "--exact" ]; then
1029 prepend=' '
1030 append='$'
1031 shift
1032 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1033 echo "usage: qpid [[--exact] <process name|pid>"
1034 return 255
1035 fi
1036
1037 local EXE="$1"
1038 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001039 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001040 else
1041 adb shell ps \
1042 | tr -d '\r' \
1043 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1044 fi
1045}
1046
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001047function pid()
1048{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001049 local prepend=''
1050 local append=''
1051 if [ "$1" = "--exact" ]; then
1052 prepend=' '
1053 append='$'
1054 shift
1055 fi
1056 local EXE="$1"
1057 if [ "$EXE" ] ; then
1058 local PID=`adb shell ps \
1059 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001060 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001061 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1062 echo "$PID"
1063 else
1064 echo "usage: pid [--exact] <process name>"
1065 return 255
1066 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001067}
1068
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001069# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001070# that has the core-file-size limit set correctly
1071#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001072# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001073# if its core-file-size limit is not set already.
1074# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1075
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001076function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077{
1078 echo "Getting root...";
1079 adb root;
1080 adb wait-for-device;
1081
1082 echo "Remounting root parition read-write...";
1083 adb shell mount -w -o remount -t rootfs rootfs;
1084 sleep 1;
1085 adb wait-for-device;
1086 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001087 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088 adb shell chmod 0777 /cores;
1089
1090 echo "Granting SELinux permission to dump in /cores...";
1091 adb shell restorecon -R /cores;
1092
1093 echo "Set core pattern.";
1094 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1095
1096 echo "Done."
1097}
1098
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001099# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001100# $1 = PID of process (e.g., $(pid mediaserver))
1101#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001102# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103# dump to actually be generated.
1104
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001105function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001106{
1107 local PID=$1;
1108 if [ -z "$PID" ]; then
1109 printf "Expecting a PID!\n";
1110 return;
1111 fi;
1112 echo "Setting core limit for $PID to infinite...";
1113 adb shell prlimit $PID 4 -1 -1
1114}
1115
1116# core - send SIGV and pull the core for process
1117# $1 = PID of process (e.g., $(pid mediaserver))
1118#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001119# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001120# enabled globally.
1121
1122function core()
1123{
1124 local PID=$1;
1125
1126 if [ -z "$PID" ]; then
1127 printf "Expecting a PID!\n";
1128 return;
1129 fi;
1130
1131 local CORENAME=core.$PID;
1132 local COREPATH=/cores/$CORENAME;
1133 local SIG=SEGV;
1134
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001135 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001136
1137 local done=0;
1138 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1139 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1140 adb shell kill -$SIG $PID;
1141 sleep 1;
1142 done;
1143
1144 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1145 echo "Done: core is under $COREPATH on device.";
1146}
1147
Christopher Tate744ee802009-11-12 15:33:08 -08001148# systemstack - dump the current stack trace of all threads in the system process
1149# to the usual ANR traces file
1150function systemstack()
1151{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001152 stacks system_server
1153}
1154
1155function stacks()
1156{
1157 if [[ $1 =~ ^[0-9]+$ ]] ; then
1158 local PID="$1"
1159 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001160 local PIDLIST="$(pid $1)"
1161 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1162 local PID="$PIDLIST"
1163 elif [ "$PIDLIST" ] ; then
1164 echo "more than one process: $1"
1165 else
1166 echo "no such process: $1"
1167 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001168 else
1169 echo "usage: stacks [pid|process name]"
1170 fi
1171
1172 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001173 # Determine whether the process is native
1174 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1175 # Dump stacks of Dalvik process
1176 local TRACES=/data/anr/traces.txt
1177 local ORIG=/data/anr/traces.orig
1178 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001179
Jeff Brownb12c2e52013-08-19 15:14:16 -07001180 # Keep original traces to avoid clobbering
1181 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001182
Jeff Brownb12c2e52013-08-19 15:14:16 -07001183 # Make sure we have a usable file
1184 adb shell touch $TRACES
1185 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001186
Jeff Brownb12c2e52013-08-19 15:14:16 -07001187 # Dump stacks and wait for dump to finish
1188 adb shell kill -3 $PID
1189 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001190
Jeff Brownb12c2e52013-08-19 15:14:16 -07001191 # Restore original stacks, and show current output
1192 adb shell mv $TRACES $TMP
1193 adb shell mv $ORIG $TRACES
1194 adb shell cat $TMP
1195 else
1196 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001197 local USE64BIT="$(is64bit $PID)"
1198 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001199 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001200 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001201}
1202
Michael Wrightaeed7212014-06-19 19:58:12 -07001203# Read the ELF header from /proc/$PID/exe to determine if the process is
1204# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001205function is64bit()
1206{
1207 local PID="$1"
1208 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001209 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001210 echo "64"
1211 else
1212 echo ""
1213 fi
1214 else
1215 echo ""
1216 fi
1217}
1218
Clark Scheff75b36a42014-12-23 13:30:51 -08001219function dddclient()
1220{
1221 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1222 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1223 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1224 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1225 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1226 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1227 local ARCH=$(get_build_var TARGET_ARCH)
1228 local GDB
1229 case "$ARCH" in
1230 arm) GDB=arm-linux-androideabi-gdb;;
1231 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1232 mips|mips64) GDB=mips64el-linux-android-gdb;;
1233 x86) GDB=x86_64-linux-android-gdb;;
1234 x86_64) GDB=x86_64-linux-android-gdb;;
1235 *) echo "Unknown arch $ARCH"; return 1;;
1236 esac
1237
1238 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1239 local EXE="$1"
1240 if [ "$EXE" ] ; then
1241 EXE=$1
1242 if [[ $EXE =~ ^[^/].* ]] ; then
1243 EXE="system/bin/"$EXE
1244 fi
1245 else
1246 EXE="app_process"
1247 fi
1248
1249 local PORT="$2"
1250 if [ "$PORT" ] ; then
1251 PORT=$2
1252 else
1253 PORT=":5039"
1254 fi
1255
1256 local PID="$3"
1257 if [ "$PID" ] ; then
1258 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1259 PID=`pid $3`
1260 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1261 # that likely didn't work because of returning multiple processes
1262 # try again, filtering by root processes (don't contain colon)
1263 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1264 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1265 then
1266 echo "Couldn't resolve '$3' to single PID"
1267 return 1
1268 else
1269 echo ""
1270 echo "WARNING: multiple processes matching '$3' observed, using root process"
1271 echo ""
1272 fi
1273 fi
1274 fi
1275 adb forward "tcp$PORT" "tcp$PORT"
1276 local USE64BIT="$(is64bit $PID)"
1277 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1278 sleep 2
1279 else
1280 echo ""
1281 echo "If you haven't done so already, do this first on the device:"
1282 echo " gdbserver $PORT /system/bin/$EXE"
1283 echo " or"
1284 echo " gdbserver $PORT --attach <PID>"
1285 echo ""
1286 fi
1287
1288 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1289 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1290
1291 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1292 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl"
1293 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1294 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1295 # Enable special debugging for ART processes.
1296 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1297 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1298 fi
1299 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1300
1301 local WHICH_GDB=
1302 # 64-bit exe found
1303 if [ "$USE64BIT" != "" ] ; then
1304 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1305 # 32-bit exe / 32-bit platform
1306 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1307 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1308 # 32-bit exe / 64-bit platform
1309 else
1310 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1311 fi
1312
1313 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1314 else
1315 echo "Unable to determine build system output dir."
1316 fi
1317}
1318
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001319case `uname -s` in
1320 Darwin)
1321 function sgrep()
1322 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001323 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 -07001324 }
1325
1326 ;;
1327 *)
1328 function sgrep()
1329 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001330 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 -07001331 }
1332 ;;
1333esac
1334
Raghu Gandham8da43102012-07-25 19:57:22 -07001335function gettargetarch
1336{
1337 get_build_var TARGET_ARCH
1338}
1339
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001340function ggrep()
1341{
1342 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1343}
1344
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001345function jgrep()
1346{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001347 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 -07001348}
1349
1350function cgrep()
1351{
Dan Albert01961192014-11-22 10:16:01 -08001352 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 -07001353}
1354
1355function resgrep()
1356{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001357 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 -07001358}
1359
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001360function mangrep()
1361{
1362 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1363}
1364
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001365function sepgrep()
1366{
1367 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 "$@"
1368}
1369
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001370function rcgrep()
1371{
1372 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1373}
1374
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001375case `uname -s` in
1376 Darwin)
1377 function mgrep()
1378 {
Ying Wang324c2b22012-08-17 15:03:20 -07001379 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 -07001380 }
1381
1382 function treegrep()
1383 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001384 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 -07001385 }
1386
1387 ;;
1388 *)
1389 function mgrep()
1390 {
Ying Wang324c2b22012-08-17 15:03:20 -07001391 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 -07001392 }
1393
1394 function treegrep()
1395 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001396 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 -07001397 }
1398
1399 ;;
1400esac
1401
1402function getprebuilt
1403{
1404 get_abs_build_var ANDROID_PREBUILTS
1405}
1406
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001407function tracedmdump()
1408{
1409 T=$(gettop)
1410 if [ ! "$T" ]; then
1411 echo "Couldn't locate the top of the tree. Try setting TOP."
1412 return
1413 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001414 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001415 local arch=$(gettargetarch)
1416 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001417
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001418 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001419 if [ ! "$TRACE" ] ; then
1420 echo "usage: tracedmdump tracename"
1421 return
1422 fi
1423
Jack Veenstra60116fc2009-04-09 18:12:34 -07001424 if [ ! -r "$KERNEL" ] ; then
1425 echo "Error: cannot find kernel: '$KERNEL'"
1426 return
1427 fi
1428
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001429 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001430 if [ "$BASETRACE" = "$TRACE" ] ; then
1431 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1432 fi
1433
1434 echo "post-processing traces..."
1435 rm -f $TRACE/qtrace.dexlist
1436 post_trace $TRACE
1437 if [ $? -ne 0 ]; then
1438 echo "***"
1439 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1440 echo "***"
1441 return
1442 fi
1443 echo "generating dexlist output..."
1444 /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
1445 echo "generating dmtrace data..."
1446 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1447 echo "generating html file..."
1448 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1449 echo "done, see $TRACE/dmtrace.html for details"
1450 echo "or run:"
1451 echo " traceview $TRACE/dmtrace"
1452}
1453
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001454# communicate with a running device or emulator, set up necessary state,
1455# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001456function runhat()
1457{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001458 # process standard adb options
1459 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001460 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001461 adbTarget=$1
1462 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001463 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001464 adbTarget="$1 $2"
1465 shift 2
1466 fi
1467 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001468 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001469
1470 # runhat options
1471 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001472
1473 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001474 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001475 return
1476 fi
1477
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001478 # confirm hat is available
1479 if [ -z $(which hat) ]; then
1480 echo "hat is not available in this configuration."
1481 return
1482 fi
1483
Andy McFaddenb6289852010-07-12 08:00:19 -07001484 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001485 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001486 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001487 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001488 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001489 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001490 echo -n "> "
1491 read
1492
The Android Open Source Project88b60792009-03-03 19:28:42 -08001493 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001494
The Android Open Source Project88b60792009-03-03 19:28:42 -08001495 echo "Retrieving file $devFile..."
1496 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001497
The Android Open Source Project88b60792009-03-03 19:28:42 -08001498 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001499
The Android Open Source Project88b60792009-03-03 19:28:42 -08001500 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001501 echo "View the output by pointing your browser at http://localhost:7000/"
1502 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001503 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001504}
1505
1506function getbugreports()
1507{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001508 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001509
1510 if [ ! "$reports" ]; then
1511 echo "Could not locate any bugreports."
1512 return
1513 fi
1514
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001515 local report
1516 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001517 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001518 echo "/sdcard/bugreports/${report}"
1519 adb pull /sdcard/bugreports/${report} ${report}
1520 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001521 done
1522}
1523
Victoria Lease1b296b42012-08-21 15:44:06 -07001524function getsdcardpath()
1525{
1526 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1527}
1528
1529function getscreenshotpath()
1530{
1531 echo "$(getsdcardpath)/Pictures/Screenshots"
1532}
1533
1534function getlastscreenshot()
1535{
1536 local screenshot_path=$(getscreenshotpath)
1537 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1538 if [ "$screenshot" = "" ]; then
1539 echo "No screenshots found."
1540 return
1541 fi
1542 echo "${screenshot}"
1543 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1544}
1545
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001546function startviewserver()
1547{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001548 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001549 if [ $# -gt 0 ]; then
1550 port=$1
1551 fi
1552 adb shell service call window 1 i32 $port
1553}
1554
1555function stopviewserver()
1556{
1557 adb shell service call window 2
1558}
1559
1560function isviewserverstarted()
1561{
1562 adb shell service call window 3
1563}
1564
Romain Guyb84049a2010-10-04 16:56:11 -07001565function key_home()
1566{
1567 adb shell input keyevent 3
1568}
1569
1570function key_back()
1571{
1572 adb shell input keyevent 4
1573}
1574
1575function key_menu()
1576{
1577 adb shell input keyevent 82
1578}
1579
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001580function smoketest()
1581{
1582 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1583 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1584 return
1585 fi
1586 T=$(gettop)
1587 if [ ! "$T" ]; then
1588 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1589 return
1590 fi
1591
Ying Wang9cd17642012-12-13 10:52:07 -08001592 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001593 adb uninstall com.android.smoketest > /dev/null &&
1594 adb uninstall com.android.smoketest.tests > /dev/null &&
1595 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1596 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1597 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1598}
1599
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001600# simple shortcut to the runtest command
1601function runtest()
1602{
1603 T=$(gettop)
1604 if [ ! "$T" ]; then
1605 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1606 return
1607 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001608 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001609}
1610
The Android Open Source Project88b60792009-03-03 19:28:42 -08001611function godir () {
1612 if [[ -z "$1" ]]; then
1613 echo "Usage: godir <regex>"
1614 return
1615 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001616 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001617 if [[ ! -f $T/filelist ]]; then
1618 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001619 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001620 echo " Done"
1621 echo ""
1622 fi
1623 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001624 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001625 if [[ ${#lines[@]} = 0 ]]; then
1626 echo "Not found"
1627 return
1628 fi
1629 local pathname
1630 local choice
1631 if [[ ${#lines[@]} > 1 ]]; then
1632 while [[ -z "$pathname" ]]; do
1633 local index=1
1634 local line
1635 for line in ${lines[@]}; do
1636 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001637 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001638 done
1639 echo
1640 echo -n "Select one: "
1641 unset choice
1642 read choice
1643 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1644 echo "Invalid choice"
1645 continue
1646 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001647 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001648 done
1649 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001650 pathname=${lines[0]}
1651 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001652 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001653}
1654
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001655function cmremote()
1656{
1657 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301658 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001659 if [ -z "$GERRIT_REMOTE" ]
1660 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301661 echo Unable to set up the git remote, are you under a git repo?
1662 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001663 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301664 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001665 if [ -z "$CMUSER" ]
1666 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001667 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001668 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001669 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001670 fi
1671 echo You can now push to "cmremote".
1672}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001673
Steve Kondik873fa562012-09-17 11:33:18 -07001674function aospremote()
1675{
1676 git remote rm aosp 2> /dev/null
1677 if [ ! -d .git ]
1678 then
1679 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1680 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001681 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001682 if (echo $PROJECT | grep -qv "^device")
1683 then
1684 PFX="platform/"
1685 fi
1686 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1687 echo "Remote 'aosp' created"
1688}
Steve Kondik873fa562012-09-17 11:33:18 -07001689
Steve Kondik20c21d22013-10-27 13:34:36 -07001690function cafremote()
1691{
1692 git remote rm caf 2> /dev/null
1693 if [ ! -d .git ]
1694 then
1695 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1696 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001697 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001698 if (echo $PROJECT | grep -qv "^device")
1699 then
1700 PFX="platform/"
1701 fi
1702 git remote add caf git://codeaurora.org/$PFX$PROJECT
1703 echo "Remote 'caf' created"
1704}
Steve Kondik20c21d22013-10-27 13:34:36 -07001705
Steve Kondikf00e7d92012-09-23 23:46:55 -07001706function installboot()
1707{
1708 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1709 then
1710 echo "No recovery.fstab found. Build recovery first."
1711 return 1
1712 fi
1713 if [ ! -e "$OUT/boot.img" ];
1714 then
1715 echo "No boot.img found. Run make bootimage first."
1716 return 1
1717 fi
1718 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1719 if [ -z "$PARTITION" ];
1720 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001721 # Try for RECOVERY_FSTAB_VERSION = 2
1722 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1723 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1724 if [ -z "$PARTITION" ];
1725 then
1726 echo "Unable to determine boot partition."
1727 return 1
1728 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001729 fi
1730 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001731 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001732 adb root
1733 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001734 adb wait-for-online shell mount /system 2>&1 > /dev/null
1735 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001736 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1737 then
1738 adb push $OUT/boot.img /cache/
1739 for i in $OUT/system/lib/modules/*;
1740 do
1741 adb push $i /system/lib/modules/
1742 done
1743 adb shell dd if=/cache/boot.img of=$PARTITION
1744 adb shell chmod 644 /system/lib/modules/*
1745 echo "Installation complete."
1746 else
1747 echo "The connected device does not appear to be $CM_BUILD, run away!"
1748 fi
1749}
1750
Steve Kondik83c03d52012-10-24 16:40:42 -07001751function installrecovery()
1752{
1753 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1754 then
1755 echo "No recovery.fstab found. Build recovery first."
1756 return 1
1757 fi
1758 if [ ! -e "$OUT/recovery.img" ];
1759 then
1760 echo "No recovery.img found. Run make recoveryimage first."
1761 return 1
1762 fi
1763 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1764 if [ -z "$PARTITION" ];
1765 then
Steve Kondik75f10762013-08-09 21:03:42 -07001766 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001767 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1768 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001769 if [ -z "$PARTITION" ];
1770 then
1771 echo "Unable to determine recovery partition."
1772 return 1
1773 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001774 fi
1775 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001776 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001777 adb root
1778 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001779 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1780 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001781 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1782 then
1783 adb push $OUT/recovery.img /cache/
1784 adb shell dd if=/cache/recovery.img of=$PARTITION
1785 echo "Installation complete."
1786 else
1787 echo "The connected device does not appear to be $CM_BUILD, run away!"
1788 fi
1789}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001790
Koushik Duttab55f13a2012-05-14 16:14:36 -07001791function makerecipe() {
1792 if [ -z "$1" ]
1793 then
1794 echo "No branch name provided."
1795 return 1
1796 fi
1797 cd android
1798 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1799 git commit -a -m "$1"
1800 cd ..
1801
1802 repo forall -c '
1803
1804 if [ "$REPO_REMOTE" == "github" ]
1805 then
1806 pwd
1807 cmremote
1808 git push cmremote HEAD:refs/heads/'$1'
1809 fi
1810 '
1811}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001812
1813function cmgerrit() {
1814 if [ $# -eq 0 ]; then
1815 $FUNCNAME help
1816 return 1
1817 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001818 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001819 local review=`git config --get remote.github.review`
1820 local project=`git config --get remote.github.projectname`
1821 local command=$1
1822 shift
1823 case $command in
1824 help)
1825 if [ $# -eq 0 ]; then
1826 cat <<EOF
1827Usage:
1828 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1829
1830Commands:
1831 fetch Just fetch the change as FETCH_HEAD
1832 help Show this help, or for a specific command
1833 pull Pull a change into current branch
1834 push Push HEAD or a local branch to Gerrit for a specific branch
1835
1836Any other Git commands that support refname would work as:
1837 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1838
1839See '$FUNCNAME help COMMAND' for more information on a specific command.
1840
1841Example:
1842 $FUNCNAME checkout -b topic 1234/5
1843works as:
1844 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1845 && git checkout -b topic FETCH_HEAD
1846will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1847Patch-set 1 will be fetched if omitted.
1848EOF
1849 return
1850 fi
1851 case $1 in
1852 __cmg_*) echo "For internal use only." ;;
1853 changes|for)
1854 if [ "$FUNCNAME" = "cmgerrit" ]; then
1855 echo "'$FUNCNAME $1' is deprecated."
1856 fi
1857 ;;
1858 help) $FUNCNAME help ;;
1859 fetch|pull) cat <<EOF
1860usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1861
1862works as:
1863 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1864 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1865
1866Example:
1867 $FUNCNAME $1 1234
1868will $1 patch-set 1 of change 1234
1869EOF
1870 ;;
1871 push) cat <<EOF
1872usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1873
1874works as:
1875 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1876 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1877
1878Example:
1879 $FUNCNAME push fix6789:gingerbread
1880will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1881HEAD will be pushed from local if omitted.
1882EOF
1883 ;;
1884 *)
1885 $FUNCNAME __cmg_err_not_supported $1 && return
1886 cat <<EOF
1887usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1888
1889works as:
1890 git fetch http://DOMAIN/p/PROJECT \\
1891 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1892 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1893EOF
1894 ;;
1895 esac
1896 ;;
1897 __cmg_get_ref)
1898 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1899 local change_id patchset_id hash
1900 case $1 in
1901 */*)
1902 change_id=${1%%/*}
1903 patchset_id=${1#*/}
1904 ;;
1905 *)
1906 change_id=$1
1907 patchset_id=1
1908 ;;
1909 esac
1910 hash=$(($change_id % 100))
1911 case $hash in
1912 [0-9]) hash="0$hash" ;;
1913 esac
1914 echo "refs/changes/$hash/$change_id/$patchset_id"
1915 ;;
1916 fetch|pull)
1917 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1918 $FUNCNAME __cmg_err_not_repo && return 1
1919 local change=$1
1920 shift
1921 git $command $@ http://$review/p/$project \
1922 $($FUNCNAME __cmg_get_ref $change) || return 1
1923 ;;
1924 push)
1925 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1926 $FUNCNAME __cmg_err_not_repo && return 1
1927 if [ -z "$user" ]; then
1928 echo >&2 "Gerrit username not found."
1929 return 1
1930 fi
1931 local local_branch remote_branch
1932 case $1 in
1933 *:*)
1934 local_branch=${1%:*}
1935 remote_branch=${1##*:}
1936 ;;
1937 *)
1938 local_branch=HEAD
1939 remote_branch=$1
1940 ;;
1941 esac
1942 shift
1943 git push $@ ssh://$user@$review:29418/$project \
1944 $local_branch:refs/for/$remote_branch || return 1
1945 ;;
1946 changes|for)
1947 if [ "$FUNCNAME" = "cmgerrit" ]; then
1948 echo >&2 "'$FUNCNAME $command' is deprecated."
1949 fi
1950 ;;
1951 __cmg_err_no_arg)
1952 if [ $# -lt 2 ]; then
1953 echo >&2 "'$FUNCNAME $command' missing argument."
1954 elif [ $2 -eq 0 ]; then
1955 if [ -n "$3" ]; then
1956 $FUNCNAME help $1
1957 else
1958 echo >&2 "'$FUNCNAME $1' missing argument."
1959 fi
1960 else
1961 return 1
1962 fi
1963 ;;
1964 __cmg_err_not_repo)
1965 if [ -z "$review" -o -z "$project" ]; then
1966 echo >&2 "Not currently in any reviewable repository."
1967 else
1968 return 1
1969 fi
1970 ;;
1971 __cmg_err_not_supported)
1972 $FUNCNAME __cmg_err_no_arg $command $# && return
1973 case $1 in
1974 #TODO: filter more git commands that don't use refname
1975 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1976 echo >&2 "'$FUNCNAME $1' is not supported."
1977 ;;
1978 *) return 1 ;;
1979 esac
1980 ;;
1981 #TODO: other special cases?
1982 *)
1983 $FUNCNAME __cmg_err_not_supported $command && return 1
1984 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1985 $FUNCNAME __cmg_err_not_repo && return 1
1986 local args="$@"
1987 local change pre_args refs_arg post_args
1988 case "$args" in
1989 *--\ *)
1990 pre_args=${args%%-- *}
1991 post_args="-- ${args#*-- }"
1992 ;;
1993 *) pre_args="$args" ;;
1994 esac
1995 args=($pre_args)
1996 pre_args=
1997 if [ ${#args[@]} -gt 0 ]; then
1998 change=${args[${#args[@]}-1]}
1999 fi
2000 if [ ${#args[@]} -gt 1 ]; then
2001 pre_args=${args[0]}
2002 for ((i=1; i<${#args[@]}-1; i++)); do
2003 pre_args="$pre_args ${args[$i]}"
2004 done
2005 fi
2006 while ((1)); do
2007 case $change in
2008 ""|--)
2009 $FUNCNAME help $command
2010 return 1
2011 ;;
2012 *@*)
2013 if [ -z "$refs_arg" ]; then
2014 refs_arg="@${change#*@}"
2015 change=${change%%@*}
2016 fi
2017 ;;
2018 *~*)
2019 if [ -z "$refs_arg" ]; then
2020 refs_arg="~${change#*~}"
2021 change=${change%%~*}
2022 fi
2023 ;;
2024 *^*)
2025 if [ -z "$refs_arg" ]; then
2026 refs_arg="^${change#*^}"
2027 change=${change%%^*}
2028 fi
2029 ;;
2030 *:*)
2031 if [ -z "$refs_arg" ]; then
2032 refs_arg=":${change#*:}"
2033 change=${change%%:*}
2034 fi
2035 ;;
2036 *) break ;;
2037 esac
2038 done
2039 $FUNCNAME fetch $change \
2040 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2041 || return 1
2042 ;;
2043 esac
2044}
2045
2046function cmrebase() {
2047 local repo=$1
2048 local refs=$2
2049 local pwd="$(pwd)"
2050 local dir="$(gettop)/$repo"
2051
2052 if [ -z $repo ] || [ -z $refs ]; then
2053 echo "CyanogenMod Gerrit Rebase Usage: "
2054 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2055 echo " The patch IDs appear on the Gerrit commands that are offered."
2056 echo " They consist on a series of numbers and slashes, after the text"
2057 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2058 echo ""
2059 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2060 echo ""
2061 return
2062 fi
2063
2064 if [ ! -d $dir ]; then
2065 echo "Directory $dir doesn't exist in tree."
2066 return
2067 fi
2068 cd $dir
2069 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2070 echo "Starting branch..."
2071 repo start tmprebase .
2072 echo "Bringing it up to date..."
2073 repo sync .
2074 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07002075 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002076 if [ "$?" != "0" ]; then
2077 echo "Error cherry-picking. Not uploading!"
2078 return
2079 fi
2080 echo "Uploading..."
2081 repo upload .
2082 echo "Cleaning up..."
2083 repo abandon tmprebase .
2084 cd $pwd
2085}
2086
2087function mka() {
2088 case `uname -s` in
2089 Darwin)
2090 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2091 ;;
2092 *)
Anthony King40b093f2015-04-30 22:19:48 +01002093 mk_timer schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002094 ;;
2095 esac
2096}
2097
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302098function cmka() {
2099 if [ ! -z "$1" ]; then
2100 for i in "$@"; do
2101 case $i in
2102 bacon|otapackage|systemimage)
2103 mka installclean
2104 mka $i
2105 ;;
2106 *)
2107 mka clean-$i
2108 mka $i
2109 ;;
2110 esac
2111 done
2112 else
2113 mka clean
2114 mka
2115 fi
2116}
2117
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002118function reposync() {
2119 case `uname -s` in
2120 Darwin)
2121 repo sync -j 4 "$@"
2122 ;;
2123 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002124 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002125 ;;
2126 esac
2127}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002128
2129function repodiff() {
2130 if [ -z "$*" ]; then
2131 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2132 return
2133 fi
2134 diffopts=$* repo forall -c \
2135 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2136}
2137
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302138# Credit for color strip sed: http://goo.gl/BoIcm
2139function dopush()
2140{
2141 local func=$1
2142 shift
2143
2144 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2145 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2146 echo "No device is online. Waiting for one..."
2147 echo "Please connect USB and/or enable USB debugging"
2148 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2149 sleep 1
2150 done
2151 echo "Device Found."
2152 fi
2153
Chirayu Desai6dadb572012-12-26 10:53:58 +05302154 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2155 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002156 # retrieve IP and PORT info if we're using a TCP connection
2157 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2158 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302159 adb root &> /dev/null
2160 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002161 if [ -n "$TCPIPPORT" ]
2162 then
2163 # adb root just killed our connection
2164 # so reconnect...
2165 adb connect "$TCPIPPORT"
2166 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302167 adb wait-for-device &> /dev/null
2168 sleep 0.3
2169 adb remount &> /dev/null
2170
Matt Mower668ea262014-05-20 02:52:23 -05002171 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00002172 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2173 ret=$?;
2174 if [ $ret -ne 0 ]; then
2175 rm -f $OUT/.log;return $ret
2176 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302177
2178 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002179 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 +05302180
2181 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002182 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 +05302183
Matt Mower668ea262014-05-20 02:52:23 -05002184 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302185 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002186 # Make sure file is in $OUT/system
2187 case $FILE in
2188 $OUT/system/*)
2189 # Get target file name (i.e. /system/bin/adb)
2190 TARGET=$(echo $FILE | sed "s#$OUT##")
2191 ;;
2192 *) continue ;;
2193 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302194
Matt Mower668ea262014-05-20 02:52:23 -05002195 case $TARGET in
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002196 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002197 # Only need to stop services once
2198 if ! $stop_n_start; then
2199 adb shell stop
2200 stop_n_start=true
2201 fi
2202 echo "Pushing: $TARGET"
2203 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302204 ;;
2205 *)
Matt Mower668ea262014-05-20 02:52:23 -05002206 echo "Pushing: $TARGET"
2207 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302208 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002209 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302210 done
Matt Mower668ea262014-05-20 02:52:23 -05002211 if $stop_n_start; then
2212 adb shell start
2213 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302214 rm -f $OUT/.log
2215 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302216 else
2217 echo "The connected device does not appear to be $CM_BUILD, run away!"
2218 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302219}
2220
2221alias mmp='dopush mm'
2222alias mmmp='dopush mmm'
2223alias mkap='dopush mka'
2224alias cmkap='dopush cmka'
2225
Chirayu Desai4a319b82013-06-05 20:14:33 +05302226function repopick() {
2227 T=$(gettop)
2228 $T/build/tools/repopick.py $@
2229}
2230
Chirayu Desaib89b3242013-06-30 10:04:25 +05302231function fixup_common_out_dir() {
2232 common_out_dir=$(get_build_var OUT_DIR)/target/common
2233 target_device=$(get_build_var TARGET_DEVICE)
2234 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2235 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2236 mv ${common_out_dir} ${common_out_dir}-${target_device}
2237 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2238 else
2239 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2240 mkdir -p ${common_out_dir}-${target_device}
2241 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2242 fi
2243 else
2244 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2245 mkdir -p ${common_out_dir}
2246 fi
2247}
2248
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002249# 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 +00002250#
2251# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2252# For some reason, installing the JDK doesn't make it show up in the
2253# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002254function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002255 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002256 # we can reset it later, depending on the version of java the build
2257 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002258 #
2259 # If we don't do this, the JAVA_HOME value set by the first call to
2260 # build/envsetup.sh will persist forever.
2261 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2262 export JAVA_HOME=""
2263 fi
2264
Andy McFaddenbd960942010-06-24 12:52:51 -07002265 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002266 case `uname -s` in
2267 Darwin)
2268 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2269 ;;
2270 *)
2271 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2272 ;;
2273 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002274
2275 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2276 # we can change it on the next envsetup.sh, if required.
2277 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002278 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002279}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002280
Alex Rayf0d08eb2013-03-08 15:15:06 -08002281# Print colored exit condition
2282function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002283 "$@"
2284 local retval=$?
2285 if [ $retval -ne 0 ]
2286 then
2287 echo -e "\e[0;31mFAILURE\e[00m"
2288 else
2289 echo -e "\e[0;32mSUCCESS\e[00m"
2290 fi
2291 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002292}
2293
Ying Wanged21d4c2014-08-24 22:14:19 -07002294function get_make_command()
2295{
2296 echo command make
2297}
2298
Anthony King40b093f2015-04-30 22:19:48 +01002299function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002300{
2301 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002302 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002303 local ret=$?
2304 local end_time=$(date +"%s")
2305 local tdiff=$(($end_time-$start_time))
2306 local hours=$(($tdiff / 3600 ))
2307 local mins=$((($tdiff % 3600) / 60))
2308 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002309 local ncolors=$(tput colors 2>/dev/null)
2310 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2311 color_failed="\e[0;31m"
2312 color_success="\e[0;32m"
2313 color_reset="\e[00m"
2314 else
2315 color_failed=""
2316 color_success=""
2317 color_reset=""
2318 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002319 echo
2320 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002321 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002322 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002323 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002324 fi
2325 if [ $hours -gt 0 ] ; then
2326 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2327 elif [ $mins -gt 0 ] ; then
2328 printf "(%02g:%02g (mm:ss))" $mins $secs
2329 elif [ $secs -gt 0 ] ; then
2330 printf "(%s seconds)" $secs
2331 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002332 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002333 echo
2334 return $ret
2335}
2336
Anthony King40b093f2015-04-30 22:19:48 +01002337function make()
2338{
2339 mk_timer $(get_make_command) "$@"
2340}
2341
Raphael Moll70a86b02011-06-20 16:03:14 -07002342if [ "x$SHELL" != "x/bin/bash" ]; then
2343 case `ps -o command -p $$` in
2344 *bash*)
2345 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002346 *zsh*)
2347 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002348 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002349 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002350 ;;
2351 esac
2352fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002353
2354# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002355for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2356 `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 -08002357do
2358 echo "including $f"
2359 . $f
2360done
2361unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002362
Kyle Ladd031a0b62013-09-11 20:43:42 -04002363# Add completions
2364check_bash_version && {
2365 dirs="sdk/bash_completion vendor/cm/bash_completion"
2366 for dir in $dirs; do
2367 if [ -d ${dir} ]; then
2368 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2369 echo "including $f"
2370 . $f
2371 done
2372 fi
2373 done
2374}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302375
2376export ANDROID_BUILD_TOP=$(gettop)