blob: 58b38e39b4f82c238e18c490d809e9540925ef20 [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)
45 local A
46 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070047 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070048 A="$A $i"
49 done
50 echo $A
51}
52
53# Get the value of a build variable as an absolute path.
54function get_abs_build_var()
55{
56 T=$(gettop)
57 if [ ! "$T" ]; then
58 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
59 return
60 fi
Ying Wang9cd17642012-12-13 10:52:07 -080061 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070062 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070063}
64
65# Get the exact value of a build variable.
66function get_build_var()
67{
68 T=$(gettop)
69 if [ ! "$T" ]; then
70 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
71 return
72 fi
Andrew Boie6905e212013-12-19 13:21:46 -080073 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070074 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080075}
76
77# check to see if the supplied product is one we can build
78function check_product()
79{
80 T=$(gettop)
81 if [ ! "$T" ]; then
82 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
83 return
84 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000085
86 if (echo -n $1 | grep -q -e "^cm_") ; then
87 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
Ricardo Cerqueira34ae3232013-09-26 00:10:20 +010088 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 +000089 else
90 CM_BUILD=
91 fi
92 export CM_BUILD
93
Jeff Browne33ba4c2011-07-11 22:11:46 -070094 TARGET_PRODUCT=$1 \
95 TARGET_BUILD_VARIANT= \
96 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070097 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080098 get_build_var TARGET_DEVICE > /dev/null
99 # hide successful answers, but allow the errors to show
100}
101
102VARIANT_CHOICES=(user userdebug eng)
103
104# check to see if the supplied variant is valid
105function check_variant()
106{
107 for v in ${VARIANT_CHOICES[@]}
108 do
109 if [ "$v" = "$1" ]
110 then
111 return 0
112 fi
113 done
114 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700115}
116
117function setpaths()
118{
119 T=$(gettop)
120 if [ ! "$T" ]; then
121 echo "Couldn't locate the top of the tree. Try setting TOP."
122 return
123 fi
124
125 ##################################################################
126 # #
127 # Read me before you modify this code #
128 # #
129 # This function sets ANDROID_BUILD_PATHS to what it is adding #
130 # to PATH, and the next time it is run, it removes that from #
131 # PATH. This is required so lunch can be run more than once #
132 # and still have working paths. #
133 # #
134 ##################################################################
135
Raphael Mollc639c782011-06-20 17:25:01 -0700136 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
137 # due to "C:\Program Files" being in the path.
138
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700139 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700140 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700141 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
142 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700143 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700144 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800145 # strip leading ':', if any
146 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500147 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700148
149 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700150 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700151 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700152
Ben Cheng8bc4c432012-11-16 13:29:13 -0800153 # defined in core/config.mk
154 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700155 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800156 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800157
Raphael Mollc639c782011-06-20 17:25:01 -0700158 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800159 export ANDROID_TOOLCHAIN=
160 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200161 local ARCH=$(get_build_var TARGET_ARCH)
162 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400163 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700164 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400165 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
166 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800167 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200168 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800169 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700170 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700171 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700172 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000173 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200174 *)
175 echo "Can't find toolchain for unknown architecture: $ARCH"
176 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700177 ;;
178 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700179 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800180 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700181 fi
Raphael732936d2011-06-22 14:35:32 -0700182
Ben Chengfba67bf2014-02-25 10:27:07 -0800183 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
184 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
185 fi
186
187 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700188 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700189 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800190 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800191 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700192 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100193 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
194 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700195 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700196 ;;
197 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700198 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700199 ;;
200 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700201
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700202 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700203 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 +0200204
205 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
206 # to ensure that the corresponding 'emulator' binaries are used.
207 case $(uname -s) in
208 Darwin)
209 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
210 ;;
211 Linux)
212 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
213 ;;
214 *)
215 ANDROID_EMULATOR_PREBUILTS=
216 ;;
217 esac
218 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700219 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200220 export ANDROID_EMULATOR_PREBUILTS
221 fi
222
Ying Wangaa1c9b52012-11-26 20:51:59 -0800223 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800224
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500225 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900226 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500227 if [ -n "$JAVA_HOME" ]; then
228 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900229 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
230 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500231 fi
232
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700234 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
235 export OUT=$ANDROID_PRODUCT_OUT
236
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700237 unset ANDROID_HOST_OUT
238 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
239
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800240 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700241 # TODO: fix the path
242 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
243}
244
245function printconfig()
246{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800247 T=$(gettop)
248 if [ ! "$T" ]; then
249 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
250 return
251 fi
252 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253}
254
255function set_stuff_for_environment()
256{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800257 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500258 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800259 setpaths
260 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261
Ben Chengaac3f812013-08-13 14:38:15 -0700262 # With this environment variable new GCC can apply colors to warnings/errors
263 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 -0700264 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700265}
266
267function set_sequence_number()
268{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700269 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700270}
271
272function settitle()
273{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800274 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700275 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700276 local product=$TARGET_PRODUCT
277 local variant=$TARGET_BUILD_VARIANT
278 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800279 if [ -z "$PROMPT_COMMAND" ]; then
280 # No prompts
281 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
282 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
283 # Prompts exist, but no hardstatus
284 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700285 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800286 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500287 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800288 fi
289
290 if [ -z "$apps" ]; then
291 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
292 else
293 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
294 fi
295 export ANDROID_PROMPT_PREFIX
296
297 # Inject build data into hardstatus
298 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 -0800299 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300}
301
Kyle Ladd031a0b62013-09-11 20:43:42 -0400302function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700303{
Kenny Root52aa81c2011-07-15 11:07:06 -0700304 # Keep us from trying to run in something that isn't bash.
305 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400306 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700307 fi
308
309 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200310 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400311 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700312 fi
313
Kyle Ladd031a0b62013-09-11 20:43:42 -0400314 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700315}
316
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317function choosetype()
318{
319 echo "Build type choices are:"
320 echo " 1. release"
321 echo " 2. debug"
322 echo
323
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800324 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700325 DEFAULT_NUM=1
326 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800328 export TARGET_BUILD_TYPE=
329 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330 while [ -z $TARGET_BUILD_TYPE ]
331 do
332 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 if [ -z "$1" ] ; then
334 read ANSWER
335 else
336 echo $1
337 ANSWER=$1
338 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 case $ANSWER in
340 "")
341 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
342 ;;
343 1)
344 export TARGET_BUILD_TYPE=release
345 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800346 release)
347 export TARGET_BUILD_TYPE=release
348 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700349 2)
350 export TARGET_BUILD_TYPE=debug
351 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352 debug)
353 export TARGET_BUILD_TYPE=debug
354 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355 *)
356 echo
357 echo "I didn't understand your response. Please try again."
358 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700359 ;;
360 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800361 if [ -n "$1" ] ; then
362 break
363 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 done
365
366 set_stuff_for_environment
367}
368
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800369#
370# This function isn't really right: It chooses a TARGET_PRODUCT
371# based on the list of boards. Usually, that gets you something
372# that kinda works with a generic product, but really, you should
373# pick a product by name.
374#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700375function chooseproduct()
376{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377 if [ "x$TARGET_PRODUCT" != x ] ; then
378 default_value=$TARGET_PRODUCT
379 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700380 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700381 fi
382
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800383 export TARGET_PRODUCT=
384 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700385 while [ -z "$TARGET_PRODUCT" ]
386 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700387 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800388 if [ -z "$1" ] ; then
389 read ANSWER
390 else
391 echo $1
392 ANSWER=$1
393 fi
394
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700395 if [ -z "$ANSWER" ] ; then
396 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800397 else
398 if check_product $ANSWER
399 then
400 export TARGET_PRODUCT=$ANSWER
401 else
402 echo "** Not a valid product: $ANSWER"
403 fi
404 fi
405 if [ -n "$1" ] ; then
406 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407 fi
408 done
409
410 set_stuff_for_environment
411}
412
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800413function choosevariant()
414{
415 echo "Variant choices are:"
416 local index=1
417 local v
418 for v in ${VARIANT_CHOICES[@]}
419 do
420 # The product name is the name of the directory containing
421 # the makefile we found, above.
422 echo " $index. $v"
423 index=$(($index+1))
424 done
425
426 local default_value=eng
427 local ANSWER
428
429 export TARGET_BUILD_VARIANT=
430 while [ -z "$TARGET_BUILD_VARIANT" ]
431 do
432 echo -n "Which would you like? [$default_value] "
433 if [ -z "$1" ] ; then
434 read ANSWER
435 else
436 echo $1
437 ANSWER=$1
438 fi
439
440 if [ -z "$ANSWER" ] ; then
441 export TARGET_BUILD_VARIANT=$default_value
442 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
443 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800444 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800445 fi
446 else
447 if check_variant $ANSWER
448 then
449 export TARGET_BUILD_VARIANT=$ANSWER
450 else
451 echo "** Not a valid variant: $ANSWER"
452 fi
453 fi
454 if [ -n "$1" ] ; then
455 break
456 fi
457 done
458}
459
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460function choosecombo()
461{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700462 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463
464 echo
465 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700466 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467
468 echo
469 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700470 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800471
472 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800474 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475}
476
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477# Clear this variable. It will be built up again when the vendorsetup.sh
478# files are included at the end of this file.
479unset LUNCH_MENU_CHOICES
480function add_lunch_combo()
481{
482 local new_combo=$1
483 local c
484 for c in ${LUNCH_MENU_CHOICES[@]} ; do
485 if [ "$new_combo" = "$c" ] ; then
486 return
487 fi
488 done
489 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
490}
491
492# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700493add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800494add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000495add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800496add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000497add_lunch_combo aosp_x86-eng
498add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700500function print_lunch_menu()
501{
502 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503 echo
504 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000505 if [ "$(uname)" = "Darwin" ] ; then
506 echo " (ohai, koush!)"
507 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000509 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
510 echo "Breakfast menu... pick a combo:"
511 else
512 echo "Lunch menu... pick a combo:"
513 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514
515 local i=1
516 local choice
517 for choice in ${LUNCH_MENU_CHOICES[@]}
518 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100519 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100521 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000523 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
524 echo "... and don't forget the bacon!"
525 fi
526
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700527 echo
528}
529
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000530function brunch()
531{
532 breakfast $*
533 if [ $? -eq 0 ]; then
534 mka bacon
535 else
536 echo "No such item in brunch menu. Try 'breakfast'"
537 return 1
538 fi
539 return $?
540}
541
542function breakfast()
543{
544 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200545 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000546 CM_DEVICES_ONLY="true"
547 unset LUNCH_MENU_CHOICES
548 add_lunch_combo full-eng
549 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
550 do
551 echo "including $f"
552 . $f
553 done
554 unset f
555
556 if [ $# -eq 0 ]; then
557 # No arguments, so let's have the full menu
558 lunch
559 else
560 echo "z$target" | grep -q "-"
561 if [ $? -eq 0 ]; then
562 # A buildtype was specified, assume a full device name
563 lunch $target
564 else
565 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200566 if [ -z "$variant" ]; then
567 variant="userdebug"
568 fi
569 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000570 fi
571 fi
572 return $?
573}
574
575alias bib=breakfast
576
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700577function lunch()
578{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800579 local answer
Anthony King850627c2015-04-30 22:57:08 +0100580 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584 else
585 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700586 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588 fi
589
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 local selection=
591
592 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700593 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700594 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
596 then
597 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
598 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800599 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800600 fi
601 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
602 then
603 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 fi
605
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 if [ -z "$selection" ]
607 then
608 echo
609 echo "Invalid lunch combo: $answer"
610 return 1
611 fi
612
Joe Onoratoda12daf2010-06-09 18:18:31 -0700613 export TARGET_BUILD_APPS=
614
Jeff Browne33ba4c2011-07-11 22:11:46 -0700615 local product=$(echo -n $selection | sed -e "s/-.*$//")
616 check_product $product
617 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800619 # if we can't find a product, try to grab it off the CM github
620 T=$(gettop)
621 pushd $T > /dev/null
622 build/tools/roomservice.py $product
623 popd > /dev/null
624 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000625 else
626 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800627 fi
628 if [ $? -ne 0 ]
629 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700630 echo
631 echo "** Don't have a product spec for: '$product'"
632 echo "** Do you have the right repo manifest?"
633 product=
634 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800635
Jeff Browne33ba4c2011-07-11 22:11:46 -0700636 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
637 check_variant $variant
638 if [ $? -ne 0 ]
639 then
640 echo
641 echo "** Invalid variant: '$variant'"
642 echo "** Must be one of ${VARIANT_CHOICES[@]}"
643 variant=
644 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645
Jeff Browne33ba4c2011-07-11 22:11:46 -0700646 if [ -z "$product" -o -z "$variant" ]
647 then
648 echo
649 return 1
650 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800651
Jeff Browne33ba4c2011-07-11 22:11:46 -0700652 export TARGET_PRODUCT=$product
653 export TARGET_BUILD_VARIANT=$variant
654 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655
656 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800657
Chirayu Desaib89b3242013-06-30 10:04:25 +0530658 fixup_common_out_dir
659
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800661 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662}
663
Jeff Davidson513d7a42010-08-02 10:00:44 -0700664# Tab completion for lunch.
665function _lunch()
666{
667 local cur prev opts
668 COMPREPLY=()
669 cur="${COMP_WORDS[COMP_CWORD]}"
670 prev="${COMP_WORDS[COMP_CWORD-1]}"
671
672 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
673 return 0
674}
Emilio López9ad6eea2013-11-03 13:02:13 -0300675complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700676
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700678# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700679function tapas()
680{
Ying Wangb541ab62014-05-29 17:57:40 -0700681 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700682 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700683 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
684 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700685
Ying Wang67f02922012-08-22 10:25:20 -0700686 if [ $(echo $arch | wc -w) -gt 1 ]; then
687 echo "tapas: Error: Multiple build archs supplied: $arch"
688 return
689 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700690 if [ $(echo $variant | wc -w) -gt 1 ]; then
691 echo "tapas: Error: Multiple build variants supplied: $variant"
692 return
693 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700694 if [ $(echo $density | wc -w) -gt 1 ]; then
695 echo "tapas: Error: Multiple densities supplied: $density"
696 return
697 fi
Ying Wang67f02922012-08-22 10:25:20 -0700698
699 local product=full
700 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700701 x86) product=full_x86;;
702 mips) product=full_mips;;
703 armv5) product=generic_armv5;;
704 arm64) product=aosp_arm64;;
705 x86_64) product=aosp_x86_64;;
706 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700707 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700708 if [ -z "$variant" ]; then
709 variant=eng
710 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700711 if [ -z "$apps" ]; then
712 apps=all
713 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600714 if [ -z "$density" ]; then
715 density=alldpi
716 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700717
Ying Wang67f02922012-08-22 10:25:20 -0700718 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700719 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700720 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700721 export TARGET_BUILD_TYPE=release
722 export TARGET_BUILD_APPS=$apps
723
724 set_stuff_for_environment
725 printconfig
726}
727
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100728function eat()
729{
730 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530731 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100732 ZIPFILE=cm-$MODVERSION.zip
733 ZIPPATH=$OUT/$ZIPFILE
734 if [ ! -f $ZIPPATH ] ; then
735 echo "Nothing to eat"
736 return 1
737 fi
738 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
739 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
740 echo "No device is online. Waiting for one..."
741 echo "Please connect USB and/or enable USB debugging"
742 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
743 sleep 1
744 done
745 echo "Device Found.."
746 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530747 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
748 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100749 # if adbd isn't root we can't write to /cache/recovery/
750 adb root
751 sleep 1
752 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700753 cat << EOF > /tmp/command
754--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100755EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700756 if adb push /tmp/command /cache/recovery/ ; then
757 echo "Rebooting into recovery for sideload installation"
758 adb reboot recovery
759 adb wait-for-sideload
760 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100761 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700762 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100763 else
764 echo "Nothing to eat"
765 return 1
766 fi
767 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530768 else
769 echo "The connected device does not appear to be $CM_BUILD, run away!"
770 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100771}
772
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000773function omnom
774{
775 brunch $*
776 eat
777}
778
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779function gettop
780{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800781 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700783 # The following circumlocution ensures we remove symlinks from TOP.
784 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 else
786 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800787 # The following circumlocution (repeated below as well) ensures
788 # that we record the true directory name and not one that is
789 # faked up with symlink names.
790 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800792 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 T=
794 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800795 \cd ..
synergyb112a402013-07-05 19:47:47 -0700796 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 done
Ying Wang9cd17642012-12-13 10:52:07 -0800798 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799 if [ -f "$T/$TOPFILE" ]; then
800 echo $T
801 fi
802 fi
803 fi
804}
805
Andrew Hsieh906cb782013-09-10 17:37:14 +0800806# Return driver for "make", if any (eg. static analyzer)
807function getdriver()
808{
809 local T="$1"
810 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
811 if [ -n "$WITH_STATIC_ANALYZER" ]; then
812 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800813$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
814--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800815--status-bugs \
816--top=$T"
817 fi
818}
819
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700820function m()
821{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800822 local T=$(gettop)
823 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800825 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700826 else
827 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700828 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829 fi
830}
831
832function findmakefile()
833{
834 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800835 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 T=
837 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700838 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 if [ -f "$T/Android.mk" ]; then
840 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800841 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842 return
843 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800844 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 done
Ying Wang9cd17642012-12-13 10:52:07 -0800846 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847}
848
849function mm()
850{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800851 local T=$(gettop)
852 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700853 # If we're sitting in the root of the build tree, just do a
854 # normal make.
855 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800856 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700857 else
858 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800859 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700860 local MODULES=
861 local GET_INSTALL_PATH=
862 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700863 # Remove the path to top as the makefilepath needs to be relative
864 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700865 if [ ! "$T" ]; then
866 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700867 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868 elif [ ! "$M" ]; then
869 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700870 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871 else
Ying Wanga7deb082013-08-16 13:24:47 -0700872 for ARG in $@; do
873 case $ARG in
874 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
875 esac
876 done
877 if [ -n "$GET_INSTALL_PATH" ]; then
878 MODULES=
879 ARGS=GET-INSTALL-PATH
880 else
881 MODULES=all_modules
882 ARGS=$@
883 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700884 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700885 fi
886 fi
887}
888
889function mmm()
890{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800891 local T=$(gettop)
892 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700893 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800894 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800895 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800896 local ARGS=
897 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700898 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800899 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
900 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
901 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800902 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
903 if [ "$MODULES" = "" ]; then
904 MODULES=all_modules
905 fi
906 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700907 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700908 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
909 local TO_CHOP=`expr $TO_CHOP + 1`
910 local START=`PWD= /bin/pwd`
911 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700912 if [ "$MFILE" = "" ] ; then
913 MFILE=$DIR/Android.mk
914 else
915 MFILE=$MFILE/$DIR/Android.mk
916 fi
917 MAKEFILE="$MAKEFILE $MFILE"
918 else
Ying Wanga7deb082013-08-16 13:24:47 -0700919 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100920 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700921 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
922 *) echo "No Android.mk in $DIR."; return 1;;
923 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700924 fi
925 done
Ying Wanga7deb082013-08-16 13:24:47 -0700926 if [ -n "$GET_INSTALL_PATH" ]; then
927 ARGS=$GET_INSTALL_PATH
928 MODULES=
929 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800930 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700931 else
932 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700933 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700934 fi
935}
936
Ying Wangb607f7b2013-02-08 18:01:04 -0800937function mma()
938{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800939 local T=$(gettop)
940 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800941 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800942 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800943 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 if [ ! "$T" ]; then
945 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700946 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800947 fi
948 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800949 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800950 fi
951}
952
953function mmma()
954{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800955 local T=$(gettop)
956 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800957 if [ "$T" ]; then
958 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
959 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
960 local MY_PWD=`PWD= /bin/pwd`
961 if [ "$MY_PWD" = "$T" ]; then
962 MY_PWD=
963 else
964 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
965 fi
966 local DIR=
967 local MODULE_PATHS=
968 local ARGS=
969 for DIR in $DIRS ; do
970 if [ -d $DIR ]; then
971 if [ "$MY_PWD" = "" ]; then
972 MODULE_PATHS="$MODULE_PATHS $DIR"
973 else
974 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
975 fi
976 else
977 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100978 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800979 *) echo "Couldn't find directory $DIR"; return 1;;
980 esac
981 fi
982 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800983 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
Ying Wangb607f7b2013-02-08 18:01:04 -0800984 else
985 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700986 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800987 fi
988}
989
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700990function croot()
991{
992 T=$(gettop)
993 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800994 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700995 else
996 echo "Couldn't locate the top of the tree. Try setting TOP."
997 fi
998}
999
nebkatfb67a1e2012-12-28 10:40:45 +00001000function cout()
1001{
1002 if [ "$OUT" ]; then
1003 cd $OUT
1004 else
1005 echo "Couldn't locate out directory. Try setting OUT."
1006 fi
1007}
1008
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001009function cproj()
1010{
1011 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001012 local HERE=$PWD
1013 T=
1014 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1015 T=$PWD
1016 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001017 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001018 return
1019 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001020 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001021 done
Ying Wang9cd17642012-12-13 10:52:07 -08001022 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001023 echo "can't find Android.mk"
1024}
1025
Daniel Sandler47e0a882013-07-30 13:23:52 -04001026# simplified version of ps; output in the form
1027# <pid> <procname>
1028function qpid() {
1029 local prepend=''
1030 local append=''
1031 if [ "$1" = "--exact" ]; then
1032 prepend=' '
1033 append='$'
1034 shift
1035 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1036 echo "usage: qpid [[--exact] <process name|pid>"
1037 return 255
1038 fi
1039
1040 local EXE="$1"
1041 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001042 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001043 else
1044 adb shell ps \
1045 | tr -d '\r' \
1046 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1047 fi
1048}
1049
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001050function pid()
1051{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001052 local prepend=''
1053 local append=''
1054 if [ "$1" = "--exact" ]; then
1055 prepend=' '
1056 append='$'
1057 shift
1058 fi
1059 local EXE="$1"
1060 if [ "$EXE" ] ; then
1061 local PID=`adb shell ps \
1062 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001063 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001064 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1065 echo "$PID"
1066 else
1067 echo "usage: pid [--exact] <process name>"
1068 return 255
1069 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001070}
1071
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001072# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001073# that has the core-file-size limit set correctly
1074#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001075# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001076# if its core-file-size limit is not set already.
1077# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1078
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001079function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080{
1081 echo "Getting root...";
1082 adb root;
1083 adb wait-for-device;
1084
1085 echo "Remounting root parition read-write...";
1086 adb shell mount -w -o remount -t rootfs rootfs;
1087 sleep 1;
1088 adb wait-for-device;
1089 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001090 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001091 adb shell chmod 0777 /cores;
1092
1093 echo "Granting SELinux permission to dump in /cores...";
1094 adb shell restorecon -R /cores;
1095
1096 echo "Set core pattern.";
1097 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1098
1099 echo "Done."
1100}
1101
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001102# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103# $1 = PID of process (e.g., $(pid mediaserver))
1104#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001105# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001106# dump to actually be generated.
1107
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001108function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001109{
1110 local PID=$1;
1111 if [ -z "$PID" ]; then
1112 printf "Expecting a PID!\n";
1113 return;
1114 fi;
1115 echo "Setting core limit for $PID to infinite...";
1116 adb shell prlimit $PID 4 -1 -1
1117}
1118
1119# core - send SIGV and pull the core for process
1120# $1 = PID of process (e.g., $(pid mediaserver))
1121#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001122# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001123# enabled globally.
1124
1125function core()
1126{
1127 local PID=$1;
1128
1129 if [ -z "$PID" ]; then
1130 printf "Expecting a PID!\n";
1131 return;
1132 fi;
1133
1134 local CORENAME=core.$PID;
1135 local COREPATH=/cores/$CORENAME;
1136 local SIG=SEGV;
1137
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001138 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001139
1140 local done=0;
1141 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1142 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1143 adb shell kill -$SIG $PID;
1144 sleep 1;
1145 done;
1146
1147 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1148 echo "Done: core is under $COREPATH on device.";
1149}
1150
Christopher Tate744ee802009-11-12 15:33:08 -08001151# systemstack - dump the current stack trace of all threads in the system process
1152# to the usual ANR traces file
1153function systemstack()
1154{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001155 stacks system_server
1156}
1157
1158function stacks()
1159{
1160 if [[ $1 =~ ^[0-9]+$ ]] ; then
1161 local PID="$1"
1162 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001163 local PIDLIST="$(pid $1)"
1164 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1165 local PID="$PIDLIST"
1166 elif [ "$PIDLIST" ] ; then
1167 echo "more than one process: $1"
1168 else
1169 echo "no such process: $1"
1170 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001171 else
1172 echo "usage: stacks [pid|process name]"
1173 fi
1174
1175 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001176 # Determine whether the process is native
1177 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1178 # Dump stacks of Dalvik process
1179 local TRACES=/data/anr/traces.txt
1180 local ORIG=/data/anr/traces.orig
1181 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001182
Jeff Brownb12c2e52013-08-19 15:14:16 -07001183 # Keep original traces to avoid clobbering
1184 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001185
Jeff Brownb12c2e52013-08-19 15:14:16 -07001186 # Make sure we have a usable file
1187 adb shell touch $TRACES
1188 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001189
Jeff Brownb12c2e52013-08-19 15:14:16 -07001190 # Dump stacks and wait for dump to finish
1191 adb shell kill -3 $PID
1192 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001193
Jeff Brownb12c2e52013-08-19 15:14:16 -07001194 # Restore original stacks, and show current output
1195 adb shell mv $TRACES $TMP
1196 adb shell mv $ORIG $TRACES
1197 adb shell cat $TMP
1198 else
1199 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001200 local USE64BIT="$(is64bit $PID)"
1201 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001202 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001203 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001204}
1205
Michael Wrightaeed7212014-06-19 19:58:12 -07001206# Read the ELF header from /proc/$PID/exe to determine if the process is
1207# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001208function is64bit()
1209{
1210 local PID="$1"
1211 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001212 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001213 echo "64"
1214 else
1215 echo ""
1216 fi
1217 else
1218 echo ""
1219 fi
1220}
1221
Clark Scheff75b36a42014-12-23 13:30:51 -08001222function dddclient()
1223{
1224 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1225 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1226 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1227 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1228 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1229 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1230 local ARCH=$(get_build_var TARGET_ARCH)
1231 local GDB
1232 case "$ARCH" in
1233 arm) GDB=arm-linux-androideabi-gdb;;
1234 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1235 mips|mips64) GDB=mips64el-linux-android-gdb;;
1236 x86) GDB=x86_64-linux-android-gdb;;
1237 x86_64) GDB=x86_64-linux-android-gdb;;
1238 *) echo "Unknown arch $ARCH"; return 1;;
1239 esac
1240
1241 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1242 local EXE="$1"
1243 if [ "$EXE" ] ; then
1244 EXE=$1
1245 if [[ $EXE =~ ^[^/].* ]] ; then
1246 EXE="system/bin/"$EXE
1247 fi
1248 else
1249 EXE="app_process"
1250 fi
1251
1252 local PORT="$2"
1253 if [ "$PORT" ] ; then
1254 PORT=$2
1255 else
1256 PORT=":5039"
1257 fi
1258
1259 local PID="$3"
1260 if [ "$PID" ] ; then
1261 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1262 PID=`pid $3`
1263 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1264 # that likely didn't work because of returning multiple processes
1265 # try again, filtering by root processes (don't contain colon)
1266 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1267 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1268 then
1269 echo "Couldn't resolve '$3' to single PID"
1270 return 1
1271 else
1272 echo ""
1273 echo "WARNING: multiple processes matching '$3' observed, using root process"
1274 echo ""
1275 fi
1276 fi
1277 fi
1278 adb forward "tcp$PORT" "tcp$PORT"
1279 local USE64BIT="$(is64bit $PID)"
1280 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1281 sleep 2
1282 else
1283 echo ""
1284 echo "If you haven't done so already, do this first on the device:"
1285 echo " gdbserver $PORT /system/bin/$EXE"
1286 echo " or"
1287 echo " gdbserver $PORT --attach <PID>"
1288 echo ""
1289 fi
1290
1291 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1292 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1293
1294 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1295 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"
1296 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1297 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1298 # Enable special debugging for ART processes.
1299 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1300 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1301 fi
1302 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1303
1304 local WHICH_GDB=
1305 # 64-bit exe found
1306 if [ "$USE64BIT" != "" ] ; then
1307 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1308 # 32-bit exe / 32-bit platform
1309 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1310 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1311 # 32-bit exe / 64-bit platform
1312 else
1313 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1314 fi
1315
1316 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1317 else
1318 echo "Unable to determine build system output dir."
1319 fi
1320}
1321
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322case `uname -s` in
1323 Darwin)
1324 function sgrep()
1325 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001326 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 -07001327 }
1328
1329 ;;
1330 *)
1331 function sgrep()
1332 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001333 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 -07001334 }
1335 ;;
1336esac
1337
Raghu Gandham8da43102012-07-25 19:57:22 -07001338function gettargetarch
1339{
1340 get_build_var TARGET_ARCH
1341}
1342
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001343function ggrep()
1344{
1345 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1346}
1347
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001348function jgrep()
1349{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001350 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 -07001351}
1352
1353function cgrep()
1354{
Dan Albert01961192014-11-22 10:16:01 -08001355 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 -07001356}
1357
1358function resgrep()
1359{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001360 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 -07001361}
1362
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001363function mangrep()
1364{
1365 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1366}
1367
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001368function sepgrep()
1369{
1370 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 "$@"
1371}
1372
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001373function rcgrep()
1374{
1375 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1376}
1377
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001378case `uname -s` in
1379 Darwin)
1380 function mgrep()
1381 {
Ying Wang324c2b22012-08-17 15:03:20 -07001382 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 -07001383 }
1384
1385 function treegrep()
1386 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001387 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 -07001388 }
1389
1390 ;;
1391 *)
1392 function mgrep()
1393 {
Ying Wang324c2b22012-08-17 15:03:20 -07001394 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 -07001395 }
1396
1397 function treegrep()
1398 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001399 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 -07001400 }
1401
1402 ;;
1403esac
1404
1405function getprebuilt
1406{
1407 get_abs_build_var ANDROID_PREBUILTS
1408}
1409
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001410function tracedmdump()
1411{
1412 T=$(gettop)
1413 if [ ! "$T" ]; then
1414 echo "Couldn't locate the top of the tree. Try setting TOP."
1415 return
1416 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001417 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001418 local arch=$(gettargetarch)
1419 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001421 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001422 if [ ! "$TRACE" ] ; then
1423 echo "usage: tracedmdump tracename"
1424 return
1425 fi
1426
Jack Veenstra60116fc2009-04-09 18:12:34 -07001427 if [ ! -r "$KERNEL" ] ; then
1428 echo "Error: cannot find kernel: '$KERNEL'"
1429 return
1430 fi
1431
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001432 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001433 if [ "$BASETRACE" = "$TRACE" ] ; then
1434 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1435 fi
1436
1437 echo "post-processing traces..."
1438 rm -f $TRACE/qtrace.dexlist
1439 post_trace $TRACE
1440 if [ $? -ne 0 ]; then
1441 echo "***"
1442 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1443 echo "***"
1444 return
1445 fi
1446 echo "generating dexlist output..."
1447 /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
1448 echo "generating dmtrace data..."
1449 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1450 echo "generating html file..."
1451 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1452 echo "done, see $TRACE/dmtrace.html for details"
1453 echo "or run:"
1454 echo " traceview $TRACE/dmtrace"
1455}
1456
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001457# communicate with a running device or emulator, set up necessary state,
1458# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001459function runhat()
1460{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001461 # process standard adb options
1462 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001463 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001464 adbTarget=$1
1465 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001466 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001467 adbTarget="$1 $2"
1468 shift 2
1469 fi
1470 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001471 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001472
1473 # runhat options
1474 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001475
1476 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001477 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001478 return
1479 fi
1480
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001481 # confirm hat is available
1482 if [ -z $(which hat) ]; then
1483 echo "hat is not available in this configuration."
1484 return
1485 fi
1486
Andy McFaddenb6289852010-07-12 08:00:19 -07001487 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001488 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001489 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001490 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001491 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001492 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001493 echo -n "> "
1494 read
1495
The Android Open Source Project88b60792009-03-03 19:28:42 -08001496 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001497
The Android Open Source Project88b60792009-03-03 19:28:42 -08001498 echo "Retrieving file $devFile..."
1499 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001500
The Android Open Source Project88b60792009-03-03 19:28:42 -08001501 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001502
The Android Open Source Project88b60792009-03-03 19:28:42 -08001503 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001504 echo "View the output by pointing your browser at http://localhost:7000/"
1505 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001506 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001507}
1508
1509function getbugreports()
1510{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001511 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001512
1513 if [ ! "$reports" ]; then
1514 echo "Could not locate any bugreports."
1515 return
1516 fi
1517
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001518 local report
1519 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001520 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001521 echo "/sdcard/bugreports/${report}"
1522 adb pull /sdcard/bugreports/${report} ${report}
1523 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001524 done
1525}
1526
Victoria Lease1b296b42012-08-21 15:44:06 -07001527function getsdcardpath()
1528{
1529 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1530}
1531
1532function getscreenshotpath()
1533{
1534 echo "$(getsdcardpath)/Pictures/Screenshots"
1535}
1536
1537function getlastscreenshot()
1538{
1539 local screenshot_path=$(getscreenshotpath)
1540 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1541 if [ "$screenshot" = "" ]; then
1542 echo "No screenshots found."
1543 return
1544 fi
1545 echo "${screenshot}"
1546 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1547}
1548
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001549function startviewserver()
1550{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001551 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001552 if [ $# -gt 0 ]; then
1553 port=$1
1554 fi
1555 adb shell service call window 1 i32 $port
1556}
1557
1558function stopviewserver()
1559{
1560 adb shell service call window 2
1561}
1562
1563function isviewserverstarted()
1564{
1565 adb shell service call window 3
1566}
1567
Romain Guyb84049a2010-10-04 16:56:11 -07001568function key_home()
1569{
1570 adb shell input keyevent 3
1571}
1572
1573function key_back()
1574{
1575 adb shell input keyevent 4
1576}
1577
1578function key_menu()
1579{
1580 adb shell input keyevent 82
1581}
1582
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001583function smoketest()
1584{
1585 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1586 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1587 return
1588 fi
1589 T=$(gettop)
1590 if [ ! "$T" ]; then
1591 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1592 return
1593 fi
1594
Ying Wang9cd17642012-12-13 10:52:07 -08001595 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001596 adb uninstall com.android.smoketest > /dev/null &&
1597 adb uninstall com.android.smoketest.tests > /dev/null &&
1598 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1599 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1600 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1601}
1602
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001603# simple shortcut to the runtest command
1604function runtest()
1605{
1606 T=$(gettop)
1607 if [ ! "$T" ]; then
1608 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1609 return
1610 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001611 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001612}
1613
The Android Open Source Project88b60792009-03-03 19:28:42 -08001614function godir () {
1615 if [[ -z "$1" ]]; then
1616 echo "Usage: godir <regex>"
1617 return
1618 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001619 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001620 if [[ ! -f $T/filelist ]]; then
1621 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001622 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001623 echo " Done"
1624 echo ""
1625 fi
1626 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001627 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001628 if [[ ${#lines[@]} = 0 ]]; then
1629 echo "Not found"
1630 return
1631 fi
1632 local pathname
1633 local choice
1634 if [[ ${#lines[@]} > 1 ]]; then
1635 while [[ -z "$pathname" ]]; do
1636 local index=1
1637 local line
1638 for line in ${lines[@]}; do
1639 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001640 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001641 done
1642 echo
1643 echo -n "Select one: "
1644 unset choice
1645 read choice
1646 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1647 echo "Invalid choice"
1648 continue
1649 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001650 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001651 done
1652 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001653 pathname=${lines[0]}
1654 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001655 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001656}
1657
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001658function cmremote()
1659{
1660 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301661 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001662 if [ -z "$GERRIT_REMOTE" ]
1663 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301664 echo Unable to set up the git remote, are you under a git repo?
1665 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001666 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301667 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001668 if [ -z "$CMUSER" ]
1669 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001670 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001671 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001672 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001673 fi
1674 echo You can now push to "cmremote".
1675}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001676
Steve Kondik873fa562012-09-17 11:33:18 -07001677function aospremote()
1678{
1679 git remote rm aosp 2> /dev/null
1680 if [ ! -d .git ]
1681 then
1682 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1683 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001684 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001685 if (echo $PROJECT | grep -qv "^device")
1686 then
1687 PFX="platform/"
1688 fi
1689 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1690 echo "Remote 'aosp' created"
1691}
Steve Kondik873fa562012-09-17 11:33:18 -07001692
Steve Kondik20c21d22013-10-27 13:34:36 -07001693function cafremote()
1694{
1695 git remote rm caf 2> /dev/null
1696 if [ ! -d .git ]
1697 then
1698 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1699 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001700 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001701 if (echo $PROJECT | grep -qv "^device")
1702 then
1703 PFX="platform/"
1704 fi
1705 git remote add caf git://codeaurora.org/$PFX$PROJECT
1706 echo "Remote 'caf' created"
1707}
Steve Kondik20c21d22013-10-27 13:34:36 -07001708
Steve Kondikf00e7d92012-09-23 23:46:55 -07001709function installboot()
1710{
1711 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1712 then
1713 echo "No recovery.fstab found. Build recovery first."
1714 return 1
1715 fi
1716 if [ ! -e "$OUT/boot.img" ];
1717 then
1718 echo "No boot.img found. Run make bootimage first."
1719 return 1
1720 fi
1721 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1722 if [ -z "$PARTITION" ];
1723 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001724 # Try for RECOVERY_FSTAB_VERSION = 2
1725 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1726 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1727 if [ -z "$PARTITION" ];
1728 then
1729 echo "Unable to determine boot partition."
1730 return 1
1731 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001732 fi
1733 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001734 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001735 adb root
1736 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001737 adb wait-for-online shell mount /system 2>&1 > /dev/null
1738 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001739 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1740 then
1741 adb push $OUT/boot.img /cache/
1742 for i in $OUT/system/lib/modules/*;
1743 do
1744 adb push $i /system/lib/modules/
1745 done
1746 adb shell dd if=/cache/boot.img of=$PARTITION
1747 adb shell chmod 644 /system/lib/modules/*
1748 echo "Installation complete."
1749 else
1750 echo "The connected device does not appear to be $CM_BUILD, run away!"
1751 fi
1752}
1753
Steve Kondik83c03d52012-10-24 16:40:42 -07001754function installrecovery()
1755{
1756 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1757 then
1758 echo "No recovery.fstab found. Build recovery first."
1759 return 1
1760 fi
1761 if [ ! -e "$OUT/recovery.img" ];
1762 then
1763 echo "No recovery.img found. Run make recoveryimage first."
1764 return 1
1765 fi
1766 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1767 if [ -z "$PARTITION" ];
1768 then
Steve Kondik75f10762013-08-09 21:03:42 -07001769 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001770 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1771 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001772 if [ -z "$PARTITION" ];
1773 then
1774 echo "Unable to determine recovery partition."
1775 return 1
1776 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001777 fi
1778 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001779 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001780 adb root
1781 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001782 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1783 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001784 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1785 then
1786 adb push $OUT/recovery.img /cache/
1787 adb shell dd if=/cache/recovery.img of=$PARTITION
1788 echo "Installation complete."
1789 else
1790 echo "The connected device does not appear to be $CM_BUILD, run away!"
1791 fi
1792}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001793
Koushik Duttab55f13a2012-05-14 16:14:36 -07001794function makerecipe() {
1795 if [ -z "$1" ]
1796 then
1797 echo "No branch name provided."
1798 return 1
1799 fi
1800 cd android
1801 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1802 git commit -a -m "$1"
1803 cd ..
1804
1805 repo forall -c '
1806
1807 if [ "$REPO_REMOTE" == "github" ]
1808 then
1809 pwd
1810 cmremote
1811 git push cmremote HEAD:refs/heads/'$1'
1812 fi
1813 '
1814}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001815
1816function cmgerrit() {
1817 if [ $# -eq 0 ]; then
1818 $FUNCNAME help
1819 return 1
1820 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001821 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001822 local review=`git config --get remote.github.review`
1823 local project=`git config --get remote.github.projectname`
1824 local command=$1
1825 shift
1826 case $command in
1827 help)
1828 if [ $# -eq 0 ]; then
1829 cat <<EOF
1830Usage:
1831 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1832
1833Commands:
1834 fetch Just fetch the change as FETCH_HEAD
1835 help Show this help, or for a specific command
1836 pull Pull a change into current branch
1837 push Push HEAD or a local branch to Gerrit for a specific branch
1838
1839Any other Git commands that support refname would work as:
1840 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1841
1842See '$FUNCNAME help COMMAND' for more information on a specific command.
1843
1844Example:
1845 $FUNCNAME checkout -b topic 1234/5
1846works as:
1847 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1848 && git checkout -b topic FETCH_HEAD
1849will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1850Patch-set 1 will be fetched if omitted.
1851EOF
1852 return
1853 fi
1854 case $1 in
1855 __cmg_*) echo "For internal use only." ;;
1856 changes|for)
1857 if [ "$FUNCNAME" = "cmgerrit" ]; then
1858 echo "'$FUNCNAME $1' is deprecated."
1859 fi
1860 ;;
1861 help) $FUNCNAME help ;;
1862 fetch|pull) cat <<EOF
1863usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1864
1865works as:
1866 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1867 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1868
1869Example:
1870 $FUNCNAME $1 1234
1871will $1 patch-set 1 of change 1234
1872EOF
1873 ;;
1874 push) cat <<EOF
1875usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1876
1877works as:
1878 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1879 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1880
1881Example:
1882 $FUNCNAME push fix6789:gingerbread
1883will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1884HEAD will be pushed from local if omitted.
1885EOF
1886 ;;
1887 *)
1888 $FUNCNAME __cmg_err_not_supported $1 && return
1889 cat <<EOF
1890usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1891
1892works as:
1893 git fetch http://DOMAIN/p/PROJECT \\
1894 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1895 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1896EOF
1897 ;;
1898 esac
1899 ;;
1900 __cmg_get_ref)
1901 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1902 local change_id patchset_id hash
1903 case $1 in
1904 */*)
1905 change_id=${1%%/*}
1906 patchset_id=${1#*/}
1907 ;;
1908 *)
1909 change_id=$1
1910 patchset_id=1
1911 ;;
1912 esac
1913 hash=$(($change_id % 100))
1914 case $hash in
1915 [0-9]) hash="0$hash" ;;
1916 esac
1917 echo "refs/changes/$hash/$change_id/$patchset_id"
1918 ;;
1919 fetch|pull)
1920 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1921 $FUNCNAME __cmg_err_not_repo && return 1
1922 local change=$1
1923 shift
1924 git $command $@ http://$review/p/$project \
1925 $($FUNCNAME __cmg_get_ref $change) || return 1
1926 ;;
1927 push)
1928 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1929 $FUNCNAME __cmg_err_not_repo && return 1
1930 if [ -z "$user" ]; then
1931 echo >&2 "Gerrit username not found."
1932 return 1
1933 fi
1934 local local_branch remote_branch
1935 case $1 in
1936 *:*)
1937 local_branch=${1%:*}
1938 remote_branch=${1##*:}
1939 ;;
1940 *)
1941 local_branch=HEAD
1942 remote_branch=$1
1943 ;;
1944 esac
1945 shift
1946 git push $@ ssh://$user@$review:29418/$project \
1947 $local_branch:refs/for/$remote_branch || return 1
1948 ;;
1949 changes|for)
1950 if [ "$FUNCNAME" = "cmgerrit" ]; then
1951 echo >&2 "'$FUNCNAME $command' is deprecated."
1952 fi
1953 ;;
1954 __cmg_err_no_arg)
1955 if [ $# -lt 2 ]; then
1956 echo >&2 "'$FUNCNAME $command' missing argument."
1957 elif [ $2 -eq 0 ]; then
1958 if [ -n "$3" ]; then
1959 $FUNCNAME help $1
1960 else
1961 echo >&2 "'$FUNCNAME $1' missing argument."
1962 fi
1963 else
1964 return 1
1965 fi
1966 ;;
1967 __cmg_err_not_repo)
1968 if [ -z "$review" -o -z "$project" ]; then
1969 echo >&2 "Not currently in any reviewable repository."
1970 else
1971 return 1
1972 fi
1973 ;;
1974 __cmg_err_not_supported)
1975 $FUNCNAME __cmg_err_no_arg $command $# && return
1976 case $1 in
1977 #TODO: filter more git commands that don't use refname
1978 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1979 echo >&2 "'$FUNCNAME $1' is not supported."
1980 ;;
1981 *) return 1 ;;
1982 esac
1983 ;;
1984 #TODO: other special cases?
1985 *)
1986 $FUNCNAME __cmg_err_not_supported $command && return 1
1987 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1988 $FUNCNAME __cmg_err_not_repo && return 1
1989 local args="$@"
1990 local change pre_args refs_arg post_args
1991 case "$args" in
1992 *--\ *)
1993 pre_args=${args%%-- *}
1994 post_args="-- ${args#*-- }"
1995 ;;
1996 *) pre_args="$args" ;;
1997 esac
1998 args=($pre_args)
1999 pre_args=
2000 if [ ${#args[@]} -gt 0 ]; then
2001 change=${args[${#args[@]}-1]}
2002 fi
2003 if [ ${#args[@]} -gt 1 ]; then
2004 pre_args=${args[0]}
2005 for ((i=1; i<${#args[@]}-1; i++)); do
2006 pre_args="$pre_args ${args[$i]}"
2007 done
2008 fi
2009 while ((1)); do
2010 case $change in
2011 ""|--)
2012 $FUNCNAME help $command
2013 return 1
2014 ;;
2015 *@*)
2016 if [ -z "$refs_arg" ]; then
2017 refs_arg="@${change#*@}"
2018 change=${change%%@*}
2019 fi
2020 ;;
2021 *~*)
2022 if [ -z "$refs_arg" ]; then
2023 refs_arg="~${change#*~}"
2024 change=${change%%~*}
2025 fi
2026 ;;
2027 *^*)
2028 if [ -z "$refs_arg" ]; then
2029 refs_arg="^${change#*^}"
2030 change=${change%%^*}
2031 fi
2032 ;;
2033 *:*)
2034 if [ -z "$refs_arg" ]; then
2035 refs_arg=":${change#*:}"
2036 change=${change%%:*}
2037 fi
2038 ;;
2039 *) break ;;
2040 esac
2041 done
2042 $FUNCNAME fetch $change \
2043 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2044 || return 1
2045 ;;
2046 esac
2047}
2048
2049function cmrebase() {
2050 local repo=$1
2051 local refs=$2
2052 local pwd="$(pwd)"
2053 local dir="$(gettop)/$repo"
2054
2055 if [ -z $repo ] || [ -z $refs ]; then
2056 echo "CyanogenMod Gerrit Rebase Usage: "
2057 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2058 echo " The patch IDs appear on the Gerrit commands that are offered."
2059 echo " They consist on a series of numbers and slashes, after the text"
2060 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2061 echo ""
2062 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2063 echo ""
2064 return
2065 fi
2066
2067 if [ ! -d $dir ]; then
2068 echo "Directory $dir doesn't exist in tree."
2069 return
2070 fi
2071 cd $dir
2072 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2073 echo "Starting branch..."
2074 repo start tmprebase .
2075 echo "Bringing it up to date..."
2076 repo sync .
2077 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07002078 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002079 if [ "$?" != "0" ]; then
2080 echo "Error cherry-picking. Not uploading!"
2081 return
2082 fi
2083 echo "Uploading..."
2084 repo upload .
2085 echo "Cleaning up..."
2086 repo abandon tmprebase .
2087 cd $pwd
2088}
2089
2090function mka() {
2091 case `uname -s` in
2092 Darwin)
2093 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2094 ;;
2095 *)
Anthony King40b093f2015-04-30 22:19:48 +01002096 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 -06002097 ;;
2098 esac
2099}
2100
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302101function cmka() {
2102 if [ ! -z "$1" ]; then
2103 for i in "$@"; do
2104 case $i in
2105 bacon|otapackage|systemimage)
2106 mka installclean
2107 mka $i
2108 ;;
2109 *)
2110 mka clean-$i
2111 mka $i
2112 ;;
2113 esac
2114 done
2115 else
2116 mka clean
2117 mka
2118 fi
2119}
2120
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002121function reposync() {
2122 case `uname -s` in
2123 Darwin)
2124 repo sync -j 4 "$@"
2125 ;;
2126 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002127 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002128 ;;
2129 esac
2130}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002131
2132function repodiff() {
2133 if [ -z "$*" ]; then
2134 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2135 return
2136 fi
2137 diffopts=$* repo forall -c \
2138 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2139}
2140
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302141# Credit for color strip sed: http://goo.gl/BoIcm
2142function dopush()
2143{
2144 local func=$1
2145 shift
2146
2147 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2148 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2149 echo "No device is online. Waiting for one..."
2150 echo "Please connect USB and/or enable USB debugging"
2151 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2152 sleep 1
2153 done
2154 echo "Device Found."
2155 fi
2156
Chirayu Desai6dadb572012-12-26 10:53:58 +05302157 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2158 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002159 # retrieve IP and PORT info if we're using a TCP connection
2160 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2161 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302162 adb root &> /dev/null
2163 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002164 if [ -n "$TCPIPPORT" ]
2165 then
2166 # adb root just killed our connection
2167 # so reconnect...
2168 adb connect "$TCPIPPORT"
2169 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302170 adb wait-for-device &> /dev/null
2171 sleep 0.3
2172 adb remount &> /dev/null
2173
Matt Mower668ea262014-05-20 02:52:23 -05002174 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00002175 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2176 ret=$?;
2177 if [ $ret -ne 0 ]; then
2178 rm -f $OUT/.log;return $ret
2179 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302180
2181 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002182 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 +05302183
2184 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002185 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 +05302186
Matt Mower668ea262014-05-20 02:52:23 -05002187 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302188 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002189 # Make sure file is in $OUT/system
2190 case $FILE in
2191 $OUT/system/*)
2192 # Get target file name (i.e. /system/bin/adb)
2193 TARGET=$(echo $FILE | sed "s#$OUT##")
2194 ;;
2195 *) continue ;;
2196 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302197
Matt Mower668ea262014-05-20 02:52:23 -05002198 case $TARGET in
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002199 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002200 # Only need to stop services once
2201 if ! $stop_n_start; then
2202 adb shell stop
2203 stop_n_start=true
2204 fi
2205 echo "Pushing: $TARGET"
2206 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302207 ;;
2208 *)
Matt Mower668ea262014-05-20 02:52:23 -05002209 echo "Pushing: $TARGET"
2210 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302211 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002212 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302213 done
Matt Mower668ea262014-05-20 02:52:23 -05002214 if $stop_n_start; then
2215 adb shell start
2216 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302217 rm -f $OUT/.log
2218 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302219 else
2220 echo "The connected device does not appear to be $CM_BUILD, run away!"
2221 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302222}
2223
2224alias mmp='dopush mm'
2225alias mmmp='dopush mmm'
2226alias mkap='dopush mka'
2227alias cmkap='dopush cmka'
2228
Chirayu Desai4a319b82013-06-05 20:14:33 +05302229function repopick() {
2230 T=$(gettop)
2231 $T/build/tools/repopick.py $@
2232}
2233
Chirayu Desaib89b3242013-06-30 10:04:25 +05302234function fixup_common_out_dir() {
2235 common_out_dir=$(get_build_var OUT_DIR)/target/common
2236 target_device=$(get_build_var TARGET_DEVICE)
2237 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2238 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2239 mv ${common_out_dir} ${common_out_dir}-${target_device}
2240 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2241 else
2242 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2243 mkdir -p ${common_out_dir}-${target_device}
2244 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2245 fi
2246 else
2247 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2248 mkdir -p ${common_out_dir}
2249 fi
2250}
2251
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002252# 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 +00002253#
2254# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2255# For some reason, installing the JDK doesn't make it show up in the
2256# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002257function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002258 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002259 # we can reset it later, depending on the version of java the build
2260 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002261 #
2262 # If we don't do this, the JAVA_HOME value set by the first call to
2263 # build/envsetup.sh will persist forever.
2264 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2265 export JAVA_HOME=""
2266 fi
2267
Andy McFaddenbd960942010-06-24 12:52:51 -07002268 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002269 case `uname -s` in
2270 Darwin)
2271 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2272 ;;
2273 *)
2274 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2275 ;;
2276 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002277
2278 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2279 # we can change it on the next envsetup.sh, if required.
2280 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002281 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002282}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002283
Alex Rayf0d08eb2013-03-08 15:15:06 -08002284# Print colored exit condition
2285function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002286 "$@"
2287 local retval=$?
2288 if [ $retval -ne 0 ]
2289 then
2290 echo -e "\e[0;31mFAILURE\e[00m"
2291 else
2292 echo -e "\e[0;32mSUCCESS\e[00m"
2293 fi
2294 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002295}
2296
Ying Wanged21d4c2014-08-24 22:14:19 -07002297function get_make_command()
2298{
2299 echo command make
2300}
2301
Anthony King40b093f2015-04-30 22:19:48 +01002302function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002303{
2304 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002305 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002306 local ret=$?
2307 local end_time=$(date +"%s")
2308 local tdiff=$(($end_time-$start_time))
2309 local hours=$(($tdiff / 3600 ))
2310 local mins=$((($tdiff % 3600) / 60))
2311 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002312 local ncolors=$(tput colors 2>/dev/null)
2313 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2314 color_failed="\e[0;31m"
2315 color_success="\e[0;32m"
2316 color_reset="\e[00m"
2317 else
2318 color_failed=""
2319 color_success=""
2320 color_reset=""
2321 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002322 echo
2323 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002324 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002325 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002326 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002327 fi
2328 if [ $hours -gt 0 ] ; then
2329 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2330 elif [ $mins -gt 0 ] ; then
2331 printf "(%02g:%02g (mm:ss))" $mins $secs
2332 elif [ $secs -gt 0 ] ; then
2333 printf "(%s seconds)" $secs
2334 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002335 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002336 echo
2337 return $ret
2338}
2339
Anthony King40b093f2015-04-30 22:19:48 +01002340function make()
2341{
2342 mk_timer $(get_make_command) "$@"
2343}
2344
Raphael Moll70a86b02011-06-20 16:03:14 -07002345if [ "x$SHELL" != "x/bin/bash" ]; then
2346 case `ps -o command -p $$` in
2347 *bash*)
2348 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002349 *zsh*)
2350 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002351 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002352 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002353 ;;
2354 esac
2355fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002356
2357# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002358for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2359 `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 -08002360do
2361 echo "including $f"
2362 . $f
2363done
2364unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002365
Kyle Ladd031a0b62013-09-11 20:43:42 -04002366# Add completions
2367check_bash_version && {
2368 dirs="sdk/bash_completion vendor/cm/bash_completion"
2369 for dir in $dirs; do
2370 if [ -d ${dir} ]; then
2371 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2372 echo "including $f"
2373 . $f
2374 done
2375 fi
2376 done
2377}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302378
2379export ANDROID_BUILD_TOP=$(gettop)