blob: 314a539f257f522155039403d44ef8a1840e8fe4 [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
580
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800582 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583 else
584 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700585 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587 fi
588
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 local selection=
590
591 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700593 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800594 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
595 then
596 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
597 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800598 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800599 fi
600 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
601 then
602 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700603 fi
604
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800605 if [ -z "$selection" ]
606 then
607 echo
608 echo "Invalid lunch combo: $answer"
609 return 1
610 fi
611
Joe Onoratoda12daf2010-06-09 18:18:31 -0700612 export TARGET_BUILD_APPS=
613
Jeff Browne33ba4c2011-07-11 22:11:46 -0700614 local product=$(echo -n $selection | sed -e "s/-.*$//")
615 check_product $product
616 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800617 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800618 # if we can't find a product, try to grab it off the CM github
619 T=$(gettop)
620 pushd $T > /dev/null
621 build/tools/roomservice.py $product
622 popd > /dev/null
623 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000624 else
625 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800626 fi
627 if [ $? -ne 0 ]
628 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700629 echo
630 echo "** Don't have a product spec for: '$product'"
631 echo "** Do you have the right repo manifest?"
632 product=
633 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800634
Jeff Browne33ba4c2011-07-11 22:11:46 -0700635 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
636 check_variant $variant
637 if [ $? -ne 0 ]
638 then
639 echo
640 echo "** Invalid variant: '$variant'"
641 echo "** Must be one of ${VARIANT_CHOICES[@]}"
642 variant=
643 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800644
Jeff Browne33ba4c2011-07-11 22:11:46 -0700645 if [ -z "$product" -o -z "$variant" ]
646 then
647 echo
648 return 1
649 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800650
Jeff Browne33ba4c2011-07-11 22:11:46 -0700651 export TARGET_PRODUCT=$product
652 export TARGET_BUILD_VARIANT=$variant
653 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654
655 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800656
Chirayu Desaib89b3242013-06-30 10:04:25 +0530657 fixup_common_out_dir
658
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800660 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661}
662
Jeff Davidson513d7a42010-08-02 10:00:44 -0700663# Tab completion for lunch.
664function _lunch()
665{
666 local cur prev opts
667 COMPREPLY=()
668 cur="${COMP_WORDS[COMP_CWORD]}"
669 prev="${COMP_WORDS[COMP_CWORD-1]}"
670
671 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
672 return 0
673}
Emilio López9ad6eea2013-11-03 13:02:13 -0300674complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700675
Joe Onoratoda12daf2010-06-09 18:18:31 -0700676# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700677# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700678function tapas()
679{
Ying Wangb541ab62014-05-29 17:57:40 -0700680 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 -0700681 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700682 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
683 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 -0700684
Ying Wang67f02922012-08-22 10:25:20 -0700685 if [ $(echo $arch | wc -w) -gt 1 ]; then
686 echo "tapas: Error: Multiple build archs supplied: $arch"
687 return
688 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700689 if [ $(echo $variant | wc -w) -gt 1 ]; then
690 echo "tapas: Error: Multiple build variants supplied: $variant"
691 return
692 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700693 if [ $(echo $density | wc -w) -gt 1 ]; then
694 echo "tapas: Error: Multiple densities supplied: $density"
695 return
696 fi
Ying Wang67f02922012-08-22 10:25:20 -0700697
698 local product=full
699 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700700 x86) product=full_x86;;
701 mips) product=full_mips;;
702 armv5) product=generic_armv5;;
703 arm64) product=aosp_arm64;;
704 x86_64) product=aosp_x86_64;;
705 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700706 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700707 if [ -z "$variant" ]; then
708 variant=eng
709 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700710 if [ -z "$apps" ]; then
711 apps=all
712 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600713 if [ -z "$density" ]; then
714 density=alldpi
715 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700716
Ying Wang67f02922012-08-22 10:25:20 -0700717 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700718 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700719 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700720 export TARGET_BUILD_TYPE=release
721 export TARGET_BUILD_APPS=$apps
722
723 set_stuff_for_environment
724 printconfig
725}
726
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100727function eat()
728{
729 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530730 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100731 ZIPFILE=cm-$MODVERSION.zip
732 ZIPPATH=$OUT/$ZIPFILE
733 if [ ! -f $ZIPPATH ] ; then
734 echo "Nothing to eat"
735 return 1
736 fi
737 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
738 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
739 echo "No device is online. Waiting for one..."
740 echo "Please connect USB and/or enable USB debugging"
741 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
742 sleep 1
743 done
744 echo "Device Found.."
745 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530746 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
747 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100748 # if adbd isn't root we can't write to /cache/recovery/
749 adb root
750 sleep 1
751 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700752 cat << EOF > /tmp/command
753--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100754EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700755 if adb push /tmp/command /cache/recovery/ ; then
756 echo "Rebooting into recovery for sideload installation"
757 adb reboot recovery
758 adb wait-for-sideload
759 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100760 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700761 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100762 else
763 echo "Nothing to eat"
764 return 1
765 fi
766 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530767 else
768 echo "The connected device does not appear to be $CM_BUILD, run away!"
769 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100770}
771
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000772function omnom
773{
774 brunch $*
775 eat
776}
777
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700778function gettop
779{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800780 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700782 # The following circumlocution ensures we remove symlinks from TOP.
783 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 else
785 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800786 # The following circumlocution (repeated below as well) ensures
787 # that we record the true directory name and not one that is
788 # faked up with symlink names.
789 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800791 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792 T=
793 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800794 \cd ..
synergyb112a402013-07-05 19:47:47 -0700795 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 done
Ying Wang9cd17642012-12-13 10:52:07 -0800797 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700798 if [ -f "$T/$TOPFILE" ]; then
799 echo $T
800 fi
801 fi
802 fi
803}
804
Andrew Hsieh906cb782013-09-10 17:37:14 +0800805# Return driver for "make", if any (eg. static analyzer)
806function getdriver()
807{
808 local T="$1"
809 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
810 if [ -n "$WITH_STATIC_ANALYZER" ]; then
811 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800812$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
813--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800814--status-bugs \
815--top=$T"
816 fi
817}
818
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819function m()
820{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800821 local T=$(gettop)
822 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800824 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700825 else
826 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700827 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700828 fi
829}
830
831function findmakefile()
832{
833 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800834 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835 T=
836 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700837 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838 if [ -f "$T/Android.mk" ]; then
839 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800840 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700841 return
842 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800843 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844 done
Ying Wang9cd17642012-12-13 10:52:07 -0800845 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846}
847
848function mm()
849{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800850 local T=$(gettop)
851 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700852 # If we're sitting in the root of the build tree, just do a
853 # normal make.
854 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800855 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700856 else
857 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800858 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700859 local MODULES=
860 local GET_INSTALL_PATH=
861 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700862 # Remove the path to top as the makefilepath needs to be relative
863 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864 if [ ! "$T" ]; then
865 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700866 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867 elif [ ! "$M" ]; then
868 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700869 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870 else
Ying Wanga7deb082013-08-16 13:24:47 -0700871 for ARG in $@; do
872 case $ARG in
873 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
874 esac
875 done
876 if [ -n "$GET_INSTALL_PATH" ]; then
877 MODULES=
878 ARGS=GET-INSTALL-PATH
879 else
880 MODULES=all_modules
881 ARGS=$@
882 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700883 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 -0700884 fi
885 fi
886}
887
888function mmm()
889{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800890 local T=$(gettop)
891 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700892 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800893 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800894 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800895 local ARGS=
896 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700897 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800898 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
899 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
900 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800901 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
902 if [ "$MODULES" = "" ]; then
903 MODULES=all_modules
904 fi
905 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700906 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700907 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
908 local TO_CHOP=`expr $TO_CHOP + 1`
909 local START=`PWD= /bin/pwd`
910 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 if [ "$MFILE" = "" ] ; then
912 MFILE=$DIR/Android.mk
913 else
914 MFILE=$MFILE/$DIR/Android.mk
915 fi
916 MAKEFILE="$MAKEFILE $MFILE"
917 else
Ying Wanga7deb082013-08-16 13:24:47 -0700918 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100919 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700920 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
921 *) echo "No Android.mk in $DIR."; return 1;;
922 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700923 fi
924 done
Ying Wanga7deb082013-08-16 13:24:47 -0700925 if [ -n "$GET_INSTALL_PATH" ]; then
926 ARGS=$GET_INSTALL_PATH
927 MODULES=
928 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800929 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 -0700930 else
931 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700932 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700933 fi
934}
935
Ying Wangb607f7b2013-02-08 18:01:04 -0800936function mma()
937{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800938 local T=$(gettop)
939 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800940 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800941 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800942 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800943 if [ ! "$T" ]; then
944 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700945 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800946 fi
947 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800948 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800949 fi
950}
951
952function mmma()
953{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800954 local T=$(gettop)
955 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800956 if [ "$T" ]; then
957 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
958 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
959 local MY_PWD=`PWD= /bin/pwd`
960 if [ "$MY_PWD" = "$T" ]; then
961 MY_PWD=
962 else
963 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
964 fi
965 local DIR=
966 local MODULE_PATHS=
967 local ARGS=
968 for DIR in $DIRS ; do
969 if [ -d $DIR ]; then
970 if [ "$MY_PWD" = "" ]; then
971 MODULE_PATHS="$MODULE_PATHS $DIR"
972 else
973 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
974 fi
975 else
976 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100977 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800978 *) echo "Couldn't find directory $DIR"; return 1;;
979 esac
980 fi
981 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800982 $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 -0800983 else
984 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700985 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800986 fi
987}
988
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700989function croot()
990{
991 T=$(gettop)
992 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800993 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700994 else
995 echo "Couldn't locate the top of the tree. Try setting TOP."
996 fi
997}
998
nebkatfb67a1e2012-12-28 10:40:45 +0000999function cout()
1000{
1001 if [ "$OUT" ]; then
1002 cd $OUT
1003 else
1004 echo "Couldn't locate out directory. Try setting OUT."
1005 fi
1006}
1007
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001008function cproj()
1009{
1010 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001011 local HERE=$PWD
1012 T=
1013 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1014 T=$PWD
1015 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001016 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001017 return
1018 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001019 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 done
Ying Wang9cd17642012-12-13 10:52:07 -08001021 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001022 echo "can't find Android.mk"
1023}
1024
Daniel Sandler47e0a882013-07-30 13:23:52 -04001025# simplified version of ps; output in the form
1026# <pid> <procname>
1027function qpid() {
1028 local prepend=''
1029 local append=''
1030 if [ "$1" = "--exact" ]; then
1031 prepend=' '
1032 append='$'
1033 shift
1034 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1035 echo "usage: qpid [[--exact] <process name|pid>"
1036 return 255
1037 fi
1038
1039 local EXE="$1"
1040 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001041 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001042 else
1043 adb shell ps \
1044 | tr -d '\r' \
1045 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1046 fi
1047}
1048
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001049function pid()
1050{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001051 local prepend=''
1052 local append=''
1053 if [ "$1" = "--exact" ]; then
1054 prepend=' '
1055 append='$'
1056 shift
1057 fi
1058 local EXE="$1"
1059 if [ "$EXE" ] ; then
1060 local PID=`adb shell ps \
1061 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001062 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001063 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1064 echo "$PID"
1065 else
1066 echo "usage: pid [--exact] <process name>"
1067 return 255
1068 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001069}
1070
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001071# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001072# that has the core-file-size limit set correctly
1073#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001074# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075# if its core-file-size limit is not set already.
1076# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1077
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001078function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001079{
1080 echo "Getting root...";
1081 adb root;
1082 adb wait-for-device;
1083
1084 echo "Remounting root parition read-write...";
1085 adb shell mount -w -o remount -t rootfs rootfs;
1086 sleep 1;
1087 adb wait-for-device;
1088 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001089 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001090 adb shell chmod 0777 /cores;
1091
1092 echo "Granting SELinux permission to dump in /cores...";
1093 adb shell restorecon -R /cores;
1094
1095 echo "Set core pattern.";
1096 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1097
1098 echo "Done."
1099}
1100
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001101# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001102# $1 = PID of process (e.g., $(pid mediaserver))
1103#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001104# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001105# dump to actually be generated.
1106
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001107function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001108{
1109 local PID=$1;
1110 if [ -z "$PID" ]; then
1111 printf "Expecting a PID!\n";
1112 return;
1113 fi;
1114 echo "Setting core limit for $PID to infinite...";
1115 adb shell prlimit $PID 4 -1 -1
1116}
1117
1118# core - send SIGV and pull the core for process
1119# $1 = PID of process (e.g., $(pid mediaserver))
1120#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001121# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001122# enabled globally.
1123
1124function core()
1125{
1126 local PID=$1;
1127
1128 if [ -z "$PID" ]; then
1129 printf "Expecting a PID!\n";
1130 return;
1131 fi;
1132
1133 local CORENAME=core.$PID;
1134 local COREPATH=/cores/$CORENAME;
1135 local SIG=SEGV;
1136
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001137 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001138
1139 local done=0;
1140 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1141 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1142 adb shell kill -$SIG $PID;
1143 sleep 1;
1144 done;
1145
1146 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1147 echo "Done: core is under $COREPATH on device.";
1148}
1149
Christopher Tate744ee802009-11-12 15:33:08 -08001150# systemstack - dump the current stack trace of all threads in the system process
1151# to the usual ANR traces file
1152function systemstack()
1153{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001154 stacks system_server
1155}
1156
1157function stacks()
1158{
1159 if [[ $1 =~ ^[0-9]+$ ]] ; then
1160 local PID="$1"
1161 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001162 local PIDLIST="$(pid $1)"
1163 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1164 local PID="$PIDLIST"
1165 elif [ "$PIDLIST" ] ; then
1166 echo "more than one process: $1"
1167 else
1168 echo "no such process: $1"
1169 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001170 else
1171 echo "usage: stacks [pid|process name]"
1172 fi
1173
1174 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001175 # Determine whether the process is native
1176 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1177 # Dump stacks of Dalvik process
1178 local TRACES=/data/anr/traces.txt
1179 local ORIG=/data/anr/traces.orig
1180 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001181
Jeff Brownb12c2e52013-08-19 15:14:16 -07001182 # Keep original traces to avoid clobbering
1183 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001184
Jeff Brownb12c2e52013-08-19 15:14:16 -07001185 # Make sure we have a usable file
1186 adb shell touch $TRACES
1187 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001188
Jeff Brownb12c2e52013-08-19 15:14:16 -07001189 # Dump stacks and wait for dump to finish
1190 adb shell kill -3 $PID
1191 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001192
Jeff Brownb12c2e52013-08-19 15:14:16 -07001193 # Restore original stacks, and show current output
1194 adb shell mv $TRACES $TMP
1195 adb shell mv $ORIG $TRACES
1196 adb shell cat $TMP
1197 else
1198 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001199 local USE64BIT="$(is64bit $PID)"
1200 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001201 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001202 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001203}
1204
Michael Wrightaeed7212014-06-19 19:58:12 -07001205# Read the ELF header from /proc/$PID/exe to determine if the process is
1206# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001207function is64bit()
1208{
1209 local PID="$1"
1210 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001211 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001212 echo "64"
1213 else
1214 echo ""
1215 fi
1216 else
1217 echo ""
1218 fi
1219}
1220
Clark Scheff75b36a42014-12-23 13:30:51 -08001221function dddclient()
1222{
1223 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1224 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1225 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1226 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1227 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1228 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1229 local ARCH=$(get_build_var TARGET_ARCH)
1230 local GDB
1231 case "$ARCH" in
1232 arm) GDB=arm-linux-androideabi-gdb;;
1233 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1234 mips|mips64) GDB=mips64el-linux-android-gdb;;
1235 x86) GDB=x86_64-linux-android-gdb;;
1236 x86_64) GDB=x86_64-linux-android-gdb;;
1237 *) echo "Unknown arch $ARCH"; return 1;;
1238 esac
1239
1240 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1241 local EXE="$1"
1242 if [ "$EXE" ] ; then
1243 EXE=$1
1244 if [[ $EXE =~ ^[^/].* ]] ; then
1245 EXE="system/bin/"$EXE
1246 fi
1247 else
1248 EXE="app_process"
1249 fi
1250
1251 local PORT="$2"
1252 if [ "$PORT" ] ; then
1253 PORT=$2
1254 else
1255 PORT=":5039"
1256 fi
1257
1258 local PID="$3"
1259 if [ "$PID" ] ; then
1260 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1261 PID=`pid $3`
1262 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1263 # that likely didn't work because of returning multiple processes
1264 # try again, filtering by root processes (don't contain colon)
1265 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1266 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1267 then
1268 echo "Couldn't resolve '$3' to single PID"
1269 return 1
1270 else
1271 echo ""
1272 echo "WARNING: multiple processes matching '$3' observed, using root process"
1273 echo ""
1274 fi
1275 fi
1276 fi
1277 adb forward "tcp$PORT" "tcp$PORT"
1278 local USE64BIT="$(is64bit $PID)"
1279 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1280 sleep 2
1281 else
1282 echo ""
1283 echo "If you haven't done so already, do this first on the device:"
1284 echo " gdbserver $PORT /system/bin/$EXE"
1285 echo " or"
1286 echo " gdbserver $PORT --attach <PID>"
1287 echo ""
1288 fi
1289
1290 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1291 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1292
1293 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1294 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"
1295 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1296 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1297 # Enable special debugging for ART processes.
1298 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1299 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1300 fi
1301 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1302
1303 local WHICH_GDB=
1304 # 64-bit exe found
1305 if [ "$USE64BIT" != "" ] ; then
1306 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1307 # 32-bit exe / 32-bit platform
1308 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1309 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1310 # 32-bit exe / 64-bit platform
1311 else
1312 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1313 fi
1314
1315 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1316 else
1317 echo "Unable to determine build system output dir."
1318 fi
1319}
1320
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001321case `uname -s` in
1322 Darwin)
1323 function sgrep()
1324 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001325 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 -07001326 }
1327
1328 ;;
1329 *)
1330 function sgrep()
1331 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001332 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 -07001333 }
1334 ;;
1335esac
1336
Raghu Gandham8da43102012-07-25 19:57:22 -07001337function gettargetarch
1338{
1339 get_build_var TARGET_ARCH
1340}
1341
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001342function ggrep()
1343{
1344 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1345}
1346
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001347function jgrep()
1348{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001349 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 -07001350}
1351
1352function cgrep()
1353{
Dan Albert01961192014-11-22 10:16:01 -08001354 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 -07001355}
1356
1357function resgrep()
1358{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001359 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 -07001360}
1361
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001362function mangrep()
1363{
1364 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1365}
1366
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001367function sepgrep()
1368{
1369 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 "$@"
1370}
1371
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001372function rcgrep()
1373{
1374 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1375}
1376
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377case `uname -s` in
1378 Darwin)
1379 function mgrep()
1380 {
Ying Wang324c2b22012-08-17 15:03:20 -07001381 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 -07001382 }
1383
1384 function treegrep()
1385 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001386 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 -07001387 }
1388
1389 ;;
1390 *)
1391 function mgrep()
1392 {
Ying Wang324c2b22012-08-17 15:03:20 -07001393 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 -07001394 }
1395
1396 function treegrep()
1397 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001398 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 -07001399 }
1400
1401 ;;
1402esac
1403
1404function getprebuilt
1405{
1406 get_abs_build_var ANDROID_PREBUILTS
1407}
1408
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001409function tracedmdump()
1410{
1411 T=$(gettop)
1412 if [ ! "$T" ]; then
1413 echo "Couldn't locate the top of the tree. Try setting TOP."
1414 return
1415 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001416 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001417 local arch=$(gettargetarch)
1418 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001419
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001420 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001421 if [ ! "$TRACE" ] ; then
1422 echo "usage: tracedmdump tracename"
1423 return
1424 fi
1425
Jack Veenstra60116fc2009-04-09 18:12:34 -07001426 if [ ! -r "$KERNEL" ] ; then
1427 echo "Error: cannot find kernel: '$KERNEL'"
1428 return
1429 fi
1430
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001431 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001432 if [ "$BASETRACE" = "$TRACE" ] ; then
1433 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1434 fi
1435
1436 echo "post-processing traces..."
1437 rm -f $TRACE/qtrace.dexlist
1438 post_trace $TRACE
1439 if [ $? -ne 0 ]; then
1440 echo "***"
1441 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1442 echo "***"
1443 return
1444 fi
1445 echo "generating dexlist output..."
1446 /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
1447 echo "generating dmtrace data..."
1448 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1449 echo "generating html file..."
1450 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1451 echo "done, see $TRACE/dmtrace.html for details"
1452 echo "or run:"
1453 echo " traceview $TRACE/dmtrace"
1454}
1455
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001456# communicate with a running device or emulator, set up necessary state,
1457# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001458function runhat()
1459{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001460 # process standard adb options
1461 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001462 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001463 adbTarget=$1
1464 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001465 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001466 adbTarget="$1 $2"
1467 shift 2
1468 fi
1469 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001470 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001471
1472 # runhat options
1473 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001474
1475 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001476 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001477 return
1478 fi
1479
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001480 # confirm hat is available
1481 if [ -z $(which hat) ]; then
1482 echo "hat is not available in this configuration."
1483 return
1484 fi
1485
Andy McFaddenb6289852010-07-12 08:00:19 -07001486 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001487 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001488 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001489 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001490 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001491 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001492 echo -n "> "
1493 read
1494
The Android Open Source Project88b60792009-03-03 19:28:42 -08001495 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001496
The Android Open Source Project88b60792009-03-03 19:28:42 -08001497 echo "Retrieving file $devFile..."
1498 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001499
The Android Open Source Project88b60792009-03-03 19:28:42 -08001500 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001501
The Android Open Source Project88b60792009-03-03 19:28:42 -08001502 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001503 echo "View the output by pointing your browser at http://localhost:7000/"
1504 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001505 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001506}
1507
1508function getbugreports()
1509{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001510 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001511
1512 if [ ! "$reports" ]; then
1513 echo "Could not locate any bugreports."
1514 return
1515 fi
1516
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001517 local report
1518 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001519 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001520 echo "/sdcard/bugreports/${report}"
1521 adb pull /sdcard/bugreports/${report} ${report}
1522 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001523 done
1524}
1525
Victoria Lease1b296b42012-08-21 15:44:06 -07001526function getsdcardpath()
1527{
1528 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1529}
1530
1531function getscreenshotpath()
1532{
1533 echo "$(getsdcardpath)/Pictures/Screenshots"
1534}
1535
1536function getlastscreenshot()
1537{
1538 local screenshot_path=$(getscreenshotpath)
1539 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1540 if [ "$screenshot" = "" ]; then
1541 echo "No screenshots found."
1542 return
1543 fi
1544 echo "${screenshot}"
1545 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1546}
1547
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001548function startviewserver()
1549{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001550 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001551 if [ $# -gt 0 ]; then
1552 port=$1
1553 fi
1554 adb shell service call window 1 i32 $port
1555}
1556
1557function stopviewserver()
1558{
1559 adb shell service call window 2
1560}
1561
1562function isviewserverstarted()
1563{
1564 adb shell service call window 3
1565}
1566
Romain Guyb84049a2010-10-04 16:56:11 -07001567function key_home()
1568{
1569 adb shell input keyevent 3
1570}
1571
1572function key_back()
1573{
1574 adb shell input keyevent 4
1575}
1576
1577function key_menu()
1578{
1579 adb shell input keyevent 82
1580}
1581
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001582function smoketest()
1583{
1584 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1585 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1586 return
1587 fi
1588 T=$(gettop)
1589 if [ ! "$T" ]; then
1590 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1591 return
1592 fi
1593
Ying Wang9cd17642012-12-13 10:52:07 -08001594 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001595 adb uninstall com.android.smoketest > /dev/null &&
1596 adb uninstall com.android.smoketest.tests > /dev/null &&
1597 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1598 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1599 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1600}
1601
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001602# simple shortcut to the runtest command
1603function runtest()
1604{
1605 T=$(gettop)
1606 if [ ! "$T" ]; then
1607 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1608 return
1609 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001610 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001611}
1612
The Android Open Source Project88b60792009-03-03 19:28:42 -08001613function godir () {
1614 if [[ -z "$1" ]]; then
1615 echo "Usage: godir <regex>"
1616 return
1617 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001618 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001619 if [[ ! -f $T/filelist ]]; then
1620 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001621 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001622 echo " Done"
1623 echo ""
1624 fi
1625 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001626 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001627 if [[ ${#lines[@]} = 0 ]]; then
1628 echo "Not found"
1629 return
1630 fi
1631 local pathname
1632 local choice
1633 if [[ ${#lines[@]} > 1 ]]; then
1634 while [[ -z "$pathname" ]]; do
1635 local index=1
1636 local line
1637 for line in ${lines[@]}; do
1638 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001639 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001640 done
1641 echo
1642 echo -n "Select one: "
1643 unset choice
1644 read choice
1645 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1646 echo "Invalid choice"
1647 continue
1648 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001649 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001650 done
1651 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001652 pathname=${lines[0]}
1653 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001654 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001655}
1656
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001657function cmremote()
1658{
1659 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301660 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001661 if [ -z "$GERRIT_REMOTE" ]
1662 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301663 echo Unable to set up the git remote, are you under a git repo?
1664 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001665 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301666 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001667 if [ -z "$CMUSER" ]
1668 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001669 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001670 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001671 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001672 fi
1673 echo You can now push to "cmremote".
1674}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001675
Steve Kondik873fa562012-09-17 11:33:18 -07001676function aospremote()
1677{
1678 git remote rm aosp 2> /dev/null
1679 if [ ! -d .git ]
1680 then
1681 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1682 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001683 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001684 if (echo $PROJECT | grep -qv "^device")
1685 then
1686 PFX="platform/"
1687 fi
1688 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1689 echo "Remote 'aosp' created"
1690}
Steve Kondik873fa562012-09-17 11:33:18 -07001691
Steve Kondik20c21d22013-10-27 13:34:36 -07001692function cafremote()
1693{
1694 git remote rm caf 2> /dev/null
1695 if [ ! -d .git ]
1696 then
1697 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1698 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001699 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001700 if (echo $PROJECT | grep -qv "^device")
1701 then
1702 PFX="platform/"
1703 fi
1704 git remote add caf git://codeaurora.org/$PFX$PROJECT
1705 echo "Remote 'caf' created"
1706}
Steve Kondik20c21d22013-10-27 13:34:36 -07001707
Steve Kondikf00e7d92012-09-23 23:46:55 -07001708function installboot()
1709{
1710 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1711 then
1712 echo "No recovery.fstab found. Build recovery first."
1713 return 1
1714 fi
1715 if [ ! -e "$OUT/boot.img" ];
1716 then
1717 echo "No boot.img found. Run make bootimage first."
1718 return 1
1719 fi
1720 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1721 if [ -z "$PARTITION" ];
1722 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001723 # Try for RECOVERY_FSTAB_VERSION = 2
1724 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1725 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1726 if [ -z "$PARTITION" ];
1727 then
1728 echo "Unable to determine boot partition."
1729 return 1
1730 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001731 fi
1732 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001733 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001734 adb root
1735 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001736 adb wait-for-online shell mount /system 2>&1 > /dev/null
1737 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001738 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1739 then
1740 adb push $OUT/boot.img /cache/
1741 for i in $OUT/system/lib/modules/*;
1742 do
1743 adb push $i /system/lib/modules/
1744 done
1745 adb shell dd if=/cache/boot.img of=$PARTITION
1746 adb shell chmod 644 /system/lib/modules/*
1747 echo "Installation complete."
1748 else
1749 echo "The connected device does not appear to be $CM_BUILD, run away!"
1750 fi
1751}
1752
Steve Kondik83c03d52012-10-24 16:40:42 -07001753function installrecovery()
1754{
1755 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1756 then
1757 echo "No recovery.fstab found. Build recovery first."
1758 return 1
1759 fi
1760 if [ ! -e "$OUT/recovery.img" ];
1761 then
1762 echo "No recovery.img found. Run make recoveryimage first."
1763 return 1
1764 fi
1765 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1766 if [ -z "$PARTITION" ];
1767 then
Steve Kondik75f10762013-08-09 21:03:42 -07001768 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001769 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1770 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001771 if [ -z "$PARTITION" ];
1772 then
1773 echo "Unable to determine recovery partition."
1774 return 1
1775 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001776 fi
1777 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001778 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001779 adb root
1780 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001781 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1782 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001783 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1784 then
1785 adb push $OUT/recovery.img /cache/
1786 adb shell dd if=/cache/recovery.img of=$PARTITION
1787 echo "Installation complete."
1788 else
1789 echo "The connected device does not appear to be $CM_BUILD, run away!"
1790 fi
1791}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001792
Koushik Duttab55f13a2012-05-14 16:14:36 -07001793function makerecipe() {
1794 if [ -z "$1" ]
1795 then
1796 echo "No branch name provided."
1797 return 1
1798 fi
1799 cd android
1800 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1801 git commit -a -m "$1"
1802 cd ..
1803
1804 repo forall -c '
1805
1806 if [ "$REPO_REMOTE" == "github" ]
1807 then
1808 pwd
1809 cmremote
1810 git push cmremote HEAD:refs/heads/'$1'
1811 fi
1812 '
1813}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001814
1815function cmgerrit() {
1816 if [ $# -eq 0 ]; then
1817 $FUNCNAME help
1818 return 1
1819 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001820 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001821 local review=`git config --get remote.github.review`
1822 local project=`git config --get remote.github.projectname`
1823 local command=$1
1824 shift
1825 case $command in
1826 help)
1827 if [ $# -eq 0 ]; then
1828 cat <<EOF
1829Usage:
1830 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1831
1832Commands:
1833 fetch Just fetch the change as FETCH_HEAD
1834 help Show this help, or for a specific command
1835 pull Pull a change into current branch
1836 push Push HEAD or a local branch to Gerrit for a specific branch
1837
1838Any other Git commands that support refname would work as:
1839 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1840
1841See '$FUNCNAME help COMMAND' for more information on a specific command.
1842
1843Example:
1844 $FUNCNAME checkout -b topic 1234/5
1845works as:
1846 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1847 && git checkout -b topic FETCH_HEAD
1848will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1849Patch-set 1 will be fetched if omitted.
1850EOF
1851 return
1852 fi
1853 case $1 in
1854 __cmg_*) echo "For internal use only." ;;
1855 changes|for)
1856 if [ "$FUNCNAME" = "cmgerrit" ]; then
1857 echo "'$FUNCNAME $1' is deprecated."
1858 fi
1859 ;;
1860 help) $FUNCNAME help ;;
1861 fetch|pull) cat <<EOF
1862usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1863
1864works as:
1865 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1866 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1867
1868Example:
1869 $FUNCNAME $1 1234
1870will $1 patch-set 1 of change 1234
1871EOF
1872 ;;
1873 push) cat <<EOF
1874usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1875
1876works as:
1877 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1878 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1879
1880Example:
1881 $FUNCNAME push fix6789:gingerbread
1882will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1883HEAD will be pushed from local if omitted.
1884EOF
1885 ;;
1886 *)
1887 $FUNCNAME __cmg_err_not_supported $1 && return
1888 cat <<EOF
1889usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1890
1891works as:
1892 git fetch http://DOMAIN/p/PROJECT \\
1893 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1894 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1895EOF
1896 ;;
1897 esac
1898 ;;
1899 __cmg_get_ref)
1900 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1901 local change_id patchset_id hash
1902 case $1 in
1903 */*)
1904 change_id=${1%%/*}
1905 patchset_id=${1#*/}
1906 ;;
1907 *)
1908 change_id=$1
1909 patchset_id=1
1910 ;;
1911 esac
1912 hash=$(($change_id % 100))
1913 case $hash in
1914 [0-9]) hash="0$hash" ;;
1915 esac
1916 echo "refs/changes/$hash/$change_id/$patchset_id"
1917 ;;
1918 fetch|pull)
1919 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1920 $FUNCNAME __cmg_err_not_repo && return 1
1921 local change=$1
1922 shift
1923 git $command $@ http://$review/p/$project \
1924 $($FUNCNAME __cmg_get_ref $change) || return 1
1925 ;;
1926 push)
1927 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1928 $FUNCNAME __cmg_err_not_repo && return 1
1929 if [ -z "$user" ]; then
1930 echo >&2 "Gerrit username not found."
1931 return 1
1932 fi
1933 local local_branch remote_branch
1934 case $1 in
1935 *:*)
1936 local_branch=${1%:*}
1937 remote_branch=${1##*:}
1938 ;;
1939 *)
1940 local_branch=HEAD
1941 remote_branch=$1
1942 ;;
1943 esac
1944 shift
1945 git push $@ ssh://$user@$review:29418/$project \
1946 $local_branch:refs/for/$remote_branch || return 1
1947 ;;
1948 changes|for)
1949 if [ "$FUNCNAME" = "cmgerrit" ]; then
1950 echo >&2 "'$FUNCNAME $command' is deprecated."
1951 fi
1952 ;;
1953 __cmg_err_no_arg)
1954 if [ $# -lt 2 ]; then
1955 echo >&2 "'$FUNCNAME $command' missing argument."
1956 elif [ $2 -eq 0 ]; then
1957 if [ -n "$3" ]; then
1958 $FUNCNAME help $1
1959 else
1960 echo >&2 "'$FUNCNAME $1' missing argument."
1961 fi
1962 else
1963 return 1
1964 fi
1965 ;;
1966 __cmg_err_not_repo)
1967 if [ -z "$review" -o -z "$project" ]; then
1968 echo >&2 "Not currently in any reviewable repository."
1969 else
1970 return 1
1971 fi
1972 ;;
1973 __cmg_err_not_supported)
1974 $FUNCNAME __cmg_err_no_arg $command $# && return
1975 case $1 in
1976 #TODO: filter more git commands that don't use refname
1977 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1978 echo >&2 "'$FUNCNAME $1' is not supported."
1979 ;;
1980 *) return 1 ;;
1981 esac
1982 ;;
1983 #TODO: other special cases?
1984 *)
1985 $FUNCNAME __cmg_err_not_supported $command && return 1
1986 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1987 $FUNCNAME __cmg_err_not_repo && return 1
1988 local args="$@"
1989 local change pre_args refs_arg post_args
1990 case "$args" in
1991 *--\ *)
1992 pre_args=${args%%-- *}
1993 post_args="-- ${args#*-- }"
1994 ;;
1995 *) pre_args="$args" ;;
1996 esac
1997 args=($pre_args)
1998 pre_args=
1999 if [ ${#args[@]} -gt 0 ]; then
2000 change=${args[${#args[@]}-1]}
2001 fi
2002 if [ ${#args[@]} -gt 1 ]; then
2003 pre_args=${args[0]}
2004 for ((i=1; i<${#args[@]}-1; i++)); do
2005 pre_args="$pre_args ${args[$i]}"
2006 done
2007 fi
2008 while ((1)); do
2009 case $change in
2010 ""|--)
2011 $FUNCNAME help $command
2012 return 1
2013 ;;
2014 *@*)
2015 if [ -z "$refs_arg" ]; then
2016 refs_arg="@${change#*@}"
2017 change=${change%%@*}
2018 fi
2019 ;;
2020 *~*)
2021 if [ -z "$refs_arg" ]; then
2022 refs_arg="~${change#*~}"
2023 change=${change%%~*}
2024 fi
2025 ;;
2026 *^*)
2027 if [ -z "$refs_arg" ]; then
2028 refs_arg="^${change#*^}"
2029 change=${change%%^*}
2030 fi
2031 ;;
2032 *:*)
2033 if [ -z "$refs_arg" ]; then
2034 refs_arg=":${change#*:}"
2035 change=${change%%:*}
2036 fi
2037 ;;
2038 *) break ;;
2039 esac
2040 done
2041 $FUNCNAME fetch $change \
2042 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2043 || return 1
2044 ;;
2045 esac
2046}
2047
2048function cmrebase() {
2049 local repo=$1
2050 local refs=$2
2051 local pwd="$(pwd)"
2052 local dir="$(gettop)/$repo"
2053
2054 if [ -z $repo ] || [ -z $refs ]; then
2055 echo "CyanogenMod Gerrit Rebase Usage: "
2056 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2057 echo " The patch IDs appear on the Gerrit commands that are offered."
2058 echo " They consist on a series of numbers and slashes, after the text"
2059 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2060 echo ""
2061 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2062 echo ""
2063 return
2064 fi
2065
2066 if [ ! -d $dir ]; then
2067 echo "Directory $dir doesn't exist in tree."
2068 return
2069 fi
2070 cd $dir
2071 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2072 echo "Starting branch..."
2073 repo start tmprebase .
2074 echo "Bringing it up to date..."
2075 repo sync .
2076 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07002077 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002078 if [ "$?" != "0" ]; then
2079 echo "Error cherry-picking. Not uploading!"
2080 return
2081 fi
2082 echo "Uploading..."
2083 repo upload .
2084 echo "Cleaning up..."
2085 repo abandon tmprebase .
2086 cd $pwd
2087}
2088
2089function mka() {
2090 case `uname -s` in
2091 Darwin)
2092 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2093 ;;
2094 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07002095 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002096 ;;
2097 esac
2098}
2099
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302100function cmka() {
2101 if [ ! -z "$1" ]; then
2102 for i in "$@"; do
2103 case $i in
2104 bacon|otapackage|systemimage)
2105 mka installclean
2106 mka $i
2107 ;;
2108 *)
2109 mka clean-$i
2110 mka $i
2111 ;;
2112 esac
2113 done
2114 else
2115 mka clean
2116 mka
2117 fi
2118}
2119
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002120function reposync() {
2121 case `uname -s` in
2122 Darwin)
2123 repo sync -j 4 "$@"
2124 ;;
2125 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002126 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002127 ;;
2128 esac
2129}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002130
2131function repodiff() {
2132 if [ -z "$*" ]; then
2133 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2134 return
2135 fi
2136 diffopts=$* repo forall -c \
2137 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2138}
2139
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302140# Credit for color strip sed: http://goo.gl/BoIcm
2141function dopush()
2142{
2143 local func=$1
2144 shift
2145
2146 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2147 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2148 echo "No device is online. Waiting for one..."
2149 echo "Please connect USB and/or enable USB debugging"
2150 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2151 sleep 1
2152 done
2153 echo "Device Found."
2154 fi
2155
Chirayu Desai6dadb572012-12-26 10:53:58 +05302156 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2157 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002158 # retrieve IP and PORT info if we're using a TCP connection
2159 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2160 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302161 adb root &> /dev/null
2162 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002163 if [ -n "$TCPIPPORT" ]
2164 then
2165 # adb root just killed our connection
2166 # so reconnect...
2167 adb connect "$TCPIPPORT"
2168 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302169 adb wait-for-device &> /dev/null
2170 sleep 0.3
2171 adb remount &> /dev/null
2172
Matt Mower668ea262014-05-20 02:52:23 -05002173 mkdir -p $OUT
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302174 $func $* | tee $OUT/.log
2175
2176 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002177 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 +05302178
2179 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002180 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 +05302181
Matt Mower668ea262014-05-20 02:52:23 -05002182 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302183 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002184 # Make sure file is in $OUT/system
2185 case $FILE in
2186 $OUT/system/*)
2187 # Get target file name (i.e. /system/bin/adb)
2188 TARGET=$(echo $FILE | sed "s#$OUT##")
2189 ;;
2190 *) continue ;;
2191 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302192
Matt Mower668ea262014-05-20 02:52:23 -05002193 case $TARGET in
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002194 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002195 # Only need to stop services once
2196 if ! $stop_n_start; then
2197 adb shell stop
2198 stop_n_start=true
2199 fi
2200 echo "Pushing: $TARGET"
2201 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302202 ;;
2203 *)
Matt Mower668ea262014-05-20 02:52:23 -05002204 echo "Pushing: $TARGET"
2205 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302206 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002207 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302208 done
Matt Mower668ea262014-05-20 02:52:23 -05002209 if $stop_n_start; then
2210 adb shell start
2211 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302212 rm -f $OUT/.log
2213 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302214 else
2215 echo "The connected device does not appear to be $CM_BUILD, run away!"
2216 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302217}
2218
2219alias mmp='dopush mm'
2220alias mmmp='dopush mmm'
2221alias mkap='dopush mka'
2222alias cmkap='dopush cmka'
2223
Chirayu Desai4a319b82013-06-05 20:14:33 +05302224function repopick() {
2225 T=$(gettop)
2226 $T/build/tools/repopick.py $@
2227}
2228
Chirayu Desaib89b3242013-06-30 10:04:25 +05302229function fixup_common_out_dir() {
2230 common_out_dir=$(get_build_var OUT_DIR)/target/common
2231 target_device=$(get_build_var TARGET_DEVICE)
2232 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2233 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2234 mv ${common_out_dir} ${common_out_dir}-${target_device}
2235 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2236 else
2237 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2238 mkdir -p ${common_out_dir}-${target_device}
2239 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2240 fi
2241 else
2242 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2243 mkdir -p ${common_out_dir}
2244 fi
2245}
2246
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002247# 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 +00002248#
2249# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2250# For some reason, installing the JDK doesn't make it show up in the
2251# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002252function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002253 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002254 # we can reset it later, depending on the version of java the build
2255 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002256 #
2257 # If we don't do this, the JAVA_HOME value set by the first call to
2258 # build/envsetup.sh will persist forever.
2259 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2260 export JAVA_HOME=""
2261 fi
2262
Andy McFaddenbd960942010-06-24 12:52:51 -07002263 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002264 case `uname -s` in
2265 Darwin)
2266 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2267 ;;
2268 *)
2269 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2270 ;;
2271 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002272
2273 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2274 # we can change it on the next envsetup.sh, if required.
2275 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002276 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002277}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002278
Alex Rayf0d08eb2013-03-08 15:15:06 -08002279# Print colored exit condition
2280function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002281 "$@"
2282 local retval=$?
2283 if [ $retval -ne 0 ]
2284 then
2285 echo -e "\e[0;31mFAILURE\e[00m"
2286 else
2287 echo -e "\e[0;32mSUCCESS\e[00m"
2288 fi
2289 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002290}
2291
Ying Wanged21d4c2014-08-24 22:14:19 -07002292function get_make_command()
2293{
2294 echo command make
2295}
2296
Ed Heylcc6be0a2014-06-18 14:55:58 -07002297function make()
2298{
2299 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002300 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002301 local ret=$?
2302 local end_time=$(date +"%s")
2303 local tdiff=$(($end_time-$start_time))
2304 local hours=$(($tdiff / 3600 ))
2305 local mins=$((($tdiff % 3600) / 60))
2306 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002307 local ncolors=$(tput colors 2>/dev/null)
2308 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2309 color_failed="\e[0;31m"
2310 color_success="\e[0;32m"
2311 color_reset="\e[00m"
2312 else
2313 color_failed=""
2314 color_success=""
2315 color_reset=""
2316 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002317 echo
2318 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002319 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002320 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002321 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002322 fi
2323 if [ $hours -gt 0 ] ; then
2324 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2325 elif [ $mins -gt 0 ] ; then
2326 printf "(%02g:%02g (mm:ss))" $mins $secs
2327 elif [ $secs -gt 0 ] ; then
2328 printf "(%s seconds)" $secs
2329 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002330 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002331 echo
2332 return $ret
2333}
2334
Raphael Moll70a86b02011-06-20 16:03:14 -07002335if [ "x$SHELL" != "x/bin/bash" ]; then
2336 case `ps -o command -p $$` in
2337 *bash*)
2338 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002339 *zsh*)
2340 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002341 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002342 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002343 ;;
2344 esac
2345fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002346
2347# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002348for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2349 `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 -08002350do
2351 echo "including $f"
2352 . $f
2353done
2354unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002355
Kyle Ladd031a0b62013-09-11 20:43:42 -04002356# Add completions
2357check_bash_version && {
2358 dirs="sdk/bash_completion vendor/cm/bash_completion"
2359 for dir in $dirs; do
2360 if [ -d ${dir} ]; then
2361 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2362 echo "including $f"
2363 . $f
2364 done
2365 fi
2366 done
2367}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302368
2369export ANDROID_BUILD_TOP=$(gettop)