blob: 96af100d9fcd3dd2ed8e9b161b4e04d2b533b4e3 [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)
Dark Eyesc978fe32015-12-19 08:06:48 -0500152 targetgcckernelversion=$(get_build_var TARGET_KERNEL_CUSTOM_TOOLCHAIN)
Ben Cheng15266702012-12-10 16:04:39 -0800153 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800154
Dark Eyesc978fe32015-12-19 08:06:48 -0500155 if [ -z "$targetgcckernelversion" ]; then
156 targetgcckernelversion="4.9-linaro"
157 export TARGET_GCC_VERSION_KERNEL="4.9-linaro"
158 else
159 export TARGET_GCC_VERSION_KERNEL="$targetgcckernelversion"
160 fi
161
Raphael Mollc639c782011-06-20 17:25:01 -0700162 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800163 export ANDROID_TOOLCHAIN=
164 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200165 local ARCH=$(get_build_var TARGET_ARCH)
166 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400167 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700168 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400169 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
170 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800171 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200172 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800173 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700174 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700175 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700176 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000177 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200178 *)
179 echo "Can't find toolchain for unknown architecture: $ARCH"
180 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700181 ;;
182 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700183 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800184 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700185 fi
Raphael732936d2011-06-22 14:35:32 -0700186
Ben Chengfba67bf2014-02-25 10:27:07 -0800187 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
188 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
189 fi
190
191 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700192 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700193 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800194 # Legacy toolchain configuration used for ARM kernel compilation
Dark Eyesc978fe32015-12-19 08:06:48 -0500195 toolchaindir=arm/arm-eabi-$targetgcckernelversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700196 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100197 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
198 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700199 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700200 ;;
201 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700202 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700203 ;;
204 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700205
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700206 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700207 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 +0200208
209 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
210 # to ensure that the corresponding 'emulator' binaries are used.
211 case $(uname -s) in
212 Darwin)
213 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
214 ;;
215 Linux)
216 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
217 ;;
218 *)
219 ANDROID_EMULATOR_PREBUILTS=
220 ;;
221 esac
222 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700223 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200224 export ANDROID_EMULATOR_PREBUILTS
225 fi
226
Ying Wangaa1c9b52012-11-26 20:51:59 -0800227 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800228
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500229 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900230 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500231 if [ -n "$JAVA_HOME" ]; then
232 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900233 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
234 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500235 fi
236
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800237 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700238 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
239 export OUT=$ANDROID_PRODUCT_OUT
240
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700241 unset ANDROID_HOST_OUT
242 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
243
Matt Mowerf8ff73e2015-06-09 19:35:53 -0500244 if [ -n "$ANDROID_CCACHE_DIR" ]; then
245 export CCACHE_DIR=$ANDROID_CCACHE_DIR
246 fi
247
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800248 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700249 # TODO: fix the path
250 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
251}
252
253function printconfig()
254{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800255 T=$(gettop)
256 if [ ! "$T" ]; then
257 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
258 return
259 fi
260 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261}
262
263function set_stuff_for_environment()
264{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800265 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500266 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800267 setpaths
268 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700269
Ben Chengaac3f812013-08-13 14:38:15 -0700270 # With this environment variable new GCC can apply colors to warnings/errors
271 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 -0700272 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700273}
274
275function set_sequence_number()
276{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700277 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700278}
279
280function settitle()
281{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800282 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700283 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700284 local product=$TARGET_PRODUCT
285 local variant=$TARGET_BUILD_VARIANT
286 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800287 if [ -z "$PROMPT_COMMAND" ]; then
288 # No prompts
289 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
290 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
291 # Prompts exist, but no hardstatus
292 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700293 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800294 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500295 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800296 fi
297
298 if [ -z "$apps" ]; then
299 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
300 else
301 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
302 fi
303 export ANDROID_PROMPT_PREFIX
304
305 # Inject build data into hardstatus
306 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 -0800307 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308}
309
Kyle Ladd031a0b62013-09-11 20:43:42 -0400310function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700311{
Kenny Root52aa81c2011-07-15 11:07:06 -0700312 # Keep us from trying to run in something that isn't bash.
313 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400314 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700315 fi
316
317 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200318 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400319 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700320 fi
321
Kyle Ladd031a0b62013-09-11 20:43:42 -0400322 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700323}
324
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325function choosetype()
326{
327 echo "Build type choices are:"
328 echo " 1. release"
329 echo " 2. debug"
330 echo
331
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700333 DEFAULT_NUM=1
334 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 export TARGET_BUILD_TYPE=
337 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 while [ -z $TARGET_BUILD_TYPE ]
339 do
340 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 if [ -z "$1" ] ; then
342 read ANSWER
343 else
344 echo $1
345 ANSWER=$1
346 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 case $ANSWER in
348 "")
349 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
350 ;;
351 1)
352 export TARGET_BUILD_TYPE=release
353 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800354 release)
355 export TARGET_BUILD_TYPE=release
356 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357 2)
358 export TARGET_BUILD_TYPE=debug
359 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800360 debug)
361 export TARGET_BUILD_TYPE=debug
362 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700363 *)
364 echo
365 echo "I didn't understand your response. Please try again."
366 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367 ;;
368 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800369 if [ -n "$1" ] ; then
370 break
371 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700372 done
373
374 set_stuff_for_environment
375}
376
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800377#
378# This function isn't really right: It chooses a TARGET_PRODUCT
379# based on the list of boards. Usually, that gets you something
380# that kinda works with a generic product, but really, you should
381# pick a product by name.
382#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383function chooseproduct()
384{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700385 if [ "x$TARGET_PRODUCT" != x ] ; then
386 default_value=$TARGET_PRODUCT
387 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700388 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700389 fi
390
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800391 export TARGET_PRODUCT=
392 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700393 while [ -z "$TARGET_PRODUCT" ]
394 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700395 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800396 if [ -z "$1" ] ; then
397 read ANSWER
398 else
399 echo $1
400 ANSWER=$1
401 fi
402
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700403 if [ -z "$ANSWER" ] ; then
404 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800405 else
406 if check_product $ANSWER
407 then
408 export TARGET_PRODUCT=$ANSWER
409 else
410 echo "** Not a valid product: $ANSWER"
411 fi
412 fi
413 if [ -n "$1" ] ; then
414 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700415 fi
416 done
417
418 set_stuff_for_environment
419}
420
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421function choosevariant()
422{
423 echo "Variant choices are:"
424 local index=1
425 local v
426 for v in ${VARIANT_CHOICES[@]}
427 do
428 # The product name is the name of the directory containing
429 # the makefile we found, above.
430 echo " $index. $v"
431 index=$(($index+1))
432 done
433
434 local default_value=eng
435 local ANSWER
436
437 export TARGET_BUILD_VARIANT=
438 while [ -z "$TARGET_BUILD_VARIANT" ]
439 do
440 echo -n "Which would you like? [$default_value] "
441 if [ -z "$1" ] ; then
442 read ANSWER
443 else
444 echo $1
445 ANSWER=$1
446 fi
447
448 if [ -z "$ANSWER" ] ; then
449 export TARGET_BUILD_VARIANT=$default_value
450 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
451 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800452 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453 fi
454 else
455 if check_variant $ANSWER
456 then
457 export TARGET_BUILD_VARIANT=$ANSWER
458 else
459 echo "** Not a valid variant: $ANSWER"
460 fi
461 fi
462 if [ -n "$1" ] ; then
463 break
464 fi
465 done
466}
467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468function choosecombo()
469{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700470 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471
472 echo
473 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700474 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475
476 echo
477 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700478 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479
480 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700481 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483}
484
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485# Clear this variable. It will be built up again when the vendorsetup.sh
486# files are included at the end of this file.
487unset LUNCH_MENU_CHOICES
488function add_lunch_combo()
489{
490 local new_combo=$1
491 local c
492 for c in ${LUNCH_MENU_CHOICES[@]} ; do
493 if [ "$new_combo" = "$c" ] ; then
494 return
495 fi
496 done
497 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
498}
499
500# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700501add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800502add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000503add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800504add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000505add_lunch_combo aosp_x86-eng
506add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508function print_lunch_menu()
509{
510 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700511 echo
512 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000513 if [ "$(uname)" = "Darwin" ] ; then
514 echo " (ohai, koush!)"
515 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516 echo
Dark Eyesdafcfe82015-12-11 20:51:02 -0500517 if [ "z${BLISS_DEVICES_ONLY}" != "z" ]; then
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000518 echo "Breakfast menu... pick a combo:"
519 else
520 echo "Lunch menu... pick a combo:"
521 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522
523 local i=1
524 local choice
525 for choice in ${LUNCH_MENU_CHOICES[@]}
526 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100527 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800528 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100529 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530
Dark Eyesdafcfe82015-12-11 20:51:02 -0500531 if [ "z${BLISS_DEVICES_ONLY}" != "z" ]; then
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000532 echo "... and don't forget the bacon!"
533 fi
534
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535 echo
536}
537
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000538function brunch()
539{
540 breakfast $*
541 if [ $? -eq 0 ]; then
542 mka bacon
543 else
544 echo "No such item in brunch menu. Try 'breakfast'"
545 return 1
546 fi
547 return $?
548}
549
550function breakfast()
551{
552 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200553 local variant=$2
Dark Eyesdafcfe82015-12-11 20:51:02 -0500554 BLISS_DEVICES_ONLY="true"
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000555 unset LUNCH_MENU_CHOICES
556 add_lunch_combo full-eng
Dark Eyesdafcfe82015-12-11 20:51:02 -0500557 for f in `/bin/ls vendor/bliss/vendorsetup.sh 2> /dev/null`
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000558 do
559 echo "including $f"
560 . $f
561 done
562 unset f
563
564 if [ $# -eq 0 ]; then
565 # No arguments, so let's have the full menu
566 lunch
567 else
568 echo "z$target" | grep -q "-"
569 if [ $? -eq 0 ]; then
570 # A buildtype was specified, assume a full device name
571 lunch $target
572 else
Dark Eyesdafcfe82015-12-11 20:51:02 -0500573 # This is probably just the Bliss model name
JustArchif70c7e62014-06-22 14:37:30 +0200574 if [ -z "$variant" ]; then
575 variant="userdebug"
576 fi
Dark Eyesdafcfe82015-12-11 20:51:02 -0500577 lunch bliss_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000578 fi
579 fi
580 return $?
581}
582
583alias bib=breakfast
584
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585function lunch()
586{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 local answer
Anthony King850627c2015-04-30 22:57:08 +0100588 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800591 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 else
593 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700594 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 fi
597
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 local selection=
599
600 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700602 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
604 then
605 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
606 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800607 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800608 fi
609 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
610 then
611 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700612 fi
613
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800614 if [ -z "$selection" ]
615 then
616 echo
617 echo "Invalid lunch combo: $answer"
618 return 1
619 fi
620
Joe Onoratoda12daf2010-06-09 18:18:31 -0700621 export TARGET_BUILD_APPS=
622
Jeff Browne33ba4c2011-07-11 22:11:46 -0700623 local product=$(echo -n $selection | sed -e "s/-.*$//")
624 check_product $product
625 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800626 then
Dark Eyesdafcfe82015-12-11 20:51:02 -0500627 # if we can't find a product, try to grab it off the BLISS github
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800628 T=$(gettop)
629 pushd $T > /dev/null
630 build/tools/roomservice.py $product
631 popd > /dev/null
632 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000633 else
634 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800635 fi
636 if [ $? -ne 0 ]
637 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700638 echo
639 echo "** Don't have a product spec for: '$product'"
640 echo "** Do you have the right repo manifest?"
641 product=
642 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643
Jeff Browne33ba4c2011-07-11 22:11:46 -0700644 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
645 check_variant $variant
646 if [ $? -ne 0 ]
647 then
648 echo
649 echo "** Invalid variant: '$variant'"
650 echo "** Must be one of ${VARIANT_CHOICES[@]}"
651 variant=
652 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800653
Jeff Browne33ba4c2011-07-11 22:11:46 -0700654 if [ -z "$product" -o -z "$variant" ]
655 then
656 echo
657 return 1
658 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659
Jeff Browne33ba4c2011-07-11 22:11:46 -0700660 export TARGET_PRODUCT=$product
661 export TARGET_BUILD_VARIANT=$variant
662 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663
664 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800665
Dark Eyesdafcfe82015-12-11 20:51:02 -0500666 export TARGET_DEVICE=$(get_build_var TARGET_DEVICE)
667
Chirayu Desaib89b3242013-06-30 10:04:25 +0530668 fixup_common_out_dir
669
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700670 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800671 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700672}
673
Jeff Davidson513d7a42010-08-02 10:00:44 -0700674# Tab completion for lunch.
675function _lunch()
676{
677 local cur prev opts
678 COMPREPLY=()
679 cur="${COMP_WORDS[COMP_CWORD]}"
680 prev="${COMP_WORDS[COMP_CWORD-1]}"
681
682 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
683 return 0
684}
Emilio López9ad6eea2013-11-03 13:02:13 -0300685complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700686
Joe Onoratoda12daf2010-06-09 18:18:31 -0700687# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700688# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700689function tapas()
690{
Ying Wangb541ab62014-05-29 17:57:40 -0700691 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 -0700692 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700693 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
694 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 -0700695
Ying Wang67f02922012-08-22 10:25:20 -0700696 if [ $(echo $arch | wc -w) -gt 1 ]; then
697 echo "tapas: Error: Multiple build archs supplied: $arch"
698 return
699 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700700 if [ $(echo $variant | wc -w) -gt 1 ]; then
701 echo "tapas: Error: Multiple build variants supplied: $variant"
702 return
703 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700704 if [ $(echo $density | wc -w) -gt 1 ]; then
705 echo "tapas: Error: Multiple densities supplied: $density"
706 return
707 fi
Ying Wang67f02922012-08-22 10:25:20 -0700708
709 local product=full
710 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700711 x86) product=full_x86;;
712 mips) product=full_mips;;
713 armv5) product=generic_armv5;;
714 arm64) product=aosp_arm64;;
715 x86_64) product=aosp_x86_64;;
716 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700717 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700718 if [ -z "$variant" ]; then
719 variant=eng
720 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700721 if [ -z "$apps" ]; then
722 apps=all
723 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600724 if [ -z "$density" ]; then
725 density=alldpi
726 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700727
Ying Wang67f02922012-08-22 10:25:20 -0700728 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700729 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700730 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700731 export TARGET_BUILD_TYPE=release
732 export TARGET_BUILD_APPS=$apps
733
734 set_stuff_for_environment
735 printconfig
736}
737
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100738function eat()
739{
740 if [ "$OUT" ] ; then
Dark Eyesdafcfe82015-12-11 20:51:02 -0500741 MODVERSION=$(get_build_var BLISS_VERSION)
742 ZIPFILE=bliss-$MODVERSION.zip
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100743 ZIPPATH=$OUT/$ZIPFILE
744 if [ ! -f $ZIPPATH ] ; then
745 echo "Nothing to eat"
746 return 1
747 fi
748 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
Steve Kondik58fa7162015-11-15 18:47:58 -0800749 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 +0100750 echo "No device is online. Waiting for one..."
751 echo "Please connect USB and/or enable USB debugging"
Steve Kondik58fa7162015-11-15 18:47:58 -0800752 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 +0100753 sleep 1
754 done
755 echo "Device Found.."
756 fi
Dark Eyesdafcfe82015-12-11 20:51:02 -0500757 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Chirayu Desai6dadb572012-12-26 10:53:58 +0530758 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100759 # if adbd isn't root we can't write to /cache/recovery/
760 adb root
761 sleep 1
762 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700763 cat << EOF > /tmp/command
Steve Kondike9f828c2015-11-10 23:51:21 +0100764--sideload_auto_reboot
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100765EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700766 if adb push /tmp/command /cache/recovery/ ; then
767 echo "Rebooting into recovery for sideload installation"
768 adb reboot recovery
769 adb wait-for-sideload
770 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100771 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700772 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100773 else
774 echo "Nothing to eat"
775 return 1
776 fi
777 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530778 else
Dark Eyesdafcfe82015-12-11 20:51:02 -0500779 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Chirayu Desai6dadb572012-12-26 10:53:58 +0530780 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100781}
782
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000783function omnom
784{
785 brunch $*
786 eat
787}
788
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789function gettop
790{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800791 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700793 # The following circumlocution ensures we remove symlinks from TOP.
794 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700795 else
796 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800797 # The following circumlocution (repeated below as well) ensures
798 # that we record the true directory name and not one that is
799 # faked up with symlink names.
800 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800802 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 T=
804 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800805 \cd ..
synergyb112a402013-07-05 19:47:47 -0700806 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700807 done
Ying Wang9cd17642012-12-13 10:52:07 -0800808 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700809 if [ -f "$T/$TOPFILE" ]; then
810 echo $T
811 fi
812 fi
813 fi
814}
815
Andrew Hsieh906cb782013-09-10 17:37:14 +0800816# Return driver for "make", if any (eg. static analyzer)
817function getdriver()
818{
819 local T="$1"
820 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
821 if [ -n "$WITH_STATIC_ANALYZER" ]; then
822 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800823$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
824--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800825--status-bugs \
826--top=$T"
827 fi
828}
829
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700830function m()
831{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800832 local T=$(gettop)
833 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800835 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 else
837 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700838 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 fi
840}
841
842function findmakefile()
843{
844 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800845 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846 T=
847 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700848 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700849 if [ -f "$T/Android.mk" ]; then
850 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800851 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700852 return
853 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800854 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855 done
Ying Wang9cd17642012-12-13 10:52:07 -0800856 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700857}
858
859function mm()
860{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800861 local T=$(gettop)
862 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700863 # If we're sitting in the root of the build tree, just do a
864 # normal make.
865 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800866 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867 else
868 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800869 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700870 local MODULES=
871 local GET_INSTALL_PATH=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700872 # Remove the path to top as the makefilepath needs to be relative
873 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700874 if [ ! "$T" ]; then
875 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700876 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700877 elif [ ! "$M" ]; then
878 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700879 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700880 else
Ying Wanga7deb082013-08-16 13:24:47 -0700881 for ARG in $@; do
882 case $ARG in
883 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
884 esac
885 done
886 if [ -n "$GET_INSTALL_PATH" ]; then
887 MODULES=
Khalid Zubaircbf96922016-03-02 14:01:45 -0800888 # set all args to 'GET-INSTALL-PATH'
889 set -- GET-INSTALL-PATH
Ying Wanga7deb082013-08-16 13:24:47 -0700890 else
891 MODULES=all_modules
Ying Wanga7deb082013-08-16 13:24:47 -0700892 fi
Khalid Zubaircbf96922016-03-02 14:01:45 -0800893 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700894 fi
895 fi
896}
897
898function mmm()
899{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800900 local T=$(gettop)
901 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700902 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800903 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800904 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800905 local ARGS=
906 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700907 local GET_INSTALL_PATH=
Khalid Zubair521aa1e2016-02-11 14:34:12 -0800908
Roman Birg5771f5d2016-03-01 10:27:51 -0800909 if [ "$(__detect_shell)" = "zsh" ]; then
Khalid Zubair521aa1e2016-02-11 14:34:12 -0800910 set -lA DASH_ARGS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
911 set -lA DIRS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
912 else
913 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
914 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
915 fi
916
The Android Open Source Project88b60792009-03-03 19:28:42 -0800917 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800918 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
919 if [ "$MODULES" = "" ]; then
920 MODULES=all_modules
921 fi
922 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700923 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700924 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
925 local TO_CHOP=`expr $TO_CHOP + 1`
926 local START=`PWD= /bin/pwd`
927 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700928 if [ "$MFILE" = "" ] ; then
929 MFILE=$DIR/Android.mk
930 else
931 MFILE=$MFILE/$DIR/Android.mk
932 fi
933 MAKEFILE="$MAKEFILE $MFILE"
934 else
Ying Wanga7deb082013-08-16 13:24:47 -0700935 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100936 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700937 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997c3eb1072015-10-18 19:49:13 +0200938 *) if [ -d $DIR ]; then
939 echo "No Android.mk in $DIR.";
940 else
941 echo "Couldn't locate the directory $DIR";
942 fi
943 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700944 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700945 fi
946 done
Ying Wanga7deb082013-08-16 13:24:47 -0700947 if [ -n "$GET_INSTALL_PATH" ]; then
948 ARGS=$GET_INSTALL_PATH
949 MODULES=
950 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800951 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 -0700952 else
953 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700954 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700955 fi
956}
957
Ying Wangb607f7b2013-02-08 18:01:04 -0800958function mma()
959{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800960 local T=$(gettop)
961 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800962 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800963 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800964 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800965 if [ ! "$T" ]; then
966 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700967 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800968 fi
969 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800970 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800971 fi
972}
973
974function mmma()
975{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800976 local T=$(gettop)
977 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800978 if [ "$T" ]; then
Roman Birg5771f5d2016-03-01 10:27:51 -0800979 if [ "$(__detect_shell)" = "zsh" ]; then
Khalid Zubair521aa1e2016-02-11 14:34:12 -0800980 set -lA DASH_ARGS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
981 set -lA DIRS $(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
982 else
983 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
984 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
985 fi
Ying Wangb607f7b2013-02-08 18:01:04 -0800986 local MY_PWD=`PWD= /bin/pwd`
987 if [ "$MY_PWD" = "$T" ]; then
988 MY_PWD=
989 else
990 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
991 fi
992 local DIR=
993 local MODULE_PATHS=
994 local ARGS=
995 for DIR in $DIRS ; do
996 if [ -d $DIR ]; then
997 if [ "$MY_PWD" = "" ]; then
998 MODULE_PATHS="$MODULE_PATHS $DIR"
999 else
1000 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
1001 fi
1002 else
1003 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +01001004 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -08001005 *) echo "Couldn't find directory $DIR"; return 1;;
1006 esac
1007 fi
1008 done
Andrew Hsieh906cb782013-09-10 17:37:14 +08001009 $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 -08001010 else
1011 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -07001012 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -08001013 fi
1014}
1015
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001016function croot()
1017{
1018 T=$(gettop)
1019 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001020 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001021 else
1022 echo "Couldn't locate the top of the tree. Try setting TOP."
1023 fi
1024}
1025
nebkatfb67a1e2012-12-28 10:40:45 +00001026function cout()
1027{
1028 if [ "$OUT" ]; then
1029 cd $OUT
1030 else
1031 echo "Couldn't locate out directory. Try setting OUT."
1032 fi
1033}
1034
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001035function cproj()
1036{
1037 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001038 local HERE=$PWD
1039 T=
1040 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1041 T=$PWD
1042 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001043 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001044 return
1045 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001046 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001047 done
Ying Wang9cd17642012-12-13 10:52:07 -08001048 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001049 echo "can't find Android.mk"
1050}
1051
Daniel Sandler47e0a882013-07-30 13:23:52 -04001052# simplified version of ps; output in the form
1053# <pid> <procname>
1054function qpid() {
1055 local prepend=''
1056 local append=''
1057 if [ "$1" = "--exact" ]; then
1058 prepend=' '
1059 append='$'
1060 shift
1061 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1062 echo "usage: qpid [[--exact] <process name|pid>"
1063 return 255
1064 fi
1065
1066 local EXE="$1"
1067 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001068 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001069 else
1070 adb shell ps \
1071 | tr -d '\r' \
1072 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1073 fi
1074}
1075
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001076function pid()
1077{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001078 local prepend=''
1079 local append=''
1080 if [ "$1" = "--exact" ]; then
1081 prepend=' '
1082 append='$'
1083 shift
1084 fi
1085 local EXE="$1"
1086 if [ "$EXE" ] ; then
1087 local PID=`adb shell ps \
1088 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001089 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001090 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1091 echo "$PID"
1092 else
1093 echo "usage: pid [--exact] <process name>"
1094 return 255
1095 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001096}
1097
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001098# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001099# that has the core-file-size limit set correctly
1100#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001101# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001102# if its core-file-size limit is not set already.
1103# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1104
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001105function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001106{
1107 echo "Getting root...";
1108 adb root;
1109 adb wait-for-device;
1110
1111 echo "Remounting root parition read-write...";
1112 adb shell mount -w -o remount -t rootfs rootfs;
1113 sleep 1;
1114 adb wait-for-device;
1115 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001116 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001117 adb shell chmod 0777 /cores;
1118
1119 echo "Granting SELinux permission to dump in /cores...";
1120 adb shell restorecon -R /cores;
1121
1122 echo "Set core pattern.";
1123 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1124
1125 echo "Done."
1126}
1127
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001128# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001129# $1 = PID of process (e.g., $(pid mediaserver))
1130#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001131# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001132# dump to actually be generated.
1133
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001134function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001135{
1136 local PID=$1;
1137 if [ -z "$PID" ]; then
1138 printf "Expecting a PID!\n";
1139 return;
1140 fi;
1141 echo "Setting core limit for $PID to infinite...";
1142 adb shell prlimit $PID 4 -1 -1
1143}
1144
1145# core - send SIGV and pull the core for process
1146# $1 = PID of process (e.g., $(pid mediaserver))
1147#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001148# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001149# enabled globally.
1150
1151function core()
1152{
1153 local PID=$1;
1154
1155 if [ -z "$PID" ]; then
1156 printf "Expecting a PID!\n";
1157 return;
1158 fi;
1159
1160 local CORENAME=core.$PID;
1161 local COREPATH=/cores/$CORENAME;
1162 local SIG=SEGV;
1163
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001164 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001165
1166 local done=0;
1167 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1168 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1169 adb shell kill -$SIG $PID;
1170 sleep 1;
1171 done;
1172
1173 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1174 echo "Done: core is under $COREPATH on device.";
1175}
1176
Christopher Tate744ee802009-11-12 15:33:08 -08001177# systemstack - dump the current stack trace of all threads in the system process
1178# to the usual ANR traces file
1179function systemstack()
1180{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001181 stacks system_server
1182}
1183
1184function stacks()
1185{
1186 if [[ $1 =~ ^[0-9]+$ ]] ; then
1187 local PID="$1"
1188 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001189 local PIDLIST="$(pid $1)"
1190 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1191 local PID="$PIDLIST"
1192 elif [ "$PIDLIST" ] ; then
1193 echo "more than one process: $1"
1194 else
1195 echo "no such process: $1"
1196 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001197 else
1198 echo "usage: stacks [pid|process name]"
1199 fi
1200
1201 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001202 # Determine whether the process is native
1203 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1204 # Dump stacks of Dalvik process
1205 local TRACES=/data/anr/traces.txt
1206 local ORIG=/data/anr/traces.orig
1207 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001208
Jeff Brownb12c2e52013-08-19 15:14:16 -07001209 # Keep original traces to avoid clobbering
1210 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001211
Jeff Brownb12c2e52013-08-19 15:14:16 -07001212 # Make sure we have a usable file
1213 adb shell touch $TRACES
1214 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001215
Jeff Brownb12c2e52013-08-19 15:14:16 -07001216 # Dump stacks and wait for dump to finish
1217 adb shell kill -3 $PID
1218 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001219
Jeff Brownb12c2e52013-08-19 15:14:16 -07001220 # Restore original stacks, and show current output
1221 adb shell mv $TRACES $TMP
1222 adb shell mv $ORIG $TRACES
1223 adb shell cat $TMP
1224 else
1225 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001226 local USE64BIT="$(is64bit $PID)"
1227 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001228 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001229 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001230}
1231
Michael Wrightaeed7212014-06-19 19:58:12 -07001232# Read the ELF header from /proc/$PID/exe to determine if the process is
1233# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001234function is64bit()
1235{
1236 local PID="$1"
1237 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001238 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001239 echo "64"
1240 else
1241 echo ""
1242 fi
1243 else
1244 echo ""
1245 fi
1246}
1247
Clark Scheff75b36a42014-12-23 13:30:51 -08001248function dddclient()
1249{
1250 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1251 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1252 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1253 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1254 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1255 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1256 local ARCH=$(get_build_var TARGET_ARCH)
1257 local GDB
1258 case "$ARCH" in
1259 arm) GDB=arm-linux-androideabi-gdb;;
1260 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1261 mips|mips64) GDB=mips64el-linux-android-gdb;;
1262 x86) GDB=x86_64-linux-android-gdb;;
1263 x86_64) GDB=x86_64-linux-android-gdb;;
1264 *) echo "Unknown arch $ARCH"; return 1;;
1265 esac
1266
1267 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1268 local EXE="$1"
1269 if [ "$EXE" ] ; then
1270 EXE=$1
1271 if [[ $EXE =~ ^[^/].* ]] ; then
1272 EXE="system/bin/"$EXE
1273 fi
1274 else
1275 EXE="app_process"
1276 fi
1277
1278 local PORT="$2"
1279 if [ "$PORT" ] ; then
1280 PORT=$2
1281 else
1282 PORT=":5039"
1283 fi
1284
1285 local PID="$3"
1286 if [ "$PID" ] ; then
1287 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1288 PID=`pid $3`
1289 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1290 # that likely didn't work because of returning multiple processes
1291 # try again, filtering by root processes (don't contain colon)
1292 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1293 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1294 then
1295 echo "Couldn't resolve '$3' to single PID"
1296 return 1
1297 else
1298 echo ""
1299 echo "WARNING: multiple processes matching '$3' observed, using root process"
1300 echo ""
1301 fi
1302 fi
1303 fi
1304 adb forward "tcp$PORT" "tcp$PORT"
1305 local USE64BIT="$(is64bit $PID)"
1306 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1307 sleep 2
1308 else
1309 echo ""
1310 echo "If you haven't done so already, do this first on the device:"
1311 echo " gdbserver $PORT /system/bin/$EXE"
1312 echo " or"
1313 echo " gdbserver $PORT --attach <PID>"
1314 echo ""
1315 fi
1316
1317 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1318 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1319
1320 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1321 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"
1322 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1323 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1324 # Enable special debugging for ART processes.
1325 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1326 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1327 fi
1328 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1329
1330 local WHICH_GDB=
1331 # 64-bit exe found
1332 if [ "$USE64BIT" != "" ] ; then
1333 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1334 # 32-bit exe / 32-bit platform
1335 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1336 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1337 # 32-bit exe / 64-bit platform
1338 else
1339 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1340 fi
1341
1342 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1343 else
1344 echo "Unable to determine build system output dir."
1345 fi
1346}
1347
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001348case `uname -s` in
1349 Darwin)
1350 function sgrep()
1351 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001352 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 -07001353 }
1354
1355 ;;
1356 *)
1357 function sgrep()
1358 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001359 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 -07001360 }
1361 ;;
1362esac
1363
Raghu Gandham8da43102012-07-25 19:57:22 -07001364function gettargetarch
1365{
1366 get_build_var TARGET_ARCH
1367}
1368
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001369function ggrep()
1370{
1371 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1372}
1373
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001374function jgrep()
1375{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001376 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 -07001377}
1378
1379function cgrep()
1380{
Dan Albert01961192014-11-22 10:16:01 -08001381 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 -07001382}
1383
1384function resgrep()
1385{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001386 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 -07001387}
1388
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001389function mangrep()
1390{
1391 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1392}
1393
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001394function sepgrep()
1395{
1396 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 "$@"
1397}
1398
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001399function rcgrep()
1400{
1401 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1402}
1403
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001404case `uname -s` in
1405 Darwin)
1406 function mgrep()
1407 {
Ying Wang324c2b22012-08-17 15:03:20 -07001408 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 -07001409 }
1410
1411 function treegrep()
1412 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001413 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 -07001414 }
1415
1416 ;;
1417 *)
1418 function mgrep()
1419 {
Ying Wang324c2b22012-08-17 15:03:20 -07001420 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 -07001421 }
1422
1423 function treegrep()
1424 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001425 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 -07001426 }
1427
1428 ;;
1429esac
1430
1431function getprebuilt
1432{
1433 get_abs_build_var ANDROID_PREBUILTS
1434}
1435
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001436function tracedmdump()
1437{
1438 T=$(gettop)
1439 if [ ! "$T" ]; then
1440 echo "Couldn't locate the top of the tree. Try setting TOP."
1441 return
1442 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001443 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001444 local arch=$(gettargetarch)
1445 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001446
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001447 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001448 if [ ! "$TRACE" ] ; then
1449 echo "usage: tracedmdump tracename"
1450 return
1451 fi
1452
Jack Veenstra60116fc2009-04-09 18:12:34 -07001453 if [ ! -r "$KERNEL" ] ; then
1454 echo "Error: cannot find kernel: '$KERNEL'"
1455 return
1456 fi
1457
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001458 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001459 if [ "$BASETRACE" = "$TRACE" ] ; then
1460 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1461 fi
1462
1463 echo "post-processing traces..."
1464 rm -f $TRACE/qtrace.dexlist
1465 post_trace $TRACE
1466 if [ $? -ne 0 ]; then
1467 echo "***"
1468 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1469 echo "***"
1470 return
1471 fi
1472 echo "generating dexlist output..."
1473 /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
1474 echo "generating dmtrace data..."
1475 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1476 echo "generating html file..."
1477 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1478 echo "done, see $TRACE/dmtrace.html for details"
1479 echo "or run:"
1480 echo " traceview $TRACE/dmtrace"
1481}
1482
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001483# communicate with a running device or emulator, set up necessary state,
1484# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001485function runhat()
1486{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001487 # process standard adb options
1488 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001489 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001490 adbTarget=$1
1491 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001492 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001493 adbTarget="$1 $2"
1494 shift 2
1495 fi
1496 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001497 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001498
1499 # runhat options
1500 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001501
1502 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001503 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001504 return
1505 fi
1506
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001507 # confirm hat is available
1508 if [ -z $(which hat) ]; then
1509 echo "hat is not available in this configuration."
1510 return
1511 fi
1512
Andy McFaddenb6289852010-07-12 08:00:19 -07001513 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001514 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001515 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001516 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001517 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001518 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001519 echo -n "> "
1520 read
1521
The Android Open Source Project88b60792009-03-03 19:28:42 -08001522 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001523
The Android Open Source Project88b60792009-03-03 19:28:42 -08001524 echo "Retrieving file $devFile..."
1525 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001526
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001528
The Android Open Source Project88b60792009-03-03 19:28:42 -08001529 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001530 echo "View the output by pointing your browser at http://localhost:7000/"
1531 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001532 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001533}
1534
1535function getbugreports()
1536{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001537 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001538
1539 if [ ! "$reports" ]; then
1540 echo "Could not locate any bugreports."
1541 return
1542 fi
1543
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001544 local report
1545 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001546 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001547 echo "/sdcard/bugreports/${report}"
1548 adb pull /sdcard/bugreports/${report} ${report}
1549 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001550 done
1551}
1552
Victoria Lease1b296b42012-08-21 15:44:06 -07001553function getsdcardpath()
1554{
1555 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1556}
1557
1558function getscreenshotpath()
1559{
1560 echo "$(getsdcardpath)/Pictures/Screenshots"
1561}
1562
1563function getlastscreenshot()
1564{
1565 local screenshot_path=$(getscreenshotpath)
1566 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1567 if [ "$screenshot" = "" ]; then
1568 echo "No screenshots found."
1569 return
1570 fi
1571 echo "${screenshot}"
1572 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1573}
1574
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001575function startviewserver()
1576{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001577 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001578 if [ $# -gt 0 ]; then
1579 port=$1
1580 fi
1581 adb shell service call window 1 i32 $port
1582}
1583
1584function stopviewserver()
1585{
1586 adb shell service call window 2
1587}
1588
1589function isviewserverstarted()
1590{
1591 adb shell service call window 3
1592}
1593
Romain Guyb84049a2010-10-04 16:56:11 -07001594function key_home()
1595{
1596 adb shell input keyevent 3
1597}
1598
1599function key_back()
1600{
1601 adb shell input keyevent 4
1602}
1603
1604function key_menu()
1605{
1606 adb shell input keyevent 82
1607}
1608
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001609function smoketest()
1610{
1611 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1612 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1613 return
1614 fi
1615 T=$(gettop)
1616 if [ ! "$T" ]; then
1617 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1618 return
1619 fi
1620
Ying Wang9cd17642012-12-13 10:52:07 -08001621 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001622 adb uninstall com.android.smoketest > /dev/null &&
1623 adb uninstall com.android.smoketest.tests > /dev/null &&
1624 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1625 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1626 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1627}
1628
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001629# simple shortcut to the runtest command
1630function runtest()
1631{
1632 T=$(gettop)
1633 if [ ! "$T" ]; then
1634 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1635 return
1636 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001637 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001638}
1639
The Android Open Source Project88b60792009-03-03 19:28:42 -08001640function godir () {
1641 if [[ -z "$1" ]]; then
1642 echo "Usage: godir <regex>"
1643 return
1644 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001645 T=$(gettop)
Brian Carlstromf2257422015-09-30 20:28:54 -07001646 if [ ! "$OUT_DIR" = "" ]; then
1647 mkdir -p $OUT_DIR
1648 FILELIST=$OUT_DIR/filelist
1649 else
1650 FILELIST=$T/filelist
1651 fi
1652 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001653 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001654 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001655 echo " Done"
1656 echo ""
1657 fi
1658 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001659 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001660 if [[ ${#lines[@]} = 0 ]]; then
1661 echo "Not found"
1662 return
1663 fi
1664 local pathname
1665 local choice
1666 if [[ ${#lines[@]} > 1 ]]; then
1667 while [[ -z "$pathname" ]]; do
1668 local index=1
1669 local line
1670 for line in ${lines[@]}; do
1671 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001672 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001673 done
1674 echo
1675 echo -n "Select one: "
1676 unset choice
1677 read choice
1678 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1679 echo "Invalid choice"
1680 continue
1681 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001682 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001683 done
1684 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001685 pathname=${lines[0]}
1686 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001687 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001688}
1689
Steve Kondikf00e7d92012-09-23 23:46:55 -07001690function installboot()
1691{
1692 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1693 then
1694 echo "No recovery.fstab found. Build recovery first."
1695 return 1
1696 fi
1697 if [ ! -e "$OUT/boot.img" ];
1698 then
1699 echo "No boot.img found. Run make bootimage first."
1700 return 1
1701 fi
1702 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1703 if [ -z "$PARTITION" ];
1704 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001705 # Try for RECOVERY_FSTAB_VERSION = 2
1706 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1707 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1708 if [ -z "$PARTITION" ];
1709 then
1710 echo "Unable to determine boot partition."
1711 return 1
1712 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001713 fi
1714 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001715 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001716 adb root
1717 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001718 adb wait-for-online shell mount /system 2>&1 > /dev/null
1719 adb wait-for-online remount
Dark Eyesdafcfe82015-12-11 20:51:02 -05001720 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Steve Kondikf00e7d92012-09-23 23:46:55 -07001721 then
1722 adb push $OUT/boot.img /cache/
1723 for i in $OUT/system/lib/modules/*;
1724 do
1725 adb push $i /system/lib/modules/
1726 done
1727 adb shell dd if=/cache/boot.img of=$PARTITION
1728 adb shell chmod 644 /system/lib/modules/*
1729 echo "Installation complete."
1730 else
Dark Eyesdafcfe82015-12-11 20:51:02 -05001731 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Steve Kondikf00e7d92012-09-23 23:46:55 -07001732 fi
1733}
1734
Steve Kondik83c03d52012-10-24 16:40:42 -07001735function installrecovery()
1736{
1737 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1738 then
1739 echo "No recovery.fstab found. Build recovery first."
1740 return 1
1741 fi
1742 if [ ! -e "$OUT/recovery.img" ];
1743 then
1744 echo "No recovery.img found. Run make recoveryimage first."
1745 return 1
1746 fi
1747 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1748 if [ -z "$PARTITION" ];
1749 then
Steve Kondik75f10762013-08-09 21:03:42 -07001750 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001751 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1752 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001753 if [ -z "$PARTITION" ];
1754 then
1755 echo "Unable to determine recovery partition."
1756 return 1
1757 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001758 fi
1759 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001760 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001761 adb root
1762 sleep 1
Dark Eyesdafcfe82015-12-11 20:51:02 -05001763 adb wait-for-online shell mount /system 2>&1 > /dev/null
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001764 adb wait-for-online remount
Dark Eyesdafcfe82015-12-11 20:51:02 -05001765 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD");
Steve Kondik83c03d52012-10-24 16:40:42 -07001766 then
1767 adb push $OUT/recovery.img /cache/
1768 adb shell dd if=/cache/recovery.img of=$PARTITION
1769 echo "Installation complete."
1770 else
Dark Eyesdafcfe82015-12-11 20:51:02 -05001771 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Steve Kondik83c03d52012-10-24 16:40:42 -07001772 fi
1773}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001774
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001775function mka() {
Khalid Zubairabcd1942015-10-06 11:00:55 -07001776 local T=$(gettop)
1777 if [ "$T" ]; then
1778 case `uname -s` in
1779 Darwin)
1780 make -C $T -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1781 ;;
1782 *)
1783 mk_timer schedtool -B -n 1 -e ionice -n 1 make -C $T -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
1784 ;;
1785 esac
1786
1787 else
1788 echo "Couldn't locate the top of the tree. Try setting TOP."
1789 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001790}
1791
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05301792function cmka() {
1793 if [ ! -z "$1" ]; then
1794 for i in "$@"; do
1795 case $i in
1796 bacon|otapackage|systemimage)
1797 mka installclean
1798 mka $i
1799 ;;
1800 *)
1801 mka clean-$i
1802 mka $i
1803 ;;
1804 esac
1805 done
1806 else
1807 mka clean
1808 mka
1809 fi
1810}
1811
Khalid Zubairfdc26cd2015-10-21 12:43:14 -07001812function mms() {
1813 local T=$(gettop)
1814 if [ -z "$T" ]
1815 then
1816 echo "Couldn't locate the top of the tree. Try setting TOP."
1817 return 1
1818 fi
1819
1820 case `uname -s` in
1821 Darwin)
1822 local NUM_CPUS=$(sysctl hw.ncpu|cut -d" " -f2)
1823 ONE_SHOT_MAKEFILE="__none__" \
1824 make -C $T -j $NUM_CPUS "$@"
1825 ;;
1826 *)
1827 local NUM_CPUS=$(cat /proc/cpuinfo | grep "^processor" | wc -l)
1828 ONE_SHOT_MAKEFILE="__none__" \
1829 mk_timer schedtool -B -n 1 -e ionice -n 1 \
1830 make -C $T -j $NUM_CPUS "$@"
1831 ;;
1832 esac
1833}
1834
1835
Matt Mower8dacaed2013-12-29 12:57:20 -06001836function repolastsync() {
1837 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
1838 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
1839 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
1840 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
1841}
1842
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001843function reposync() {
1844 case `uname -s` in
1845 Darwin)
1846 repo sync -j 4 "$@"
1847 ;;
1848 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001849 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001850 ;;
1851 esac
1852}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001853
1854function repodiff() {
1855 if [ -z "$*" ]; then
1856 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1857 return
1858 fi
1859 diffopts=$* repo forall -c \
1860 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1861}
1862
Khalid Zubair63eabff2016-02-02 12:00:14 -08001863# Return success if adb is up and not in recovery
1864function _adb_connected {
1865 {
1866 if [[ "$(adb get-state)" == device &&
1867 "$(adb shell test -e /sbin/recovery; echo $?)" == 0 ]]
1868 then
1869 return 0
1870 fi
1871 } 2>/dev/null
1872
1873 return 1
1874};
1875
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301876# Credit for color strip sed: http://goo.gl/BoIcm
1877function dopush()
1878{
1879 local func=$1
1880 shift
1881
1882 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
Khalid Zubair63eabff2016-02-02 12:00:14 -08001883 if ! _adb_connected; then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301884 echo "No device is online. Waiting for one..."
1885 echo "Please connect USB and/or enable USB debugging"
Khalid Zubair63eabff2016-02-02 12:00:14 -08001886 until _adb_connected; do
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301887 sleep 1
1888 done
1889 echo "Device Found."
1890 fi
1891
Dark Eyesdafcfe82015-12-11 20:51:02 -05001892 if (adb shell getprop ro.bliss.device | grep -q "$BLISS_BUILD") || [ "$FORCE_PUSH" == "true" ];
Chirayu Desai6dadb572012-12-26 10:53:58 +05301893 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07001894 # retrieve IP and PORT info if we're using a TCP connection
1895 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
1896 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301897 adb root &> /dev/null
1898 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07001899 if [ -n "$TCPIPPORT" ]
1900 then
1901 # adb root just killed our connection
1902 # so reconnect...
1903 adb connect "$TCPIPPORT"
1904 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301905 adb wait-for-device &> /dev/null
1906 sleep 0.3
1907 adb remount &> /dev/null
1908
Matt Mower668ea262014-05-20 02:52:23 -05001909 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00001910 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
1911 ret=$?;
1912 if [ $ret -ne 0 ]; then
1913 rm -f $OUT/.log;return $ret
1914 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301915
1916 # Install: <file>
LuK133756041e72015-12-01 14:53:23 +01001917 if [ `uname` = "Linux" ]; then
1918 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)"
1919 else
1920 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)"
1921 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301922
1923 # Copy: <file>
LuK133756041e72015-12-01 14:53:23 +01001924 if [ `uname` = "Linux" ]; then
1925 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)"
1926 else
1927 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)"
1928 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301929
Matt Mowerdfd4c082014-05-20 02:52:23 -05001930 # If any files are going to /data, push an octal file permissions reader to device
1931 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
1932 CHKPERM="/data/local/tmp/chkfileperm.sh"
1933(
1934cat <<'EOF'
1935#!/system/xbin/sh
1936FILE=$@
1937if [ -e $FILE ]; then
1938 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
1939fi
1940EOF
1941) > $OUT/.chkfileperm.sh
1942 echo "Pushing file permissions checker to device"
1943 adb push $OUT/.chkfileperm.sh $CHKPERM
1944 adb shell chmod 755 $CHKPERM
1945 rm -f $OUT/.chkfileperm.sh
1946 fi
1947
Matt Mower668ea262014-05-20 02:52:23 -05001948 stop_n_start=false
Luca Stefani406c2af2015-11-02 05:33:10 -08001949 for FILE in $(echo $LOC | tr " " "\n"); do
Matt Mowerdfd4c082014-05-20 02:52:23 -05001950 # Make sure file is in $OUT/system or $OUT/data
Matt Mower668ea262014-05-20 02:52:23 -05001951 case $FILE in
Matt Mowerdfd4c082014-05-20 02:52:23 -05001952 $OUT/system/*|$OUT/data/*)
Matt Mower668ea262014-05-20 02:52:23 -05001953 # Get target file name (i.e. /system/bin/adb)
1954 TARGET=$(echo $FILE | sed "s#$OUT##")
1955 ;;
1956 *) continue ;;
1957 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301958
Matt Mower668ea262014-05-20 02:52:23 -05001959 case $TARGET in
Matt Mowerdfd4c082014-05-20 02:52:23 -05001960 /data/*)
1961 # fs_config only sets permissions and se labels for files pushed to /system
1962 if [ -n "$CHKPERM" ]; then
1963 OLDPERM=$(adb shell $CHKPERM $TARGET)
1964 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
1965 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
1966 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
1967 fi
1968 echo "Pushing: $TARGET"
1969 adb push $FILE $TARGET
1970 if [ -n "$OLDPERM" ]; then
1971 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
1972 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
1973 adb shell chmod "$OLDPERM" $TARGET
1974 else
1975 echo "$TARGET did not exist previously, you should set file permissions manually"
1976 fi
1977 adb shell restorecon "$TARGET"
1978 ;;
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07001979 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05001980 # Only need to stop services once
1981 if ! $stop_n_start; then
1982 adb shell stop
1983 stop_n_start=true
1984 fi
1985 echo "Pushing: $TARGET"
1986 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301987 ;;
1988 *)
Matt Mower668ea262014-05-20 02:52:23 -05001989 echo "Pushing: $TARGET"
1990 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301991 ;;
Matt Mower668ea262014-05-20 02:52:23 -05001992 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301993 done
Matt Mowerdfd4c082014-05-20 02:52:23 -05001994 if [ -n "$CHKPERM" ]; then
1995 adb shell rm $CHKPERM
1996 fi
Matt Mower668ea262014-05-20 02:52:23 -05001997 if $stop_n_start; then
1998 adb shell start
1999 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302000 rm -f $OUT/.log
2001 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302002 else
Dark Eyesdafcfe82015-12-11 20:51:02 -05002003 echo "The connected device does not appear to be $BLISS_BUILD, run away!"
Chirayu Desai6dadb572012-12-26 10:53:58 +05302004 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302005}
2006
2007alias mmp='dopush mm'
2008alias mmmp='dopush mmm'
Martin Brabhamb77db582016-02-05 15:59:21 -05002009alias mmap='dopush mma'
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302010alias mkap='dopush mka'
2011alias cmkap='dopush cmka'
2012
Chirayu Desai4a319b82013-06-05 20:14:33 +05302013function repopick() {
2014 T=$(gettop)
2015 $T/build/tools/repopick.py $@
2016}
2017
Chirayu Desaib89b3242013-06-30 10:04:25 +05302018function fixup_common_out_dir() {
2019 common_out_dir=$(get_build_var OUT_DIR)/target/common
2020 target_device=$(get_build_var TARGET_DEVICE)
Dark Eyesdafcfe82015-12-11 20:51:02 -05002021 if [ ! -z $BLISS_FIXUP_COMMON_OUT ]; then
Chirayu Desaib89b3242013-06-30 10:04:25 +05302022 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2023 mv ${common_out_dir} ${common_out_dir}-${target_device}
2024 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2025 else
2026 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2027 mkdir -p ${common_out_dir}-${target_device}
2028 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2029 fi
2030 else
2031 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2032 mkdir -p ${common_out_dir}
2033 fi
2034}
2035
Neil Fuller2c54f172015-11-19 15:51:47 +00002036# Force JAVA_HOME to point to java 1.7/1.8 if it isn't already set.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002037function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002038 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002039 # we can reset it later, depending on the version of java the build
2040 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002041 #
2042 # If we don't do this, the JAVA_HOME value set by the first call to
2043 # build/envsetup.sh will persist forever.
2044 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2045 export JAVA_HOME=""
2046 fi
2047
Andy McFaddenbd960942010-06-24 12:52:51 -07002048 if [ ! "$JAVA_HOME" ]; then
Neil Fuller2c54f172015-11-19 15:51:47 +00002049 if [ ! "$EXPERIMENTAL_USE_JAVA8" ]; then
2050 case `uname -s` in
2051 Darwin)
2052 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2053 ;;
2054 *)
2055 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2056 ;;
2057 esac
Adrian DC1c61d082016-10-06 13:42:43 +02002058 fi
2059 if [ ! "$JAVA_HOME" ] || [ ! -d "$JAVA_HOME" ]; then
Neil Fuller2c54f172015-11-19 15:51:47 +00002060 case `uname -s` in
2061 Darwin)
2062 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
2063 ;;
2064 *)
2065 export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
2066 ;;
2067 esac
2068 fi
Narayan Kamath9260bba2014-01-17 10:05:25 +00002069
2070 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2071 # we can change it on the next envsetup.sh, if required.
2072 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002073 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002074}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002075
Alex Rayf0d08eb2013-03-08 15:15:06 -08002076# Print colored exit condition
2077function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002078 "$@"
2079 local retval=$?
2080 if [ $retval -ne 0 ]
2081 then
Roman Birgead9a5c2015-10-16 10:29:06 -07002082 printf "\e[0;31mFAILURE\e[00m\n"
Michael Wrighteb733842013-03-08 17:34:02 -08002083 else
Roman Birgead9a5c2015-10-16 10:29:06 -07002084 printf "\e[0;32mSUCCESS\e[00m\n"
Michael Wrighteb733842013-03-08 17:34:02 -08002085 fi
2086 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002087}
2088
Ying Wanged21d4c2014-08-24 22:14:19 -07002089function get_make_command()
2090{
2091 echo command make
2092}
2093
Anthony King40b093f2015-04-30 22:19:48 +01002094function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002095{
2096 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002097 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002098 local ret=$?
2099 local end_time=$(date +"%s")
2100 local tdiff=$(($end_time-$start_time))
2101 local hours=$(($tdiff / 3600 ))
2102 local mins=$((($tdiff % 3600) / 60))
2103 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002104 local ncolors=$(tput colors 2>/dev/null)
2105 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2106 color_failed="\e[0;31m"
2107 color_success="\e[0;32m"
Roman Birgead9a5c2015-10-16 10:29:06 -07002108 color_reset="\e[0m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002109 else
2110 color_failed=""
2111 color_success=""
2112 color_reset=""
2113 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002114 echo
2115 if [ $ret -eq 0 ] ; then
Roman Birgead9a5c2015-10-16 10:29:06 -07002116 printf "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002117 else
Roman Birgead9a5c2015-10-16 10:29:06 -07002118 printf "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002119 fi
2120 if [ $hours -gt 0 ] ; then
2121 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2122 elif [ $mins -gt 0 ] ; then
2123 printf "(%02g:%02g (mm:ss))" $mins $secs
2124 elif [ $secs -gt 0 ] ; then
2125 printf "(%s seconds)" $secs
2126 fi
Roman Birgead9a5c2015-10-16 10:29:06 -07002127 printf " ####${color_reset}\n\n"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002128 return $ret
2129}
2130
Anthony King40b093f2015-04-30 22:19:48 +01002131function make()
2132{
2133 mk_timer $(get_make_command) "$@"
2134}
2135
Khalid Zubair695992c2016-02-08 16:27:55 -08002136function __detect_shell() {
Raphael Moll70a86b02011-06-20 16:03:14 -07002137 case `ps -o command -p $$` in
2138 *bash*)
Khalid Zubair695992c2016-02-08 16:27:55 -08002139 echo bash
Raphael Moll70a86b02011-06-20 16:03:14 -07002140 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002141 *zsh*)
Khalid Zubair695992c2016-02-08 16:27:55 -08002142 echo zsh
Emilio López7ff9caa2013-11-03 13:05:43 -03002143 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002144 *)
Khalid Zubair695992c2016-02-08 16:27:55 -08002145 echo unknown
2146 return 1
Raphael Moll70a86b02011-06-20 16:03:14 -07002147 ;;
2148 esac
Khalid Zubair695992c2016-02-08 16:27:55 -08002149 return
2150}
2151
2152
2153if ! __detect_shell > /dev/null; then
2154 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002155fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002156
2157# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002158for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2159 `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 -08002160do
2161 echo "including $f"
2162 . $f
2163done
2164unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002165
Kyle Ladd031a0b62013-09-11 20:43:42 -04002166# Add completions
2167check_bash_version && {
Dark Eyesdafcfe82015-12-11 20:51:02 -05002168 dirs="sdk/bash_completion vendor/bliss/bash_completion"
Kyle Ladd031a0b62013-09-11 20:43:42 -04002169 for dir in $dirs; do
2170 if [ -d ${dir} ]; then
2171 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2172 echo "including $f"
2173 . $f
2174 done
2175 fi
2176 done
2177}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302178
2179export ANDROID_BUILD_TOP=$(gettop)