blob: f5de79c3c3a5b3a41b1b5367e280f365e78bbb27 [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.
Anthony Kingd4dbe2d2014-11-05 22:46:32 +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.
Anthony Kingd4dbe2d2014-11-05 22:46:32 +000013- mmp: Builds all of the modules in the current directory and pushes them to the device.
14- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Nicholas Flinthamb0f1e292014-12-03 22:31:49 +000015- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070016- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070017- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070018- jgrep: Greps on all local Java files.
19- resgrep: Greps on all local res/*.xml files.
Jeff Brown46cbd202014-07-26 15:15:41 -070020- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080021- godir: Go to the directory containing a file.
Steve Kondik10789d72012-09-17 11:33:18 -070022- aospremote: Add git remote for matching AOSP repository
Steve Kondikd412ec52013-10-27 13:34:36 -070023- cafremote: Add git remote for matching CodeAurora repository.
Nicholas Flinthamb0f1e292014-12-03 22:31:49 +000024- cmremote: Add a git remote for matching CM repository.
FuckingShitUpe79ba2d2014-12-19 17:57:26 -060025- brokenremote: Add a git remote for matching BROKEN repository.
Andrew Sutherland4bafca52011-11-18 00:45:55 -060026- mka: Builds using SCHED_BATCH on all processors
27- reposync: Parallel repo sync using ionice and SCHED_BATCH
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070028
29Look at the source to view more functions. The complete list is:
30EOF
31 T=$(gettop)
32 local A
33 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070034 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070035 A="$A $i"
36 done
37 echo $A
38}
39
40# Get the value of a build variable as an absolute path.
41function get_abs_build_var()
42{
43 T=$(gettop)
44 if [ ! "$T" ]; then
45 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
46 return
47 fi
Ying Wang9cd17642012-12-13 10:52:07 -080048 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070049 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070050}
51
52# Get the exact value of a build variable.
53function get_build_var()
54{
55 T=$(gettop)
56 if [ ! "$T" ]; then
57 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
58 return
59 fi
Andrew Boie6905e212013-12-19 13:21:46 -080060 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070061 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080062}
63
64# check to see if the supplied product is one we can build
65function check_product()
66{
67 T=$(gettop)
68 if [ ! "$T" ]; then
69 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
70 return
71 fi
Anthony Kingd4dbe2d2014-11-05 22:46:32 +000072
FuckingShitUpe79ba2d2014-12-19 17:57:26 -060073 if (echo -n $1 | grep -q -e "^broken_") ; then
74 BROKEN_BUILD=$(echo -n $1 | sed -e 's/^broken_//g')
Anthony Kingd4dbe2d2014-11-05 22:46:32 +000075 else
FuckingShitUpe79ba2d2014-12-19 17:57:26 -060076 BROKEN_BUILD=
Anthony Kingd4dbe2d2014-11-05 22:46:32 +000077 fi
FuckingShitUpe79ba2d2014-12-19 17:57:26 -060078 export BROKEN_BUILD
Anthony Kingd4dbe2d2014-11-05 22:46:32 +000079
Jeff Browne33ba4c2011-07-11 22:11:46 -070080 TARGET_PRODUCT=$1 \
81 TARGET_BUILD_VARIANT= \
82 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070083 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080084 get_build_var TARGET_DEVICE > /dev/null
85 # hide successful answers, but allow the errors to show
86}
87
88VARIANT_CHOICES=(user userdebug eng)
89
90# check to see if the supplied variant is valid
91function check_variant()
92{
93 for v in ${VARIANT_CHOICES[@]}
94 do
95 if [ "$v" = "$1" ]
96 then
97 return 0
98 fi
99 done
100 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700101}
102
103function setpaths()
104{
105 T=$(gettop)
106 if [ ! "$T" ]; then
107 echo "Couldn't locate the top of the tree. Try setting TOP."
108 return
109 fi
110
111 ##################################################################
112 # #
113 # Read me before you modify this code #
114 # #
115 # This function sets ANDROID_BUILD_PATHS to what it is adding #
116 # to PATH, and the next time it is run, it removes that from #
117 # PATH. This is required so lunch can be run more than once #
118 # and still have working paths. #
119 # #
120 ##################################################################
121
Raphael Mollc639c782011-06-20 17:25:01 -0700122 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
123 # due to "C:\Program Files" being in the path.
124
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700125 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700126 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700127 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
128 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700129 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700130 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800131 # strip leading ':', if any
132 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500133 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700134
135 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700136 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700137 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700138
Ben Cheng8bc4c432012-11-16 13:29:13 -0800139 # defined in core/config.mk
140 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700141 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800142 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800143
Raphael Mollc639c782011-06-20 17:25:01 -0700144 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800145 export ANDROID_TOOLCHAIN=
146 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200147 local ARCH=$(get_build_var TARGET_ARCH)
148 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400149 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700150 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400151 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
152 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800153 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200154 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800155 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700156 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700157 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700158 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000159 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200160 *)
161 echo "Can't find toolchain for unknown architecture: $ARCH"
162 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700163 ;;
164 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700165 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800166 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700167 fi
Raphael732936d2011-06-22 14:35:32 -0700168
Ben Chengfba67bf2014-02-25 10:27:07 -0800169 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
170 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
171 fi
172
173 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700174 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700175 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800176 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800177 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700178 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100179 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
180 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700181 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700182 ;;
183 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700184 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700185 ;;
186 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700187
Ying Wang564f9122013-03-29 17:40:14 -0700188 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
Ying Wang2a859d52014-06-30 10:25:33 -0700189 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 +0200190
191 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
192 # to ensure that the corresponding 'emulator' binaries are used.
193 case $(uname -s) in
194 Darwin)
195 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
196 ;;
197 Linux)
198 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
199 ;;
200 *)
201 ANDROID_EMULATOR_PREBUILTS=
202 ;;
203 esac
204 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700205 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200206 export ANDROID_EMULATOR_PREBUILTS
207 fi
208
Ying Wangaa1c9b52012-11-26 20:51:59 -0800209 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800210
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500211 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900212 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500213 if [ -n "$JAVA_HOME" ]; then
214 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900215 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
216 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500217 fi
218
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800219 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700220 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
221 export OUT=$ANDROID_PRODUCT_OUT
222
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700223 unset ANDROID_HOST_OUT
224 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
225
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800226 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700227 # TODO: fix the path
228 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
229}
230
231function printconfig()
232{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 T=$(gettop)
234 if [ ! "$T" ]; then
235 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
236 return
237 fi
238 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239}
240
241function set_stuff_for_environment()
242{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800243 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500244 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800245 setpaths
246 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247
Ben Chengaac3f812013-08-13 14:38:15 -0700248 # With this environment variable new GCC can apply colors to warnings/errors
249 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700250}
251
252function set_sequence_number()
253{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700254 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255}
256
257function settitle()
258{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800259 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700260 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700261 local product=$TARGET_PRODUCT
262 local variant=$TARGET_BUILD_VARIANT
263 local apps=$TARGET_BUILD_APPS
Steve Kondik06c3d912012-12-27 15:28:34 -0800264 if [ -z "$PROMPT_COMMAND" ]; then
265 # No prompts
266 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
267 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
268 # Prompts exist, but no hardstatus
269 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700270 fi
Steve Kondik06c3d912012-12-27 15:28:34 -0800271 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Lais0e485b82013-06-03 15:15:39 -0500272 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondik06c3d912012-12-27 15:28:34 -0800273 fi
274
275 if [ -z "$apps" ]; then
276 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
277 else
278 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
279 fi
280 export ANDROID_PROMPT_PREFIX
281
282 # Inject build data into hardstatus
283 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 -0800284 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700285}
286
Kenny Root52aa81c2011-07-15 11:07:06 -0700287function addcompletions()
288{
Kenny Root52aa81c2011-07-15 11:07:06 -0700289 # Keep us from trying to run in something that isn't bash.
290 if [ -z "${BASH_VERSION}" ]; then
291 return
292 fi
293
294 # Keep us from trying to run in bash that's too old.
James Roberts-Thomsonddd4bd62013-04-16 15:53:39 +1200295 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kenny Root52aa81c2011-07-15 11:07:06 -0700296 return
297 fi
298
299 dir="sdk/bash_completion"
300 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700301 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700302 echo "including $f"
303 . $f
304 done
305 fi
306}
307
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700308function choosetype()
309{
310 echo "Build type choices are:"
311 echo " 1. release"
312 echo " 2. debug"
313 echo
314
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800315 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700316 DEFAULT_NUM=1
317 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700318
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800319 export TARGET_BUILD_TYPE=
320 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700321 while [ -z $TARGET_BUILD_TYPE ]
322 do
323 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800324 if [ -z "$1" ] ; then
325 read ANSWER
326 else
327 echo $1
328 ANSWER=$1
329 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330 case $ANSWER in
331 "")
332 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
333 ;;
334 1)
335 export TARGET_BUILD_TYPE=release
336 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800337 release)
338 export TARGET_BUILD_TYPE=release
339 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700340 2)
341 export TARGET_BUILD_TYPE=debug
342 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800343 debug)
344 export TARGET_BUILD_TYPE=debug
345 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700346 *)
347 echo
348 echo "I didn't understand your response. Please try again."
349 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700350 ;;
351 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352 if [ -n "$1" ] ; then
353 break
354 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355 done
356
357 set_stuff_for_environment
358}
359
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800360#
361# This function isn't really right: It chooses a TARGET_PRODUCT
362# based on the list of boards. Usually, that gets you something
363# that kinda works with a generic product, but really, you should
364# pick a product by name.
365#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700366function chooseproduct()
367{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700368 if [ "x$TARGET_PRODUCT" != x ] ; then
369 default_value=$TARGET_PRODUCT
370 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700371 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700372 fi
373
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800374 export TARGET_PRODUCT=
375 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700376 while [ -z "$TARGET_PRODUCT" ]
377 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700378 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800379 if [ -z "$1" ] ; then
380 read ANSWER
381 else
382 echo $1
383 ANSWER=$1
384 fi
385
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700386 if [ -z "$ANSWER" ] ; then
387 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800388 else
389 if check_product $ANSWER
390 then
391 export TARGET_PRODUCT=$ANSWER
392 else
393 echo "** Not a valid product: $ANSWER"
394 fi
395 fi
396 if [ -n "$1" ] ; then
397 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700398 fi
399 done
400
401 set_stuff_for_environment
402}
403
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800404function choosevariant()
405{
406 echo "Variant choices are:"
407 local index=1
408 local v
409 for v in ${VARIANT_CHOICES[@]}
410 do
411 # The product name is the name of the directory containing
412 # the makefile we found, above.
413 echo " $index. $v"
414 index=$(($index+1))
415 done
416
417 local default_value=eng
418 local ANSWER
419
420 export TARGET_BUILD_VARIANT=
421 while [ -z "$TARGET_BUILD_VARIANT" ]
422 do
423 echo -n "Which would you like? [$default_value] "
424 if [ -z "$1" ] ; then
425 read ANSWER
426 else
427 echo $1
428 ANSWER=$1
429 fi
430
431 if [ -z "$ANSWER" ] ; then
432 export TARGET_BUILD_VARIANT=$default_value
433 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
434 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800435 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800436 fi
437 else
438 if check_variant $ANSWER
439 then
440 export TARGET_BUILD_VARIANT=$ANSWER
441 else
442 echo "** Not a valid variant: $ANSWER"
443 fi
444 fi
445 if [ -n "$1" ] ; then
446 break
447 fi
448 done
449}
450
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700451function choosecombo()
452{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700453 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700454
455 echo
456 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700457 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458
459 echo
460 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700461 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800462
463 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700464 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800465 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466}
467
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800468# Clear this variable. It will be built up again when the vendorsetup.sh
469# files are included at the end of this file.
470unset LUNCH_MENU_CHOICES
471function add_lunch_combo()
472{
473 local new_combo=$1
474 local c
475 for c in ${LUNCH_MENU_CHOICES[@]} ; do
476 if [ "$new_combo" = "$c" ] ; then
477 return
478 fi
479 done
480 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
481}
482
483# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700484add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800485add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000486add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800487add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000488add_lunch_combo aosp_x86-eng
489add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800490
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700491function print_lunch_menu()
492{
493 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700494 echo
495 echo "You're building on" $uname
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700496 echo
497 echo "Lunch menu... pick a combo:"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800498
499 local i=1
500 local choice
501 for choice in ${LUNCH_MENU_CHOICES[@]}
502 do
Anthony Kingd4dbe2d2014-11-05 22:46:32 +0000503 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504 i=$(($i+1))
Anthony Kingd4dbe2d2014-11-05 22:46:32 +0000505 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800506
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700507 echo
508}
509
Nicholas Flintham133c1882013-11-01 17:40:32 +0000510function brunch()
511{
512 breakfast $*
513 if [ $? -eq 0 ]; then
FuckingShitUpe79ba2d2014-12-19 17:57:26 -0600514mka broken
Nicholas Flintham133c1882013-11-01 17:40:32 +0000515 else
516echo "No such item in brunch menu. Try 'breakfast'"
517 return 1
518 fi
519return $?
520}
521
522function mka() {
523 case `uname -s` in
524 Darwin)
525 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
526 ;;
527 *)
528 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
529 ;;
530 esac
531}
532
533function breakfast()
534{
535 target=$1
JustArchi899b1272014-06-22 14:37:30 +0200536 local variant=$2
FuckingShitUpe79ba2d2014-12-19 17:57:26 -0600537 BROKEN_DEVICES_ONLY="true"
Nicholas Flintham133c1882013-11-01 17:40:32 +0000538 unset LUNCH_MENU_CHOICES
539 add_lunch_combo full-eng
FuckingShitUpe79ba2d2014-12-19 17:57:26 -0600540 for f in `/bin/ls vendor/broken/vendorsetup.sh 2> /dev/null`
Nicholas Flintham133c1882013-11-01 17:40:32 +0000541 do
542echo "including $f"
543 . $f
544 done
545unset f
546
547 if [ $# -eq 0 ]; then
548 # No arguments, so let's have the full menu
549 lunch
550 else
551echo "z$target" | grep -q "-"
552 if [ $? -eq 0 ]; then
553 # A buildtype was specified, assume a full device name
554 lunch $target
555 else
FuckingShitUpe79ba2d2014-12-19 17:57:26 -0600556 # This is probably just the BROKEN model name
JustArchi899b1272014-06-22 14:37:30 +0200557 if [ -z "$variant" ]; then
558 variant="userdebug"
559 fi
FuckingShitUpe79ba2d2014-12-19 17:57:26 -0600560 lunch broken_$target-$variant
Nicholas Flintham133c1882013-11-01 17:40:32 +0000561 fi
562fi
563return $?
564}
565
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700566function lunch()
567{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800568 local answer
569
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700570 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800571 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700572 else
573 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700574 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800575 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700576 fi
577
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800578 local selection=
579
580 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700582 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
584 then
585 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
586 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800587 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 fi
589 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
590 then
591 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 fi
593
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800594 if [ -z "$selection" ]
595 then
596 echo
597 echo "Invalid lunch combo: $answer"
598 return 1
599 fi
600
Joe Onoratoda12daf2010-06-09 18:18:31 -0700601 export TARGET_BUILD_APPS=
602
Jeff Browne33ba4c2011-07-11 22:11:46 -0700603 local product=$(echo -n $selection | sed -e "s/-.*$//")
604 check_product $product
605 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 then
FuckingShitUpe79ba2d2014-12-19 17:57:26 -0600607 # if we can't find a product, try to grab it off the BrokenOs github
Anthony King5f63b352014-11-05 19:25:54 +0000608 T=$(gettop)
609 pushd $T > /dev/null
610 build/tools/roomservice.py $product
611 popd > /dev/null
612 check_product $product
613 else
614 build/tools/roomservice.py $product true
615 fi
616 if [ $? -ne 0 ]
617 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700618 echo
619 echo "** Don't have a product spec for: '$product'"
620 echo "** Do you have the right repo manifest?"
621 product=
622 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800623
Jeff Browne33ba4c2011-07-11 22:11:46 -0700624 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
625 check_variant $variant
626 if [ $? -ne 0 ]
627 then
628 echo
629 echo "** Invalid variant: '$variant'"
630 echo "** Must be one of ${VARIANT_CHOICES[@]}"
631 variant=
632 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800633
Jeff Browne33ba4c2011-07-11 22:11:46 -0700634 if [ -z "$product" -o -z "$variant" ]
635 then
636 echo
637 return 1
638 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800639
Jeff Browne33ba4c2011-07-11 22:11:46 -0700640 export TARGET_PRODUCT=$product
641 export TARGET_BUILD_VARIANT=$variant
642 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700643
644 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645
Jiangyi069ceb52014-07-18 15:53:13 -0400646 if [[ $USE_PREBUILT_CHROMIUM -eq 1 ]]; then
647 chromium_prebuilt
648 else
649 # Unset flag in case user opts out later on
650 export PRODUCT_PREBUILT_WEBVIEWCHROMIUM=""
651 fi
652
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655}
656
Jeff Davidson513d7a42010-08-02 10:00:44 -0700657# Tab completion for lunch.
658function _lunch()
659{
660 local cur prev opts
661 COMPREPLY=()
662 cur="${COMP_WORDS[COMP_CWORD]}"
663 prev="${COMP_WORDS[COMP_CWORD-1]}"
664
665 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
666 return 0
667}
Emilio López3113f822013-11-03 13:02:13 -0300668complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700669
Joe Onoratoda12daf2010-06-09 18:18:31 -0700670# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700671# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700672function tapas()
673{
Ying Wangb541ab62014-05-29 17:57:40 -0700674 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 -0700675 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Ying Wangb541ab62014-05-29 17:57:40 -0700676 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677
Ying Wang67f02922012-08-22 10:25:20 -0700678 if [ $(echo $arch | wc -w) -gt 1 ]; then
679 echo "tapas: Error: Multiple build archs supplied: $arch"
680 return
681 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700682 if [ $(echo $variant | wc -w) -gt 1 ]; then
683 echo "tapas: Error: Multiple build variants supplied: $variant"
684 return
685 fi
Ying Wang67f02922012-08-22 10:25:20 -0700686
687 local product=full
688 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700689 x86) product=full_x86;;
690 mips) product=full_mips;;
691 armv5) product=generic_armv5;;
692 arm64) product=aosp_arm64;;
693 x86_64) product=aosp_x86_64;;
694 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700695 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700696 if [ -z "$variant" ]; then
697 variant=eng
698 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700699 if [ -z "$apps" ]; then
700 apps=all
701 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700702
Ying Wang67f02922012-08-22 10:25:20 -0700703 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700704 export TARGET_BUILD_VARIANT=$variant
Joe Onoratoda12daf2010-06-09 18:18:31 -0700705 export TARGET_BUILD_TYPE=release
706 export TARGET_BUILD_APPS=$apps
707
708 set_stuff_for_environment
709 printconfig
710}
711
Anthony Kingd4dbe2d2014-11-05 22:46:32 +0000712# Credit for color strip sed: http://goo.gl/BoIcm
713function mmmp()
714{
715 if [[ $# < 1 || $1 == "--help" || $1 == "-h" ]]; then
716 echo "mmmp [make arguments] <path-to-project>"
717 return 1
718 fi
719
720 # Get product name from cm_<product>
721 PRODUCT=`echo $TARGET_PRODUCT | tr "_" "\n" | tail -n 1`
722
723 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
724 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
725 echo "No device is online. Waiting for one..."
726 echo "Please connect USB and/or enable USB debugging"
727 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
728 sleep 1
729 done
730 echo "Device Found.."
731 fi
732
733 adb root &> /dev/null
734 sleep 0.3
735 adb wait-for-device &> /dev/null
736 sleep 0.3
737 adb remount &> /dev/null
738
739 mmm $* | tee .log
740
741 # Install: <file>
742 LOC=$(cat .log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Install' | cut -d ':' -f 2)
743
744 # Copy: <file>
745 LOC=$LOC $(cat .log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep 'Copy' | cut -d ':' -f 2)
746
747 for FILE in $LOC; do
748 # Get target file name (i.e. system/bin/adb)
749 TARGET=$(echo $FILE | sed "s/\/$PRODUCT\//\n/" | tail -n 1)
750
751 # Don't send files that are not in /system.
752 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
753 continue
754 else
755 echo "Pushing: $TARGET"
756 adb push $FILE $TARGET
757 fi
758 done
759 rm -f .log
760 return 0
761}
762
763alias mmp='mmmp .'
764
Chirayu Desaie2595d32012-10-13 13:05:29 +0530765function eat()
766{
767 if [ "$OUT" ] ; then
FuckingShitUpe79ba2d2014-12-19 17:57:26 -0600768 MODVERSION=`sed -n -e'/ro\.broken\.version/s/.*=//p' $OUT/system/build.prop`
769 ZIPFILE=broken-$MODVERSION.zip
Chirayu Desaie2595d32012-10-13 13:05:29 +0530770 ZIPPATH=$OUT/$ZIPFILE
771 if [ ! -f $ZIPPATH ] ; then
772 echo "Nothing to eat"
773 return 1
774 fi
775 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
776 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
777 echo "No device is online. Waiting for one..."
778 echo "Please connect USB and/or enable USB debugging"
779 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
780 sleep 1
781 done
782 echo "Device Found.."
783 fi
784 # if adbd isn't root we can't write to /cache/recovery/
785 adb root
786 sleep 1
787 adb wait-for-device
Steve Kondik000cdef2013-04-13 07:19:52 -0700788 cat << EOF > /tmp/command
789--sideload
Chirayu Desaie2595d32012-10-13 13:05:29 +0530790EOF
Steve Kondik000cdef2013-04-13 07:19:52 -0700791 if adb push /tmp/command /cache/recovery/ ; then
792 echo "Rebooting into recovery for sideload installation"
793 adb reboot recovery
794 adb wait-for-sideload
795 adb sideload $ZIPPATH
Chirayu Desaie2595d32012-10-13 13:05:29 +0530796 fi
Steve Kondik000cdef2013-04-13 07:19:52 -0700797 rm /tmp/command
Chirayu Desaie2595d32012-10-13 13:05:29 +0530798 else
799 echo "Nothing to eat"
800 return 1
801 fi
802 return $?
803}
804
Nebojsa Cvetkovicfff0af82012-11-09 23:02:54 +0000805function omnom
806{
807 brunch $*
808 eat
809}
810
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700811function gettop
812{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800813 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700814 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700815 # The following circumlocution ensures we remove symlinks from TOP.
816 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700817 else
818 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800819 # The following circumlocution (repeated below as well) ensures
820 # that we record the true directory name and not one that is
821 # faked up with symlink names.
822 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800824 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700825 T=
826 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800827 \cd ..
synergyb112a402013-07-05 19:47:47 -0700828 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829 done
Ying Wang9cd17642012-12-13 10:52:07 -0800830 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831 if [ -f "$T/$TOPFILE" ]; then
832 echo $T
833 fi
834 fi
835 fi
836}
837
Andrew Hsieh906cb782013-09-10 17:37:14 +0800838# Return driver for "make", if any (eg. static analyzer)
839function getdriver()
840{
841 local T="$1"
842 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
843 if [ -n "$WITH_STATIC_ANALYZER" ]; then
844 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800845$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
846--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800847--status-bugs \
848--top=$T"
849 fi
850}
851
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700852function m()
853{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800854 local T=$(gettop)
855 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700856 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800857 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700858 else
859 echo "Couldn't locate the top of the tree. Try setting TOP."
860 fi
861}
862
863function findmakefile()
864{
865 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800866 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867 T=
868 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700869 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870 if [ -f "$T/Android.mk" ]; then
871 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800872 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873 return
874 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800875 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700876 done
Ying Wang9cd17642012-12-13 10:52:07 -0800877 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700878}
879
880function mm()
881{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800882 local T=$(gettop)
883 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884 # If we're sitting in the root of the build tree, just do a
885 # normal make.
886 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800887 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700888 else
889 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800890 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700891 local MODULES=
892 local GET_INSTALL_PATH=
893 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700894 # Remove the path to top as the makefilepath needs to be relative
895 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700896 if [ ! "$T" ]; then
897 echo "Couldn't locate the top of the tree. Try setting TOP."
898 elif [ ! "$M" ]; then
899 echo "Couldn't locate a makefile from the current directory."
900 else
Ying Wanga7deb082013-08-16 13:24:47 -0700901 for ARG in $@; do
902 case $ARG in
903 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
904 esac
905 done
906 if [ -n "$GET_INSTALL_PATH" ]; then
907 MODULES=
908 ARGS=GET-INSTALL-PATH
909 else
910 MODULES=all_modules
911 ARGS=$@
912 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700913 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700914 fi
915 fi
916}
917
918function mmm()
919{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800920 local T=$(gettop)
921 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800923 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800924 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800925 local ARGS=
926 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700927 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800928 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
929 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
930 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800931 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
932 if [ "$MODULES" = "" ]; then
933 MODULES=all_modules
934 fi
935 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700936 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700937 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
938 local TO_CHOP=`expr $TO_CHOP + 1`
939 local START=`PWD= /bin/pwd`
940 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700941 if [ "$MFILE" = "" ] ; then
942 MFILE=$DIR/Android.mk
943 else
944 MFILE=$MFILE/$DIR/Android.mk
945 fi
946 MAKEFILE="$MAKEFILE $MFILE"
947 else
Ying Wanga7deb082013-08-16 13:24:47 -0700948 case $DIR in
949 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
950 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
951 *) echo "No Android.mk in $DIR."; return 1;;
952 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700953 fi
954 done
Ying Wanga7deb082013-08-16 13:24:47 -0700955 if [ -n "$GET_INSTALL_PATH" ]; then
956 ARGS=$GET_INSTALL_PATH
957 MODULES=
958 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800959 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 -0700960 else
961 echo "Couldn't locate the top of the tree. Try setting TOP."
962 fi
963}
964
Ying Wangb607f7b2013-02-08 18:01:04 -0800965function mma()
966{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800967 local T=$(gettop)
968 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800969 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800970 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800971 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800972 if [ ! "$T" ]; then
973 echo "Couldn't locate the top of the tree. Try setting TOP."
974 fi
975 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800976 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800977 fi
978}
979
980function mmma()
981{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800982 local T=$(gettop)
983 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800984 if [ "$T" ]; then
985 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
986 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
987 local MY_PWD=`PWD= /bin/pwd`
988 if [ "$MY_PWD" = "$T" ]; then
989 MY_PWD=
990 else
991 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
992 fi
993 local DIR=
994 local MODULE_PATHS=
995 local ARGS=
996 for DIR in $DIRS ; do
997 if [ -d $DIR ]; then
998 if [ "$MY_PWD" = "" ]; then
999 MODULE_PATHS="$MODULE_PATHS $DIR"
1000 else
1001 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
1002 fi
1003 else
1004 case $DIR in
1005 showcommands | snod | dist | incrementaljavac) ARGS="$ARGS $DIR";;
1006 *) echo "Couldn't find directory $DIR"; return 1;;
1007 esac
1008 fi
1009 done
Andrew Hsieh906cb782013-09-10 17:37:14 +08001010 $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 -08001011 else
1012 echo "Couldn't locate the top of the tree. Try setting TOP."
1013 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
Anthony Kingd4dbe2d2014-11-05 22:46:32 +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
Christopher Tate744ee802009-11-12 15:33:08 -08001098# systemstack - dump the current stack trace of all threads in the system process
1099# to the usual ANR traces file
1100function systemstack()
1101{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001102 stacks system_server
1103}
1104
1105function stacks()
1106{
1107 if [[ $1 =~ ^[0-9]+$ ]] ; then
1108 local PID="$1"
1109 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001110 local PIDLIST="$(pid $1)"
1111 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1112 local PID="$PIDLIST"
1113 elif [ "$PIDLIST" ] ; then
1114 echo "more than one process: $1"
1115 else
1116 echo "no such process: $1"
1117 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001118 else
1119 echo "usage: stacks [pid|process name]"
1120 fi
1121
1122 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001123 # Determine whether the process is native
1124 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1125 # Dump stacks of Dalvik process
1126 local TRACES=/data/anr/traces.txt
1127 local ORIG=/data/anr/traces.orig
1128 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001129
Jeff Brownb12c2e52013-08-19 15:14:16 -07001130 # Keep original traces to avoid clobbering
1131 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001132
Jeff Brownb12c2e52013-08-19 15:14:16 -07001133 # Make sure we have a usable file
1134 adb shell touch $TRACES
1135 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001136
Jeff Brownb12c2e52013-08-19 15:14:16 -07001137 # Dump stacks and wait for dump to finish
1138 adb shell kill -3 $PID
1139 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001140
Jeff Brownb12c2e52013-08-19 15:14:16 -07001141 # Restore original stacks, and show current output
1142 adb shell mv $TRACES $TMP
1143 adb shell mv $ORIG $TRACES
1144 adb shell cat $TMP
1145 else
1146 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001147 local USE64BIT="$(is64bit $PID)"
1148 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001149 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001150 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001151}
1152
John Michelau50200252012-11-09 11:48:04 -06001153function gdbwrapper()
1154{
Ben Chengfba67bf2014-02-25 10:27:07 -08001155 local GDB_CMD="$1"
1156 shift 1
1157 $GDB_CMD -x "$@"
John Michelau50200252012-11-09 11:48:04 -06001158}
1159
Brigid Smith0a2712d2014-05-28 14:36:43 -07001160function get_symbols_directory()
1161{
1162 echo $(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1163}
1164
Michael Wrightaeed7212014-06-19 19:58:12 -07001165# Read the ELF header from /proc/$PID/exe to determine if the process is
1166# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001167function is64bit()
1168{
1169 local PID="$1"
1170 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001171 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001172 echo "64"
1173 else
1174 echo ""
1175 fi
1176 else
1177 echo ""
1178 fi
1179}
1180
1181# gdbclient now determines whether the user wants to debug a 32-bit or 64-bit
1182# executable, set up the approriate gdbserver, then invokes the proper host
1183# gdb.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001184function gdbclient()
1185{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001186 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1187 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1188 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
Colin Cross3655a682014-05-22 11:59:10 -07001189 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
Brigid Smith0a2712d2014-05-28 14:36:43 -07001190 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001191 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001192 local ARCH=$(get_build_var TARGET_ARCH)
1193 local GDB
1194 case "$ARCH" in
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001195 arm) GDB=arm-linux-androideabi-gdb;;
Ben Chengfba67bf2014-02-25 10:27:07 -08001196 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
Duane Sand3c4fcd82014-07-22 14:34:00 -07001197 mips|mips64) GDB=mips64el-linux-android-gdb;;
Serban Constantinescu9b68fb22014-01-14 10:33:53 +00001198 x86) GDB=x86_64-linux-android-gdb;;
1199 x86_64) GDB=x86_64-linux-android-gdb;;
Nick Kralevich0ab21d32011-11-11 09:02:01 -08001200 *) echo "Unknown arch $ARCH"; return 1;;
1201 esac
1202
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001203 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1204 local EXE="$1"
1205 if [ "$EXE" ] ; then
1206 EXE=$1
Brigid Smith7a569a62014-06-20 14:12:12 -07001207 if [[ $EXE =~ ^[^/].* ]] ; then
1208 EXE="system/bin/"$EXE
1209 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001210 else
1211 EXE="app_process"
1212 fi
1213
1214 local PORT="$2"
1215 if [ "$PORT" ] ; then
1216 PORT=$2
1217 else
1218 PORT=":5039"
1219 fi
1220
Chris Craik20c136a2012-11-09 18:02:19 -08001221 local PID="$3"
1222 if [ "$PID" ] ; then
1223 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
Grace Klobae9d04bf2011-04-30 11:04:05 -07001224 PID=`pid $3`
Chris Craik20c136a2012-11-09 18:02:19 -08001225 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1226 # that likely didn't work because of returning multiple processes
1227 # try again, filtering by root processes (don't contain colon)
Mathias Agopian44583272013-08-27 14:15:50 -07001228 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
Chris Craik20c136a2012-11-09 18:02:19 -08001229 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1230 then
1231 echo "Couldn't resolve '$3' to single PID"
1232 return 1
1233 else
1234 echo ""
1235 echo "WARNING: multiple processes matching '$3' observed, using root process"
1236 echo ""
1237 fi
1238 fi
Grace Klobae9d04bf2011-04-30 11:04:05 -07001239 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001240 adb forward "tcp$PORT" "tcp$PORT"
Ben Chengfba67bf2014-02-25 10:27:07 -08001241 local USE64BIT="$(is64bit $PID)"
1242 adb shell gdbserver$USE64BIT $PORT --attach $PID &
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001243 sleep 2
1244 else
1245 echo ""
1246 echo "If you haven't done so already, do this first on the device:"
1247 echo " gdbserver $PORT /system/bin/$EXE"
1248 echo " or"
Chris Craik20c136a2012-11-09 18:02:19 -08001249 echo " gdbserver $PORT --attach <PID>"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001250 echo ""
1251 fi
1252
Colin Cross84480ad2014-04-10 12:51:39 -07001253 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
Colin Crossa58f8e02014-06-20 13:33:36 -07001254 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
Colin Cross84480ad2014-04-10 12:51:39 -07001255
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001256 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
Colin Cross3655a682014-05-22 11:59:10 -07001257 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"
Ben Cheng72398162013-06-24 14:36:21 -07001258 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001259 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
Christopher Ferris855d27f2014-10-03 17:29:27 -07001260 # Enable special debugging for ART processes.
1261 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1262 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1263 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001264 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1265
Ben Chengfba67bf2014-02-25 10:27:07 -08001266 local WHICH_GDB=
1267 # 64-bit exe found
1268 if [ "$USE64BIT" != "" ] ; then
1269 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1270 # 32-bit exe / 32-bit platform
1271 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1272 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1273 # 32-bit exe / 64-bit platform
1274 else
1275 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1276 fi
Brigid Smith0a2712d2014-05-28 14:36:43 -07001277
Ben Chengfba67bf2014-02-25 10:27:07 -08001278 gdbwrapper $WHICH_GDB "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001279 else
1280 echo "Unable to determine build system output dir."
1281 fi
1282
1283}
1284
1285case `uname -s` in
1286 Darwin)
1287 function sgrep()
1288 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001289 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 -07001290 }
1291
1292 ;;
1293 *)
1294 function sgrep()
1295 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001296 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 -07001297 }
1298 ;;
1299esac
1300
Raghu Gandham8da43102012-07-25 19:57:22 -07001301function gettargetarch
1302{
1303 get_build_var TARGET_ARCH
1304}
1305
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001306function ggrep()
1307{
1308 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1309}
1310
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001311function jgrep()
1312{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001313 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 -07001314}
1315
1316function cgrep()
1317{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001318 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' \) -print0 | xargs -0 grep --color -n "$@"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001319}
1320
1321function resgrep()
1322{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001323 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 -07001324}
1325
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001326function mangrep()
1327{
1328 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1329}
1330
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001331function sepgrep()
1332{
1333 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 "$@"
1334}
1335
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001336case `uname -s` in
1337 Darwin)
1338 function mgrep()
1339 {
Ying Wang324c2b22012-08-17 15:03:20 -07001340 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 -07001341 }
1342
1343 function treegrep()
1344 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001345 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 -07001346 }
1347
1348 ;;
1349 *)
1350 function mgrep()
1351 {
Ying Wang324c2b22012-08-17 15:03:20 -07001352 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 -07001353 }
1354
1355 function treegrep()
1356 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001357 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 -07001358 }
1359
1360 ;;
1361esac
1362
1363function getprebuilt
1364{
1365 get_abs_build_var ANDROID_PREBUILTS
1366}
1367
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001368function tracedmdump()
1369{
1370 T=$(gettop)
1371 if [ ! "$T" ]; then
1372 echo "Couldn't locate the top of the tree. Try setting TOP."
1373 return
1374 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001375 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001376 local arch=$(gettargetarch)
1377 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001378
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001379 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380 if [ ! "$TRACE" ] ; then
1381 echo "usage: tracedmdump tracename"
1382 return
1383 fi
1384
Jack Veenstra60116fc2009-04-09 18:12:34 -07001385 if [ ! -r "$KERNEL" ] ; then
1386 echo "Error: cannot find kernel: '$KERNEL'"
1387 return
1388 fi
1389
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001390 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001391 if [ "$BASETRACE" = "$TRACE" ] ; then
1392 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1393 fi
1394
1395 echo "post-processing traces..."
1396 rm -f $TRACE/qtrace.dexlist
1397 post_trace $TRACE
1398 if [ $? -ne 0 ]; then
1399 echo "***"
1400 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1401 echo "***"
1402 return
1403 fi
1404 echo "generating dexlist output..."
1405 /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
1406 echo "generating dmtrace data..."
1407 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1408 echo "generating html file..."
1409 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1410 echo "done, see $TRACE/dmtrace.html for details"
1411 echo "or run:"
1412 echo " traceview $TRACE/dmtrace"
1413}
1414
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001415# communicate with a running device or emulator, set up necessary state,
1416# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001417function runhat()
1418{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001419 # process standard adb options
1420 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001421 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001422 adbTarget=$1
1423 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001424 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001425 adbTarget="$1 $2"
1426 shift 2
1427 fi
1428 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001429 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001430
1431 # runhat options
1432 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001433
1434 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001435 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001436 return
1437 fi
1438
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001439 # confirm hat is available
1440 if [ -z $(which hat) ]; then
1441 echo "hat is not available in this configuration."
1442 return
1443 fi
1444
Andy McFaddenb6289852010-07-12 08:00:19 -07001445 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001446 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001447 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001448 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001449 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001450 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001451 echo -n "> "
1452 read
1453
The Android Open Source Project88b60792009-03-03 19:28:42 -08001454 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001455
The Android Open Source Project88b60792009-03-03 19:28:42 -08001456 echo "Retrieving file $devFile..."
1457 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001458
The Android Open Source Project88b60792009-03-03 19:28:42 -08001459 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001460
The Android Open Source Project88b60792009-03-03 19:28:42 -08001461 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001462 echo "View the output by pointing your browser at http://localhost:7000/"
1463 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001464 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001465}
1466
1467function getbugreports()
1468{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001469 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001470
1471 if [ ! "$reports" ]; then
1472 echo "Could not locate any bugreports."
1473 return
1474 fi
1475
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001476 local report
1477 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001478 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001479 echo "/sdcard/bugreports/${report}"
1480 adb pull /sdcard/bugreports/${report} ${report}
1481 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001482 done
1483}
1484
Victoria Lease1b296b42012-08-21 15:44:06 -07001485function getsdcardpath()
1486{
1487 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1488}
1489
1490function getscreenshotpath()
1491{
1492 echo "$(getsdcardpath)/Pictures/Screenshots"
1493}
1494
1495function getlastscreenshot()
1496{
1497 local screenshot_path=$(getscreenshotpath)
1498 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1499 if [ "$screenshot" = "" ]; then
1500 echo "No screenshots found."
1501 return
1502 fi
1503 echo "${screenshot}"
1504 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1505}
1506
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001507function startviewserver()
1508{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001509 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001510 if [ $# -gt 0 ]; then
1511 port=$1
1512 fi
1513 adb shell service call window 1 i32 $port
1514}
1515
1516function stopviewserver()
1517{
1518 adb shell service call window 2
1519}
1520
1521function isviewserverstarted()
1522{
1523 adb shell service call window 3
1524}
1525
Romain Guyb84049a2010-10-04 16:56:11 -07001526function key_home()
1527{
1528 adb shell input keyevent 3
1529}
1530
1531function key_back()
1532{
1533 adb shell input keyevent 4
1534}
1535
1536function key_menu()
1537{
1538 adb shell input keyevent 82
1539}
1540
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001541function smoketest()
1542{
1543 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1544 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1545 return
1546 fi
1547 T=$(gettop)
1548 if [ ! "$T" ]; then
1549 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1550 return
1551 fi
1552
Ying Wang9cd17642012-12-13 10:52:07 -08001553 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001554 adb uninstall com.android.smoketest > /dev/null &&
1555 adb uninstall com.android.smoketest.tests > /dev/null &&
1556 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1557 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1558 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1559}
1560
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001561# simple shortcut to the runtest command
1562function runtest()
1563{
1564 T=$(gettop)
1565 if [ ! "$T" ]; then
1566 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1567 return
1568 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001569 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001570}
1571
The Android Open Source Project88b60792009-03-03 19:28:42 -08001572function godir () {
1573 if [[ -z "$1" ]]; then
1574 echo "Usage: godir <regex>"
1575 return
1576 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001577 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001578 if [[ ! -f $T/filelist ]]; then
1579 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001580 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001581 echo " Done"
1582 echo ""
1583 fi
1584 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001585 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001586 if [[ ${#lines[@]} = 0 ]]; then
1587 echo "Not found"
1588 return
1589 fi
1590 local pathname
1591 local choice
1592 if [[ ${#lines[@]} > 1 ]]; then
1593 while [[ -z "$pathname" ]]; do
1594 local index=1
1595 local line
1596 for line in ${lines[@]}; do
1597 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001598 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001599 done
1600 echo
1601 echo -n "Select one: "
1602 unset choice
1603 read choice
1604 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1605 echo "Invalid choice"
1606 continue
1607 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001608 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001609 done
1610 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001611 pathname=${lines[0]}
1612 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001613 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001614}
1615
Steve Kondik10789d72012-09-17 11:33:18 -07001616function aospremote()
1617{
1618 git remote rm aosp 2> /dev/null
1619 if [ ! -d .git ]
1620 then
1621 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1622 fi
Steve Kondikdbdd9d02013-11-16 03:48:30 -08001623 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik10789d72012-09-17 11:33:18 -07001624 if (echo $PROJECT | grep -qv "^device")
1625 then
1626 PFX="platform/"
1627 fi
1628 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1629 echo "Remote 'aosp' created"
1630}
Steve Kondik10789d72012-09-17 11:33:18 -07001631
Steve Kondikd412ec52013-10-27 13:34:36 -07001632function cafremote()
1633{
1634 git remote rm caf 2> /dev/null
1635 if [ ! -d .git ]
1636 then
1637 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1638 fi
Steve Kondikdbdd9d02013-11-16 03:48:30 -08001639 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondikd412ec52013-10-27 13:34:36 -07001640 if (echo $PROJECT | grep -qv "^device")
1641 then
1642 PFX="platform/"
1643 fi
1644 git remote add caf git://codeaurora.org/$PFX$PROJECT
1645 echo "Remote 'caf' created"
1646}
Steve Kondikd412ec52013-10-27 13:34:36 -07001647
Nicholas Flinthamb0f1e292014-12-03 22:31:49 +00001648function cmremote()
1649{
1650 git remote rm cm 2> /dev/null
1651 if [ ! -d .git ]
1652 then
1653 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1654 fi
1655 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
1656 PFX="android_$(echo $PROJECT | sed 's/\//_/g')"
1657 git remote add cm git@github.com:CyanogenMod/$PFX
1658 echo "Remote 'cm' created"
1659}
1660
FuckingShitUpe79ba2d2014-12-19 17:57:26 -06001661function brokenremote()
Nicholas Flinthamb0f1e292014-12-03 22:31:49 +00001662{
FuckingShitUpe79ba2d2014-12-19 17:57:26 -06001663 git remote rm broken 2> /dev/null
Nicholas Flinthamb0f1e292014-12-03 22:31:49 +00001664 PFX=""
1665 if [ ! -d .git ]
1666 then
1667 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1668 else
1669 PROJ=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
1670
1671 if (echo $PROJ | egrep -q 'external|system|build|bionic|art|libcore|prebuilt|dalvik') ; then
1672 PFX="android_"
1673 fi
1674
1675 PROJECT="$(echo $PROJ | sed 's/\//_/g')"
1676
FuckingShitUpe79ba2d2014-12-19 17:57:26 -06001677 git remote add broken git@github.com:BrokenOs/$PFX$PROJECT
1678 echo "Remote 'broken' created"
Nicholas Flinthamb0f1e292014-12-03 22:31:49 +00001679 fi
1680}
1681
Tanguy Pruvot76976262012-06-06 21:39:23 +02001682function repodiff() {
1683 if [ -z "$*" ]; then
1684 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1685 return
1686 fi
1687 diffopts=$* repo forall -c \
1688 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1689}
1690
Andrew Sutherland4bafca52011-11-18 00:45:55 -06001691function mka() {
1692 case `uname -s` in
1693 Darwin)
1694 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1695 ;;
1696 *)
Arnav Gupta8abd2c82012-11-23 10:47:44 -07001697 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherland4bafca52011-11-18 00:45:55 -06001698 ;;
1699 esac
1700}
1701
1702function reposync() {
1703 case `uname -s` in
1704 Darwin)
1705 repo sync -j 4 "$@"
1706 ;;
1707 *)
1708 schedtool -B -n 1 -e ionice -n 1 repo sync -j 4 "$@"
1709 ;;
1710 esac
1711}
Narayan Kamath9260bba2014-01-17 10:05:25 +00001712# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
1713#
1714# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
1715# For some reason, installing the JDK doesn't make it show up in the
1716# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001717function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00001718 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01001719 # we can reset it later, depending on the version of java the build
1720 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00001721 #
1722 # If we don't do this, the JAVA_HOME value set by the first call to
1723 # build/envsetup.sh will persist forever.
1724 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
1725 export JAVA_HOME=""
1726 fi
1727
Andy McFaddenbd960942010-06-24 12:52:51 -07001728 if [ ! "$JAVA_HOME" ]; then
Narayan Kamathc84889b2014-04-01 14:16:26 +01001729 if [ -n "$LEGACY_USE_JAVA6" ]; then
Andy McFaddenbd960942010-06-24 12:52:51 -07001730 case `uname -s` in
1731 Darwin)
1732 export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
1733 ;;
1734 *)
1735 export JAVA_HOME=/usr/lib/jvm/java-6-sun
1736 ;;
1737 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00001738 else
1739 case `uname -s` in
1740 Darwin)
Jason Parks13b2e192014-04-28 13:32:10 -05001741 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
Narayan Kamath9260bba2014-01-17 10:05:25 +00001742 ;;
1743 *)
1744 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
1745 ;;
1746 esac
1747 fi
1748
1749 # Keep track of the fact that we set JAVA_HOME ourselves, so that
1750 # we can change it on the next envsetup.sh, if required.
1751 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001752 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05001753}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05001754
Pulsera0f7ec52013-09-29 09:56:55 +01001755function repopick() {
1756 set_stuff_for_environment
1757 T=$(gettop)
1758 $T/build/tools/repopick.py $@
1759}
1760
1761
Alex Rayf0d08eb2013-03-08 15:15:06 -08001762# Print colored exit condition
1763function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08001764 "$@"
1765 local retval=$?
1766 if [ $retval -ne 0 ]
1767 then
1768 echo -e "\e[0;31mFAILURE\e[00m"
1769 else
1770 echo -e "\e[0;32mSUCCESS\e[00m"
1771 fi
1772 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08001773}
1774
Ying Wanged21d4c2014-08-24 22:14:19 -07001775function get_make_command()
1776{
1777 echo command make
1778}
1779
Ed Heylcc6be0a2014-06-18 14:55:58 -07001780function make()
1781{
1782 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07001783 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001784 local ret=$?
1785 local end_time=$(date +"%s")
1786 local tdiff=$(($end_time-$start_time))
1787 local hours=$(($tdiff / 3600 ))
1788 local mins=$((($tdiff % 3600) / 60))
1789 local secs=$(($tdiff % 60))
1790 echo
1791 if [ $ret -eq 0 ] ; then
Ed Heylc6d11f82014-06-27 13:32:39 -07001792 echo -n -e "#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001793 else
Ed Heylc6d11f82014-06-27 13:32:39 -07001794 echo -n -e "#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07001795 fi
1796 if [ $hours -gt 0 ] ; then
1797 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
1798 elif [ $mins -gt 0 ] ; then
1799 printf "(%02g:%02g (mm:ss))" $mins $secs
1800 elif [ $secs -gt 0 ] ; then
1801 printf "(%s seconds)" $secs
1802 fi
Ed Heylc6d11f82014-06-27 13:32:39 -07001803 echo -e " ####"
Ed Heylcc6be0a2014-06-18 14:55:58 -07001804 echo
1805 return $ret
1806}
1807
Jiangyi069ceb52014-07-18 15:53:13 -04001808function chromium_prebuilt() {
1809 T=$(gettop)
1810 export TARGET_DEVICE=$(get_build_var TARGET_DEVICE)
1811 hash=$T/prebuilts/chromium/$TARGET_DEVICE/hash.txt
Ed Heylcc6be0a2014-06-18 14:55:58 -07001812
JoseGalRe13ad32a2014-09-29 20:26:10 -06001813 # Colors
1814 txtbld=$(tput bold)
1815 bldblu=${txtbld}$(tput setaf 4)
1816 bldgrn=${txtbld}$(tput setaf 2)
1817
1818 if [ -r $hash ] && [ $(git --git-dir=$T/external/chromium_org/.git --work-tree=$T/external/chromium_org rev-parse --verify HEAD) == $(cat $hash) ] && [ -f $libsCheck ] && [ -d $appCheck ]; then
Jiangyi069ceb52014-07-18 15:53:13 -04001819 export PRODUCT_PREBUILT_WEBVIEWCHROMIUM=yes
JoseGalRe13ad32a2014-09-29 20:26:10 -06001820 echo -e ${bldblu}"Prebuilt Chromium is up-to-date: ${bldgrn}Will be used for build"${txtrst}
1821 echo -e ""
Jiangyi069ceb52014-07-18 15:53:13 -04001822 else
1823 export PRODUCT_PREBUILT_WEBVIEWCHROMIUM=no
JoseGalRe13ad32a2014-09-29 20:26:10 -06001824 echo -e ${bldblu}"Prebuilt Chromium out-of-date or not found: ${bldgrn}Will build from source"${txtrst}
1825 echo -e ""
Jiangyi069ceb52014-07-18 15:53:13 -04001826 fi
1827}
Ed Heylcc6be0a2014-06-18 14:55:58 -07001828
Raphael Moll70a86b02011-06-20 16:03:14 -07001829if [ "x$SHELL" != "x/bin/bash" ]; then
1830 case `ps -o command -p $$` in
1831 *bash*)
1832 ;;
Emilio Lópezc49fbd42013-11-03 13:05:43 -03001833 *zsh*)
1834 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07001835 *)
Emilio Lópezc49fbd42013-11-03 13:05:43 -03001836 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07001837 ;;
1838 esac
1839fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001840
1841# Execute the contents of any vendorsetup.sh files we can find.
Ying Wang506410a2014-07-09 15:37:34 -07001842for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null` \
1843 `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null`
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001844do
1845 echo "including $f"
1846 . $f
1847done
1848unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07001849
1850addcompletions
Anthony Kingd4dbe2d2014-11-05 22:46:32 +00001851
1852export ANDROID_BUILD_TOP=$(gettop)