blob: db0ab189d96f16cb22d59931aea0985b3d2747f9 [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -07005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
nebkatfb67a1e2012-12-28 10:40:45 +00007- cout: Changes directory to out.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07008- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08009- mm: Builds all of the modules in the current directory, but not their dependencies.
10- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000011 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080012- mma: Builds all of the modules in the current directory, and their dependencies.
Daniel Bateman22185ba2012-08-04 03:48:09 -050013- mmp: Builds all of the modules in the current directory and pushes them to the device.
14- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080015- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070016- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070017- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070018- jgrep: Greps on all local Java files.
19- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000020- mangrep: Greps on all local AndroidManifest.xml files.
21- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070022- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080023- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060024- cmremote: Add git remote for CM Gerrit Review
25- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
26- cmrebase: Rebase a Gerrit change and push it again
Steve Kondik873fa562012-09-17 11:33:18 -070027- aospremote: Add git remote for matching AOSP repository
Steve Kondik20c21d22013-10-27 13:34:36 -070028- cafremote: Add git remote for matching CodeAurora repository.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060029- mka: Builds using SCHED_BATCH on all processors
Chirayu Desaicf2bdb62012-09-28 11:56:02 +053030- mkap: Builds the module(s) using mka and pushes them to the device.
31- cmka: Cleans and builds using mka.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060032- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053033- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070034- installboot: Installs a boot.img to the connected device.
35- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070036
Dan Albert4ae5d4b2014-10-31 16:23:08 -070037Environemnt options:
38- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
39 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
40 build is leak-check clean.
41
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070042Look at the source to view more functions. The complete list is:
43EOF
44 T=$(gettop)
45 local A
46 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070047 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070048 A="$A $i"
49 done
50 echo $A
51}
52
53# Get the value of a build variable as an absolute path.
54function get_abs_build_var()
55{
56 T=$(gettop)
57 if [ ! "$T" ]; then
58 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
59 return
60 fi
Ying Wang9cd17642012-12-13 10:52:07 -080061 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070062 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070063}
64
65# Get the exact value of a build variable.
66function get_build_var()
67{
68 T=$(gettop)
69 if [ ! "$T" ]; then
70 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
71 return
72 fi
Andrew Boie6905e212013-12-19 13:21:46 -080073 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070074 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080075}
76
77# check to see if the supplied product is one we can build
78function check_product()
79{
80 T=$(gettop)
81 if [ ! "$T" ]; then
82 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
83 return
84 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000085
86 if (echo -n $1 | grep -q -e "^cm_") ; then
87 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
Ricardo Cerqueira34ae3232013-09-26 00:10:20 +010088 export BUILD_NUMBER=$((date +%s%N ; echo $CM_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10)
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000089 else
90 CM_BUILD=
91 fi
92 export CM_BUILD
93
Jeff Browne33ba4c2011-07-11 22:11:46 -070094 TARGET_PRODUCT=$1 \
95 TARGET_BUILD_VARIANT= \
96 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070097 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080098 get_build_var TARGET_DEVICE > /dev/null
99 # hide successful answers, but allow the errors to show
100}
101
102VARIANT_CHOICES=(user userdebug eng)
103
104# check to see if the supplied variant is valid
105function check_variant()
106{
107 for v in ${VARIANT_CHOICES[@]}
108 do
109 if [ "$v" = "$1" ]
110 then
111 return 0
112 fi
113 done
114 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700115}
116
117function setpaths()
118{
119 T=$(gettop)
120 if [ ! "$T" ]; then
121 echo "Couldn't locate the top of the tree. Try setting TOP."
122 return
123 fi
124
125 ##################################################################
126 # #
127 # Read me before you modify this code #
128 # #
129 # This function sets ANDROID_BUILD_PATHS to what it is adding #
130 # to PATH, and the next time it is run, it removes that from #
131 # PATH. This is required so lunch can be run more than once #
132 # and still have working paths. #
133 # #
134 ##################################################################
135
Raphael Mollc639c782011-06-20 17:25:01 -0700136 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
137 # due to "C:\Program Files" being in the path.
138
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700139 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700140 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700141 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
142 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700143 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700144 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800145 # strip leading ':', if any
146 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500147 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700148
149 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700150 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700151 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700152
Ben Cheng8bc4c432012-11-16 13:29:13 -0800153 # defined in core/config.mk
154 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700155 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800156 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800157
Raphael Mollc639c782011-06-20 17:25:01 -0700158 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800159 export ANDROID_TOOLCHAIN=
160 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200161 local ARCH=$(get_build_var TARGET_ARCH)
162 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400163 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700164 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400165 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
166 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800167 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200168 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800169 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700170 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700171 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700172 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000173 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200174 *)
175 echo "Can't find toolchain for unknown architecture: $ARCH"
176 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700177 ;;
178 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700179 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800180 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700181 fi
Raphael732936d2011-06-22 14:35:32 -0700182
Ben Chengfba67bf2014-02-25 10:27:07 -0800183 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
184 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
185 fi
186
187 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700188 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700189 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800190 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800191 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700192 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100193 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
194 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700195 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700196 ;;
197 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700198 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700199 ;;
200 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700201
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700202 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700203 export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN:$ANDROID_TOOLCHAIN_2ND_ARCH:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200204
205 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
206 # to ensure that the corresponding 'emulator' binaries are used.
207 case $(uname -s) in
208 Darwin)
209 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
210 ;;
211 Linux)
212 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
213 ;;
214 *)
215 ANDROID_EMULATOR_PREBUILTS=
216 ;;
217 esac
218 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700219 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200220 export ANDROID_EMULATOR_PREBUILTS
221 fi
222
Ying Wangaa1c9b52012-11-26 20:51:59 -0800223 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800224
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500225 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900226 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500227 if [ -n "$JAVA_HOME" ]; then
228 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900229 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
230 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500231 fi
232
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800233 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700234 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
235 export OUT=$ANDROID_PRODUCT_OUT
236
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700237 unset ANDROID_HOST_OUT
238 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
239
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800240 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700241 # TODO: fix the path
242 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
243}
244
245function printconfig()
246{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800247 T=$(gettop)
248 if [ ! "$T" ]; then
249 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
250 return
251 fi
252 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700253}
254
255function set_stuff_for_environment()
256{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800257 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500258 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800259 setpaths
260 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700261
Ben Chengaac3f812013-08-13 14:38:15 -0700262 # With this environment variable new GCC can apply colors to warnings/errors
263 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700264 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700265}
266
267function set_sequence_number()
268{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700269 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700270}
271
272function settitle()
273{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800274 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700275 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700276 local product=$TARGET_PRODUCT
277 local variant=$TARGET_BUILD_VARIANT
278 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800279 if [ -z "$PROMPT_COMMAND" ]; then
280 # No prompts
281 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
282 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
283 # Prompts exist, but no hardstatus
284 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700285 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800286 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500287 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800288 fi
289
290 if [ -z "$apps" ]; then
291 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
292 else
293 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
294 fi
295 export ANDROID_PROMPT_PREFIX
296
297 # Inject build data into hardstatus
298 export PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/\\033]0;\(.*\)\\007/\\033]0;$ANDROID_PROMPT_PREFIX \1\\007/g')"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800299 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700300}
301
Kyle Ladd031a0b62013-09-11 20:43:42 -0400302function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700303{
Kenny Root52aa81c2011-07-15 11:07:06 -0700304 # Keep us from trying to run in something that isn't bash.
305 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400306 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700307 fi
308
309 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200310 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400311 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700312 fi
313
Kyle Ladd031a0b62013-09-11 20:43:42 -0400314 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700315}
316
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700317function choosetype()
318{
319 echo "Build type choices are:"
320 echo " 1. release"
321 echo " 2. debug"
322 echo
323
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800324 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700325 DEFAULT_NUM=1
326 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700327
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800328 export TARGET_BUILD_TYPE=
329 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330 while [ -z $TARGET_BUILD_TYPE ]
331 do
332 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 if [ -z "$1" ] ; then
334 read ANSWER
335 else
336 echo $1
337 ANSWER=$1
338 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700339 case $ANSWER in
340 "")
341 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
342 ;;
343 1)
344 export TARGET_BUILD_TYPE=release
345 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800346 release)
347 export TARGET_BUILD_TYPE=release
348 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700349 2)
350 export TARGET_BUILD_TYPE=debug
351 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352 debug)
353 export TARGET_BUILD_TYPE=debug
354 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355 *)
356 echo
357 echo "I didn't understand your response. Please try again."
358 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700359 ;;
360 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800361 if [ -n "$1" ] ; then
362 break
363 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 done
365
366 set_stuff_for_environment
367}
368
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800369#
370# This function isn't really right: It chooses a TARGET_PRODUCT
371# based on the list of boards. Usually, that gets you something
372# that kinda works with a generic product, but really, you should
373# pick a product by name.
374#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700375function chooseproduct()
376{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377 if [ "x$TARGET_PRODUCT" != x ] ; then
378 default_value=$TARGET_PRODUCT
379 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700380 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700381 fi
382
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800383 export TARGET_PRODUCT=
384 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700385 while [ -z "$TARGET_PRODUCT" ]
386 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700387 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800388 if [ -z "$1" ] ; then
389 read ANSWER
390 else
391 echo $1
392 ANSWER=$1
393 fi
394
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700395 if [ -z "$ANSWER" ] ; then
396 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800397 else
398 if check_product $ANSWER
399 then
400 export TARGET_PRODUCT=$ANSWER
401 else
402 echo "** Not a valid product: $ANSWER"
403 fi
404 fi
405 if [ -n "$1" ] ; then
406 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700407 fi
408 done
409
410 set_stuff_for_environment
411}
412
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800413function choosevariant()
414{
415 echo "Variant choices are:"
416 local index=1
417 local v
418 for v in ${VARIANT_CHOICES[@]}
419 do
420 # The product name is the name of the directory containing
421 # the makefile we found, above.
422 echo " $index. $v"
423 index=$(($index+1))
424 done
425
426 local default_value=eng
427 local ANSWER
428
429 export TARGET_BUILD_VARIANT=
430 while [ -z "$TARGET_BUILD_VARIANT" ]
431 do
432 echo -n "Which would you like? [$default_value] "
433 if [ -z "$1" ] ; then
434 read ANSWER
435 else
436 echo $1
437 ANSWER=$1
438 fi
439
440 if [ -z "$ANSWER" ] ; then
441 export TARGET_BUILD_VARIANT=$default_value
442 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
443 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800444 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800445 fi
446 else
447 if check_variant $ANSWER
448 then
449 export TARGET_BUILD_VARIANT=$ANSWER
450 else
451 echo "** Not a valid variant: $ANSWER"
452 fi
453 fi
454 if [ -n "$1" ] ; then
455 break
456 fi
457 done
458}
459
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700460function choosecombo()
461{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700462 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463
464 echo
465 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700466 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700467
468 echo
469 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700470 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800471
472 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800474 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475}
476
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477# Clear this variable. It will be built up again when the vendorsetup.sh
478# files are included at the end of this file.
479unset LUNCH_MENU_CHOICES
480function add_lunch_combo()
481{
482 local new_combo=$1
483 local c
484 for c in ${LUNCH_MENU_CHOICES[@]} ; do
485 if [ "$new_combo" = "$c" ] ; then
486 return
487 fi
488 done
489 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
490}
491
492# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700493add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800494add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000495add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800496add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000497add_lunch_combo aosp_x86-eng
498add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800499
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700500function print_lunch_menu()
501{
502 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503 echo
504 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000505 if [ "$(uname)" = "Darwin" ] ; then
506 echo " (ohai, koush!)"
507 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000509 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
510 echo "Breakfast menu... pick a combo:"
511 else
512 echo "Lunch menu... pick a combo:"
513 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800514
515 local i=1
516 local choice
517 for choice in ${LUNCH_MENU_CHOICES[@]}
518 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100519 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100521 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000523 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
524 echo "... and don't forget the bacon!"
525 fi
526
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700527 echo
528}
529
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000530function brunch()
531{
532 breakfast $*
533 if [ $? -eq 0 ]; then
534 mka bacon
535 else
536 echo "No such item in brunch menu. Try 'breakfast'"
537 return 1
538 fi
539 return $?
540}
541
542function breakfast()
543{
544 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200545 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000546 CM_DEVICES_ONLY="true"
547 unset LUNCH_MENU_CHOICES
548 add_lunch_combo full-eng
549 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
550 do
551 echo "including $f"
552 . $f
553 done
554 unset f
555
556 if [ $# -eq 0 ]; then
557 # No arguments, so let's have the full menu
558 lunch
559 else
560 echo "z$target" | grep -q "-"
561 if [ $? -eq 0 ]; then
562 # A buildtype was specified, assume a full device name
563 lunch $target
564 else
565 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200566 if [ -z "$variant" ]; then
567 variant="userdebug"
568 fi
569 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000570 fi
571 fi
572 return $?
573}
574
575alias bib=breakfast
576
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700577function lunch()
578{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800579 local answer
580
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800582 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583 else
584 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700585 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587 fi
588
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 local selection=
590
591 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700592 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700593 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800594 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
595 then
596 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
597 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800598 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800599 fi
600 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
601 then
602 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700603 fi
604
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800605 if [ -z "$selection" ]
606 then
607 echo
608 echo "Invalid lunch combo: $answer"
609 return 1
610 fi
611
Joe Onoratoda12daf2010-06-09 18:18:31 -0700612 export TARGET_BUILD_APPS=
613
Jeff Browne33ba4c2011-07-11 22:11:46 -0700614 local product=$(echo -n $selection | sed -e "s/-.*$//")
615 check_product $product
616 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800617 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800618 # if we can't find a product, try to grab it off the CM github
619 T=$(gettop)
620 pushd $T > /dev/null
621 build/tools/roomservice.py $product
622 popd > /dev/null
623 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000624 else
625 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800626 fi
627 if [ $? -ne 0 ]
628 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700629 echo
630 echo "** Don't have a product spec for: '$product'"
631 echo "** Do you have the right repo manifest?"
632 product=
633 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800634
Jeff Browne33ba4c2011-07-11 22:11:46 -0700635 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
636 check_variant $variant
637 if [ $? -ne 0 ]
638 then
639 echo
640 echo "** Invalid variant: '$variant'"
641 echo "** Must be one of ${VARIANT_CHOICES[@]}"
642 variant=
643 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800644
Jeff Browne33ba4c2011-07-11 22:11:46 -0700645 if [ -z "$product" -o -z "$variant" ]
646 then
647 echo
648 return 1
649 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800650
Jeff Browne33ba4c2011-07-11 22:11:46 -0700651 export TARGET_PRODUCT=$product
652 export TARGET_BUILD_VARIANT=$variant
653 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700654
655 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800656
Chirayu Desaib89b3242013-06-30 10:04:25 +0530657 fixup_common_out_dir
658
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800660 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661}
662
Jeff Davidson513d7a42010-08-02 10:00:44 -0700663# Tab completion for lunch.
664function _lunch()
665{
666 local cur prev opts
667 COMPREPLY=()
668 cur="${COMP_WORDS[COMP_CWORD]}"
669 prev="${COMP_WORDS[COMP_CWORD-1]}"
670
671 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
672 return 0
673}
Emilio López9ad6eea2013-11-03 13:02:13 -0300674complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700675
Joe Onoratoda12daf2010-06-09 18:18:31 -0700676# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700677# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700678function tapas()
679{
Ying Wangb541ab62014-05-29 17:57:40 -0700680 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700681 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700682 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
683 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700684
Ying Wang67f02922012-08-22 10:25:20 -0700685 if [ $(echo $arch | wc -w) -gt 1 ]; then
686 echo "tapas: Error: Multiple build archs supplied: $arch"
687 return
688 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700689 if [ $(echo $variant | wc -w) -gt 1 ]; then
690 echo "tapas: Error: Multiple build variants supplied: $variant"
691 return
692 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700693 if [ $(echo $density | wc -w) -gt 1 ]; then
694 echo "tapas: Error: Multiple densities supplied: $density"
695 return
696 fi
Ying Wang67f02922012-08-22 10:25:20 -0700697
698 local product=full
699 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700700 x86) product=full_x86;;
701 mips) product=full_mips;;
702 armv5) product=generic_armv5;;
703 arm64) product=aosp_arm64;;
704 x86_64) product=aosp_x86_64;;
705 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700706 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700707 if [ -z "$variant" ]; then
708 variant=eng
709 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700710 if [ -z "$apps" ]; then
711 apps=all
712 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600713 if [ -z "$density" ]; then
714 density=alldpi
715 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700716
Ying Wang67f02922012-08-22 10:25:20 -0700717 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700718 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700719 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700720 export TARGET_BUILD_TYPE=release
721 export TARGET_BUILD_APPS=$apps
722
723 set_stuff_for_environment
724 printconfig
725}
726
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100727function eat()
728{
729 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530730 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100731 ZIPFILE=cm-$MODVERSION.zip
732 ZIPPATH=$OUT/$ZIPFILE
733 if [ ! -f $ZIPPATH ] ; then
734 echo "Nothing to eat"
735 return 1
736 fi
737 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
738 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
739 echo "No device is online. Waiting for one..."
740 echo "Please connect USB and/or enable USB debugging"
741 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
742 sleep 1
743 done
744 echo "Device Found.."
745 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530746 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
747 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100748 # if adbd isn't root we can't write to /cache/recovery/
749 adb root
750 sleep 1
751 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700752 cat << EOF > /tmp/command
753--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100754EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700755 if adb push /tmp/command /cache/recovery/ ; then
756 echo "Rebooting into recovery for sideload installation"
757 adb reboot recovery
758 adb wait-for-sideload
759 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100760 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700761 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100762 else
763 echo "Nothing to eat"
764 return 1
765 fi
766 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530767 else
768 echo "The connected device does not appear to be $CM_BUILD, run away!"
769 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100770}
771
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000772function omnom
773{
774 brunch $*
775 eat
776}
777
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700778function gettop
779{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800780 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700782 # The following circumlocution ensures we remove symlinks from TOP.
783 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 else
785 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800786 # The following circumlocution (repeated below as well) ensures
787 # that we record the true directory name and not one that is
788 # faked up with symlink names.
789 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800791 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792 T=
793 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800794 \cd ..
synergyb112a402013-07-05 19:47:47 -0700795 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 done
Ying Wang9cd17642012-12-13 10:52:07 -0800797 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700798 if [ -f "$T/$TOPFILE" ]; then
799 echo $T
800 fi
801 fi
802 fi
803}
804
Andrew Hsieh906cb782013-09-10 17:37:14 +0800805# Return driver for "make", if any (eg. static analyzer)
806function getdriver()
807{
808 local T="$1"
809 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
810 if [ -n "$WITH_STATIC_ANALYZER" ]; then
811 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800812$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
813--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800814--status-bugs \
815--top=$T"
816 fi
817}
818
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700819function m()
820{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800821 local T=$(gettop)
822 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800824 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700825 else
826 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700827 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700828 fi
829}
830
831function findmakefile()
832{
833 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800834 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835 T=
836 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700837 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838 if [ -f "$T/Android.mk" ]; then
839 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800840 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700841 return
842 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800843 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844 done
Ying Wang9cd17642012-12-13 10:52:07 -0800845 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846}
847
848function mm()
849{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800850 local T=$(gettop)
851 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700852 # If we're sitting in the root of the build tree, just do a
853 # normal make.
854 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800855 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700856 else
857 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800858 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700859 local MODULES=
860 local GET_INSTALL_PATH=
861 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700862 # Remove the path to top as the makefilepath needs to be relative
863 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864 if [ ! "$T" ]; then
865 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700866 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867 elif [ ! "$M" ]; then
868 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700869 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870 else
Ying Wanga7deb082013-08-16 13:24:47 -0700871 for ARG in $@; do
872 case $ARG in
873 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
874 esac
875 done
876 if [ -n "$GET_INSTALL_PATH" ]; then
877 MODULES=
878 ARGS=GET-INSTALL-PATH
879 else
880 MODULES=all_modules
881 ARGS=$@
882 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700883 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700884 fi
885 fi
886}
887
888function mmm()
889{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800890 local T=$(gettop)
891 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700892 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800893 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800894 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800895 local ARGS=
896 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700897 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800898 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
899 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
900 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800901 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
902 if [ "$MODULES" = "" ]; then
903 MODULES=all_modules
904 fi
905 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700906 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700907 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
908 local TO_CHOP=`expr $TO_CHOP + 1`
909 local START=`PWD= /bin/pwd`
910 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700911 if [ "$MFILE" = "" ] ; then
912 MFILE=$DIR/Android.mk
913 else
914 MFILE=$MFILE/$DIR/Android.mk
915 fi
916 MAKEFILE="$MAKEFILE $MFILE"
917 else
Ying Wanga7deb082013-08-16 13:24:47 -0700918 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100919 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700920 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
921 *) echo "No Android.mk in $DIR."; return 1;;
922 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700923 fi
924 done
Ying Wanga7deb082013-08-16 13:24:47 -0700925 if [ -n "$GET_INSTALL_PATH" ]; then
926 ARGS=$GET_INSTALL_PATH
927 MODULES=
928 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800929 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700930 else
931 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700932 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700933 fi
934}
935
Ying Wangb607f7b2013-02-08 18:01:04 -0800936function mma()
937{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800938 local T=$(gettop)
939 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800940 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800941 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800942 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800943 if [ ! "$T" ]; then
944 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700945 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800946 fi
947 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800948 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800949 fi
950}
951
952function mmma()
953{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800954 local T=$(gettop)
955 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800956 if [ "$T" ]; then
957 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
958 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
959 local MY_PWD=`PWD= /bin/pwd`
960 if [ "$MY_PWD" = "$T" ]; then
961 MY_PWD=
962 else
963 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
964 fi
965 local DIR=
966 local MODULE_PATHS=
967 local ARGS=
968 for DIR in $DIRS ; do
969 if [ -d $DIR ]; then
970 if [ "$MY_PWD" = "" ]; then
971 MODULE_PATHS="$MODULE_PATHS $DIR"
972 else
973 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
974 fi
975 else
976 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100977 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800978 *) echo "Couldn't find directory $DIR"; return 1;;
979 esac
980 fi
981 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800982 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
Ying Wangb607f7b2013-02-08 18:01:04 -0800983 else
984 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700985 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800986 fi
987}
988
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700989function croot()
990{
991 T=$(gettop)
992 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800993 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700994 else
995 echo "Couldn't locate the top of the tree. Try setting TOP."
996 fi
997}
998
nebkatfb67a1e2012-12-28 10:40:45 +0000999function cout()
1000{
1001 if [ "$OUT" ]; then
1002 cd $OUT
1003 else
1004 echo "Couldn't locate out directory. Try setting OUT."
1005 fi
1006}
1007
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001008function cproj()
1009{
1010 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001011 local HERE=$PWD
1012 T=
1013 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1014 T=$PWD
1015 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001016 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001017 return
1018 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001019 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 done
Ying Wang9cd17642012-12-13 10:52:07 -08001021 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001022 echo "can't find Android.mk"
1023}
1024
Daniel Sandler47e0a882013-07-30 13:23:52 -04001025# simplified version of ps; output in the form
1026# <pid> <procname>
1027function qpid() {
1028 local prepend=''
1029 local append=''
1030 if [ "$1" = "--exact" ]; then
1031 prepend=' '
1032 append='$'
1033 shift
1034 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1035 echo "usage: qpid [[--exact] <process name|pid>"
1036 return 255
1037 fi
1038
1039 local EXE="$1"
1040 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001041 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001042 else
1043 adb shell ps \
1044 | tr -d '\r' \
1045 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1046 fi
1047}
1048
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001049function pid()
1050{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001051 local prepend=''
1052 local append=''
1053 if [ "$1" = "--exact" ]; then
1054 prepend=' '
1055 append='$'
1056 shift
1057 fi
1058 local EXE="$1"
1059 if [ "$EXE" ] ; then
1060 local PID=`adb shell ps \
1061 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001062 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001063 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1064 echo "$PID"
1065 else
1066 echo "usage: pid [--exact] <process name>"
1067 return 255
1068 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001069}
1070
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001071# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001072# that has the core-file-size limit set correctly
1073#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001074# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075# if its core-file-size limit is not set already.
1076# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1077
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001078function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001079{
1080 echo "Getting root...";
1081 adb root;
1082 adb wait-for-device;
1083
1084 echo "Remounting root parition read-write...";
1085 adb shell mount -w -o remount -t rootfs rootfs;
1086 sleep 1;
1087 adb wait-for-device;
1088 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001089 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001090 adb shell chmod 0777 /cores;
1091
1092 echo "Granting SELinux permission to dump in /cores...";
1093 adb shell restorecon -R /cores;
1094
1095 echo "Set core pattern.";
1096 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1097
1098 echo "Done."
1099}
1100
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001101# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001102# $1 = PID of process (e.g., $(pid mediaserver))
1103#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001104# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001105# dump to actually be generated.
1106
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001107function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001108{
1109 local PID=$1;
1110 if [ -z "$PID" ]; then
1111 printf "Expecting a PID!\n";
1112 return;
1113 fi;
1114 echo "Setting core limit for $PID to infinite...";
1115 adb shell prlimit $PID 4 -1 -1
1116}
1117
1118# core - send SIGV and pull the core for process
1119# $1 = PID of process (e.g., $(pid mediaserver))
1120#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001121# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001122# enabled globally.
1123
1124function core()
1125{
1126 local PID=$1;
1127
1128 if [ -z "$PID" ]; then
1129 printf "Expecting a PID!\n";
1130 return;
1131 fi;
1132
1133 local CORENAME=core.$PID;
1134 local COREPATH=/cores/$CORENAME;
1135 local SIG=SEGV;
1136
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001137 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001138
1139 local done=0;
1140 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1141 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1142 adb shell kill -$SIG $PID;
1143 sleep 1;
1144 done;
1145
1146 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1147 echo "Done: core is under $COREPATH on device.";
1148}
1149
Christopher Tate744ee802009-11-12 15:33:08 -08001150# systemstack - dump the current stack trace of all threads in the system process
1151# to the usual ANR traces file
1152function systemstack()
1153{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001154 stacks system_server
1155}
1156
1157function stacks()
1158{
1159 if [[ $1 =~ ^[0-9]+$ ]] ; then
1160 local PID="$1"
1161 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001162 local PIDLIST="$(pid $1)"
1163 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1164 local PID="$PIDLIST"
1165 elif [ "$PIDLIST" ] ; then
1166 echo "more than one process: $1"
1167 else
1168 echo "no such process: $1"
1169 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001170 else
1171 echo "usage: stacks [pid|process name]"
1172 fi
1173
1174 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001175 # Determine whether the process is native
1176 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1177 # Dump stacks of Dalvik process
1178 local TRACES=/data/anr/traces.txt
1179 local ORIG=/data/anr/traces.orig
1180 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001181
Jeff Brownb12c2e52013-08-19 15:14:16 -07001182 # Keep original traces to avoid clobbering
1183 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001184
Jeff Brownb12c2e52013-08-19 15:14:16 -07001185 # Make sure we have a usable file
1186 adb shell touch $TRACES
1187 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001188
Jeff Brownb12c2e52013-08-19 15:14:16 -07001189 # Dump stacks and wait for dump to finish
1190 adb shell kill -3 $PID
1191 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001192
Jeff Brownb12c2e52013-08-19 15:14:16 -07001193 # Restore original stacks, and show current output
1194 adb shell mv $TRACES $TMP
1195 adb shell mv $ORIG $TRACES
1196 adb shell cat $TMP
1197 else
1198 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001199 local USE64BIT="$(is64bit $PID)"
1200 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001201 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001202 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001203}
1204
Michael Wrightaeed7212014-06-19 19:58:12 -07001205# Read the ELF header from /proc/$PID/exe to determine if the process is
1206# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001207function is64bit()
1208{
1209 local PID="$1"
1210 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001211 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001212 echo "64"
1213 else
1214 echo ""
1215 fi
1216 else
1217 echo ""
1218 fi
1219}
1220
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001221case `uname -s` in
1222 Darwin)
1223 function sgrep()
1224 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001225 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 -07001226 }
1227
1228 ;;
1229 *)
1230 function sgrep()
1231 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001232 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 -07001233 }
1234 ;;
1235esac
1236
Raghu Gandham8da43102012-07-25 19:57:22 -07001237function gettargetarch
1238{
1239 get_build_var TARGET_ARCH
1240}
1241
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001242function ggrep()
1243{
1244 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1245}
1246
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001247function jgrep()
1248{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001249 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 -07001250}
1251
1252function cgrep()
1253{
Dan Albert01961192014-11-22 10:16:01 -08001254 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 -07001255}
1256
1257function resgrep()
1258{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001259 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 -07001260}
1261
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001262function mangrep()
1263{
1264 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1265}
1266
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001267function sepgrep()
1268{
1269 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 "$@"
1270}
1271
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001272function rcgrep()
1273{
1274 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1275}
1276
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001277case `uname -s` in
1278 Darwin)
1279 function mgrep()
1280 {
Ying Wang324c2b22012-08-17 15:03:20 -07001281 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 -07001282 }
1283
1284 function treegrep()
1285 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001286 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 -07001287 }
1288
1289 ;;
1290 *)
1291 function mgrep()
1292 {
Ying Wang324c2b22012-08-17 15:03:20 -07001293 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 -07001294 }
1295
1296 function treegrep()
1297 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001298 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 -07001299 }
1300
1301 ;;
1302esac
1303
1304function getprebuilt
1305{
1306 get_abs_build_var ANDROID_PREBUILTS
1307}
1308
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309function tracedmdump()
1310{
1311 T=$(gettop)
1312 if [ ! "$T" ]; then
1313 echo "Couldn't locate the top of the tree. Try setting TOP."
1314 return
1315 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001316 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001317 local arch=$(gettargetarch)
1318 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001319
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001320 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001321 if [ ! "$TRACE" ] ; then
1322 echo "usage: tracedmdump tracename"
1323 return
1324 fi
1325
Jack Veenstra60116fc2009-04-09 18:12:34 -07001326 if [ ! -r "$KERNEL" ] ; then
1327 echo "Error: cannot find kernel: '$KERNEL'"
1328 return
1329 fi
1330
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001331 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001332 if [ "$BASETRACE" = "$TRACE" ] ; then
1333 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1334 fi
1335
1336 echo "post-processing traces..."
1337 rm -f $TRACE/qtrace.dexlist
1338 post_trace $TRACE
1339 if [ $? -ne 0 ]; then
1340 echo "***"
1341 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1342 echo "***"
1343 return
1344 fi
1345 echo "generating dexlist output..."
1346 /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
1347 echo "generating dmtrace data..."
1348 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1349 echo "generating html file..."
1350 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1351 echo "done, see $TRACE/dmtrace.html for details"
1352 echo "or run:"
1353 echo " traceview $TRACE/dmtrace"
1354}
1355
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001356# communicate with a running device or emulator, set up necessary state,
1357# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001358function runhat()
1359{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001360 # process standard adb options
1361 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001362 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001363 adbTarget=$1
1364 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001365 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001366 adbTarget="$1 $2"
1367 shift 2
1368 fi
1369 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001370 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001371
1372 # runhat options
1373 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001374
1375 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001376 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001377 return
1378 fi
1379
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001380 # confirm hat is available
1381 if [ -z $(which hat) ]; then
1382 echo "hat is not available in this configuration."
1383 return
1384 fi
1385
Andy McFaddenb6289852010-07-12 08:00:19 -07001386 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001387 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001388 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001389 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001390 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001391 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001392 echo -n "> "
1393 read
1394
The Android Open Source Project88b60792009-03-03 19:28:42 -08001395 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001396
The Android Open Source Project88b60792009-03-03 19:28:42 -08001397 echo "Retrieving file $devFile..."
1398 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001399
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401
The Android Open Source Project88b60792009-03-03 19:28:42 -08001402 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001403 echo "View the output by pointing your browser at http://localhost:7000/"
1404 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001405 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001406}
1407
1408function getbugreports()
1409{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001410 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001411
1412 if [ ! "$reports" ]; then
1413 echo "Could not locate any bugreports."
1414 return
1415 fi
1416
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001417 local report
1418 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001419 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001420 echo "/sdcard/bugreports/${report}"
1421 adb pull /sdcard/bugreports/${report} ${report}
1422 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001423 done
1424}
1425
Victoria Lease1b296b42012-08-21 15:44:06 -07001426function getsdcardpath()
1427{
1428 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1429}
1430
1431function getscreenshotpath()
1432{
1433 echo "$(getsdcardpath)/Pictures/Screenshots"
1434}
1435
1436function getlastscreenshot()
1437{
1438 local screenshot_path=$(getscreenshotpath)
1439 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1440 if [ "$screenshot" = "" ]; then
1441 echo "No screenshots found."
1442 return
1443 fi
1444 echo "${screenshot}"
1445 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1446}
1447
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001448function startviewserver()
1449{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001450 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001451 if [ $# -gt 0 ]; then
1452 port=$1
1453 fi
1454 adb shell service call window 1 i32 $port
1455}
1456
1457function stopviewserver()
1458{
1459 adb shell service call window 2
1460}
1461
1462function isviewserverstarted()
1463{
1464 adb shell service call window 3
1465}
1466
Romain Guyb84049a2010-10-04 16:56:11 -07001467function key_home()
1468{
1469 adb shell input keyevent 3
1470}
1471
1472function key_back()
1473{
1474 adb shell input keyevent 4
1475}
1476
1477function key_menu()
1478{
1479 adb shell input keyevent 82
1480}
1481
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001482function smoketest()
1483{
1484 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1485 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1486 return
1487 fi
1488 T=$(gettop)
1489 if [ ! "$T" ]; then
1490 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1491 return
1492 fi
1493
Ying Wang9cd17642012-12-13 10:52:07 -08001494 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001495 adb uninstall com.android.smoketest > /dev/null &&
1496 adb uninstall com.android.smoketest.tests > /dev/null &&
1497 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1498 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1499 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1500}
1501
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001502# simple shortcut to the runtest command
1503function runtest()
1504{
1505 T=$(gettop)
1506 if [ ! "$T" ]; then
1507 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1508 return
1509 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001510 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001511}
1512
The Android Open Source Project88b60792009-03-03 19:28:42 -08001513function godir () {
1514 if [[ -z "$1" ]]; then
1515 echo "Usage: godir <regex>"
1516 return
1517 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001518 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001519 if [[ ! -f $T/filelist ]]; then
1520 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001521 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001522 echo " Done"
1523 echo ""
1524 fi
1525 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001526 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527 if [[ ${#lines[@]} = 0 ]]; then
1528 echo "Not found"
1529 return
1530 fi
1531 local pathname
1532 local choice
1533 if [[ ${#lines[@]} > 1 ]]; then
1534 while [[ -z "$pathname" ]]; do
1535 local index=1
1536 local line
1537 for line in ${lines[@]}; do
1538 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001539 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001540 done
1541 echo
1542 echo -n "Select one: "
1543 unset choice
1544 read choice
1545 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1546 echo "Invalid choice"
1547 continue
1548 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001549 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001550 done
1551 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001552 pathname=${lines[0]}
1553 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001554 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001555}
1556
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001557function cmremote()
1558{
1559 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301560 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001561 if [ -z "$GERRIT_REMOTE" ]
1562 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301563 echo Unable to set up the git remote, are you under a git repo?
1564 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001565 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301566 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001567 if [ -z "$CMUSER" ]
1568 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001569 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001570 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001571 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001572 fi
1573 echo You can now push to "cmremote".
1574}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001575
Steve Kondik873fa562012-09-17 11:33:18 -07001576function aospremote()
1577{
1578 git remote rm aosp 2> /dev/null
1579 if [ ! -d .git ]
1580 then
1581 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1582 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001583 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001584 if (echo $PROJECT | grep -qv "^device")
1585 then
1586 PFX="platform/"
1587 fi
1588 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1589 echo "Remote 'aosp' created"
1590}
Steve Kondik873fa562012-09-17 11:33:18 -07001591
Steve Kondik20c21d22013-10-27 13:34:36 -07001592function cafremote()
1593{
1594 git remote rm caf 2> /dev/null
1595 if [ ! -d .git ]
1596 then
1597 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1598 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001599 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001600 if (echo $PROJECT | grep -qv "^device")
1601 then
1602 PFX="platform/"
1603 fi
1604 git remote add caf git://codeaurora.org/$PFX$PROJECT
1605 echo "Remote 'caf' created"
1606}
Steve Kondik20c21d22013-10-27 13:34:36 -07001607
Steve Kondikf00e7d92012-09-23 23:46:55 -07001608function installboot()
1609{
1610 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1611 then
1612 echo "No recovery.fstab found. Build recovery first."
1613 return 1
1614 fi
1615 if [ ! -e "$OUT/boot.img" ];
1616 then
1617 echo "No boot.img found. Run make bootimage first."
1618 return 1
1619 fi
1620 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1621 if [ -z "$PARTITION" ];
1622 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001623 # Try for RECOVERY_FSTAB_VERSION = 2
1624 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1625 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1626 if [ -z "$PARTITION" ];
1627 then
1628 echo "Unable to determine boot partition."
1629 return 1
1630 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001631 fi
1632 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001633 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001634 adb root
1635 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001636 adb wait-for-online shell mount /system 2>&1 > /dev/null
1637 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001638 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1639 then
1640 adb push $OUT/boot.img /cache/
1641 for i in $OUT/system/lib/modules/*;
1642 do
1643 adb push $i /system/lib/modules/
1644 done
1645 adb shell dd if=/cache/boot.img of=$PARTITION
1646 adb shell chmod 644 /system/lib/modules/*
1647 echo "Installation complete."
1648 else
1649 echo "The connected device does not appear to be $CM_BUILD, run away!"
1650 fi
1651}
1652
Steve Kondik83c03d52012-10-24 16:40:42 -07001653function installrecovery()
1654{
1655 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1656 then
1657 echo "No recovery.fstab found. Build recovery first."
1658 return 1
1659 fi
1660 if [ ! -e "$OUT/recovery.img" ];
1661 then
1662 echo "No recovery.img found. Run make recoveryimage first."
1663 return 1
1664 fi
1665 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1666 if [ -z "$PARTITION" ];
1667 then
Steve Kondik75f10762013-08-09 21:03:42 -07001668 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001669 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1670 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001671 if [ -z "$PARTITION" ];
1672 then
1673 echo "Unable to determine recovery partition."
1674 return 1
1675 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001676 fi
1677 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001678 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001679 adb root
1680 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001681 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1682 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001683 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1684 then
1685 adb push $OUT/recovery.img /cache/
1686 adb shell dd if=/cache/recovery.img of=$PARTITION
1687 echo "Installation complete."
1688 else
1689 echo "The connected device does not appear to be $CM_BUILD, run away!"
1690 fi
1691}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001692
Koushik Duttab55f13a2012-05-14 16:14:36 -07001693function makerecipe() {
1694 if [ -z "$1" ]
1695 then
1696 echo "No branch name provided."
1697 return 1
1698 fi
1699 cd android
1700 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1701 git commit -a -m "$1"
1702 cd ..
1703
1704 repo forall -c '
1705
1706 if [ "$REPO_REMOTE" == "github" ]
1707 then
1708 pwd
1709 cmremote
1710 git push cmremote HEAD:refs/heads/'$1'
1711 fi
1712 '
1713}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001714
1715function cmgerrit() {
1716 if [ $# -eq 0 ]; then
1717 $FUNCNAME help
1718 return 1
1719 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001720 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001721 local review=`git config --get remote.github.review`
1722 local project=`git config --get remote.github.projectname`
1723 local command=$1
1724 shift
1725 case $command in
1726 help)
1727 if [ $# -eq 0 ]; then
1728 cat <<EOF
1729Usage:
1730 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1731
1732Commands:
1733 fetch Just fetch the change as FETCH_HEAD
1734 help Show this help, or for a specific command
1735 pull Pull a change into current branch
1736 push Push HEAD or a local branch to Gerrit for a specific branch
1737
1738Any other Git commands that support refname would work as:
1739 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1740
1741See '$FUNCNAME help COMMAND' for more information on a specific command.
1742
1743Example:
1744 $FUNCNAME checkout -b topic 1234/5
1745works as:
1746 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1747 && git checkout -b topic FETCH_HEAD
1748will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1749Patch-set 1 will be fetched if omitted.
1750EOF
1751 return
1752 fi
1753 case $1 in
1754 __cmg_*) echo "For internal use only." ;;
1755 changes|for)
1756 if [ "$FUNCNAME" = "cmgerrit" ]; then
1757 echo "'$FUNCNAME $1' is deprecated."
1758 fi
1759 ;;
1760 help) $FUNCNAME help ;;
1761 fetch|pull) cat <<EOF
1762usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1763
1764works as:
1765 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1766 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1767
1768Example:
1769 $FUNCNAME $1 1234
1770will $1 patch-set 1 of change 1234
1771EOF
1772 ;;
1773 push) cat <<EOF
1774usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1775
1776works as:
1777 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1778 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1779
1780Example:
1781 $FUNCNAME push fix6789:gingerbread
1782will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1783HEAD will be pushed from local if omitted.
1784EOF
1785 ;;
1786 *)
1787 $FUNCNAME __cmg_err_not_supported $1 && return
1788 cat <<EOF
1789usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1790
1791works as:
1792 git fetch http://DOMAIN/p/PROJECT \\
1793 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1794 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1795EOF
1796 ;;
1797 esac
1798 ;;
1799 __cmg_get_ref)
1800 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1801 local change_id patchset_id hash
1802 case $1 in
1803 */*)
1804 change_id=${1%%/*}
1805 patchset_id=${1#*/}
1806 ;;
1807 *)
1808 change_id=$1
1809 patchset_id=1
1810 ;;
1811 esac
1812 hash=$(($change_id % 100))
1813 case $hash in
1814 [0-9]) hash="0$hash" ;;
1815 esac
1816 echo "refs/changes/$hash/$change_id/$patchset_id"
1817 ;;
1818 fetch|pull)
1819 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1820 $FUNCNAME __cmg_err_not_repo && return 1
1821 local change=$1
1822 shift
1823 git $command $@ http://$review/p/$project \
1824 $($FUNCNAME __cmg_get_ref $change) || return 1
1825 ;;
1826 push)
1827 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1828 $FUNCNAME __cmg_err_not_repo && return 1
1829 if [ -z "$user" ]; then
1830 echo >&2 "Gerrit username not found."
1831 return 1
1832 fi
1833 local local_branch remote_branch
1834 case $1 in
1835 *:*)
1836 local_branch=${1%:*}
1837 remote_branch=${1##*:}
1838 ;;
1839 *)
1840 local_branch=HEAD
1841 remote_branch=$1
1842 ;;
1843 esac
1844 shift
1845 git push $@ ssh://$user@$review:29418/$project \
1846 $local_branch:refs/for/$remote_branch || return 1
1847 ;;
1848 changes|for)
1849 if [ "$FUNCNAME" = "cmgerrit" ]; then
1850 echo >&2 "'$FUNCNAME $command' is deprecated."
1851 fi
1852 ;;
1853 __cmg_err_no_arg)
1854 if [ $# -lt 2 ]; then
1855 echo >&2 "'$FUNCNAME $command' missing argument."
1856 elif [ $2 -eq 0 ]; then
1857 if [ -n "$3" ]; then
1858 $FUNCNAME help $1
1859 else
1860 echo >&2 "'$FUNCNAME $1' missing argument."
1861 fi
1862 else
1863 return 1
1864 fi
1865 ;;
1866 __cmg_err_not_repo)
1867 if [ -z "$review" -o -z "$project" ]; then
1868 echo >&2 "Not currently in any reviewable repository."
1869 else
1870 return 1
1871 fi
1872 ;;
1873 __cmg_err_not_supported)
1874 $FUNCNAME __cmg_err_no_arg $command $# && return
1875 case $1 in
1876 #TODO: filter more git commands that don't use refname
1877 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1878 echo >&2 "'$FUNCNAME $1' is not supported."
1879 ;;
1880 *) return 1 ;;
1881 esac
1882 ;;
1883 #TODO: other special cases?
1884 *)
1885 $FUNCNAME __cmg_err_not_supported $command && return 1
1886 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1887 $FUNCNAME __cmg_err_not_repo && return 1
1888 local args="$@"
1889 local change pre_args refs_arg post_args
1890 case "$args" in
1891 *--\ *)
1892 pre_args=${args%%-- *}
1893 post_args="-- ${args#*-- }"
1894 ;;
1895 *) pre_args="$args" ;;
1896 esac
1897 args=($pre_args)
1898 pre_args=
1899 if [ ${#args[@]} -gt 0 ]; then
1900 change=${args[${#args[@]}-1]}
1901 fi
1902 if [ ${#args[@]} -gt 1 ]; then
1903 pre_args=${args[0]}
1904 for ((i=1; i<${#args[@]}-1; i++)); do
1905 pre_args="$pre_args ${args[$i]}"
1906 done
1907 fi
1908 while ((1)); do
1909 case $change in
1910 ""|--)
1911 $FUNCNAME help $command
1912 return 1
1913 ;;
1914 *@*)
1915 if [ -z "$refs_arg" ]; then
1916 refs_arg="@${change#*@}"
1917 change=${change%%@*}
1918 fi
1919 ;;
1920 *~*)
1921 if [ -z "$refs_arg" ]; then
1922 refs_arg="~${change#*~}"
1923 change=${change%%~*}
1924 fi
1925 ;;
1926 *^*)
1927 if [ -z "$refs_arg" ]; then
1928 refs_arg="^${change#*^}"
1929 change=${change%%^*}
1930 fi
1931 ;;
1932 *:*)
1933 if [ -z "$refs_arg" ]; then
1934 refs_arg=":${change#*:}"
1935 change=${change%%:*}
1936 fi
1937 ;;
1938 *) break ;;
1939 esac
1940 done
1941 $FUNCNAME fetch $change \
1942 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1943 || return 1
1944 ;;
1945 esac
1946}
1947
1948function cmrebase() {
1949 local repo=$1
1950 local refs=$2
1951 local pwd="$(pwd)"
1952 local dir="$(gettop)/$repo"
1953
1954 if [ -z $repo ] || [ -z $refs ]; then
1955 echo "CyanogenMod Gerrit Rebase Usage: "
1956 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1957 echo " The patch IDs appear on the Gerrit commands that are offered."
1958 echo " They consist on a series of numbers and slashes, after the text"
1959 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1960 echo ""
1961 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1962 echo ""
1963 return
1964 fi
1965
1966 if [ ! -d $dir ]; then
1967 echo "Directory $dir doesn't exist in tree."
1968 return
1969 fi
1970 cd $dir
1971 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1972 echo "Starting branch..."
1973 repo start tmprebase .
1974 echo "Bringing it up to date..."
1975 repo sync .
1976 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001977 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001978 if [ "$?" != "0" ]; then
1979 echo "Error cherry-picking. Not uploading!"
1980 return
1981 fi
1982 echo "Uploading..."
1983 repo upload .
1984 echo "Cleaning up..."
1985 repo abandon tmprebase .
1986 cd $pwd
1987}
1988
1989function mka() {
1990 case `uname -s` in
1991 Darwin)
1992 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1993 ;;
1994 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001995 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001996 ;;
1997 esac
1998}
1999
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302000function cmka() {
2001 if [ ! -z "$1" ]; then
2002 for i in "$@"; do
2003 case $i in
2004 bacon|otapackage|systemimage)
2005 mka installclean
2006 mka $i
2007 ;;
2008 *)
2009 mka clean-$i
2010 mka $i
2011 ;;
2012 esac
2013 done
2014 else
2015 mka clean
2016 mka
2017 fi
2018}
2019
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002020function reposync() {
2021 case `uname -s` in
2022 Darwin)
2023 repo sync -j 4 "$@"
2024 ;;
2025 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002026 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002027 ;;
2028 esac
2029}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002030
2031function repodiff() {
2032 if [ -z "$*" ]; then
2033 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2034 return
2035 fi
2036 diffopts=$* repo forall -c \
2037 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2038}
2039
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302040# Credit for color strip sed: http://goo.gl/BoIcm
2041function dopush()
2042{
2043 local func=$1
2044 shift
2045
2046 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2047 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2048 echo "No device is online. Waiting for one..."
2049 echo "Please connect USB and/or enable USB debugging"
2050 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2051 sleep 1
2052 done
2053 echo "Device Found."
2054 fi
2055
Chirayu Desai6dadb572012-12-26 10:53:58 +05302056 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2057 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002058 # retrieve IP and PORT info if we're using a TCP connection
2059 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2060 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302061 adb root &> /dev/null
2062 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002063 if [ -n "$TCPIPPORT" ]
2064 then
2065 # adb root just killed our connection
2066 # so reconnect...
2067 adb connect "$TCPIPPORT"
2068 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302069 adb wait-for-device &> /dev/null
2070 sleep 0.3
2071 adb remount &> /dev/null
2072
Matt Mower668ea262014-05-20 02:52:23 -05002073 mkdir -p $OUT
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302074 $func $* | tee $OUT/.log
2075
2076 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002077 LOC="$(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep '^Install: ' | cut -d ':' -f 2)"
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302078
2079 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002080 LOC="$LOC $(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep '^Copy: ' | cut -d ':' -f 2)"
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302081
Matt Mower668ea262014-05-20 02:52:23 -05002082 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302083 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002084 # Make sure file is in $OUT/system
2085 case $FILE in
2086 $OUT/system/*)
2087 # Get target file name (i.e. /system/bin/adb)
2088 TARGET=$(echo $FILE | sed "s#$OUT##")
2089 ;;
2090 *) continue ;;
2091 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302092
Matt Mower668ea262014-05-20 02:52:23 -05002093 case $TARGET in
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002094 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002095 # Only need to stop services once
2096 if ! $stop_n_start; then
2097 adb shell stop
2098 stop_n_start=true
2099 fi
2100 echo "Pushing: $TARGET"
2101 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302102 ;;
2103 *)
Matt Mower668ea262014-05-20 02:52:23 -05002104 echo "Pushing: $TARGET"
2105 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302106 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002107 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302108 done
Matt Mower668ea262014-05-20 02:52:23 -05002109 if $stop_n_start; then
2110 adb shell start
2111 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302112 rm -f $OUT/.log
2113 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302114 else
2115 echo "The connected device does not appear to be $CM_BUILD, run away!"
2116 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302117}
2118
2119alias mmp='dopush mm'
2120alias mmmp='dopush mmm'
2121alias mkap='dopush mka'
2122alias cmkap='dopush cmka'
2123
Chirayu Desai4a319b82013-06-05 20:14:33 +05302124function repopick() {
2125 T=$(gettop)
2126 $T/build/tools/repopick.py $@
2127}
2128
Chirayu Desaib89b3242013-06-30 10:04:25 +05302129function fixup_common_out_dir() {
2130 common_out_dir=$(get_build_var OUT_DIR)/target/common
2131 target_device=$(get_build_var TARGET_DEVICE)
2132 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2133 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2134 mv ${common_out_dir} ${common_out_dir}-${target_device}
2135 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2136 else
2137 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2138 mkdir -p ${common_out_dir}-${target_device}
2139 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2140 fi
2141 else
2142 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2143 mkdir -p ${common_out_dir}
2144 fi
2145}
2146
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002147# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002148#
2149# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2150# For some reason, installing the JDK doesn't make it show up in the
2151# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002152function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002153 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002154 # we can reset it later, depending on the version of java the build
2155 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002156 #
2157 # If we don't do this, the JAVA_HOME value set by the first call to
2158 # build/envsetup.sh will persist forever.
2159 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2160 export JAVA_HOME=""
2161 fi
2162
Andy McFaddenbd960942010-06-24 12:52:51 -07002163 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002164 case `uname -s` in
2165 Darwin)
2166 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2167 ;;
2168 *)
2169 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2170 ;;
2171 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002172
2173 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2174 # we can change it on the next envsetup.sh, if required.
2175 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002176 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002177}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002178
Alex Rayf0d08eb2013-03-08 15:15:06 -08002179# Print colored exit condition
2180function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002181 "$@"
2182 local retval=$?
2183 if [ $retval -ne 0 ]
2184 then
2185 echo -e "\e[0;31mFAILURE\e[00m"
2186 else
2187 echo -e "\e[0;32mSUCCESS\e[00m"
2188 fi
2189 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002190}
2191
Ying Wanged21d4c2014-08-24 22:14:19 -07002192function get_make_command()
2193{
2194 echo command make
2195}
2196
Ed Heylcc6be0a2014-06-18 14:55:58 -07002197function make()
2198{
2199 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002200 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002201 local ret=$?
2202 local end_time=$(date +"%s")
2203 local tdiff=$(($end_time-$start_time))
2204 local hours=$(($tdiff / 3600 ))
2205 local mins=$((($tdiff % 3600) / 60))
2206 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002207 local ncolors=$(tput colors 2>/dev/null)
2208 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2209 color_failed="\e[0;31m"
2210 color_success="\e[0;32m"
2211 color_reset="\e[00m"
2212 else
2213 color_failed=""
2214 color_success=""
2215 color_reset=""
2216 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002217 echo
2218 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002219 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002220 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002221 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002222 fi
2223 if [ $hours -gt 0 ] ; then
2224 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2225 elif [ $mins -gt 0 ] ; then
2226 printf "(%02g:%02g (mm:ss))" $mins $secs
2227 elif [ $secs -gt 0 ] ; then
2228 printf "(%s seconds)" $secs
2229 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002230 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002231 echo
2232 return $ret
2233}
2234
Raphael Moll70a86b02011-06-20 16:03:14 -07002235if [ "x$SHELL" != "x/bin/bash" ]; then
2236 case `ps -o command -p $$` in
2237 *bash*)
2238 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002239 *zsh*)
2240 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002241 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002242 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002243 ;;
2244 esac
2245fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002246
2247# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002248for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2249 `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 -08002250do
2251 echo "including $f"
2252 . $f
2253done
2254unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002255
Kyle Ladd031a0b62013-09-11 20:43:42 -04002256# Add completions
2257check_bash_version && {
2258 dirs="sdk/bash_completion vendor/cm/bash_completion"
2259 for dir in $dirs; do
2260 if [ -d ${dir} ]; then
2261 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2262 echo "including $f"
2263 . $f
2264 done
2265 fi
2266 done
2267}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302268
2269export ANDROID_BUILD_TOP=$(gettop)