blob: 0cda8cbaa6a552d3455872dd7d8eecfad5565f5e [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
30- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053031- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070032- installboot: Installs a boot.img to the connected device.
33- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070034
Dan Albert4ae5d4b2014-10-31 16:23:08 -070035Environemnt options:
36- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
37 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
38 build is leak-check clean.
39
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070040Look at the source to view more functions. The complete list is:
41EOF
42 T=$(gettop)
43 local A
44 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070045 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 -070046 A="$A $i"
47 done
48 echo $A
49}
50
51# Get the value of a build variable as an absolute path.
52function get_abs_build_var()
53{
54 T=$(gettop)
55 if [ ! "$T" ]; then
56 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
57 return
58 fi
Ying Wang9cd17642012-12-13 10:52:07 -080059 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070060 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070061}
62
63# Get the exact value of a build variable.
64function get_build_var()
65{
66 T=$(gettop)
67 if [ ! "$T" ]; then
68 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
69 return
70 fi
Andrew Boie6905e212013-12-19 13:21:46 -080071 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070072 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080073}
74
75# check to see if the supplied product is one we can build
76function check_product()
77{
78 T=$(gettop)
79 if [ ! "$T" ]; then
80 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
81 return
82 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000083
84 if (echo -n $1 | grep -q -e "^cm_") ; then
85 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
Ricardo Cerqueira34ae3232013-09-26 00:10:20 +010086 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 +000087 else
88 CM_BUILD=
89 fi
90 export CM_BUILD
91
Jeff Browne33ba4c2011-07-11 22:11:46 -070092 TARGET_PRODUCT=$1 \
93 TARGET_BUILD_VARIANT= \
94 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070095 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080096 get_build_var TARGET_DEVICE > /dev/null
97 # hide successful answers, but allow the errors to show
98}
99
100VARIANT_CHOICES=(user userdebug eng)
101
102# check to see if the supplied variant is valid
103function check_variant()
104{
105 for v in ${VARIANT_CHOICES[@]}
106 do
107 if [ "$v" = "$1" ]
108 then
109 return 0
110 fi
111 done
112 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700113}
114
115function setpaths()
116{
117 T=$(gettop)
118 if [ ! "$T" ]; then
119 echo "Couldn't locate the top of the tree. Try setting TOP."
120 return
121 fi
122
123 ##################################################################
124 # #
125 # Read me before you modify this code #
126 # #
127 # This function sets ANDROID_BUILD_PATHS to what it is adding #
128 # to PATH, and the next time it is run, it removes that from #
129 # PATH. This is required so lunch can be run more than once #
130 # and still have working paths. #
131 # #
132 ##################################################################
133
Raphael Mollc639c782011-06-20 17:25:01 -0700134 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
135 # due to "C:\Program Files" being in the path.
136
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700138 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700139 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
140 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700141 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700142 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800143 # strip leading ':', if any
144 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500145 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700146
147 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700148 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700149 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700150
Ben Cheng8bc4c432012-11-16 13:29:13 -0800151 # defined in core/config.mk
152 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700153 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800154 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800155
Raphael Mollc639c782011-06-20 17:25:01 -0700156 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800157 export ANDROID_TOOLCHAIN=
158 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200159 local ARCH=$(get_build_var TARGET_ARCH)
160 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400161 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700162 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400163 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
164 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800165 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200166 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800167 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700168 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700169 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700170 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000171 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200172 *)
173 echo "Can't find toolchain for unknown architecture: $ARCH"
174 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700175 ;;
176 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700177 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800178 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700179 fi
Raphael732936d2011-06-22 14:35:32 -0700180
Ben Chengfba67bf2014-02-25 10:27:07 -0800181 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
182 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
183 fi
184
185 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700186 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700187 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800188 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800189 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700190 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100191 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
192 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700193 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700194 ;;
195 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700196 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700197 ;;
198 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700199
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700200 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700201 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 +0200202
203 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
204 # to ensure that the corresponding 'emulator' binaries are used.
205 case $(uname -s) in
206 Darwin)
207 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
208 ;;
209 Linux)
210 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
211 ;;
212 *)
213 ANDROID_EMULATOR_PREBUILTS=
214 ;;
215 esac
216 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700217 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200218 export ANDROID_EMULATOR_PREBUILTS
219 fi
220
Ying Wangaa1c9b52012-11-26 20:51:59 -0800221 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800222
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500223 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900224 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500225 if [ -n "$JAVA_HOME" ]; then
226 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900227 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
228 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500229 fi
230
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800231 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700232 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
233 export OUT=$ANDROID_PRODUCT_OUT
234
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700235 unset ANDROID_HOST_OUT
236 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
237
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239 # TODO: fix the path
240 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
241}
242
243function printconfig()
244{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800245 T=$(gettop)
246 if [ ! "$T" ]; then
247 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
248 return
249 fi
250 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700251}
252
253function set_stuff_for_environment()
254{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800255 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500256 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800257 setpaths
258 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700259
Ben Chengaac3f812013-08-13 14:38:15 -0700260 # With this environment variable new GCC can apply colors to warnings/errors
261 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 -0700262 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263}
264
265function set_sequence_number()
266{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700267 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268}
269
270function settitle()
271{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800272 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700273 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700274 local product=$TARGET_PRODUCT
275 local variant=$TARGET_BUILD_VARIANT
276 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800277 if [ -z "$PROMPT_COMMAND" ]; then
278 # No prompts
279 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
280 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
281 # Prompts exist, but no hardstatus
282 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700283 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800284 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500285 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800286 fi
287
288 if [ -z "$apps" ]; then
289 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
290 else
291 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
292 fi
293 export ANDROID_PROMPT_PREFIX
294
295 # Inject build data into hardstatus
296 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 -0800297 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298}
299
Kyle Ladd031a0b62013-09-11 20:43:42 -0400300function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700301{
Kenny Root52aa81c2011-07-15 11:07:06 -0700302 # Keep us from trying to run in something that isn't bash.
303 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400304 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700305 fi
306
307 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200308 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400309 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700310 fi
311
Kyle Ladd031a0b62013-09-11 20:43:42 -0400312 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700313}
314
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315function choosetype()
316{
317 echo "Build type choices are:"
318 echo " 1. release"
319 echo " 2. debug"
320 echo
321
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800322 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700323 DEFAULT_NUM=1
324 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 export TARGET_BUILD_TYPE=
327 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328 while [ -z $TARGET_BUILD_TYPE ]
329 do
330 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 if [ -z "$1" ] ; then
332 read ANSWER
333 else
334 echo $1
335 ANSWER=$1
336 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 case $ANSWER in
338 "")
339 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
340 ;;
341 1)
342 export TARGET_BUILD_TYPE=release
343 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344 release)
345 export TARGET_BUILD_TYPE=release
346 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 2)
348 export TARGET_BUILD_TYPE=debug
349 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350 debug)
351 export TARGET_BUILD_TYPE=debug
352 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700353 *)
354 echo
355 echo "I didn't understand your response. Please try again."
356 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357 ;;
358 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800359 if [ -n "$1" ] ; then
360 break
361 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 done
363
364 set_stuff_for_environment
365}
366
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800367#
368# This function isn't really right: It chooses a TARGET_PRODUCT
369# based on the list of boards. Usually, that gets you something
370# that kinda works with a generic product, but really, you should
371# pick a product by name.
372#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700373function chooseproduct()
374{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700375 if [ "x$TARGET_PRODUCT" != x ] ; then
376 default_value=$TARGET_PRODUCT
377 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700378 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700379 fi
380
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800381 export TARGET_PRODUCT=
382 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383 while [ -z "$TARGET_PRODUCT" ]
384 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700385 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800386 if [ -z "$1" ] ; then
387 read ANSWER
388 else
389 echo $1
390 ANSWER=$1
391 fi
392
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700393 if [ -z "$ANSWER" ] ; then
394 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395 else
396 if check_product $ANSWER
397 then
398 export TARGET_PRODUCT=$ANSWER
399 else
400 echo "** Not a valid product: $ANSWER"
401 fi
402 fi
403 if [ -n "$1" ] ; then
404 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700405 fi
406 done
407
408 set_stuff_for_environment
409}
410
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800411function choosevariant()
412{
413 echo "Variant choices are:"
414 local index=1
415 local v
416 for v in ${VARIANT_CHOICES[@]}
417 do
418 # The product name is the name of the directory containing
419 # the makefile we found, above.
420 echo " $index. $v"
421 index=$(($index+1))
422 done
423
424 local default_value=eng
425 local ANSWER
426
427 export TARGET_BUILD_VARIANT=
428 while [ -z "$TARGET_BUILD_VARIANT" ]
429 do
430 echo -n "Which would you like? [$default_value] "
431 if [ -z "$1" ] ; then
432 read ANSWER
433 else
434 echo $1
435 ANSWER=$1
436 fi
437
438 if [ -z "$ANSWER" ] ; then
439 export TARGET_BUILD_VARIANT=$default_value
440 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
441 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800442 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800443 fi
444 else
445 if check_variant $ANSWER
446 then
447 export TARGET_BUILD_VARIANT=$ANSWER
448 else
449 echo "** Not a valid variant: $ANSWER"
450 fi
451 fi
452 if [ -n "$1" ] ; then
453 break
454 fi
455 done
456}
457
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458function choosecombo()
459{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700460 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461
462 echo
463 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700464 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465
466 echo
467 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700468 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469
470 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473}
474
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475# Clear this variable. It will be built up again when the vendorsetup.sh
476# files are included at the end of this file.
477unset LUNCH_MENU_CHOICES
478function add_lunch_combo()
479{
480 local new_combo=$1
481 local c
482 for c in ${LUNCH_MENU_CHOICES[@]} ; do
483 if [ "$new_combo" = "$c" ] ; then
484 return
485 fi
486 done
487 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
488}
489
490# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700491add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800492add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000493add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800494add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000495add_lunch_combo aosp_x86-eng
496add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800497
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700498function print_lunch_menu()
499{
500 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700501 echo
502 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000503 if [ "$(uname)" = "Darwin" ] ; then
504 echo " (ohai, koush!)"
505 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000507 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
508 echo "Breakfast menu... pick a combo:"
509 else
510 echo "Lunch menu... pick a combo:"
511 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512
513 local i=1
514 local choice
515 for choice in ${LUNCH_MENU_CHOICES[@]}
516 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100517 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100519 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000521 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
522 echo "... and don't forget the bacon!"
523 fi
524
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700525 echo
526}
527
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000528function brunch()
529{
530 breakfast $*
531 if [ $? -eq 0 ]; then
532 mka bacon
533 else
534 echo "No such item in brunch menu. Try 'breakfast'"
535 return 1
536 fi
537 return $?
538}
539
540function breakfast()
541{
542 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200543 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000544 CM_DEVICES_ONLY="true"
545 unset LUNCH_MENU_CHOICES
546 add_lunch_combo full-eng
547 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
548 do
549 echo "including $f"
550 . $f
551 done
552 unset f
553
554 if [ $# -eq 0 ]; then
555 # No arguments, so let's have the full menu
556 lunch
557 else
558 echo "z$target" | grep -q "-"
559 if [ $? -eq 0 ]; then
560 # A buildtype was specified, assume a full device name
561 lunch $target
562 else
563 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200564 if [ -z "$variant" ]; then
565 variant="userdebug"
566 fi
567 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000568 fi
569 fi
570 return $?
571}
572
573alias bib=breakfast
574
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700575function lunch()
576{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800577 local answer
578
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700581 else
582 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700583 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800584 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 fi
586
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 local selection=
588
589 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700591 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800592 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
593 then
594 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
595 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800596 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 fi
598 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
599 then
600 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700601 fi
602
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 if [ -z "$selection" ]
604 then
605 echo
606 echo "Invalid lunch combo: $answer"
607 return 1
608 fi
609
Joe Onoratoda12daf2010-06-09 18:18:31 -0700610 export TARGET_BUILD_APPS=
611
Jeff Browne33ba4c2011-07-11 22:11:46 -0700612 local product=$(echo -n $selection | sed -e "s/-.*$//")
613 check_product $product
614 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800615 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800616 # if we can't find a product, try to grab it off the CM github
617 T=$(gettop)
618 pushd $T > /dev/null
619 build/tools/roomservice.py $product
620 popd > /dev/null
621 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000622 else
623 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800624 fi
625 if [ $? -ne 0 ]
626 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700627 echo
628 echo "** Don't have a product spec for: '$product'"
629 echo "** Do you have the right repo manifest?"
630 product=
631 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800632
Jeff Browne33ba4c2011-07-11 22:11:46 -0700633 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
634 check_variant $variant
635 if [ $? -ne 0 ]
636 then
637 echo
638 echo "** Invalid variant: '$variant'"
639 echo "** Must be one of ${VARIANT_CHOICES[@]}"
640 variant=
641 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642
Jeff Browne33ba4c2011-07-11 22:11:46 -0700643 if [ -z "$product" -o -z "$variant" ]
644 then
645 echo
646 return 1
647 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800648
Jeff Browne33ba4c2011-07-11 22:11:46 -0700649 export TARGET_PRODUCT=$product
650 export TARGET_BUILD_VARIANT=$variant
651 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700652
653 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654
Chirayu Desaib89b3242013-06-30 10:04:25 +0530655 fixup_common_out_dir
656
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800658 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700659}
660
Jeff Davidson513d7a42010-08-02 10:00:44 -0700661# Tab completion for lunch.
662function _lunch()
663{
664 local cur prev opts
665 COMPREPLY=()
666 cur="${COMP_WORDS[COMP_CWORD]}"
667 prev="${COMP_WORDS[COMP_CWORD-1]}"
668
669 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
670 return 0
671}
Emilio López9ad6eea2013-11-03 13:02:13 -0300672complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700673
Joe Onoratoda12daf2010-06-09 18:18:31 -0700674# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700675# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700676function tapas()
677{
Ying Wangb541ab62014-05-29 17:57:40 -0700678 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 -0700679 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700680 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
681 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 -0700682
Ying Wang67f02922012-08-22 10:25:20 -0700683 if [ $(echo $arch | wc -w) -gt 1 ]; then
684 echo "tapas: Error: Multiple build archs supplied: $arch"
685 return
686 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700687 if [ $(echo $variant | wc -w) -gt 1 ]; then
688 echo "tapas: Error: Multiple build variants supplied: $variant"
689 return
690 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700691 if [ $(echo $density | wc -w) -gt 1 ]; then
692 echo "tapas: Error: Multiple densities supplied: $density"
693 return
694 fi
Ying Wang67f02922012-08-22 10:25:20 -0700695
696 local product=full
697 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700698 x86) product=full_x86;;
699 mips) product=full_mips;;
700 armv5) product=generic_armv5;;
701 arm64) product=aosp_arm64;;
702 x86_64) product=aosp_x86_64;;
703 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700704 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700705 if [ -z "$variant" ]; then
706 variant=eng
707 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700708 if [ -z "$apps" ]; then
709 apps=all
710 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600711 if [ -z "$density" ]; then
712 density=alldpi
713 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700714
Ying Wang67f02922012-08-22 10:25:20 -0700715 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700716 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700717 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700718 export TARGET_BUILD_TYPE=release
719 export TARGET_BUILD_APPS=$apps
720
721 set_stuff_for_environment
722 printconfig
723}
724
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100725function eat()
726{
727 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530728 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100729 ZIPFILE=cm-$MODVERSION.zip
730 ZIPPATH=$OUT/$ZIPFILE
731 if [ ! -f $ZIPPATH ] ; then
732 echo "Nothing to eat"
733 return 1
734 fi
735 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
736 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
737 echo "No device is online. Waiting for one..."
738 echo "Please connect USB and/or enable USB debugging"
739 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
740 sleep 1
741 done
742 echo "Device Found.."
743 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530744 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
745 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100746 # if adbd isn't root we can't write to /cache/recovery/
747 adb root
748 sleep 1
749 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700750 cat << EOF > /tmp/command
751--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100752EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700753 if adb push /tmp/command /cache/recovery/ ; then
754 echo "Rebooting into recovery for sideload installation"
755 adb reboot recovery
756 adb wait-for-sideload
757 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100758 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700759 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100760 else
761 echo "Nothing to eat"
762 return 1
763 fi
764 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530765 else
766 echo "The connected device does not appear to be $CM_BUILD, run away!"
767 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100768}
769
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000770function omnom
771{
772 brunch $*
773 eat
774}
775
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700776function gettop
777{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800778 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700779 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700780 # The following circumlocution ensures we remove symlinks from TOP.
781 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782 else
783 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800784 # The following circumlocution (repeated below as well) ensures
785 # that we record the true directory name and not one that is
786 # faked up with symlink names.
787 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800789 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700790 T=
791 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800792 \cd ..
synergyb112a402013-07-05 19:47:47 -0700793 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 done
Ying Wang9cd17642012-12-13 10:52:07 -0800795 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 if [ -f "$T/$TOPFILE" ]; then
797 echo $T
798 fi
799 fi
800 fi
801}
802
Andrew Hsieh906cb782013-09-10 17:37:14 +0800803# Return driver for "make", if any (eg. static analyzer)
804function getdriver()
805{
806 local T="$1"
807 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
808 if [ -n "$WITH_STATIC_ANALYZER" ]; then
809 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800810$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
811--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800812--status-bugs \
813--top=$T"
814 fi
815}
816
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700817function m()
818{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800819 local T=$(gettop)
820 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700821 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800822 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823 else
824 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700825 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700826 fi
827}
828
829function findmakefile()
830{
831 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800832 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700833 T=
834 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700835 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 if [ -f "$T/Android.mk" ]; then
837 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800838 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 return
840 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800841 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842 done
Ying Wang9cd17642012-12-13 10:52:07 -0800843 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844}
845
846function mm()
847{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800848 local T=$(gettop)
849 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850 # If we're sitting in the root of the build tree, just do a
851 # normal make.
852 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800853 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700854 else
855 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800856 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700857 local MODULES=
858 local GET_INSTALL_PATH=
859 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700860 # Remove the path to top as the makefilepath needs to be relative
861 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700862 if [ ! "$T" ]; then
863 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700864 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700865 elif [ ! "$M" ]; then
866 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700867 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868 else
Ying Wanga7deb082013-08-16 13:24:47 -0700869 for ARG in $@; do
870 case $ARG in
871 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
872 esac
873 done
874 if [ -n "$GET_INSTALL_PATH" ]; then
875 MODULES=
876 ARGS=GET-INSTALL-PATH
877 else
878 MODULES=all_modules
879 ARGS=$@
880 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700881 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 -0700882 fi
883 fi
884}
885
886function mmm()
887{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800888 local T=$(gettop)
889 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700890 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800891 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800892 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800893 local ARGS=
894 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700895 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800896 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
897 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
898 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800899 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
900 if [ "$MODULES" = "" ]; then
901 MODULES=all_modules
902 fi
903 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700904 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700905 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
906 local TO_CHOP=`expr $TO_CHOP + 1`
907 local START=`PWD= /bin/pwd`
908 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 if [ "$MFILE" = "" ] ; then
910 MFILE=$DIR/Android.mk
911 else
912 MFILE=$MFILE/$DIR/Android.mk
913 fi
914 MAKEFILE="$MAKEFILE $MFILE"
915 else
Ying Wanga7deb082013-08-16 13:24:47 -0700916 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100917 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700918 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
919 *) echo "No Android.mk in $DIR."; return 1;;
920 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700921 fi
922 done
Ying Wanga7deb082013-08-16 13:24:47 -0700923 if [ -n "$GET_INSTALL_PATH" ]; then
924 ARGS=$GET_INSTALL_PATH
925 MODULES=
926 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800927 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 -0700928 else
929 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700930 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700931 fi
932}
933
Ying Wangb607f7b2013-02-08 18:01:04 -0800934function mma()
935{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800936 local T=$(gettop)
937 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800938 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800939 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800940 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800941 if [ ! "$T" ]; then
942 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700943 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 fi
945 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800946 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800947 fi
948}
949
950function mmma()
951{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800952 local T=$(gettop)
953 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800954 if [ "$T" ]; then
955 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
956 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
957 local MY_PWD=`PWD= /bin/pwd`
958 if [ "$MY_PWD" = "$T" ]; then
959 MY_PWD=
960 else
961 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
962 fi
963 local DIR=
964 local MODULE_PATHS=
965 local ARGS=
966 for DIR in $DIRS ; do
967 if [ -d $DIR ]; then
968 if [ "$MY_PWD" = "" ]; then
969 MODULE_PATHS="$MODULE_PATHS $DIR"
970 else
971 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
972 fi
973 else
974 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100975 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800976 *) echo "Couldn't find directory $DIR"; return 1;;
977 esac
978 fi
979 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800980 $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 -0800981 else
982 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700983 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800984 fi
985}
986
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700987function croot()
988{
989 T=$(gettop)
990 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800991 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992 else
993 echo "Couldn't locate the top of the tree. Try setting TOP."
994 fi
995}
996
nebkatfb67a1e2012-12-28 10:40:45 +0000997function cout()
998{
999 if [ "$OUT" ]; then
1000 cd $OUT
1001 else
1002 echo "Couldn't locate out directory. Try setting OUT."
1003 fi
1004}
1005
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001006function cproj()
1007{
1008 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001009 local HERE=$PWD
1010 T=
1011 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1012 T=$PWD
1013 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001014 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001015 return
1016 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001017 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001018 done
Ying Wang9cd17642012-12-13 10:52:07 -08001019 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 echo "can't find Android.mk"
1021}
1022
Daniel Sandler47e0a882013-07-30 13:23:52 -04001023# simplified version of ps; output in the form
1024# <pid> <procname>
1025function qpid() {
1026 local prepend=''
1027 local append=''
1028 if [ "$1" = "--exact" ]; then
1029 prepend=' '
1030 append='$'
1031 shift
1032 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1033 echo "usage: qpid [[--exact] <process name|pid>"
1034 return 255
1035 fi
1036
1037 local EXE="$1"
1038 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001039 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001040 else
1041 adb shell ps \
1042 | tr -d '\r' \
1043 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1044 fi
1045}
1046
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001047function pid()
1048{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001049 local prepend=''
1050 local append=''
1051 if [ "$1" = "--exact" ]; then
1052 prepend=' '
1053 append='$'
1054 shift
1055 fi
1056 local EXE="$1"
1057 if [ "$EXE" ] ; then
1058 local PID=`adb shell ps \
1059 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001060 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001061 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1062 echo "$PID"
1063 else
1064 echo "usage: pid [--exact] <process name>"
1065 return 255
1066 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001067}
1068
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001069# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001070# that has the core-file-size limit set correctly
1071#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001072# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001073# if its core-file-size limit is not set already.
1074# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1075
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001076function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001077{
1078 echo "Getting root...";
1079 adb root;
1080 adb wait-for-device;
1081
1082 echo "Remounting root parition read-write...";
1083 adb shell mount -w -o remount -t rootfs rootfs;
1084 sleep 1;
1085 adb wait-for-device;
1086 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001087 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088 adb shell chmod 0777 /cores;
1089
1090 echo "Granting SELinux permission to dump in /cores...";
1091 adb shell restorecon -R /cores;
1092
1093 echo "Set core pattern.";
1094 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1095
1096 echo "Done."
1097}
1098
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001099# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001100# $1 = PID of process (e.g., $(pid mediaserver))
1101#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001102# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001103# dump to actually be generated.
1104
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001105function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001106{
1107 local PID=$1;
1108 if [ -z "$PID" ]; then
1109 printf "Expecting a PID!\n";
1110 return;
1111 fi;
1112 echo "Setting core limit for $PID to infinite...";
1113 adb shell prlimit $PID 4 -1 -1
1114}
1115
1116# core - send SIGV and pull the core for process
1117# $1 = PID of process (e.g., $(pid mediaserver))
1118#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001119# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001120# enabled globally.
1121
1122function core()
1123{
1124 local PID=$1;
1125
1126 if [ -z "$PID" ]; then
1127 printf "Expecting a PID!\n";
1128 return;
1129 fi;
1130
1131 local CORENAME=core.$PID;
1132 local COREPATH=/cores/$CORENAME;
1133 local SIG=SEGV;
1134
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001135 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001136
1137 local done=0;
1138 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1139 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1140 adb shell kill -$SIG $PID;
1141 sleep 1;
1142 done;
1143
1144 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1145 echo "Done: core is under $COREPATH on device.";
1146}
1147
Christopher Tate744ee802009-11-12 15:33:08 -08001148# systemstack - dump the current stack trace of all threads in the system process
1149# to the usual ANR traces file
1150function systemstack()
1151{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001152 stacks system_server
1153}
1154
1155function stacks()
1156{
1157 if [[ $1 =~ ^[0-9]+$ ]] ; then
1158 local PID="$1"
1159 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001160 local PIDLIST="$(pid $1)"
1161 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1162 local PID="$PIDLIST"
1163 elif [ "$PIDLIST" ] ; then
1164 echo "more than one process: $1"
1165 else
1166 echo "no such process: $1"
1167 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001168 else
1169 echo "usage: stacks [pid|process name]"
1170 fi
1171
1172 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001173 # Determine whether the process is native
1174 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1175 # Dump stacks of Dalvik process
1176 local TRACES=/data/anr/traces.txt
1177 local ORIG=/data/anr/traces.orig
1178 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001179
Jeff Brownb12c2e52013-08-19 15:14:16 -07001180 # Keep original traces to avoid clobbering
1181 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001182
Jeff Brownb12c2e52013-08-19 15:14:16 -07001183 # Make sure we have a usable file
1184 adb shell touch $TRACES
1185 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001186
Jeff Brownb12c2e52013-08-19 15:14:16 -07001187 # Dump stacks and wait for dump to finish
1188 adb shell kill -3 $PID
1189 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001190
Jeff Brownb12c2e52013-08-19 15:14:16 -07001191 # Restore original stacks, and show current output
1192 adb shell mv $TRACES $TMP
1193 adb shell mv $ORIG $TRACES
1194 adb shell cat $TMP
1195 else
1196 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001197 local USE64BIT="$(is64bit $PID)"
1198 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001199 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001200 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001201}
1202
Michael Wrightaeed7212014-06-19 19:58:12 -07001203# Read the ELF header from /proc/$PID/exe to determine if the process is
1204# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001205function is64bit()
1206{
1207 local PID="$1"
1208 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001209 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001210 echo "64"
1211 else
1212 echo ""
1213 fi
1214 else
1215 echo ""
1216 fi
1217}
1218
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001219case `uname -s` in
1220 Darwin)
1221 function sgrep()
1222 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001223 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 -07001224 }
1225
1226 ;;
1227 *)
1228 function sgrep()
1229 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001230 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 -07001231 }
1232 ;;
1233esac
1234
Raghu Gandham8da43102012-07-25 19:57:22 -07001235function gettargetarch
1236{
1237 get_build_var TARGET_ARCH
1238}
1239
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001240function ggrep()
1241{
1242 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1243}
1244
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001245function jgrep()
1246{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001247 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 -07001248}
1249
1250function cgrep()
1251{
Dan Albert01961192014-11-22 10:16:01 -08001252 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 -07001253}
1254
1255function resgrep()
1256{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001257 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 -07001258}
1259
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001260function mangrep()
1261{
1262 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1263}
1264
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001265function sepgrep()
1266{
1267 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 "$@"
1268}
1269
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001270function rcgrep()
1271{
1272 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1273}
1274
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001275case `uname -s` in
1276 Darwin)
1277 function mgrep()
1278 {
Ying Wang324c2b22012-08-17 15:03:20 -07001279 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 -07001280 }
1281
1282 function treegrep()
1283 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001284 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 -07001285 }
1286
1287 ;;
1288 *)
1289 function mgrep()
1290 {
Ying Wang324c2b22012-08-17 15:03:20 -07001291 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 -07001292 }
1293
1294 function treegrep()
1295 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001296 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 -07001297 }
1298
1299 ;;
1300esac
1301
1302function getprebuilt
1303{
1304 get_abs_build_var ANDROID_PREBUILTS
1305}
1306
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001307function tracedmdump()
1308{
1309 T=$(gettop)
1310 if [ ! "$T" ]; then
1311 echo "Couldn't locate the top of the tree. Try setting TOP."
1312 return
1313 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001314 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001315 local arch=$(gettargetarch)
1316 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001317
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001318 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001319 if [ ! "$TRACE" ] ; then
1320 echo "usage: tracedmdump tracename"
1321 return
1322 fi
1323
Jack Veenstra60116fc2009-04-09 18:12:34 -07001324 if [ ! -r "$KERNEL" ] ; then
1325 echo "Error: cannot find kernel: '$KERNEL'"
1326 return
1327 fi
1328
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001329 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001330 if [ "$BASETRACE" = "$TRACE" ] ; then
1331 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1332 fi
1333
1334 echo "post-processing traces..."
1335 rm -f $TRACE/qtrace.dexlist
1336 post_trace $TRACE
1337 if [ $? -ne 0 ]; then
1338 echo "***"
1339 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1340 echo "***"
1341 return
1342 fi
1343 echo "generating dexlist output..."
1344 /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
1345 echo "generating dmtrace data..."
1346 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1347 echo "generating html file..."
1348 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1349 echo "done, see $TRACE/dmtrace.html for details"
1350 echo "or run:"
1351 echo " traceview $TRACE/dmtrace"
1352}
1353
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001354# communicate with a running device or emulator, set up necessary state,
1355# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001356function runhat()
1357{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001358 # process standard adb options
1359 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001360 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001361 adbTarget=$1
1362 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001363 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001364 adbTarget="$1 $2"
1365 shift 2
1366 fi
1367 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001368 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001369
1370 # runhat options
1371 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001372
1373 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001374 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001375 return
1376 fi
1377
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001378 # confirm hat is available
1379 if [ -z $(which hat) ]; then
1380 echo "hat is not available in this configuration."
1381 return
1382 fi
1383
Andy McFaddenb6289852010-07-12 08:00:19 -07001384 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001385 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001386 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001387 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001388 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001389 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001390 echo -n "> "
1391 read
1392
The Android Open Source Project88b60792009-03-03 19:28:42 -08001393 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001394
The Android Open Source Project88b60792009-03-03 19:28:42 -08001395 echo "Retrieving file $devFile..."
1396 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001397
The Android Open Source Project88b60792009-03-03 19:28:42 -08001398 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001399
The Android Open Source Project88b60792009-03-03 19:28:42 -08001400 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401 echo "View the output by pointing your browser at http://localhost:7000/"
1402 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001403 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001404}
1405
1406function getbugreports()
1407{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001408 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001409
1410 if [ ! "$reports" ]; then
1411 echo "Could not locate any bugreports."
1412 return
1413 fi
1414
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001415 local report
1416 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001417 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001418 echo "/sdcard/bugreports/${report}"
1419 adb pull /sdcard/bugreports/${report} ${report}
1420 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001421 done
1422}
1423
Victoria Lease1b296b42012-08-21 15:44:06 -07001424function getsdcardpath()
1425{
1426 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1427}
1428
1429function getscreenshotpath()
1430{
1431 echo "$(getsdcardpath)/Pictures/Screenshots"
1432}
1433
1434function getlastscreenshot()
1435{
1436 local screenshot_path=$(getscreenshotpath)
1437 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1438 if [ "$screenshot" = "" ]; then
1439 echo "No screenshots found."
1440 return
1441 fi
1442 echo "${screenshot}"
1443 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1444}
1445
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001446function startviewserver()
1447{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001448 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001449 if [ $# -gt 0 ]; then
1450 port=$1
1451 fi
1452 adb shell service call window 1 i32 $port
1453}
1454
1455function stopviewserver()
1456{
1457 adb shell service call window 2
1458}
1459
1460function isviewserverstarted()
1461{
1462 adb shell service call window 3
1463}
1464
Romain Guyb84049a2010-10-04 16:56:11 -07001465function key_home()
1466{
1467 adb shell input keyevent 3
1468}
1469
1470function key_back()
1471{
1472 adb shell input keyevent 4
1473}
1474
1475function key_menu()
1476{
1477 adb shell input keyevent 82
1478}
1479
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001480function smoketest()
1481{
1482 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1483 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1484 return
1485 fi
1486 T=$(gettop)
1487 if [ ! "$T" ]; then
1488 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1489 return
1490 fi
1491
Ying Wang9cd17642012-12-13 10:52:07 -08001492 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001493 adb uninstall com.android.smoketest > /dev/null &&
1494 adb uninstall com.android.smoketest.tests > /dev/null &&
1495 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1496 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1497 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1498}
1499
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001500# simple shortcut to the runtest command
1501function runtest()
1502{
1503 T=$(gettop)
1504 if [ ! "$T" ]; then
1505 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1506 return
1507 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001508 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001509}
1510
The Android Open Source Project88b60792009-03-03 19:28:42 -08001511function godir () {
1512 if [[ -z "$1" ]]; then
1513 echo "Usage: godir <regex>"
1514 return
1515 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001516 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001517 if [[ ! -f $T/filelist ]]; then
1518 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001519 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001520 echo " Done"
1521 echo ""
1522 fi
1523 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001524 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001525 if [[ ${#lines[@]} = 0 ]]; then
1526 echo "Not found"
1527 return
1528 fi
1529 local pathname
1530 local choice
1531 if [[ ${#lines[@]} > 1 ]]; then
1532 while [[ -z "$pathname" ]]; do
1533 local index=1
1534 local line
1535 for line in ${lines[@]}; do
1536 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001537 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001538 done
1539 echo
1540 echo -n "Select one: "
1541 unset choice
1542 read choice
1543 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1544 echo "Invalid choice"
1545 continue
1546 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001547 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001548 done
1549 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001550 pathname=${lines[0]}
1551 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001552 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001553}
1554
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001555function cmremote()
1556{
1557 git remote rm cmremote 2> /dev/null
1558 if [ ! -d .git ]
1559 then
1560 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1561 fi
1562 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1563 if [ -z "$GERRIT_REMOTE" ]
1564 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001565 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1566 if [ -z "$GERRIT_REMOTE" ]
1567 then
1568 echo Unable to set up the git remote, are you in the root of the repo?
1569 return 0
1570 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001571 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001572 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001573 if [ -z "$CMUSER" ]
1574 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001575 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001576 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001577 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001578 fi
1579 echo You can now push to "cmremote".
1580}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001581
Steve Kondik873fa562012-09-17 11:33:18 -07001582function aospremote()
1583{
1584 git remote rm aosp 2> /dev/null
1585 if [ ! -d .git ]
1586 then
1587 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1588 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001589 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001590 if (echo $PROJECT | grep -qv "^device")
1591 then
1592 PFX="platform/"
1593 fi
1594 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1595 echo "Remote 'aosp' created"
1596}
Steve Kondik873fa562012-09-17 11:33:18 -07001597
Steve Kondik20c21d22013-10-27 13:34:36 -07001598function cafremote()
1599{
1600 git remote rm caf 2> /dev/null
1601 if [ ! -d .git ]
1602 then
1603 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1604 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001605 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001606 if (echo $PROJECT | grep -qv "^device")
1607 then
1608 PFX="platform/"
1609 fi
1610 git remote add caf git://codeaurora.org/$PFX$PROJECT
1611 echo "Remote 'caf' created"
1612}
Steve Kondik20c21d22013-10-27 13:34:36 -07001613
Steve Kondikf00e7d92012-09-23 23:46:55 -07001614function installboot()
1615{
1616 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1617 then
1618 echo "No recovery.fstab found. Build recovery first."
1619 return 1
1620 fi
1621 if [ ! -e "$OUT/boot.img" ];
1622 then
1623 echo "No boot.img found. Run make bootimage first."
1624 return 1
1625 fi
1626 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1627 if [ -z "$PARTITION" ];
1628 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001629 # Try for RECOVERY_FSTAB_VERSION = 2
1630 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1631 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1632 if [ -z "$PARTITION" ];
1633 then
1634 echo "Unable to determine boot partition."
1635 return 1
1636 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001637 fi
1638 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001639 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001640 adb root
1641 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001642 adb wait-for-online shell mount /system 2>&1 > /dev/null
1643 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001644 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1645 then
1646 adb push $OUT/boot.img /cache/
1647 for i in $OUT/system/lib/modules/*;
1648 do
1649 adb push $i /system/lib/modules/
1650 done
1651 adb shell dd if=/cache/boot.img of=$PARTITION
1652 adb shell chmod 644 /system/lib/modules/*
1653 echo "Installation complete."
1654 else
1655 echo "The connected device does not appear to be $CM_BUILD, run away!"
1656 fi
1657}
1658
Steve Kondik83c03d52012-10-24 16:40:42 -07001659function installrecovery()
1660{
1661 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1662 then
1663 echo "No recovery.fstab found. Build recovery first."
1664 return 1
1665 fi
1666 if [ ! -e "$OUT/recovery.img" ];
1667 then
1668 echo "No recovery.img found. Run make recoveryimage first."
1669 return 1
1670 fi
1671 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1672 if [ -z "$PARTITION" ];
1673 then
Steve Kondik75f10762013-08-09 21:03:42 -07001674 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001675 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1676 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001677 if [ -z "$PARTITION" ];
1678 then
1679 echo "Unable to determine recovery partition."
1680 return 1
1681 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001682 fi
1683 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001684 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001685 adb root
1686 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001687 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1688 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001689 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1690 then
1691 adb push $OUT/recovery.img /cache/
1692 adb shell dd if=/cache/recovery.img of=$PARTITION
1693 echo "Installation complete."
1694 else
1695 echo "The connected device does not appear to be $CM_BUILD, run away!"
1696 fi
1697}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001698
Koushik Duttab55f13a2012-05-14 16:14:36 -07001699function makerecipe() {
1700 if [ -z "$1" ]
1701 then
1702 echo "No branch name provided."
1703 return 1
1704 fi
1705 cd android
1706 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1707 git commit -a -m "$1"
1708 cd ..
1709
1710 repo forall -c '
1711
1712 if [ "$REPO_REMOTE" == "github" ]
1713 then
1714 pwd
1715 cmremote
1716 git push cmremote HEAD:refs/heads/'$1'
1717 fi
1718 '
1719}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001720
1721function cmgerrit() {
1722 if [ $# -eq 0 ]; then
1723 $FUNCNAME help
1724 return 1
1725 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001726 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001727 local review=`git config --get remote.github.review`
1728 local project=`git config --get remote.github.projectname`
1729 local command=$1
1730 shift
1731 case $command in
1732 help)
1733 if [ $# -eq 0 ]; then
1734 cat <<EOF
1735Usage:
1736 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1737
1738Commands:
1739 fetch Just fetch the change as FETCH_HEAD
1740 help Show this help, or for a specific command
1741 pull Pull a change into current branch
1742 push Push HEAD or a local branch to Gerrit for a specific branch
1743
1744Any other Git commands that support refname would work as:
1745 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1746
1747See '$FUNCNAME help COMMAND' for more information on a specific command.
1748
1749Example:
1750 $FUNCNAME checkout -b topic 1234/5
1751works as:
1752 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1753 && git checkout -b topic FETCH_HEAD
1754will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1755Patch-set 1 will be fetched if omitted.
1756EOF
1757 return
1758 fi
1759 case $1 in
1760 __cmg_*) echo "For internal use only." ;;
1761 changes|for)
1762 if [ "$FUNCNAME" = "cmgerrit" ]; then
1763 echo "'$FUNCNAME $1' is deprecated."
1764 fi
1765 ;;
1766 help) $FUNCNAME help ;;
1767 fetch|pull) cat <<EOF
1768usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1769
1770works as:
1771 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1772 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1773
1774Example:
1775 $FUNCNAME $1 1234
1776will $1 patch-set 1 of change 1234
1777EOF
1778 ;;
1779 push) cat <<EOF
1780usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1781
1782works as:
1783 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1784 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1785
1786Example:
1787 $FUNCNAME push fix6789:gingerbread
1788will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1789HEAD will be pushed from local if omitted.
1790EOF
1791 ;;
1792 *)
1793 $FUNCNAME __cmg_err_not_supported $1 && return
1794 cat <<EOF
1795usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1796
1797works as:
1798 git fetch http://DOMAIN/p/PROJECT \\
1799 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1800 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1801EOF
1802 ;;
1803 esac
1804 ;;
1805 __cmg_get_ref)
1806 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1807 local change_id patchset_id hash
1808 case $1 in
1809 */*)
1810 change_id=${1%%/*}
1811 patchset_id=${1#*/}
1812 ;;
1813 *)
1814 change_id=$1
1815 patchset_id=1
1816 ;;
1817 esac
1818 hash=$(($change_id % 100))
1819 case $hash in
1820 [0-9]) hash="0$hash" ;;
1821 esac
1822 echo "refs/changes/$hash/$change_id/$patchset_id"
1823 ;;
1824 fetch|pull)
1825 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1826 $FUNCNAME __cmg_err_not_repo && return 1
1827 local change=$1
1828 shift
1829 git $command $@ http://$review/p/$project \
1830 $($FUNCNAME __cmg_get_ref $change) || return 1
1831 ;;
1832 push)
1833 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1834 $FUNCNAME __cmg_err_not_repo && return 1
1835 if [ -z "$user" ]; then
1836 echo >&2 "Gerrit username not found."
1837 return 1
1838 fi
1839 local local_branch remote_branch
1840 case $1 in
1841 *:*)
1842 local_branch=${1%:*}
1843 remote_branch=${1##*:}
1844 ;;
1845 *)
1846 local_branch=HEAD
1847 remote_branch=$1
1848 ;;
1849 esac
1850 shift
1851 git push $@ ssh://$user@$review:29418/$project \
1852 $local_branch:refs/for/$remote_branch || return 1
1853 ;;
1854 changes|for)
1855 if [ "$FUNCNAME" = "cmgerrit" ]; then
1856 echo >&2 "'$FUNCNAME $command' is deprecated."
1857 fi
1858 ;;
1859 __cmg_err_no_arg)
1860 if [ $# -lt 2 ]; then
1861 echo >&2 "'$FUNCNAME $command' missing argument."
1862 elif [ $2 -eq 0 ]; then
1863 if [ -n "$3" ]; then
1864 $FUNCNAME help $1
1865 else
1866 echo >&2 "'$FUNCNAME $1' missing argument."
1867 fi
1868 else
1869 return 1
1870 fi
1871 ;;
1872 __cmg_err_not_repo)
1873 if [ -z "$review" -o -z "$project" ]; then
1874 echo >&2 "Not currently in any reviewable repository."
1875 else
1876 return 1
1877 fi
1878 ;;
1879 __cmg_err_not_supported)
1880 $FUNCNAME __cmg_err_no_arg $command $# && return
1881 case $1 in
1882 #TODO: filter more git commands that don't use refname
1883 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1884 echo >&2 "'$FUNCNAME $1' is not supported."
1885 ;;
1886 *) return 1 ;;
1887 esac
1888 ;;
1889 #TODO: other special cases?
1890 *)
1891 $FUNCNAME __cmg_err_not_supported $command && return 1
1892 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1893 $FUNCNAME __cmg_err_not_repo && return 1
1894 local args="$@"
1895 local change pre_args refs_arg post_args
1896 case "$args" in
1897 *--\ *)
1898 pre_args=${args%%-- *}
1899 post_args="-- ${args#*-- }"
1900 ;;
1901 *) pre_args="$args" ;;
1902 esac
1903 args=($pre_args)
1904 pre_args=
1905 if [ ${#args[@]} -gt 0 ]; then
1906 change=${args[${#args[@]}-1]}
1907 fi
1908 if [ ${#args[@]} -gt 1 ]; then
1909 pre_args=${args[0]}
1910 for ((i=1; i<${#args[@]}-1; i++)); do
1911 pre_args="$pre_args ${args[$i]}"
1912 done
1913 fi
1914 while ((1)); do
1915 case $change in
1916 ""|--)
1917 $FUNCNAME help $command
1918 return 1
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 *:*)
1939 if [ -z "$refs_arg" ]; then
1940 refs_arg=":${change#*:}"
1941 change=${change%%:*}
1942 fi
1943 ;;
1944 *) break ;;
1945 esac
1946 done
1947 $FUNCNAME fetch $change \
1948 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1949 || return 1
1950 ;;
1951 esac
1952}
1953
1954function cmrebase() {
1955 local repo=$1
1956 local refs=$2
1957 local pwd="$(pwd)"
1958 local dir="$(gettop)/$repo"
1959
1960 if [ -z $repo ] || [ -z $refs ]; then
1961 echo "CyanogenMod Gerrit Rebase Usage: "
1962 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1963 echo " The patch IDs appear on the Gerrit commands that are offered."
1964 echo " They consist on a series of numbers and slashes, after the text"
1965 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1966 echo ""
1967 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1968 echo ""
1969 return
1970 fi
1971
1972 if [ ! -d $dir ]; then
1973 echo "Directory $dir doesn't exist in tree."
1974 return
1975 fi
1976 cd $dir
1977 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1978 echo "Starting branch..."
1979 repo start tmprebase .
1980 echo "Bringing it up to date..."
1981 repo sync .
1982 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001983 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001984 if [ "$?" != "0" ]; then
1985 echo "Error cherry-picking. Not uploading!"
1986 return
1987 fi
1988 echo "Uploading..."
1989 repo upload .
1990 echo "Cleaning up..."
1991 repo abandon tmprebase .
1992 cd $pwd
1993}
1994
1995function mka() {
1996 case `uname -s` in
1997 Darwin)
1998 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1999 ;;
2000 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07002001 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002002 ;;
2003 esac
2004}
2005
2006function reposync() {
2007 case `uname -s` in
2008 Darwin)
2009 repo sync -j 4 "$@"
2010 ;;
2011 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002012 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002013 ;;
2014 esac
2015}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002016
2017function repodiff() {
2018 if [ -z "$*" ]; then
2019 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2020 return
2021 fi
2022 diffopts=$* repo forall -c \
2023 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2024}
2025
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302026# Credit for color strip sed: http://goo.gl/BoIcm
2027function dopush()
2028{
2029 local func=$1
2030 shift
2031
2032 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2033 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2034 echo "No device is online. Waiting for one..."
2035 echo "Please connect USB and/or enable USB debugging"
2036 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2037 sleep 1
2038 done
2039 echo "Device Found."
2040 fi
2041
Chirayu Desai6dadb572012-12-26 10:53:58 +05302042 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2043 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002044 # retrieve IP and PORT info if we're using a TCP connection
2045 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2046 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302047 adb root &> /dev/null
2048 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002049 if [ -n "$TCPIPPORT" ]
2050 then
2051 # adb root just killed our connection
2052 # so reconnect...
2053 adb connect "$TCPIPPORT"
2054 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302055 adb wait-for-device &> /dev/null
2056 sleep 0.3
2057 adb remount &> /dev/null
2058
Matt Mower668ea262014-05-20 02:52:23 -05002059 mkdir -p $OUT
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302060 $func $* | tee $OUT/.log
2061
2062 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002063 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 +05302064
2065 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002066 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 +05302067
Matt Mower668ea262014-05-20 02:52:23 -05002068 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302069 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002070 # Make sure file is in $OUT/system
2071 case $FILE in
2072 $OUT/system/*)
2073 # Get target file name (i.e. /system/bin/adb)
2074 TARGET=$(echo $FILE | sed "s#$OUT##")
2075 ;;
2076 *) continue ;;
2077 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302078
Matt Mower668ea262014-05-20 02:52:23 -05002079 case $TARGET in
2080 /system/priv-app/SystemUI.apk|/system/framework/*)
2081 # Only need to stop services once
2082 if ! $stop_n_start; then
2083 adb shell stop
2084 stop_n_start=true
2085 fi
2086 echo "Pushing: $TARGET"
2087 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302088 ;;
2089 *)
Matt Mower668ea262014-05-20 02:52:23 -05002090 echo "Pushing: $TARGET"
2091 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302092 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002093 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302094 done
Matt Mower668ea262014-05-20 02:52:23 -05002095 if $stop_n_start; then
2096 adb shell start
2097 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302098 rm -f $OUT/.log
2099 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302100 else
2101 echo "The connected device does not appear to be $CM_BUILD, run away!"
2102 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302103}
2104
2105alias mmp='dopush mm'
2106alias mmmp='dopush mmm'
2107alias mkap='dopush mka'
2108alias cmkap='dopush cmka'
2109
Chirayu Desai4a319b82013-06-05 20:14:33 +05302110function repopick() {
2111 T=$(gettop)
2112 $T/build/tools/repopick.py $@
2113}
2114
Chirayu Desaib89b3242013-06-30 10:04:25 +05302115function fixup_common_out_dir() {
2116 common_out_dir=$(get_build_var OUT_DIR)/target/common
2117 target_device=$(get_build_var TARGET_DEVICE)
2118 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2119 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2120 mv ${common_out_dir} ${common_out_dir}-${target_device}
2121 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2122 else
2123 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2124 mkdir -p ${common_out_dir}-${target_device}
2125 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2126 fi
2127 else
2128 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2129 mkdir -p ${common_out_dir}
2130 fi
2131}
2132
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002133# 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 +00002134#
2135# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2136# For some reason, installing the JDK doesn't make it show up in the
2137# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002138function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002139 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002140 # we can reset it later, depending on the version of java the build
2141 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002142 #
2143 # If we don't do this, the JAVA_HOME value set by the first call to
2144 # build/envsetup.sh will persist forever.
2145 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2146 export JAVA_HOME=""
2147 fi
2148
Andy McFaddenbd960942010-06-24 12:52:51 -07002149 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002150 case `uname -s` in
2151 Darwin)
2152 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2153 ;;
2154 *)
2155 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2156 ;;
2157 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002158
2159 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2160 # we can change it on the next envsetup.sh, if required.
2161 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002162 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002163}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002164
Alex Rayf0d08eb2013-03-08 15:15:06 -08002165# Print colored exit condition
2166function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002167 "$@"
2168 local retval=$?
2169 if [ $retval -ne 0 ]
2170 then
2171 echo -e "\e[0;31mFAILURE\e[00m"
2172 else
2173 echo -e "\e[0;32mSUCCESS\e[00m"
2174 fi
2175 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002176}
2177
Ying Wanged21d4c2014-08-24 22:14:19 -07002178function get_make_command()
2179{
2180 echo command make
2181}
2182
Ed Heylcc6be0a2014-06-18 14:55:58 -07002183function make()
2184{
2185 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002186 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002187 local ret=$?
2188 local end_time=$(date +"%s")
2189 local tdiff=$(($end_time-$start_time))
2190 local hours=$(($tdiff / 3600 ))
2191 local mins=$((($tdiff % 3600) / 60))
2192 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002193 local ncolors=$(tput colors 2>/dev/null)
2194 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2195 color_failed="\e[0;31m"
2196 color_success="\e[0;32m"
2197 color_reset="\e[00m"
2198 else
2199 color_failed=""
2200 color_success=""
2201 color_reset=""
2202 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002203 echo
2204 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002205 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002206 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002207 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002208 fi
2209 if [ $hours -gt 0 ] ; then
2210 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2211 elif [ $mins -gt 0 ] ; then
2212 printf "(%02g:%02g (mm:ss))" $mins $secs
2213 elif [ $secs -gt 0 ] ; then
2214 printf "(%s seconds)" $secs
2215 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002216 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002217 echo
2218 return $ret
2219}
2220
Raphael Moll70a86b02011-06-20 16:03:14 -07002221if [ "x$SHELL" != "x/bin/bash" ]; then
2222 case `ps -o command -p $$` in
2223 *bash*)
2224 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002225 *zsh*)
2226 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002227 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002228 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002229 ;;
2230 esac
2231fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002232
2233# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002234for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2235 `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 -08002236do
2237 echo "including $f"
2238 . $f
2239done
2240unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002241
Kyle Ladd031a0b62013-09-11 20:43:42 -04002242# Add completions
2243check_bash_version && {
2244 dirs="sdk/bash_completion vendor/cm/bash_completion"
2245 for dir in $dirs; do
2246 if [ -d ${dir} ]; then
2247 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2248 echo "including $f"
2249 . $f
2250 done
2251 fi
2252 done
2253}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302254
2255export ANDROID_BUILD_TOP=$(gettop)