blob: 0211a8468852e854492c415198d75251e9ad20ef [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.
Martin Brabhamb77db582016-02-05 15:59:21 -050014- mmap: Builds all of the modules in the current directory, and its dependencies, then pushes the package to the device.
Daniel Bateman22185ba2012-08-04 03:48:09 -050015- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080016- mmma: Builds all of the modules in the supplied directories, and their dependencies.
Khalid Zubairfdc26cd2015-10-21 12:43:14 -070017- mms: Short circuit builder. Quickly re-build the kernel, rootfs, boot and system images
18 without deep dependencies. Requires the full build to have run before.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070019- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070020- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070021- jgrep: Greps on all local Java files.
22- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000023- mangrep: Greps on all local AndroidManifest.xml files.
24- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070025- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080026- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060027- mka: Builds using SCHED_BATCH on all processors
Chirayu Desaicf2bdb62012-09-28 11:56:02 +053028- mkap: Builds the module(s) using mka and pushes them to the device.
29- cmka: Cleans and builds using mka.
Matt Mower8dacaed2013-12-29 12:57:20 -060030- repolastsync: Prints date and time of last repo sync.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060031- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053032- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070033- installboot: Installs a boot.img to the connected device.
34- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070035
Dan Albert4ae5d4b2014-10-31 16:23:08 -070036Environemnt options:
37- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
38 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
39 build is leak-check clean.
40
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070041Look at the source to view more functions. The complete list is:
42EOF
43 T=$(gettop)
Jeff Brown46cbd202014-07-26 15:15:41 -070044 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
Anthony King0780f2f2015-04-30 23:16:10 +010045 echo "$i"
46 done | column
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070047}
48
49# Get the value of a build variable as an absolute path.
50function get_abs_build_var()
51{
52 T=$(gettop)
53 if [ ! "$T" ]; then
54 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
55 return
56 fi
Ying Wang9cd17642012-12-13 10:52:07 -080057 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070058 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070059}
60
61# Get the exact value of a build variable.
62function get_build_var()
63{
64 T=$(gettop)
65 if [ ! "$T" ]; then
66 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
67 return
68 fi
Andrew Boie6905e212013-12-19 13:21:46 -080069 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070070 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080071}
72
73# check to see if the supplied product is one we can build
74function check_product()
75{
76 T=$(gettop)
77 if [ ! "$T" ]; then
78 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
79 return
80 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000081
Dark Eyesdafcfe82015-12-11 20:51:02 -050082 if (echo -n $1 | grep -q -e "^bliss_") ; then
83 BLISS_BUILD=$(echo -n $1 | sed -e 's/^bliss_//g')
84 export BUILD_NUMBER=$((date +%s%N ; echo $BLISS_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10)
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000085 else
Dark Eyesdafcfe82015-12-11 20:51:02 -050086 BLISS_BUILD=
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000087 fi
Dark Eyesdafcfe82015-12-11 20:51:02 -050088 export BLISS_BUILD
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000089
Jeff Browne33ba4c2011-07-11 22:11:46 -070090 TARGET_PRODUCT=$1 \
91 TARGET_BUILD_VARIANT= \
92 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070093 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080094 get_build_var TARGET_DEVICE > /dev/null
95 # hide successful answers, but allow the errors to show
96}
97
98VARIANT_CHOICES=(user userdebug eng)
99
100# check to see if the supplied variant is valid
101function check_variant()
102{
103 for v in ${VARIANT_CHOICES[@]}
104 do
105 if [ "$v" = "$1" ]
106 then
107 return 0
108 fi
109 done
110 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700111}
112
113function setpaths()
114{
115 T=$(gettop)
116 if [ ! "$T" ]; then
117 echo "Couldn't locate the top of the tree. Try setting TOP."
118 return
119 fi
120
121 ##################################################################
122 # #
123 # Read me before you modify this code #
124 # #
125 # This function sets ANDROID_BUILD_PATHS to what it is adding #
126 # to PATH, and the next time it is run, it removes that from #
127 # PATH. This is required so lunch can be run more than once #
128 # and still have working paths. #
129 # #
130 ##################################################################
131
Raphael Mollc639c782011-06-20 17:25:01 -0700132 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
133 # due to "C:\Program Files" being in the path.
134
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700136 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
138 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700139 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700140 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800141 # strip leading ':', if any
142 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500143 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700144
145 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700146 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700147 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700148
Ben Cheng8bc4c432012-11-16 13:29:13 -0800149 # defined in core/config.mk
150 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700151 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800152 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800153
Raphael Mollc639c782011-06-20 17:25:01 -0700154 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800155 export ANDROID_TOOLCHAIN=
156 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200157 local ARCH=$(get_build_var TARGET_ARCH)
158 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400159 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700160 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400161 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
162 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800163 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200164 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800165 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700166 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700167 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700168 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000169 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200170 *)
171 echo "Can't find toolchain for unknown architecture: $ARCH"
172 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700173 ;;
174 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700175 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800176 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700177 fi
Raphael732936d2011-06-22 14:35:32 -0700178
Ben Chengfba67bf2014-02-25 10:27:07 -0800179 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
180 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
181 fi
182
183 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700184 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700185 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800186 # Legacy toolchain configuration used for ARM kernel compilation
Dark Eyesdafcfe82015-12-11 20:51:02 -0500187 toolchaindir=arm/arm-eabi-$targetgcckernelversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700188 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100189 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
190 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700191 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700192 ;;
193 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700194 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700195 ;;
196 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700197
Dark Eyesdafcfe82015-12-11 20:51:02 -0500198 targetgcckernelversion=$(get_build_var TARGET_KERNEL_CUSTOM_TOOLCHAIN)
199 if [ -z "$targetgcckernelversion" ]; then
200 export TARGET_GCC_VERSION_KERNEL="4.9-linaro"
201 else
202 export TARGET_GCC_VERSION_KERNEL="$targetgcckernelversion"
203 fi
204
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700205 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700206 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 +0200207
208 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
209 # to ensure that the corresponding 'emulator' binaries are used.
210 case $(uname -s) in
211 Darwin)
212 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
213 ;;
214 Linux)
215 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
216 ;;
217 *)
218 ANDROID_EMULATOR_PREBUILTS=
219 ;;
220 esac
221 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700222 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200223 export ANDROID_EMULATOR_PREBUILTS
224 fi
225
Ying Wangaa1c9b52012-11-26 20:51:59 -0800226 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800227
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500228 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900229 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500230 if [ -n "$JAVA_HOME" ]; then
231 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900232 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
233 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500234 fi
235
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800236 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700237 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
238 export OUT=$ANDROID_PRODUCT_OUT
239
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700240 unset ANDROID_HOST_OUT
241 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
242
Matt Mowerf8ff73e2015-06-09 19:35:53 -0500243 if [ -n "$ANDROID_CCACHE_DIR" ]; then
244 export CCACHE_DIR=$ANDROID_CCACHE_DIR
245 fi
246
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800247 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700248 # TODO: fix the path
249 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
250}
251
252function printconfig()
253{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800254 T=$(gettop)
255 if [ ! "$T" ]; then
256 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
257 return
258 fi
259 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260}
261
262function set_stuff_for_environment()
263{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800264 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500265 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800266 setpaths
267 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268
Ben Chengaac3f812013-08-13 14:38:15 -0700269 # With this environment variable new GCC can apply colors to warnings/errors
270 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 -0700271 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700272}
273
274function set_sequence_number()
275{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700276 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700277}
278
279function settitle()
280{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800281 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700282 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700283 local product=$TARGET_PRODUCT
284 local variant=$TARGET_BUILD_VARIANT
285 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800286 if [ -z "$PROMPT_COMMAND" ]; then
287 # No prompts
288 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
289 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
290 # Prompts exist, but no hardstatus
291 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700292 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800293 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500294 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800295 fi
296
297 if [ -z "$apps" ]; then
298 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
299 else
300 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
301 fi
302 export ANDROID_PROMPT_PREFIX
303
304 # Inject build data into hardstatus
305 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 -0800306 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700307}
308
Kyle Ladd031a0b62013-09-11 20:43:42 -0400309function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700310{
Kenny Root52aa81c2011-07-15 11:07:06 -0700311 # Keep us from trying to run in something that isn't bash.
312 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400313 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700314 fi
315
316 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200317 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400318 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700319 fi
320
Kyle Ladd031a0b62013-09-11 20:43:42 -0400321 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700322}
323
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700324function choosetype()
325{
326 echo "Build type choices are:"
327 echo " 1. release"
328 echo " 2. debug"
329 echo
330
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700332 DEFAULT_NUM=1
333 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700334
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 export TARGET_BUILD_TYPE=
336 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 while [ -z $TARGET_BUILD_TYPE ]
338 do
339 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800340 if [ -z "$1" ] ; then
341 read ANSWER
342 else
343 echo $1
344 ANSWER=$1
345 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 case $ANSWER in
347 "")
348 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
349 ;;
350 1)
351 export TARGET_BUILD_TYPE=release
352 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800353 release)
354 export TARGET_BUILD_TYPE=release
355 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700356 2)
357 export TARGET_BUILD_TYPE=debug
358 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800359 debug)
360 export TARGET_BUILD_TYPE=debug
361 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 *)
363 echo
364 echo "I didn't understand your response. Please try again."
365 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700366 ;;
367 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800368 if [ -n "$1" ] ; then
369 break
370 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700371 done
372
373 set_stuff_for_environment
374}
375
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800376#
377# This function isn't really right: It chooses a TARGET_PRODUCT
378# based on the list of boards. Usually, that gets you something
379# that kinda works with a generic product, but really, you should
380# pick a product by name.
381#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700382function chooseproduct()
383{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384 if [ "x$TARGET_PRODUCT" != x ] ; then
385 default_value=$TARGET_PRODUCT
386 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700387 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700388 fi
389
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800390 export TARGET_PRODUCT=
391 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700392 while [ -z "$TARGET_PRODUCT" ]
393 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700394 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395 if [ -z "$1" ] ; then
396 read ANSWER
397 else
398 echo $1
399 ANSWER=$1
400 fi
401
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700402 if [ -z "$ANSWER" ] ; then
403 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800404 else
405 if check_product $ANSWER
406 then
407 export TARGET_PRODUCT=$ANSWER
408 else
409 echo "** Not a valid product: $ANSWER"
410 fi
411 fi
412 if [ -n "$1" ] ; then
413 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700414 fi
415 done
416
417 set_stuff_for_environment
418}
419
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800420function choosevariant()
421{
422 echo "Variant choices are:"
423 local index=1
424 local v
425 for v in ${VARIANT_CHOICES[@]}
426 do
427 # The product name is the name of the directory containing
428 # the makefile we found, above.
429 echo " $index. $v"
430 index=$(($index+1))
431 done
432
433 local default_value=eng
434 local ANSWER
435
436 export TARGET_BUILD_VARIANT=
437 while [ -z "$TARGET_BUILD_VARIANT" ]
438 do
439 echo -n "Which would you like? [$default_value] "
440 if [ -z "$1" ] ; then
441 read ANSWER
442 else
443 echo $1
444 ANSWER=$1
445 fi
446
447 if [ -z "$ANSWER" ] ; then
448 export TARGET_BUILD_VARIANT=$default_value
449 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
450 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800451 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800452 fi
453 else
454 if check_variant $ANSWER
455 then
456 export TARGET_BUILD_VARIANT=$ANSWER
457 else
458 echo "** Not a valid variant: $ANSWER"
459 fi
460 fi
461 if [ -n "$1" ] ; then
462 break
463 fi
464 done
465}
466
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467function choosecombo()
468{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700469 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470
471 echo
472 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700473 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700474
475 echo
476 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700477 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800478
479 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800481 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700482}
483
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800484# Clear this variable. It will be built up again when the vendorsetup.sh
485# files are included at the end of this file.
486unset LUNCH_MENU_CHOICES
487function add_lunch_combo()
488{
489 local new_combo=$1
490 local c
491 for c in ${LUNCH_MENU_CHOICES[@]} ; do
492 if [ "$new_combo" = "$c" ] ; then
493 return
494 fi
495 done
496 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
497}
498
499# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700500add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800501add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000502add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800503add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000504add_lunch_combo aosp_x86-eng
505add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700507function print_lunch_menu()
508{
509 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510 echo
511 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000512 if [ "$(uname)" = "Darwin" ] ; then
513 echo " (ohai, koush!)"
514 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700515 echo
Dark Eyesdafcfe82015-12-11 20:51:02 -0500516 if [ "z${BLISS_DEVICES_ONLY}" != "z" ]; then
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000517 echo "Breakfast menu... pick a combo:"
518 else
519 echo "Lunch menu... pick a combo:"
520 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800521
522 local i=1
523 local choice
524 for choice in ${LUNCH_MENU_CHOICES[@]}
525 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100526 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800527 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100528 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800529
Dark Eyesdafcfe82015-12-11 20:51:02 -0500530 if [ "z${BLISS_DEVICES_ONLY}" != "z" ]; then
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000531 echo "... and don't forget the bacon!"
532 fi
533
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700534 echo
535}
536
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000537function brunch()
538{
539 breakfast $*
540 if [ $? -eq 0 ]; then
541 mka bacon
542 else
543 echo "No such item in brunch menu. Try 'breakfast'"
544 return 1
545 fi
546 return $?
547}
548
549function breakfast()
550{
551 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200552 local variant=$2
Dark Eyesdafcfe82015-12-11 20:51:02 -0500553 BLISS_DEVICES_ONLY="true"
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000554 unset LUNCH_MENU_CHOICES
555 add_lunch_combo full-eng
Dark Eyesdafcfe82015-12-11 20:51:02 -0500556 for f in `/bin/ls vendor/bliss/vendorsetup.sh 2> /dev/null`
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000557 do
558 echo "including $f"
559 . $f
560 done
561 unset f
562
563 if [ $# -eq 0 ]; then
564 # No arguments, so let's have the full menu
565 lunch
566 else
567 echo "z$target" | grep -q "-"
568 if [ $? -eq 0 ]; then
569 # A buildtype was specified, assume a full device name
570 lunch $target
571 else
Dark Eyesdafcfe82015-12-11 20:51:02 -0500572 # This is probably just the Bliss model name
JustArchif70c7e62014-06-22 14:37:30 +0200573 if [ -z "$variant" ]; then
574 variant="userdebug"
575 fi
Dark Eyesdafcfe82015-12-11 20:51:02 -0500576 lunch bliss_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000577 fi
578 fi
579 return $?
580}
581
582alias bib=breakfast
583
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584function lunch()
585{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 local answer
Anthony King850627c2015-04-30 22:57:08 +0100587 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 else
592 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700593 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800594 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595 fi
596
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 local selection=
598
599 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700600 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700601 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
603 then
604 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
605 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800606 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800607 fi
608 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
609 then
610 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700611 fi
612
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800613 if [ -z "$selection" ]
614 then
615 echo
616 echo "Invalid lunch combo: $answer"
617 return 1
618 fi
619
Joe Onoratoda12daf2010-06-09 18:18:31 -0700620 export TARGET_BUILD_APPS=
621
Jeff Browne33ba4c2011-07-11 22:11:46 -0700622 local product=$(echo -n $selection | sed -e "s/-.*$//")
623 check_product $product
624 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800625 then
Dark Eyesdafcfe82015-12-11 20:51:02 -0500626 # if we can't find a product, try to grab it off the BLISS github
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800627 T=$(gettop)
628 pushd $T > /dev/null
629 build/tools/roomservice.py $product
630 popd > /dev/null
631 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000632 else
633 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800634 fi
635 if [ $? -ne 0 ]
636 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700637 echo
638 echo "** Don't have a product spec for: '$product'"
639 echo "** Do you have the right repo manifest?"
640 product=
641 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642
Jeff Browne33ba4c2011-07-11 22:11:46 -0700643 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
644 check_variant $variant
645 if [ $? -ne 0 ]
646 then
647 echo
648 echo "** Invalid variant: '$variant'"
649 echo "** Must be one of ${VARIANT_CHOICES[@]}"
650 variant=
651 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800652
Jeff Browne33ba4c2011-07-11 22:11:46 -0700653 if [ -z "$product" -o -z "$variant" ]
654 then
655 echo
656 return 1
657 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800658
Jeff Browne33ba4c2011-07-11 22:11:46 -0700659 export TARGET_PRODUCT=$product
660 export TARGET_BUILD_VARIANT=$variant
661 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662
663 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800664
Dark Eyesdafcfe82015-12-11 20:51:02 -0500665 export TARGET_DEVICE=$(get_build_var TARGET_DEVICE)
666
Chirayu Desaib89b3242013-06-30 10:04:25 +0530667 fixup_common_out_dir
668
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700669 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800670 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700671}
672
Jeff Davidson513d7a42010-08-02 10:00:44 -0700673# Tab completion for lunch.
674function _lunch()
675{
676 local cur prev opts
677 COMPREPLY=()
678 cur="${COMP_WORDS[COMP_CWORD]}"
679 prev="${COMP_WORDS[COMP_CWORD-1]}"
680
681 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
682 return 0
683}
Emilio López9ad6eea2013-11-03 13:02:13 -0300684complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700685
Joe Onoratoda12daf2010-06-09 18:18:31 -0700686# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700687# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700688function tapas()
689{
Ying Wangb541ab62014-05-29 17:57:40 -0700690 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 -0700691 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700692 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
693 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 -0700694
Ying Wang67f02922012-08-22 10:25:20 -0700695 if [ $(echo $arch | wc -w) -gt 1 ]; then
696 echo "tapas: Error: Multiple build archs supplied: $arch"
697 return
698 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700699 if [ $(echo $variant | wc -w) -gt 1 ]; then
700 echo "tapas: Error: Multiple build variants supplied: $variant"
701 return
702 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700703 if [ $(echo $density | wc -w) -gt 1 ]; then
704 echo "tapas: Error: Multiple densities supplied: $density"
705 return
706 fi
Ying Wang67f02922012-08-22 10:25:20 -0700707
708 local product=full
709 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700710 x86) product=full_x86;;
711 mips) product=full_mips;;
712 armv5) product=generic_armv5;;
713 arm64) product=aosp_arm64;;
714 x86_64) product=aosp_x86_64;;
715 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700716 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700717 if [ -z "$variant" ]; then
718 variant=eng
719 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700720 if [ -z "$apps" ]; then
721 apps=all
722 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600723 if [ -z "$density" ]; then
724 density=alldpi
725 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700726
Ying Wang67f02922012-08-22 10:25:20 -0700727 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700728 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700729 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700730 export TARGET_BUILD_TYPE=release
731 export TARGET_BUILD_APPS=$apps
732
733 set_stuff_for_environment
734 printconfig
735}
736
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100737function eat()
738{
739 if [ "$OUT" ] ; then
Dark Eyesdafcfe82015-12-11 20:51:02 -0500740 MODVERSION=$(get_build_var BLISS_VERSION)
741 ZIPFILE=bliss-$MODVERSION.zip
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100742 ZIPPATH=$OUT/$ZIPFILE
743 if [ ! -f $ZIPPATH ] ; then
744 echo "Nothing to eat"
745 return 1
746 fi
747 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
Steve Kondik58fa7162015-11-15 18:47:58 -0800748 if [ $(adb get-state) != device -a $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100749 echo "No device is online. Waiting for one..."
750 echo "Please connect USB and/or enable USB debugging"
Steve Kondik58fa7162015-11-15 18:47:58 -0800751 until [ $(adb get-state) = device -o $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100752 sleep 1
753 done
754 echo "Device Found.."
755 fi
Dark Eyesdafcfe82015-12-11 20:51:02 -0500756 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Chirayu Desai6dadb572012-12-26 10:53:58 +0530757 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100758 # if adbd isn't root we can't write to /cache/recovery/
759 adb root
760 sleep 1
761 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700762 cat << EOF > /tmp/command
Steve Kondike9f828c2015-11-10 23:51:21 +0100763--sideload_auto_reboot
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100764EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700765 if adb push /tmp/command /cache/recovery/ ; then
766 echo "Rebooting into recovery for sideload installation"
767 adb reboot recovery
768 adb wait-for-sideload
769 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100770 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700771 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100772 else
773 echo "Nothing to eat"
774 return 1
775 fi
776 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530777 else
Dark Eyesdafcfe82015-12-11 20:51:02 -0500778 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Chirayu Desai6dadb572012-12-26 10:53:58 +0530779 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100780}
781
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000782function omnom
783{
784 brunch $*
785 eat
786}
787
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788function gettop
789{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800790 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700792 # The following circumlocution ensures we remove symlinks from TOP.
793 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 else
795 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800796 # The following circumlocution (repeated below as well) ensures
797 # that we record the true directory name and not one that is
798 # faked up with symlink names.
799 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700800 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800801 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802 T=
803 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800804 \cd ..
synergyb112a402013-07-05 19:47:47 -0700805 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700806 done
Ying Wang9cd17642012-12-13 10:52:07 -0800807 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700808 if [ -f "$T/$TOPFILE" ]; then
809 echo $T
810 fi
811 fi
812 fi
813}
814
Andrew Hsieh906cb782013-09-10 17:37:14 +0800815# Return driver for "make", if any (eg. static analyzer)
816function getdriver()
817{
818 local T="$1"
819 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
820 if [ -n "$WITH_STATIC_ANALYZER" ]; then
821 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800822$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
823--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800824--status-bugs \
825--top=$T"
826 fi
827}
828
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829function m()
830{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800831 local T=$(gettop)
832 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700833 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800834 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835 else
836 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700837 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838 fi
839}
840
841function findmakefile()
842{
843 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800844 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 T=
846 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700847 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848 if [ -f "$T/Android.mk" ]; then
849 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800850 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700851 return
852 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800853 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700854 done
Ying Wang9cd17642012-12-13 10:52:07 -0800855 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700856}
857
858function mm()
859{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800860 local T=$(gettop)
861 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700862 # If we're sitting in the root of the build tree, just do a
863 # normal make.
864 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800865 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700866 else
867 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800868 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700869 local MODULES=
870 local GET_INSTALL_PATH=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700871 # Remove the path to top as the makefilepath needs to be relative
872 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873 if [ ! "$T" ]; then
874 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700875 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700876 elif [ ! "$M" ]; then
877 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700878 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700879 else
Ying Wanga7deb082013-08-16 13:24:47 -0700880 for ARG in $@; do
881 case $ARG in
882 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
883 esac
884 done
885 if [ -n "$GET_INSTALL_PATH" ]; then
886 MODULES=
Khalid Zubaircbf96922016-03-02 14:01:45 -0800887 # set all args to 'GET-INSTALL-PATH'
888 set -- GET-INSTALL-PATH
Ying Wanga7deb082013-08-16 13:24:47 -0700889 else
890 MODULES=all_modules
Ying Wanga7deb082013-08-16 13:24:47 -0700891 fi
Khalid Zubaircbf96922016-03-02 14:01:45 -0800892 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700893 fi
894 fi
895}
896
897function mmm()
898{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800899 local T=$(gettop)
900 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700901 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800902 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800903 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800904 local ARGS=
905 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700906 local GET_INSTALL_PATH=
Khalid Zubair521aa1e2016-02-11 14:34:12 -0800907
Roman Birg5771f5d2016-03-01 10:27:51 -0800908 if [ "$(__detect_shell)" = "zsh" ]; then
Khalid Zubair521aa1e2016-02-11 14:34:12 -0800909 set -lA DASH_ARGS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
910 set -lA DIRS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
911 else
912 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
913 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
914 fi
915
The Android Open Source Project88b60792009-03-03 19:28:42 -0800916 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800917 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
918 if [ "$MODULES" = "" ]; then
919 MODULES=all_modules
920 fi
921 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700923 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
924 local TO_CHOP=`expr $TO_CHOP + 1`
925 local START=`PWD= /bin/pwd`
926 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700927 if [ "$MFILE" = "" ] ; then
928 MFILE=$DIR/Android.mk
929 else
930 MFILE=$MFILE/$DIR/Android.mk
931 fi
932 MAKEFILE="$MAKEFILE $MFILE"
933 else
Ying Wanga7deb082013-08-16 13:24:47 -0700934 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100935 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700936 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997c3eb1072015-10-18 19:49:13 +0200937 *) if [ -d $DIR ]; then
938 echo "No Android.mk in $DIR.";
939 else
940 echo "Couldn't locate the directory $DIR";
941 fi
942 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700943 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700944 fi
945 done
Ying Wanga7deb082013-08-16 13:24:47 -0700946 if [ -n "$GET_INSTALL_PATH" ]; then
947 ARGS=$GET_INSTALL_PATH
948 MODULES=
949 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800950 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 -0700951 else
952 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700953 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700954 fi
955}
956
Ying Wangb607f7b2013-02-08 18:01:04 -0800957function mma()
958{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800959 local T=$(gettop)
960 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800961 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800962 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800963 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800964 if [ ! "$T" ]; then
965 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700966 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800967 fi
968 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800969 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800970 fi
971}
972
973function mmma()
974{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800975 local T=$(gettop)
976 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800977 if [ "$T" ]; then
Roman Birg5771f5d2016-03-01 10:27:51 -0800978 if [ "$(__detect_shell)" = "zsh" ]; then
Khalid Zubair521aa1e2016-02-11 14:34:12 -0800979 set -lA DASH_ARGS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
980 set -lA DIRS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
981 else
982 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
983 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
984 fi
Ying Wangb607f7b2013-02-08 18:01:04 -0800985 local MY_PWD=`PWD= /bin/pwd`
986 if [ "$MY_PWD" = "$T" ]; then
987 MY_PWD=
988 else
989 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
990 fi
991 local DIR=
992 local MODULE_PATHS=
993 local ARGS=
994 for DIR in $DIRS ; do
995 if [ -d $DIR ]; then
996 if [ "$MY_PWD" = "" ]; then
997 MODULE_PATHS="$MODULE_PATHS $DIR"
998 else
999 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
1000 fi
1001 else
1002 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +01001003 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -08001004 *) echo "Couldn't find directory $DIR"; return 1;;
1005 esac
1006 fi
1007 done
Andrew Hsieh906cb782013-09-10 17:37:14 +08001008 $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 -08001009 else
1010 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -07001011 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -08001012 fi
1013}
1014
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001015function croot()
1016{
1017 T=$(gettop)
1018 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001019 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001020 else
1021 echo "Couldn't locate the top of the tree. Try setting TOP."
1022 fi
1023}
1024
nebkatfb67a1e2012-12-28 10:40:45 +00001025function cout()
1026{
1027 if [ "$OUT" ]; then
1028 cd $OUT
1029 else
1030 echo "Couldn't locate out directory. Try setting OUT."
1031 fi
1032}
1033
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001034function cproj()
1035{
1036 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001037 local HERE=$PWD
1038 T=
1039 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1040 T=$PWD
1041 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001042 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001043 return
1044 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001045 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001046 done
Ying Wang9cd17642012-12-13 10:52:07 -08001047 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001048 echo "can't find Android.mk"
1049}
1050
Daniel Sandler47e0a882013-07-30 13:23:52 -04001051# simplified version of ps; output in the form
1052# <pid> <procname>
1053function qpid() {
1054 local prepend=''
1055 local append=''
1056 if [ "$1" = "--exact" ]; then
1057 prepend=' '
1058 append='$'
1059 shift
1060 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1061 echo "usage: qpid [[--exact] <process name|pid>"
1062 return 255
1063 fi
1064
1065 local EXE="$1"
1066 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001067 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001068 else
1069 adb shell ps \
1070 | tr -d '\r' \
1071 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1072 fi
1073}
1074
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001075function pid()
1076{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001077 local prepend=''
1078 local append=''
1079 if [ "$1" = "--exact" ]; then
1080 prepend=' '
1081 append='$'
1082 shift
1083 fi
1084 local EXE="$1"
1085 if [ "$EXE" ] ; then
1086 local PID=`adb shell ps \
1087 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001088 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001089 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1090 echo "$PID"
1091 else
1092 echo "usage: pid [--exact] <process name>"
1093 return 255
1094 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001095}
1096
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001097# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001098# that has the core-file-size limit set correctly
1099#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001100# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001101# if its core-file-size limit is not set already.
1102# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1103
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001104function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001105{
1106 echo "Getting root...";
1107 adb root;
1108 adb wait-for-device;
1109
1110 echo "Remounting root parition read-write...";
1111 adb shell mount -w -o remount -t rootfs rootfs;
1112 sleep 1;
1113 adb wait-for-device;
1114 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001115 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001116 adb shell chmod 0777 /cores;
1117
1118 echo "Granting SELinux permission to dump in /cores...";
1119 adb shell restorecon -R /cores;
1120
1121 echo "Set core pattern.";
1122 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1123
1124 echo "Done."
1125}
1126
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001127# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001128# $1 = PID of process (e.g., $(pid mediaserver))
1129#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001130# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001131# dump to actually be generated.
1132
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001133function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001134{
1135 local PID=$1;
1136 if [ -z "$PID" ]; then
1137 printf "Expecting a PID!\n";
1138 return;
1139 fi;
1140 echo "Setting core limit for $PID to infinite...";
1141 adb shell prlimit $PID 4 -1 -1
1142}
1143
1144# core - send SIGV and pull the core for process
1145# $1 = PID of process (e.g., $(pid mediaserver))
1146#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001147# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001148# enabled globally.
1149
1150function core()
1151{
1152 local PID=$1;
1153
1154 if [ -z "$PID" ]; then
1155 printf "Expecting a PID!\n";
1156 return;
1157 fi;
1158
1159 local CORENAME=core.$PID;
1160 local COREPATH=/cores/$CORENAME;
1161 local SIG=SEGV;
1162
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001163 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001164
1165 local done=0;
1166 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1167 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1168 adb shell kill -$SIG $PID;
1169 sleep 1;
1170 done;
1171
1172 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1173 echo "Done: core is under $COREPATH on device.";
1174}
1175
Christopher Tate744ee802009-11-12 15:33:08 -08001176# systemstack - dump the current stack trace of all threads in the system process
1177# to the usual ANR traces file
1178function systemstack()
1179{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001180 stacks system_server
1181}
1182
1183function stacks()
1184{
1185 if [[ $1 =~ ^[0-9]+$ ]] ; then
1186 local PID="$1"
1187 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001188 local PIDLIST="$(pid $1)"
1189 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1190 local PID="$PIDLIST"
1191 elif [ "$PIDLIST" ] ; then
1192 echo "more than one process: $1"
1193 else
1194 echo "no such process: $1"
1195 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001196 else
1197 echo "usage: stacks [pid|process name]"
1198 fi
1199
1200 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001201 # Determine whether the process is native
1202 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1203 # Dump stacks of Dalvik process
1204 local TRACES=/data/anr/traces.txt
1205 local ORIG=/data/anr/traces.orig
1206 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001207
Jeff Brownb12c2e52013-08-19 15:14:16 -07001208 # Keep original traces to avoid clobbering
1209 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001210
Jeff Brownb12c2e52013-08-19 15:14:16 -07001211 # Make sure we have a usable file
1212 adb shell touch $TRACES
1213 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001214
Jeff Brownb12c2e52013-08-19 15:14:16 -07001215 # Dump stacks and wait for dump to finish
1216 adb shell kill -3 $PID
1217 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001218
Jeff Brownb12c2e52013-08-19 15:14:16 -07001219 # Restore original stacks, and show current output
1220 adb shell mv $TRACES $TMP
1221 adb shell mv $ORIG $TRACES
1222 adb shell cat $TMP
1223 else
1224 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001225 local USE64BIT="$(is64bit $PID)"
1226 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001227 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001228 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001229}
1230
Michael Wrightaeed7212014-06-19 19:58:12 -07001231# Read the ELF header from /proc/$PID/exe to determine if the process is
1232# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001233function is64bit()
1234{
1235 local PID="$1"
1236 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001237 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001238 echo "64"
1239 else
1240 echo ""
1241 fi
1242 else
1243 echo ""
1244 fi
1245}
1246
Clark Scheff75b36a42014-12-23 13:30:51 -08001247function dddclient()
1248{
1249 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1250 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1251 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1252 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1253 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1254 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1255 local ARCH=$(get_build_var TARGET_ARCH)
1256 local GDB
1257 case "$ARCH" in
1258 arm) GDB=arm-linux-androideabi-gdb;;
1259 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1260 mips|mips64) GDB=mips64el-linux-android-gdb;;
1261 x86) GDB=x86_64-linux-android-gdb;;
1262 x86_64) GDB=x86_64-linux-android-gdb;;
1263 *) echo "Unknown arch $ARCH"; return 1;;
1264 esac
1265
1266 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1267 local EXE="$1"
1268 if [ "$EXE" ] ; then
1269 EXE=$1
1270 if [[ $EXE =~ ^[^/].* ]] ; then
1271 EXE="system/bin/"$EXE
1272 fi
1273 else
1274 EXE="app_process"
1275 fi
1276
1277 local PORT="$2"
1278 if [ "$PORT" ] ; then
1279 PORT=$2
1280 else
1281 PORT=":5039"
1282 fi
1283
1284 local PID="$3"
1285 if [ "$PID" ] ; then
1286 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1287 PID=`pid $3`
1288 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1289 # that likely didn't work because of returning multiple processes
1290 # try again, filtering by root processes (don't contain colon)
1291 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1292 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1293 then
1294 echo "Couldn't resolve '$3' to single PID"
1295 return 1
1296 else
1297 echo ""
1298 echo "WARNING: multiple processes matching '$3' observed, using root process"
1299 echo ""
1300 fi
1301 fi
1302 fi
1303 adb forward "tcp$PORT" "tcp$PORT"
1304 local USE64BIT="$(is64bit $PID)"
1305 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1306 sleep 2
1307 else
1308 echo ""
1309 echo "If you haven't done so already, do this first on the device:"
1310 echo " gdbserver $PORT /system/bin/$EXE"
1311 echo " or"
1312 echo " gdbserver $PORT --attach <PID>"
1313 echo ""
1314 fi
1315
1316 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1317 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1318
1319 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1320 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"
1321 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1322 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1323 # Enable special debugging for ART processes.
1324 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1325 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1326 fi
1327 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1328
1329 local WHICH_GDB=
1330 # 64-bit exe found
1331 if [ "$USE64BIT" != "" ] ; then
1332 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1333 # 32-bit exe / 32-bit platform
1334 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1335 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1336 # 32-bit exe / 64-bit platform
1337 else
1338 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1339 fi
1340
1341 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1342 else
1343 echo "Unable to determine build system output dir."
1344 fi
1345}
1346
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001347case `uname -s` in
1348 Darwin)
1349 function sgrep()
1350 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001351 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 -07001352 }
1353
1354 ;;
1355 *)
1356 function sgrep()
1357 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001358 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 -07001359 }
1360 ;;
1361esac
1362
Raghu Gandham8da43102012-07-25 19:57:22 -07001363function gettargetarch
1364{
1365 get_build_var TARGET_ARCH
1366}
1367
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001368function ggrep()
1369{
1370 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1371}
1372
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001373function jgrep()
1374{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001375 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 -07001376}
1377
1378function cgrep()
1379{
Dan Albert01961192014-11-22 10:16:01 -08001380 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 -07001381}
1382
1383function resgrep()
1384{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001385 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 -07001386}
1387
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001388function mangrep()
1389{
1390 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1391}
1392
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001393function sepgrep()
1394{
1395 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 "$@"
1396}
1397
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001398function rcgrep()
1399{
1400 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1401}
1402
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001403case `uname -s` in
1404 Darwin)
1405 function mgrep()
1406 {
Ying Wang324c2b22012-08-17 15:03:20 -07001407 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 -07001408 }
1409
1410 function treegrep()
1411 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001412 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 -07001413 }
1414
1415 ;;
1416 *)
1417 function mgrep()
1418 {
Ying Wang324c2b22012-08-17 15:03:20 -07001419 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 -07001420 }
1421
1422 function treegrep()
1423 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001424 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 -07001425 }
1426
1427 ;;
1428esac
1429
1430function getprebuilt
1431{
1432 get_abs_build_var ANDROID_PREBUILTS
1433}
1434
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001435function tracedmdump()
1436{
1437 T=$(gettop)
1438 if [ ! "$T" ]; then
1439 echo "Couldn't locate the top of the tree. Try setting TOP."
1440 return
1441 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001442 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001443 local arch=$(gettargetarch)
1444 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001445
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001446 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001447 if [ ! "$TRACE" ] ; then
1448 echo "usage: tracedmdump tracename"
1449 return
1450 fi
1451
Jack Veenstra60116fc2009-04-09 18:12:34 -07001452 if [ ! -r "$KERNEL" ] ; then
1453 echo "Error: cannot find kernel: '$KERNEL'"
1454 return
1455 fi
1456
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001457 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001458 if [ "$BASETRACE" = "$TRACE" ] ; then
1459 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1460 fi
1461
1462 echo "post-processing traces..."
1463 rm -f $TRACE/qtrace.dexlist
1464 post_trace $TRACE
1465 if [ $? -ne 0 ]; then
1466 echo "***"
1467 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1468 echo "***"
1469 return
1470 fi
1471 echo "generating dexlist output..."
1472 /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
1473 echo "generating dmtrace data..."
1474 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1475 echo "generating html file..."
1476 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1477 echo "done, see $TRACE/dmtrace.html for details"
1478 echo "or run:"
1479 echo " traceview $TRACE/dmtrace"
1480}
1481
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001482# communicate with a running device or emulator, set up necessary state,
1483# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001484function runhat()
1485{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001486 # process standard adb options
1487 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001488 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001489 adbTarget=$1
1490 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001491 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001492 adbTarget="$1 $2"
1493 shift 2
1494 fi
1495 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001496 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001497
1498 # runhat options
1499 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001500
1501 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001502 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001503 return
1504 fi
1505
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001506 # confirm hat is available
1507 if [ -z $(which hat) ]; then
1508 echo "hat is not available in this configuration."
1509 return
1510 fi
1511
Andy McFaddenb6289852010-07-12 08:00:19 -07001512 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001513 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001514 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001515 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001516 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001517 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001518 echo -n "> "
1519 read
1520
The Android Open Source Project88b60792009-03-03 19:28:42 -08001521 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001522
The Android Open Source Project88b60792009-03-03 19:28:42 -08001523 echo "Retrieving file $devFile..."
1524 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001525
The Android Open Source Project88b60792009-03-03 19:28:42 -08001526 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001527
The Android Open Source Project88b60792009-03-03 19:28:42 -08001528 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001529 echo "View the output by pointing your browser at http://localhost:7000/"
1530 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001531 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001532}
1533
1534function getbugreports()
1535{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001536 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001537
1538 if [ ! "$reports" ]; then
1539 echo "Could not locate any bugreports."
1540 return
1541 fi
1542
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001543 local report
1544 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001545 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001546 echo "/sdcard/bugreports/${report}"
1547 adb pull /sdcard/bugreports/${report} ${report}
1548 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001549 done
1550}
1551
Victoria Lease1b296b42012-08-21 15:44:06 -07001552function getsdcardpath()
1553{
1554 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1555}
1556
1557function getscreenshotpath()
1558{
1559 echo "$(getsdcardpath)/Pictures/Screenshots"
1560}
1561
1562function getlastscreenshot()
1563{
1564 local screenshot_path=$(getscreenshotpath)
1565 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1566 if [ "$screenshot" = "" ]; then
1567 echo "No screenshots found."
1568 return
1569 fi
1570 echo "${screenshot}"
1571 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1572}
1573
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001574function startviewserver()
1575{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001576 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001577 if [ $# -gt 0 ]; then
1578 port=$1
1579 fi
1580 adb shell service call window 1 i32 $port
1581}
1582
1583function stopviewserver()
1584{
1585 adb shell service call window 2
1586}
1587
1588function isviewserverstarted()
1589{
1590 adb shell service call window 3
1591}
1592
Romain Guyb84049a2010-10-04 16:56:11 -07001593function key_home()
1594{
1595 adb shell input keyevent 3
1596}
1597
1598function key_back()
1599{
1600 adb shell input keyevent 4
1601}
1602
1603function key_menu()
1604{
1605 adb shell input keyevent 82
1606}
1607
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001608function smoketest()
1609{
1610 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1611 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1612 return
1613 fi
1614 T=$(gettop)
1615 if [ ! "$T" ]; then
1616 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1617 return
1618 fi
1619
Ying Wang9cd17642012-12-13 10:52:07 -08001620 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001621 adb uninstall com.android.smoketest > /dev/null &&
1622 adb uninstall com.android.smoketest.tests > /dev/null &&
1623 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1624 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1625 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1626}
1627
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001628# simple shortcut to the runtest command
1629function runtest()
1630{
1631 T=$(gettop)
1632 if [ ! "$T" ]; then
1633 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1634 return
1635 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001636 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001637}
1638
The Android Open Source Project88b60792009-03-03 19:28:42 -08001639function godir () {
1640 if [[ -z "$1" ]]; then
1641 echo "Usage: godir <regex>"
1642 return
1643 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001644 T=$(gettop)
Brian Carlstromf2257422015-09-30 20:28:54 -07001645 if [ ! "$OUT_DIR" = "" ]; then
1646 mkdir -p $OUT_DIR
1647 FILELIST=$OUT_DIR/filelist
1648 else
1649 FILELIST=$T/filelist
1650 fi
1651 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001652 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001653 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001654 echo " Done"
1655 echo ""
1656 fi
1657 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001658 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001659 if [[ ${#lines[@]} = 0 ]]; then
1660 echo "Not found"
1661 return
1662 fi
1663 local pathname
1664 local choice
1665 if [[ ${#lines[@]} > 1 ]]; then
1666 while [[ -z "$pathname" ]]; do
1667 local index=1
1668 local line
1669 for line in ${lines[@]}; do
1670 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001671 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001672 done
1673 echo
1674 echo -n "Select one: "
1675 unset choice
1676 read choice
1677 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1678 echo "Invalid choice"
1679 continue
1680 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001681 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001682 done
1683 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001684 pathname=${lines[0]}
1685 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001686 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001687}
1688
Steve Kondikf00e7d92012-09-23 23:46:55 -07001689function installboot()
1690{
1691 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1692 then
1693 echo "No recovery.fstab found. Build recovery first."
1694 return 1
1695 fi
1696 if [ ! -e "$OUT/boot.img" ];
1697 then
1698 echo "No boot.img found. Run make bootimage first."
1699 return 1
1700 fi
1701 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1702 if [ -z "$PARTITION" ];
1703 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001704 # Try for RECOVERY_FSTAB_VERSION = 2
1705 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1706 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1707 if [ -z "$PARTITION" ];
1708 then
1709 echo "Unable to determine boot partition."
1710 return 1
1711 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001712 fi
1713 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001714 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001715 adb root
1716 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001717 adb wait-for-online shell mount /system 2>&1 > /dev/null
1718 adb wait-for-online remount
Dark Eyesdafcfe82015-12-11 20:51:02 -05001719 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Steve Kondikf00e7d92012-09-23 23:46:55 -07001720 then
1721 adb push $OUT/boot.img /cache/
1722 for i in $OUT/system/lib/modules/*;
1723 do
1724 adb push $i /system/lib/modules/
1725 done
1726 adb shell dd if=/cache/boot.img of=$PARTITION
1727 adb shell chmod 644 /system/lib/modules/*
1728 echo "Installation complete."
1729 else
Dark Eyesdafcfe82015-12-11 20:51:02 -05001730 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Steve Kondikf00e7d92012-09-23 23:46:55 -07001731 fi
1732}
1733
Steve Kondik83c03d52012-10-24 16:40:42 -07001734function installrecovery()
1735{
1736 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1737 then
1738 echo "No recovery.fstab found. Build recovery first."
1739 return 1
1740 fi
1741 if [ ! -e "$OUT/recovery.img" ];
1742 then
1743 echo "No recovery.img found. Run make recoveryimage first."
1744 return 1
1745 fi
1746 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1747 if [ -z "$PARTITION" ];
1748 then
Steve Kondik75f10762013-08-09 21:03:42 -07001749 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001750 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1751 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001752 if [ -z "$PARTITION" ];
1753 then
1754 echo "Unable to determine recovery partition."
1755 return 1
1756 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001757 fi
1758 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001759 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001760 adb root
1761 sleep 1
Dark Eyesdafcfe82015-12-11 20:51:02 -05001762 adb wait-for-online shell mount /system 2>&1 > /dev/null
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001763 adb wait-for-online remount
Dark Eyesdafcfe82015-12-11 20:51:02 -05001764 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Steve Kondik83c03d52012-10-24 16:40:42 -07001765 then
1766 adb push $OUT/recovery.img /cache/
1767 adb shell dd if=/cache/recovery.img of=$PARTITION
1768 echo "Installation complete."
1769 else
Dark Eyesdafcfe82015-12-11 20:51:02 -05001770 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Steve Kondik83c03d52012-10-24 16:40:42 -07001771 fi
1772}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001773
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001774function mka() {
Khalid Zubairabcd1942015-10-06 11:00:55 -07001775 local T=$(gettop)
1776 if [ "$T" ]; then
1777 case `uname -s` in
1778 Darwin)
1779 make -C $T -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1780 ;;
1781 *)
1782 mk_timer schedtool -B -n 1 -e ionice -n 1 make -C $T -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
1783 ;;
1784 esac
1785
1786 else
1787 echo "Couldn't locate the top of the tree. Try setting TOP."
1788 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001789}
1790
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05301791function cmka() {
1792 if [ ! -z "$1" ]; then
1793 for i in "$@"; do
1794 case $i in
1795 bacon|otapackage|systemimage)
1796 mka installclean
1797 mka $i
1798 ;;
1799 *)
1800 mka clean-$i
1801 mka $i
1802 ;;
1803 esac
1804 done
1805 else
1806 mka clean
1807 mka
1808 fi
1809}
1810
Khalid Zubairfdc26cd2015-10-21 12:43:14 -07001811function mms() {
1812 local T=$(gettop)
1813 if [ -z "$T" ]
1814 then
1815 echo "Couldn't locate the top of the tree. Try setting TOP."
1816 return 1
1817 fi
1818
1819 case `uname -s` in
1820 Darwin)
1821 local NUM_CPUS=$(sysctl hw.ncpu|cut -d" " -f2)
1822 ONE_SHOT_MAKEFILE="__none__" \
1823 make -C $T -j $NUM_CPUS "$@"
1824 ;;
1825 *)
1826 local NUM_CPUS=$(cat /proc/cpuinfo | grep "^processor" | wc -l)
1827 ONE_SHOT_MAKEFILE="__none__" \
1828 mk_timer schedtool -B -n 1 -e ionice -n 1 \
1829 make -C $T -j $NUM_CPUS "$@"
1830 ;;
1831 esac
1832}
1833
1834
Matt Mower8dacaed2013-12-29 12:57:20 -06001835function repolastsync() {
1836 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
1837 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
1838 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
1839 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
1840}
1841
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001842function reposync() {
1843 case `uname -s` in
1844 Darwin)
1845 repo sync -j 4 "$@"
1846 ;;
1847 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001848 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001849 ;;
1850 esac
1851}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001852
1853function repodiff() {
1854 if [ -z "$*" ]; then
1855 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1856 return
1857 fi
1858 diffopts=$* repo forall -c \
1859 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1860}
1861
Khalid Zubair63eabff2016-02-02 12:00:14 -08001862# Return success if adb is up and not in recovery
1863function _adb_connected {
1864 {
1865 if [[ "$(adb get-state)" == device &&
1866 "$(adb shell test -e /sbin/recovery; echo $?)" == 0 ]]
1867 then
1868 return 0
1869 fi
1870 } 2>/dev/null
1871
1872 return 1
1873};
1874
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301875# Credit for color strip sed: http://goo.gl/BoIcm
1876function dopush()
1877{
1878 local func=$1
1879 shift
1880
1881 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
Khalid Zubair63eabff2016-02-02 12:00:14 -08001882 if ! _adb_connected; then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301883 echo "No device is online. Waiting for one..."
1884 echo "Please connect USB and/or enable USB debugging"
Khalid Zubair63eabff2016-02-02 12:00:14 -08001885 until _adb_connected; do
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301886 sleep 1
1887 done
1888 echo "Device Found."
1889 fi
1890
Dark Eyesdafcfe82015-12-11 20:51:02 -05001891 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD") || [ "$FORCE_PUSH" == "true" ];
Chirayu Desai6dadb572012-12-26 10:53:58 +05301892 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07001893 # retrieve IP and PORT info if we're using a TCP connection
1894 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
1895 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301896 adb root &> /dev/null
1897 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07001898 if [ -n "$TCPIPPORT" ]
1899 then
1900 # adb root just killed our connection
1901 # so reconnect...
1902 adb connect "$TCPIPPORT"
1903 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301904 adb wait-for-device &> /dev/null
1905 sleep 0.3
1906 adb remount &> /dev/null
1907
Matt Mower668ea262014-05-20 02:52:23 -05001908 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00001909 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
1910 ret=$?;
1911 if [ $ret -ne 0 ]; then
1912 rm -f $OUT/.log;return $ret
1913 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301914
1915 # Install: <file>
LuK133756041e72015-12-01 14:53:23 +01001916 if [ `uname` = "Linux" ]; then
1917 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)"
1918 else
1919 LOC="$(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" | grep '^Install: ' | cut -d ':' -f 2)"
1920 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301921
1922 # Copy: <file>
LuK133756041e72015-12-01 14:53:23 +01001923 if [ `uname` = "Linux" ]; then
1924 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)"
1925 else
1926 LOC="$LOC $(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" | grep '^Copy: ' | cut -d ':' -f 2)"
1927 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301928
Matt Mowerdfd4c082014-05-20 02:52:23 -05001929 # If any files are going to /data, push an octal file permissions reader to device
1930 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
1931 CHKPERM="/data/local/tmp/chkfileperm.sh"
1932(
1933cat <<'EOF'
1934#!/system/xbin/sh
1935FILE=$@
1936if [ -e $FILE ]; then
1937 ls -l $FILE | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' | cut -d ' ' -f1
1938fi
1939EOF
1940) > $OUT/.chkfileperm.sh
1941 echo "Pushing file permissions checker to device"
1942 adb push $OUT/.chkfileperm.sh $CHKPERM
1943 adb shell chmod 755 $CHKPERM
1944 rm -f $OUT/.chkfileperm.sh
1945 fi
1946
Matt Mower668ea262014-05-20 02:52:23 -05001947 stop_n_start=false
Luca Stefani406c2af2015-11-02 05:33:10 -08001948 for FILE in $(echo $LOC | tr " " "\n"); do
Matt Mowerdfd4c082014-05-20 02:52:23 -05001949 # Make sure file is in $OUT/system or $OUT/data
Matt Mower668ea262014-05-20 02:52:23 -05001950 case $FILE in
Matt Mowerdfd4c082014-05-20 02:52:23 -05001951 $OUT/system/*|$OUT/data/*)
Matt Mower668ea262014-05-20 02:52:23 -05001952 # Get target file name (i.e. /system/bin/adb)
1953 TARGET=$(echo $FILE | sed "s#$OUT##")
1954 ;;
1955 *) continue ;;
1956 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301957
Matt Mower668ea262014-05-20 02:52:23 -05001958 case $TARGET in
Matt Mowerdfd4c082014-05-20 02:52:23 -05001959 /data/*)
1960 # fs_config only sets permissions and se labels for files pushed to /system
1961 if [ -n "$CHKPERM" ]; then
1962 OLDPERM=$(adb shell $CHKPERM $TARGET)
1963 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
1964 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
1965 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
1966 fi
1967 echo "Pushing: $TARGET"
1968 adb push $FILE $TARGET
1969 if [ -n "$OLDPERM" ]; then
1970 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
1971 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
1972 adb shell chmod "$OLDPERM" $TARGET
1973 else
1974 echo "$TARGET did not exist previously, you should set file permissions manually"
1975 fi
1976 adb shell restorecon "$TARGET"
1977 ;;
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07001978 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05001979 # Only need to stop services once
1980 if ! $stop_n_start; then
1981 adb shell stop
1982 stop_n_start=true
1983 fi
1984 echo "Pushing: $TARGET"
1985 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301986 ;;
1987 *)
Matt Mower668ea262014-05-20 02:52:23 -05001988 echo "Pushing: $TARGET"
1989 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301990 ;;
Matt Mower668ea262014-05-20 02:52:23 -05001991 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301992 done
Matt Mowerdfd4c082014-05-20 02:52:23 -05001993 if [ -n "$CHKPERM" ]; then
1994 adb shell rm $CHKPERM
1995 fi
Matt Mower668ea262014-05-20 02:52:23 -05001996 if $stop_n_start; then
1997 adb shell start
1998 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301999 rm -f $OUT/.log
2000 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302001 else
Dark Eyesdafcfe82015-12-11 20:51:02 -05002002 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Chirayu Desai6dadb572012-12-26 10:53:58 +05302003 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302004}
2005
2006alias mmp='dopush mm'
2007alias mmmp='dopush mmm'
Martin Brabhamb77db582016-02-05 15:59:21 -05002008alias mmap='dopush mma'
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302009alias mkap='dopush mka'
2010alias cmkap='dopush cmka'
2011
Chirayu Desai4a319b82013-06-05 20:14:33 +05302012function repopick() {
2013 T=$(gettop)
2014 $T/build/tools/repopick.py $@
2015}
2016
Chirayu Desaib89b3242013-06-30 10:04:25 +05302017function fixup_common_out_dir() {
2018 common_out_dir=$(get_build_var OUT_DIR)/target/common
2019 target_device=$(get_build_var TARGET_DEVICE)
Dark Eyesdafcfe82015-12-11 20:51:02 -05002020 if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then
Chirayu Desaib89b3242013-06-30 10:04:25 +05302021 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2022 mv ${common_out_dir} ${common_out_dir}-${target_device}
2023 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2024 else
2025 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2026 mkdir -p ${common_out_dir}-${target_device}
2027 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2028 fi
2029 else
2030 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2031 mkdir -p ${common_out_dir}
2032 fi
2033}
2034
Michael Bestas163381a2015-10-23 20:36:47 +03002035# Force JAVA_HOME to point to java 1.7 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002036#
2037# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2038# For some reason, installing the JDK doesn't make it show up in the
2039# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002040function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002041 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002042 # we can reset it later, depending on the version of java the build
2043 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002044 #
2045 # If we don't do this, the JAVA_HOME value set by the first call to
2046 # build/envsetup.sh will persist forever.
2047 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2048 export JAVA_HOME=""
2049 fi
2050
Andy McFaddenbd960942010-06-24 12:52:51 -07002051 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002052 case `uname -s` in
2053 Darwin)
2054 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2055 ;;
2056 *)
2057 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2058 ;;
2059 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002060
2061 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2062 # we can change it on the next envsetup.sh, if required.
2063 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002064 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002065}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002066
Alex Rayf0d08eb2013-03-08 15:15:06 -08002067# Print colored exit condition
2068function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002069 "$@"
2070 local retval=$?
2071 if [ $retval -ne 0 ]
2072 then
Roman Birgead9a5c2015-10-16 10:29:06 -07002073 printf "\e[0;31mFAILURE\e[00m\n"
Michael Wrighteb733842013-03-08 17:34:02 -08002074 else
Roman Birgead9a5c2015-10-16 10:29:06 -07002075 printf "\e[0;32mSUCCESS\e[00m\n"
Michael Wrighteb733842013-03-08 17:34:02 -08002076 fi
2077 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002078}
2079
Ying Wanged21d4c2014-08-24 22:14:19 -07002080function get_make_command()
2081{
2082 echo command make
2083}
2084
Anthony King40b093f2015-04-30 22:19:48 +01002085function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002086{
2087 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002088 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002089 local ret=$?
2090 local end_time=$(date +"%s")
2091 local tdiff=$(($end_time-$start_time))
2092 local hours=$(($tdiff / 3600 ))
2093 local mins=$((($tdiff % 3600) / 60))
2094 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002095 local ncolors=$(tput colors 2>/dev/null)
2096 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2097 color_failed="\e[0;31m"
2098 color_success="\e[0;32m"
Roman Birgead9a5c2015-10-16 10:29:06 -07002099 color_reset="\e[0m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002100 else
2101 color_failed=""
2102 color_success=""
2103 color_reset=""
2104 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002105 echo
2106 if [ $ret -eq 0 ] ; then
Roman Birgead9a5c2015-10-16 10:29:06 -07002107 printf "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002108 else
Roman Birgead9a5c2015-10-16 10:29:06 -07002109 printf "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002110 fi
2111 if [ $hours -gt 0 ] ; then
2112 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2113 elif [ $mins -gt 0 ] ; then
2114 printf "(%02g:%02g (mm:ss))" $mins $secs
2115 elif [ $secs -gt 0 ] ; then
2116 printf "(%s seconds)" $secs
2117 fi
Roman Birgead9a5c2015-10-16 10:29:06 -07002118 printf " ####${color_reset}\n\n"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002119 return $ret
2120}
2121
Anthony King40b093f2015-04-30 22:19:48 +01002122function make()
2123{
2124 mk_timer $(get_make_command) "$@"
2125}
2126
Khalid Zubair695992c2016-02-08 16:27:55 -08002127function __detect_shell() {
Raphael Moll70a86b02011-06-20 16:03:14 -07002128 case `ps -o command -p $$` in
2129 *bash*)
Khalid Zubair695992c2016-02-08 16:27:55 -08002130 echo bash
Raphael Moll70a86b02011-06-20 16:03:14 -07002131 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002132 *zsh*)
Khalid Zubair695992c2016-02-08 16:27:55 -08002133 echo zsh
Emilio López7ff9caa2013-11-03 13:05:43 -03002134 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002135 *)
Khalid Zubair695992c2016-02-08 16:27:55 -08002136 echo unknown
2137 return 1
Raphael Moll70a86b02011-06-20 16:03:14 -07002138 ;;
2139 esac
Khalid Zubair695992c2016-02-08 16:27:55 -08002140 return
2141}
2142
2143
2144if ! __detect_shell > /dev/null; then
2145 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002146fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002147
2148# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002149for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2150 `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 -08002151do
2152 echo "including $f"
2153 . $f
2154done
2155unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002156
Kyle Ladd031a0b62013-09-11 20:43:42 -04002157# Add completions
2158check_bash_version && {
Dark Eyesdafcfe82015-12-11 20:51:02 -05002159 dirs="sdk/bash_completion vendor/bliss/bash_completion"
Kyle Ladd031a0b62013-09-11 20:43:42 -04002160 for dir in $dirs; do
2161 if [ -d ${dir} ]; then
2162 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2163 echo "including $f"
2164 . $f
2165 done
2166 fi
2167 done
2168}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302169
2170export ANDROID_BUILD_TOP=$(gettop)