blob: 8063143c747e75c4e4fad5dcc84d0c6e1f1668ef [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
Kenny Root52aa81c2011-07-15 11:07:06 -0700300function addcompletions()
301{
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
304 return
305 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
Kenny Root52aa81c2011-07-15 11:07:06 -0700309 return
310 fi
311
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200312 local T dir f
313
Chirayu Desai20a61372013-03-16 20:00:17 +0530314 dirs="sdk/bash_completion vendor/cm/bash_completion"
315 for dir in $dirs; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700316 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700317 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700318 echo "including $f"
319 . $f
320 done
321 fi
Chirayu Desai20a61372013-03-16 20:00:17 +0530322 done
Kenny Root52aa81c2011-07-15 11:07:06 -0700323}
324
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325function choosetype()
326{
327 echo "Build type choices are:"
328 echo " 1. release"
329 echo " 2. debug"
330 echo
331
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800332 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700333 DEFAULT_NUM=1
334 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 export TARGET_BUILD_TYPE=
337 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700338 while [ -z $TARGET_BUILD_TYPE ]
339 do
340 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800341 if [ -z "$1" ] ; then
342 read ANSWER
343 else
344 echo $1
345 ANSWER=$1
346 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 case $ANSWER in
348 "")
349 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
350 ;;
351 1)
352 export TARGET_BUILD_TYPE=release
353 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800354 release)
355 export TARGET_BUILD_TYPE=release
356 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357 2)
358 export TARGET_BUILD_TYPE=debug
359 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800360 debug)
361 export TARGET_BUILD_TYPE=debug
362 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700363 *)
364 echo
365 echo "I didn't understand your response. Please try again."
366 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367 ;;
368 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800369 if [ -n "$1" ] ; then
370 break
371 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700372 done
373
374 set_stuff_for_environment
375}
376
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800377#
378# This function isn't really right: It chooses a TARGET_PRODUCT
379# based on the list of boards. Usually, that gets you something
380# that kinda works with a generic product, but really, you should
381# pick a product by name.
382#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383function chooseproduct()
384{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700385 if [ "x$TARGET_PRODUCT" != x ] ; then
386 default_value=$TARGET_PRODUCT
387 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700388 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700389 fi
390
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800391 export TARGET_PRODUCT=
392 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700393 while [ -z "$TARGET_PRODUCT" ]
394 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700395 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800396 if [ -z "$1" ] ; then
397 read ANSWER
398 else
399 echo $1
400 ANSWER=$1
401 fi
402
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700403 if [ -z "$ANSWER" ] ; then
404 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800405 else
406 if check_product $ANSWER
407 then
408 export TARGET_PRODUCT=$ANSWER
409 else
410 echo "** Not a valid product: $ANSWER"
411 fi
412 fi
413 if [ -n "$1" ] ; then
414 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700415 fi
416 done
417
418 set_stuff_for_environment
419}
420
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800421function choosevariant()
422{
423 echo "Variant choices are:"
424 local index=1
425 local v
426 for v in ${VARIANT_CHOICES[@]}
427 do
428 # The product name is the name of the directory containing
429 # the makefile we found, above.
430 echo " $index. $v"
431 index=$(($index+1))
432 done
433
434 local default_value=eng
435 local ANSWER
436
437 export TARGET_BUILD_VARIANT=
438 while [ -z "$TARGET_BUILD_VARIANT" ]
439 do
440 echo -n "Which would you like? [$default_value] "
441 if [ -z "$1" ] ; then
442 read ANSWER
443 else
444 echo $1
445 ANSWER=$1
446 fi
447
448 if [ -z "$ANSWER" ] ; then
449 export TARGET_BUILD_VARIANT=$default_value
450 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
451 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800452 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800453 fi
454 else
455 if check_variant $ANSWER
456 then
457 export TARGET_BUILD_VARIANT=$ANSWER
458 else
459 echo "** Not a valid variant: $ANSWER"
460 fi
461 fi
462 if [ -n "$1" ] ; then
463 break
464 fi
465 done
466}
467
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468function choosecombo()
469{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700470 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471
472 echo
473 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700474 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475
476 echo
477 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700478 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479
480 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700481 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700483}
484
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800485# Clear this variable. It will be built up again when the vendorsetup.sh
486# files are included at the end of this file.
487unset LUNCH_MENU_CHOICES
488function add_lunch_combo()
489{
490 local new_combo=$1
491 local c
492 for c in ${LUNCH_MENU_CHOICES[@]} ; do
493 if [ "$new_combo" = "$c" ] ; then
494 return
495 fi
496 done
497 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
498}
499
500# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700501add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800502add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000503add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800504add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000505add_lunch_combo aosp_x86-eng
506add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800507
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508function print_lunch_menu()
509{
510 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700511 echo
512 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000513 if [ "$(uname)" = "Darwin" ] ; then
514 echo " (ohai, koush!)"
515 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700516 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000517 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
518 echo "Breakfast menu... pick a combo:"
519 else
520 echo "Lunch menu... pick a combo:"
521 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522
523 local i=1
524 local choice
525 for choice in ${LUNCH_MENU_CHOICES[@]}
526 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100527 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800528 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100529 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800530
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000531 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
532 echo "... and don't forget the bacon!"
533 fi
534
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700535 echo
536}
537
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000538function brunch()
539{
540 breakfast $*
541 if [ $? -eq 0 ]; then
542 mka bacon
543 else
544 echo "No such item in brunch menu. Try 'breakfast'"
545 return 1
546 fi
547 return $?
548}
549
550function breakfast()
551{
552 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200553 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000554 CM_DEVICES_ONLY="true"
555 unset LUNCH_MENU_CHOICES
556 add_lunch_combo full-eng
557 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
558 do
559 echo "including $f"
560 . $f
561 done
562 unset f
563
564 if [ $# -eq 0 ]; then
565 # No arguments, so let's have the full menu
566 lunch
567 else
568 echo "z$target" | grep -q "-"
569 if [ $? -eq 0 ]; then
570 # A buildtype was specified, assume a full device name
571 lunch $target
572 else
573 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200574 if [ -z "$variant" ]; then
575 variant="userdebug"
576 fi
577 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000578 fi
579 fi
580 return $?
581}
582
583alias bib=breakfast
584
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585function lunch()
586{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 local answer
588
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700589 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 else
592 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700593 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800594 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595 fi
596
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 local selection=
598
599 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700600 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700601 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
603 then
604 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
605 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800606 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800607 fi
608 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
609 then
610 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700611 fi
612
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800613 if [ -z "$selection" ]
614 then
615 echo
616 echo "Invalid lunch combo: $answer"
617 return 1
618 fi
619
Joe Onoratoda12daf2010-06-09 18:18:31 -0700620 export TARGET_BUILD_APPS=
621
Jeff Browne33ba4c2011-07-11 22:11:46 -0700622 local product=$(echo -n $selection | sed -e "s/-.*$//")
623 check_product $product
624 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800625 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800626 # if we can't find a product, try to grab it off the CM github
627 T=$(gettop)
628 pushd $T > /dev/null
629 build/tools/roomservice.py $product
630 popd > /dev/null
631 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000632 else
633 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800634 fi
635 if [ $? -ne 0 ]
636 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700637 echo
638 echo "** Don't have a product spec for: '$product'"
639 echo "** Do you have the right repo manifest?"
640 product=
641 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800642
Jeff Browne33ba4c2011-07-11 22:11:46 -0700643 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
644 check_variant $variant
645 if [ $? -ne 0 ]
646 then
647 echo
648 echo "** Invalid variant: '$variant'"
649 echo "** Must be one of ${VARIANT_CHOICES[@]}"
650 variant=
651 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800652
Jeff Browne33ba4c2011-07-11 22:11:46 -0700653 if [ -z "$product" -o -z "$variant" ]
654 then
655 echo
656 return 1
657 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800658
Jeff Browne33ba4c2011-07-11 22:11:46 -0700659 export TARGET_PRODUCT=$product
660 export TARGET_BUILD_VARIANT=$variant
661 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662
663 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800664
Chirayu Desaib89b3242013-06-30 10:04:25 +0530665 fixup_common_out_dir
666
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700667 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800668 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700669}
670
Jeff Davidson513d7a42010-08-02 10:00:44 -0700671# Tab completion for lunch.
672function _lunch()
673{
674 local cur prev opts
675 COMPREPLY=()
676 cur="${COMP_WORDS[COMP_CWORD]}"
677 prev="${COMP_WORDS[COMP_CWORD-1]}"
678
679 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
680 return 0
681}
Emilio López9ad6eea2013-11-03 13:02:13 -0300682complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700683
Joe Onoratoda12daf2010-06-09 18:18:31 -0700684# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700685# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700686function tapas()
687{
Ying Wangb541ab62014-05-29 17:57:40 -0700688 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 -0700689 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700690 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
691 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 -0700692
Ying Wang67f02922012-08-22 10:25:20 -0700693 if [ $(echo $arch | wc -w) -gt 1 ]; then
694 echo "tapas: Error: Multiple build archs supplied: $arch"
695 return
696 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700697 if [ $(echo $variant | wc -w) -gt 1 ]; then
698 echo "tapas: Error: Multiple build variants supplied: $variant"
699 return
700 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700701 if [ $(echo $density | wc -w) -gt 1 ]; then
702 echo "tapas: Error: Multiple densities supplied: $density"
703 return
704 fi
Ying Wang67f02922012-08-22 10:25:20 -0700705
706 local product=full
707 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700708 x86) product=full_x86;;
709 mips) product=full_mips;;
710 armv5) product=generic_armv5;;
711 arm64) product=aosp_arm64;;
712 x86_64) product=aosp_x86_64;;
713 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700714 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700715 if [ -z "$variant" ]; then
716 variant=eng
717 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700718 if [ -z "$apps" ]; then
719 apps=all
720 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600721 if [ -z "$density" ]; then
722 density=alldpi
723 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700724
Ying Wang67f02922012-08-22 10:25:20 -0700725 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700726 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700727 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700728 export TARGET_BUILD_TYPE=release
729 export TARGET_BUILD_APPS=$apps
730
731 set_stuff_for_environment
732 printconfig
733}
734
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100735function eat()
736{
737 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530738 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100739 ZIPFILE=cm-$MODVERSION.zip
740 ZIPPATH=$OUT/$ZIPFILE
741 if [ ! -f $ZIPPATH ] ; then
742 echo "Nothing to eat"
743 return 1
744 fi
745 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
746 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
747 echo "No device is online. Waiting for one..."
748 echo "Please connect USB and/or enable USB debugging"
749 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
750 sleep 1
751 done
752 echo "Device Found.."
753 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530754 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
755 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100756 # if adbd isn't root we can't write to /cache/recovery/
757 adb root
758 sleep 1
759 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700760 cat << EOF > /tmp/command
761--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100762EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700763 if adb push /tmp/command /cache/recovery/ ; then
764 echo "Rebooting into recovery for sideload installation"
765 adb reboot recovery
766 adb wait-for-sideload
767 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100768 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700769 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100770 else
771 echo "Nothing to eat"
772 return 1
773 fi
774 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530775 else
776 echo "The connected device does not appear to be $CM_BUILD, run away!"
777 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100778}
779
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000780function omnom
781{
782 brunch $*
783 eat
784}
785
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700786function gettop
787{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800788 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700790 # The following circumlocution ensures we remove symlinks from TOP.
791 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700792 else
793 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800794 # The following circumlocution (repeated below as well) ensures
795 # that we record the true directory name and not one that is
796 # faked up with symlink names.
797 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700798 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800799 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700800 T=
801 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800802 \cd ..
synergyb112a402013-07-05 19:47:47 -0700803 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700804 done
Ying Wang9cd17642012-12-13 10:52:07 -0800805 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700806 if [ -f "$T/$TOPFILE" ]; then
807 echo $T
808 fi
809 fi
810 fi
811}
812
Andrew Hsieh906cb782013-09-10 17:37:14 +0800813# Return driver for "make", if any (eg. static analyzer)
814function getdriver()
815{
816 local T="$1"
817 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
818 if [ -n "$WITH_STATIC_ANALYZER" ]; then
819 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800820$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
821--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800822--status-bugs \
823--top=$T"
824 fi
825}
826
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827function m()
828{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800829 local T=$(gettop)
830 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800832 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700833 else
834 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700835 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700836 fi
837}
838
839function findmakefile()
840{
841 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800842 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700843 T=
844 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700845 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700846 if [ -f "$T/Android.mk" ]; then
847 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800848 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700849 return
850 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800851 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700852 done
Ying Wang9cd17642012-12-13 10:52:07 -0800853 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700854}
855
856function mm()
857{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800858 local T=$(gettop)
859 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700860 # If we're sitting in the root of the build tree, just do a
861 # normal make.
862 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800863 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700864 else
865 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800866 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700867 local MODULES=
868 local GET_INSTALL_PATH=
869 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700870 # Remove the path to top as the makefilepath needs to be relative
871 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700872 if [ ! "$T" ]; then
873 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700874 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700875 elif [ ! "$M" ]; then
876 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700877 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700878 else
Ying Wanga7deb082013-08-16 13:24:47 -0700879 for ARG in $@; do
880 case $ARG in
881 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
882 esac
883 done
884 if [ -n "$GET_INSTALL_PATH" ]; then
885 MODULES=
886 ARGS=GET-INSTALL-PATH
887 else
888 MODULES=all_modules
889 ARGS=$@
890 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700891 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 -0700892 fi
893 fi
894}
895
896function mmm()
897{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800898 local T=$(gettop)
899 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700900 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800901 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800902 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800903 local ARGS=
904 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700905 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800906 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
907 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
908 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800909 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
910 if [ "$MODULES" = "" ]; then
911 MODULES=all_modules
912 fi
913 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700914 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700915 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
916 local TO_CHOP=`expr $TO_CHOP + 1`
917 local START=`PWD= /bin/pwd`
918 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700919 if [ "$MFILE" = "" ] ; then
920 MFILE=$DIR/Android.mk
921 else
922 MFILE=$MFILE/$DIR/Android.mk
923 fi
924 MAKEFILE="$MAKEFILE $MFILE"
925 else
Ying Wanga7deb082013-08-16 13:24:47 -0700926 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100927 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700928 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
929 *) echo "No Android.mk in $DIR."; return 1;;
930 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700931 fi
932 done
Ying Wanga7deb082013-08-16 13:24:47 -0700933 if [ -n "$GET_INSTALL_PATH" ]; then
934 ARGS=$GET_INSTALL_PATH
935 MODULES=
936 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800937 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 -0700938 else
939 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700940 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700941 fi
942}
943
Ying Wangb607f7b2013-02-08 18:01:04 -0800944function mma()
945{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800946 local T=$(gettop)
947 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800948 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800949 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800950 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800951 if [ ! "$T" ]; then
952 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700953 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800954 fi
955 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800956 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800957 fi
958}
959
960function mmma()
961{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800962 local T=$(gettop)
963 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800964 if [ "$T" ]; then
965 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
966 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
967 local MY_PWD=`PWD= /bin/pwd`
968 if [ "$MY_PWD" = "$T" ]; then
969 MY_PWD=
970 else
971 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
972 fi
973 local DIR=
974 local MODULE_PATHS=
975 local ARGS=
976 for DIR in $DIRS ; do
977 if [ -d $DIR ]; then
978 if [ "$MY_PWD" = "" ]; then
979 MODULE_PATHS="$MODULE_PATHS $DIR"
980 else
981 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
982 fi
983 else
984 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100985 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800986 *) echo "Couldn't find directory $DIR"; return 1;;
987 esac
988 fi
989 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800990 $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 -0800991 else
992 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700993 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800994 fi
995}
996
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700997function croot()
998{
999 T=$(gettop)
1000 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001001 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001002 else
1003 echo "Couldn't locate the top of the tree. Try setting TOP."
1004 fi
1005}
1006
nebkatfb67a1e2012-12-28 10:40:45 +00001007function cout()
1008{
1009 if [ "$OUT" ]; then
1010 cd $OUT
1011 else
1012 echo "Couldn't locate out directory. Try setting OUT."
1013 fi
1014}
1015
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001016function cproj()
1017{
1018 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001019 local HERE=$PWD
1020 T=
1021 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1022 T=$PWD
1023 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001024 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001025 return
1026 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001027 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001028 done
Ying Wang9cd17642012-12-13 10:52:07 -08001029 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001030 echo "can't find Android.mk"
1031}
1032
Daniel Sandler47e0a882013-07-30 13:23:52 -04001033# simplified version of ps; output in the form
1034# <pid> <procname>
1035function qpid() {
1036 local prepend=''
1037 local append=''
1038 if [ "$1" = "--exact" ]; then
1039 prepend=' '
1040 append='$'
1041 shift
1042 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1043 echo "usage: qpid [[--exact] <process name|pid>"
1044 return 255
1045 fi
1046
1047 local EXE="$1"
1048 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001049 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001050 else
1051 adb shell ps \
1052 | tr -d '\r' \
1053 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1054 fi
1055}
1056
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001057function pid()
1058{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001059 local prepend=''
1060 local append=''
1061 if [ "$1" = "--exact" ]; then
1062 prepend=' '
1063 append='$'
1064 shift
1065 fi
1066 local EXE="$1"
1067 if [ "$EXE" ] ; then
1068 local PID=`adb shell ps \
1069 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001070 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001071 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1072 echo "$PID"
1073 else
1074 echo "usage: pid [--exact] <process name>"
1075 return 255
1076 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001077}
1078
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001079# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080# that has the core-file-size limit set correctly
1081#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001082# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001083# if its core-file-size limit is not set already.
1084# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1085
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001086function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001087{
1088 echo "Getting root...";
1089 adb root;
1090 adb wait-for-device;
1091
1092 echo "Remounting root parition read-write...";
1093 adb shell mount -w -o remount -t rootfs rootfs;
1094 sleep 1;
1095 adb wait-for-device;
1096 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001097 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001098 adb shell chmod 0777 /cores;
1099
1100 echo "Granting SELinux permission to dump in /cores...";
1101 adb shell restorecon -R /cores;
1102
1103 echo "Set core pattern.";
1104 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1105
1106 echo "Done."
1107}
1108
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001109# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001110# $1 = PID of process (e.g., $(pid mediaserver))
1111#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001112# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001113# dump to actually be generated.
1114
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001115function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001116{
1117 local PID=$1;
1118 if [ -z "$PID" ]; then
1119 printf "Expecting a PID!\n";
1120 return;
1121 fi;
1122 echo "Setting core limit for $PID to infinite...";
1123 adb shell prlimit $PID 4 -1 -1
1124}
1125
1126# core - send SIGV and pull the core for process
1127# $1 = PID of process (e.g., $(pid mediaserver))
1128#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001129# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001130# enabled globally.
1131
1132function core()
1133{
1134 local PID=$1;
1135
1136 if [ -z "$PID" ]; then
1137 printf "Expecting a PID!\n";
1138 return;
1139 fi;
1140
1141 local CORENAME=core.$PID;
1142 local COREPATH=/cores/$CORENAME;
1143 local SIG=SEGV;
1144
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001145 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001146
1147 local done=0;
1148 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1149 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1150 adb shell kill -$SIG $PID;
1151 sleep 1;
1152 done;
1153
1154 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1155 echo "Done: core is under $COREPATH on device.";
1156}
1157
Christopher Tate744ee802009-11-12 15:33:08 -08001158# systemstack - dump the current stack trace of all threads in the system process
1159# to the usual ANR traces file
1160function systemstack()
1161{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001162 stacks system_server
1163}
1164
1165function stacks()
1166{
1167 if [[ $1 =~ ^[0-9]+$ ]] ; then
1168 local PID="$1"
1169 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001170 local PIDLIST="$(pid $1)"
1171 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1172 local PID="$PIDLIST"
1173 elif [ "$PIDLIST" ] ; then
1174 echo "more than one process: $1"
1175 else
1176 echo "no such process: $1"
1177 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001178 else
1179 echo "usage: stacks [pid|process name]"
1180 fi
1181
1182 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001183 # Determine whether the process is native
1184 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1185 # Dump stacks of Dalvik process
1186 local TRACES=/data/anr/traces.txt
1187 local ORIG=/data/anr/traces.orig
1188 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001189
Jeff Brownb12c2e52013-08-19 15:14:16 -07001190 # Keep original traces to avoid clobbering
1191 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001192
Jeff Brownb12c2e52013-08-19 15:14:16 -07001193 # Make sure we have a usable file
1194 adb shell touch $TRACES
1195 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001196
Jeff Brownb12c2e52013-08-19 15:14:16 -07001197 # Dump stacks and wait for dump to finish
1198 adb shell kill -3 $PID
1199 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001200
Jeff Brownb12c2e52013-08-19 15:14:16 -07001201 # Restore original stacks, and show current output
1202 adb shell mv $TRACES $TMP
1203 adb shell mv $ORIG $TRACES
1204 adb shell cat $TMP
1205 else
1206 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001207 local USE64BIT="$(is64bit $PID)"
1208 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001209 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001210 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001211}
1212
Michael Wrightaeed7212014-06-19 19:58:12 -07001213# Read the ELF header from /proc/$PID/exe to determine if the process is
1214# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001215function is64bit()
1216{
1217 local PID="$1"
1218 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001219 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001220 echo "64"
1221 else
1222 echo ""
1223 fi
1224 else
1225 echo ""
1226 fi
1227}
1228
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001229case `uname -s` in
1230 Darwin)
1231 function sgrep()
1232 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001233 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 -07001234 }
1235
1236 ;;
1237 *)
1238 function sgrep()
1239 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001240 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 -07001241 }
1242 ;;
1243esac
1244
Raghu Gandham8da43102012-07-25 19:57:22 -07001245function gettargetarch
1246{
1247 get_build_var TARGET_ARCH
1248}
1249
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001250function ggrep()
1251{
1252 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1253}
1254
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001255function jgrep()
1256{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001257 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 -07001258}
1259
1260function cgrep()
1261{
Dan Albert01961192014-11-22 10:16:01 -08001262 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 -07001263}
1264
1265function resgrep()
1266{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001267 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 -07001268}
1269
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001270function mangrep()
1271{
1272 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1273}
1274
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001275function sepgrep()
1276{
1277 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 "$@"
1278}
1279
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001280function rcgrep()
1281{
1282 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1283}
1284
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001285case `uname -s` in
1286 Darwin)
1287 function mgrep()
1288 {
Ying Wang324c2b22012-08-17 15:03:20 -07001289 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 -07001290 }
1291
1292 function treegrep()
1293 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001294 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 -07001295 }
1296
1297 ;;
1298 *)
1299 function mgrep()
1300 {
Ying Wang324c2b22012-08-17 15:03:20 -07001301 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 -07001302 }
1303
1304 function treegrep()
1305 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001306 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 -07001307 }
1308
1309 ;;
1310esac
1311
1312function getprebuilt
1313{
1314 get_abs_build_var ANDROID_PREBUILTS
1315}
1316
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001317function tracedmdump()
1318{
1319 T=$(gettop)
1320 if [ ! "$T" ]; then
1321 echo "Couldn't locate the top of the tree. Try setting TOP."
1322 return
1323 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001324 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001325 local arch=$(gettargetarch)
1326 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001327
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001328 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001329 if [ ! "$TRACE" ] ; then
1330 echo "usage: tracedmdump tracename"
1331 return
1332 fi
1333
Jack Veenstra60116fc2009-04-09 18:12:34 -07001334 if [ ! -r "$KERNEL" ] ; then
1335 echo "Error: cannot find kernel: '$KERNEL'"
1336 return
1337 fi
1338
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001339 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001340 if [ "$BASETRACE" = "$TRACE" ] ; then
1341 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1342 fi
1343
1344 echo "post-processing traces..."
1345 rm -f $TRACE/qtrace.dexlist
1346 post_trace $TRACE
1347 if [ $? -ne 0 ]; then
1348 echo "***"
1349 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1350 echo "***"
1351 return
1352 fi
1353 echo "generating dexlist output..."
1354 /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
1355 echo "generating dmtrace data..."
1356 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1357 echo "generating html file..."
1358 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1359 echo "done, see $TRACE/dmtrace.html for details"
1360 echo "or run:"
1361 echo " traceview $TRACE/dmtrace"
1362}
1363
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001364# communicate with a running device or emulator, set up necessary state,
1365# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001366function runhat()
1367{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001368 # process standard adb options
1369 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001370 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001371 adbTarget=$1
1372 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001373 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001374 adbTarget="$1 $2"
1375 shift 2
1376 fi
1377 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001378 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001379
1380 # runhat options
1381 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001382
1383 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001384 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001385 return
1386 fi
1387
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001388 # confirm hat is available
1389 if [ -z $(which hat) ]; then
1390 echo "hat is not available in this configuration."
1391 return
1392 fi
1393
Andy McFaddenb6289852010-07-12 08:00:19 -07001394 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001395 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001396 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001397 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001398 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001399 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001400 echo -n "> "
1401 read
1402
The Android Open Source Project88b60792009-03-03 19:28:42 -08001403 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001404
The Android Open Source Project88b60792009-03-03 19:28:42 -08001405 echo "Retrieving file $devFile..."
1406 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001407
The Android Open Source Project88b60792009-03-03 19:28:42 -08001408 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001409
The Android Open Source Project88b60792009-03-03 19:28:42 -08001410 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001411 echo "View the output by pointing your browser at http://localhost:7000/"
1412 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001413 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001414}
1415
1416function getbugreports()
1417{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001418 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001419
1420 if [ ! "$reports" ]; then
1421 echo "Could not locate any bugreports."
1422 return
1423 fi
1424
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001425 local report
1426 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001427 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001428 echo "/sdcard/bugreports/${report}"
1429 adb pull /sdcard/bugreports/${report} ${report}
1430 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001431 done
1432}
1433
Victoria Lease1b296b42012-08-21 15:44:06 -07001434function getsdcardpath()
1435{
1436 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1437}
1438
1439function getscreenshotpath()
1440{
1441 echo "$(getsdcardpath)/Pictures/Screenshots"
1442}
1443
1444function getlastscreenshot()
1445{
1446 local screenshot_path=$(getscreenshotpath)
1447 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1448 if [ "$screenshot" = "" ]; then
1449 echo "No screenshots found."
1450 return
1451 fi
1452 echo "${screenshot}"
1453 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1454}
1455
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001456function startviewserver()
1457{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001458 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001459 if [ $# -gt 0 ]; then
1460 port=$1
1461 fi
1462 adb shell service call window 1 i32 $port
1463}
1464
1465function stopviewserver()
1466{
1467 adb shell service call window 2
1468}
1469
1470function isviewserverstarted()
1471{
1472 adb shell service call window 3
1473}
1474
Romain Guyb84049a2010-10-04 16:56:11 -07001475function key_home()
1476{
1477 adb shell input keyevent 3
1478}
1479
1480function key_back()
1481{
1482 adb shell input keyevent 4
1483}
1484
1485function key_menu()
1486{
1487 adb shell input keyevent 82
1488}
1489
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001490function smoketest()
1491{
1492 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1493 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1494 return
1495 fi
1496 T=$(gettop)
1497 if [ ! "$T" ]; then
1498 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1499 return
1500 fi
1501
Ying Wang9cd17642012-12-13 10:52:07 -08001502 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001503 adb uninstall com.android.smoketest > /dev/null &&
1504 adb uninstall com.android.smoketest.tests > /dev/null &&
1505 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1506 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1507 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1508}
1509
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001510# simple shortcut to the runtest command
1511function runtest()
1512{
1513 T=$(gettop)
1514 if [ ! "$T" ]; then
1515 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1516 return
1517 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001518 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001519}
1520
The Android Open Source Project88b60792009-03-03 19:28:42 -08001521function godir () {
1522 if [[ -z "$1" ]]; then
1523 echo "Usage: godir <regex>"
1524 return
1525 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001526 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001527 if [[ ! -f $T/filelist ]]; then
1528 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001529 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001530 echo " Done"
1531 echo ""
1532 fi
1533 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001534 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001535 if [[ ${#lines[@]} = 0 ]]; then
1536 echo "Not found"
1537 return
1538 fi
1539 local pathname
1540 local choice
1541 if [[ ${#lines[@]} > 1 ]]; then
1542 while [[ -z "$pathname" ]]; do
1543 local index=1
1544 local line
1545 for line in ${lines[@]}; do
1546 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001547 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001548 done
1549 echo
1550 echo -n "Select one: "
1551 unset choice
1552 read choice
1553 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1554 echo "Invalid choice"
1555 continue
1556 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001557 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001558 done
1559 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001560 pathname=${lines[0]}
1561 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001562 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001563}
1564
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001565function cmremote()
1566{
1567 git remote rm cmremote 2> /dev/null
1568 if [ ! -d .git ]
1569 then
1570 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1571 fi
1572 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1573 if [ -z "$GERRIT_REMOTE" ]
1574 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001575 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1576 if [ -z "$GERRIT_REMOTE" ]
1577 then
1578 echo Unable to set up the git remote, are you in the root of the repo?
1579 return 0
1580 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001581 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001582 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001583 if [ -z "$CMUSER" ]
1584 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001585 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001586 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001587 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001588 fi
1589 echo You can now push to "cmremote".
1590}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001591
Steve Kondik873fa562012-09-17 11:33:18 -07001592function aospremote()
1593{
1594 git remote rm aosp 2> /dev/null
1595 if [ ! -d .git ]
1596 then
1597 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1598 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001599 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001600 if (echo $PROJECT | grep -qv "^device")
1601 then
1602 PFX="platform/"
1603 fi
1604 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1605 echo "Remote 'aosp' created"
1606}
Steve Kondik873fa562012-09-17 11:33:18 -07001607
Steve Kondik20c21d22013-10-27 13:34:36 -07001608function cafremote()
1609{
1610 git remote rm caf 2> /dev/null
1611 if [ ! -d .git ]
1612 then
1613 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1614 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001615 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001616 if (echo $PROJECT | grep -qv "^device")
1617 then
1618 PFX="platform/"
1619 fi
1620 git remote add caf git://codeaurora.org/$PFX$PROJECT
1621 echo "Remote 'caf' created"
1622}
Steve Kondik20c21d22013-10-27 13:34:36 -07001623
Steve Kondikf00e7d92012-09-23 23:46:55 -07001624function installboot()
1625{
1626 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1627 then
1628 echo "No recovery.fstab found. Build recovery first."
1629 return 1
1630 fi
1631 if [ ! -e "$OUT/boot.img" ];
1632 then
1633 echo "No boot.img found. Run make bootimage first."
1634 return 1
1635 fi
1636 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1637 if [ -z "$PARTITION" ];
1638 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001639 # Try for RECOVERY_FSTAB_VERSION = 2
1640 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1641 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1642 if [ -z "$PARTITION" ];
1643 then
1644 echo "Unable to determine boot partition."
1645 return 1
1646 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001647 fi
1648 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001649 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001650 adb root
1651 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001652 adb wait-for-online shell mount /system 2>&1 > /dev/null
1653 adb wait-for-online remount
Steve Kondikf00e7d92012-09-23 23:46:55 -07001654 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1655 then
1656 adb push $OUT/boot.img /cache/
1657 for i in $OUT/system/lib/modules/*;
1658 do
1659 adb push $i /system/lib/modules/
1660 done
1661 adb shell dd if=/cache/boot.img of=$PARTITION
1662 adb shell chmod 644 /system/lib/modules/*
1663 echo "Installation complete."
1664 else
1665 echo "The connected device does not appear to be $CM_BUILD, run away!"
1666 fi
1667}
1668
Steve Kondik83c03d52012-10-24 16:40:42 -07001669function installrecovery()
1670{
1671 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1672 then
1673 echo "No recovery.fstab found. Build recovery first."
1674 return 1
1675 fi
1676 if [ ! -e "$OUT/recovery.img" ];
1677 then
1678 echo "No recovery.img found. Run make recoveryimage first."
1679 return 1
1680 fi
1681 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1682 if [ -z "$PARTITION" ];
1683 then
Steve Kondik75f10762013-08-09 21:03:42 -07001684 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001685 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1686 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001687 if [ -z "$PARTITION" ];
1688 then
1689 echo "Unable to determine recovery partition."
1690 return 1
1691 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001692 fi
1693 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001694 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001695 adb root
1696 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001697 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1698 adb wait-for-online remount
Steve Kondik83c03d52012-10-24 16:40:42 -07001699 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1700 then
1701 adb push $OUT/recovery.img /cache/
1702 adb shell dd if=/cache/recovery.img of=$PARTITION
1703 echo "Installation complete."
1704 else
1705 echo "The connected device does not appear to be $CM_BUILD, run away!"
1706 fi
1707}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001708
Koushik Duttab55f13a2012-05-14 16:14:36 -07001709function makerecipe() {
1710 if [ -z "$1" ]
1711 then
1712 echo "No branch name provided."
1713 return 1
1714 fi
1715 cd android
1716 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1717 git commit -a -m "$1"
1718 cd ..
1719
1720 repo forall -c '
1721
1722 if [ "$REPO_REMOTE" == "github" ]
1723 then
1724 pwd
1725 cmremote
1726 git push cmremote HEAD:refs/heads/'$1'
1727 fi
1728 '
1729}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001730
1731function cmgerrit() {
1732 if [ $# -eq 0 ]; then
1733 $FUNCNAME help
1734 return 1
1735 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001736 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001737 local review=`git config --get remote.github.review`
1738 local project=`git config --get remote.github.projectname`
1739 local command=$1
1740 shift
1741 case $command in
1742 help)
1743 if [ $# -eq 0 ]; then
1744 cat <<EOF
1745Usage:
1746 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1747
1748Commands:
1749 fetch Just fetch the change as FETCH_HEAD
1750 help Show this help, or for a specific command
1751 pull Pull a change into current branch
1752 push Push HEAD or a local branch to Gerrit for a specific branch
1753
1754Any other Git commands that support refname would work as:
1755 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1756
1757See '$FUNCNAME help COMMAND' for more information on a specific command.
1758
1759Example:
1760 $FUNCNAME checkout -b topic 1234/5
1761works as:
1762 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1763 && git checkout -b topic FETCH_HEAD
1764will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1765Patch-set 1 will be fetched if omitted.
1766EOF
1767 return
1768 fi
1769 case $1 in
1770 __cmg_*) echo "For internal use only." ;;
1771 changes|for)
1772 if [ "$FUNCNAME" = "cmgerrit" ]; then
1773 echo "'$FUNCNAME $1' is deprecated."
1774 fi
1775 ;;
1776 help) $FUNCNAME help ;;
1777 fetch|pull) cat <<EOF
1778usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1779
1780works as:
1781 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1782 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1783
1784Example:
1785 $FUNCNAME $1 1234
1786will $1 patch-set 1 of change 1234
1787EOF
1788 ;;
1789 push) cat <<EOF
1790usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1791
1792works as:
1793 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1794 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1795
1796Example:
1797 $FUNCNAME push fix6789:gingerbread
1798will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1799HEAD will be pushed from local if omitted.
1800EOF
1801 ;;
1802 *)
1803 $FUNCNAME __cmg_err_not_supported $1 && return
1804 cat <<EOF
1805usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1806
1807works as:
1808 git fetch http://DOMAIN/p/PROJECT \\
1809 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1810 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1811EOF
1812 ;;
1813 esac
1814 ;;
1815 __cmg_get_ref)
1816 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1817 local change_id patchset_id hash
1818 case $1 in
1819 */*)
1820 change_id=${1%%/*}
1821 patchset_id=${1#*/}
1822 ;;
1823 *)
1824 change_id=$1
1825 patchset_id=1
1826 ;;
1827 esac
1828 hash=$(($change_id % 100))
1829 case $hash in
1830 [0-9]) hash="0$hash" ;;
1831 esac
1832 echo "refs/changes/$hash/$change_id/$patchset_id"
1833 ;;
1834 fetch|pull)
1835 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1836 $FUNCNAME __cmg_err_not_repo && return 1
1837 local change=$1
1838 shift
1839 git $command $@ http://$review/p/$project \
1840 $($FUNCNAME __cmg_get_ref $change) || return 1
1841 ;;
1842 push)
1843 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1844 $FUNCNAME __cmg_err_not_repo && return 1
1845 if [ -z "$user" ]; then
1846 echo >&2 "Gerrit username not found."
1847 return 1
1848 fi
1849 local local_branch remote_branch
1850 case $1 in
1851 *:*)
1852 local_branch=${1%:*}
1853 remote_branch=${1##*:}
1854 ;;
1855 *)
1856 local_branch=HEAD
1857 remote_branch=$1
1858 ;;
1859 esac
1860 shift
1861 git push $@ ssh://$user@$review:29418/$project \
1862 $local_branch:refs/for/$remote_branch || return 1
1863 ;;
1864 changes|for)
1865 if [ "$FUNCNAME" = "cmgerrit" ]; then
1866 echo >&2 "'$FUNCNAME $command' is deprecated."
1867 fi
1868 ;;
1869 __cmg_err_no_arg)
1870 if [ $# -lt 2 ]; then
1871 echo >&2 "'$FUNCNAME $command' missing argument."
1872 elif [ $2 -eq 0 ]; then
1873 if [ -n "$3" ]; then
1874 $FUNCNAME help $1
1875 else
1876 echo >&2 "'$FUNCNAME $1' missing argument."
1877 fi
1878 else
1879 return 1
1880 fi
1881 ;;
1882 __cmg_err_not_repo)
1883 if [ -z "$review" -o -z "$project" ]; then
1884 echo >&2 "Not currently in any reviewable repository."
1885 else
1886 return 1
1887 fi
1888 ;;
1889 __cmg_err_not_supported)
1890 $FUNCNAME __cmg_err_no_arg $command $# && return
1891 case $1 in
1892 #TODO: filter more git commands that don't use refname
1893 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1894 echo >&2 "'$FUNCNAME $1' is not supported."
1895 ;;
1896 *) return 1 ;;
1897 esac
1898 ;;
1899 #TODO: other special cases?
1900 *)
1901 $FUNCNAME __cmg_err_not_supported $command && return 1
1902 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1903 $FUNCNAME __cmg_err_not_repo && return 1
1904 local args="$@"
1905 local change pre_args refs_arg post_args
1906 case "$args" in
1907 *--\ *)
1908 pre_args=${args%%-- *}
1909 post_args="-- ${args#*-- }"
1910 ;;
1911 *) pre_args="$args" ;;
1912 esac
1913 args=($pre_args)
1914 pre_args=
1915 if [ ${#args[@]} -gt 0 ]; then
1916 change=${args[${#args[@]}-1]}
1917 fi
1918 if [ ${#args[@]} -gt 1 ]; then
1919 pre_args=${args[0]}
1920 for ((i=1; i<${#args[@]}-1; i++)); do
1921 pre_args="$pre_args ${args[$i]}"
1922 done
1923 fi
1924 while ((1)); do
1925 case $change in
1926 ""|--)
1927 $FUNCNAME help $command
1928 return 1
1929 ;;
1930 *@*)
1931 if [ -z "$refs_arg" ]; then
1932 refs_arg="@${change#*@}"
1933 change=${change%%@*}
1934 fi
1935 ;;
1936 *~*)
1937 if [ -z "$refs_arg" ]; then
1938 refs_arg="~${change#*~}"
1939 change=${change%%~*}
1940 fi
1941 ;;
1942 *^*)
1943 if [ -z "$refs_arg" ]; then
1944 refs_arg="^${change#*^}"
1945 change=${change%%^*}
1946 fi
1947 ;;
1948 *:*)
1949 if [ -z "$refs_arg" ]; then
1950 refs_arg=":${change#*:}"
1951 change=${change%%:*}
1952 fi
1953 ;;
1954 *) break ;;
1955 esac
1956 done
1957 $FUNCNAME fetch $change \
1958 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1959 || return 1
1960 ;;
1961 esac
1962}
1963
1964function cmrebase() {
1965 local repo=$1
1966 local refs=$2
1967 local pwd="$(pwd)"
1968 local dir="$(gettop)/$repo"
1969
1970 if [ -z $repo ] || [ -z $refs ]; then
1971 echo "CyanogenMod Gerrit Rebase Usage: "
1972 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1973 echo " The patch IDs appear on the Gerrit commands that are offered."
1974 echo " They consist on a series of numbers and slashes, after the text"
1975 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1976 echo ""
1977 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1978 echo ""
1979 return
1980 fi
1981
1982 if [ ! -d $dir ]; then
1983 echo "Directory $dir doesn't exist in tree."
1984 return
1985 fi
1986 cd $dir
1987 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1988 echo "Starting branch..."
1989 repo start tmprebase .
1990 echo "Bringing it up to date..."
1991 repo sync .
1992 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001993 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001994 if [ "$?" != "0" ]; then
1995 echo "Error cherry-picking. Not uploading!"
1996 return
1997 fi
1998 echo "Uploading..."
1999 repo upload .
2000 echo "Cleaning up..."
2001 repo abandon tmprebase .
2002 cd $pwd
2003}
2004
2005function mka() {
2006 case `uname -s` in
2007 Darwin)
2008 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2009 ;;
2010 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07002011 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002012 ;;
2013 esac
2014}
2015
2016function reposync() {
2017 case `uname -s` in
2018 Darwin)
2019 repo sync -j 4 "$@"
2020 ;;
2021 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002022 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002023 ;;
2024 esac
2025}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002026
2027function repodiff() {
2028 if [ -z "$*" ]; then
2029 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2030 return
2031 fi
2032 diffopts=$* repo forall -c \
2033 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2034}
2035
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302036# Credit for color strip sed: http://goo.gl/BoIcm
2037function dopush()
2038{
2039 local func=$1
2040 shift
2041
2042 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2043 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2044 echo "No device is online. Waiting for one..."
2045 echo "Please connect USB and/or enable USB debugging"
2046 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2047 sleep 1
2048 done
2049 echo "Device Found."
2050 fi
2051
Chirayu Desai6dadb572012-12-26 10:53:58 +05302052 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2053 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002054 # retrieve IP and PORT info if we're using a TCP connection
2055 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2056 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302057 adb root &> /dev/null
2058 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002059 if [ -n "$TCPIPPORT" ]
2060 then
2061 # adb root just killed our connection
2062 # so reconnect...
2063 adb connect "$TCPIPPORT"
2064 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302065 adb wait-for-device &> /dev/null
2066 sleep 0.3
2067 adb remount &> /dev/null
2068
Matt Mower668ea262014-05-20 02:52:23 -05002069 mkdir -p $OUT
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302070 $func $* | tee $OUT/.log
2071
2072 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002073 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 +05302074
2075 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002076 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 +05302077
Matt Mower668ea262014-05-20 02:52:23 -05002078 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302079 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002080 # Make sure file is in $OUT/system
2081 case $FILE in
2082 $OUT/system/*)
2083 # Get target file name (i.e. /system/bin/adb)
2084 TARGET=$(echo $FILE | sed "s#$OUT##")
2085 ;;
2086 *) continue ;;
2087 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302088
Matt Mower668ea262014-05-20 02:52:23 -05002089 case $TARGET in
2090 /system/priv-app/SystemUI.apk|/system/framework/*)
2091 # Only need to stop services once
2092 if ! $stop_n_start; then
2093 adb shell stop
2094 stop_n_start=true
2095 fi
2096 echo "Pushing: $TARGET"
2097 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302098 ;;
2099 *)
Matt Mower668ea262014-05-20 02:52:23 -05002100 echo "Pushing: $TARGET"
2101 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302102 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002103 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302104 done
Matt Mower668ea262014-05-20 02:52:23 -05002105 if $stop_n_start; then
2106 adb shell start
2107 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302108 rm -f $OUT/.log
2109 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302110 else
2111 echo "The connected device does not appear to be $CM_BUILD, run away!"
2112 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302113}
2114
2115alias mmp='dopush mm'
2116alias mmmp='dopush mmm'
2117alias mkap='dopush mka'
2118alias cmkap='dopush cmka'
2119
Chirayu Desai4a319b82013-06-05 20:14:33 +05302120function repopick() {
2121 T=$(gettop)
2122 $T/build/tools/repopick.py $@
2123}
2124
Chirayu Desaib89b3242013-06-30 10:04:25 +05302125function fixup_common_out_dir() {
2126 common_out_dir=$(get_build_var OUT_DIR)/target/common
2127 target_device=$(get_build_var TARGET_DEVICE)
2128 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2129 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2130 mv ${common_out_dir} ${common_out_dir}-${target_device}
2131 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2132 else
2133 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2134 mkdir -p ${common_out_dir}-${target_device}
2135 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2136 fi
2137 else
2138 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2139 mkdir -p ${common_out_dir}
2140 fi
2141}
2142
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002143# 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 +00002144#
2145# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2146# For some reason, installing the JDK doesn't make it show up in the
2147# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002148function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002149 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002150 # we can reset it later, depending on the version of java the build
2151 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002152 #
2153 # If we don't do this, the JAVA_HOME value set by the first call to
2154 # build/envsetup.sh will persist forever.
2155 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2156 export JAVA_HOME=""
2157 fi
2158
Andy McFaddenbd960942010-06-24 12:52:51 -07002159 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002160 case `uname -s` in
2161 Darwin)
2162 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2163 ;;
2164 *)
2165 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2166 ;;
2167 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002168
2169 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2170 # we can change it on the next envsetup.sh, if required.
2171 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002172 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002173}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002174
Alex Rayf0d08eb2013-03-08 15:15:06 -08002175# Print colored exit condition
2176function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002177 "$@"
2178 local retval=$?
2179 if [ $retval -ne 0 ]
2180 then
2181 echo -e "\e[0;31mFAILURE\e[00m"
2182 else
2183 echo -e "\e[0;32mSUCCESS\e[00m"
2184 fi
2185 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002186}
2187
Ying Wanged21d4c2014-08-24 22:14:19 -07002188function get_make_command()
2189{
2190 echo command make
2191}
2192
Ed Heylcc6be0a2014-06-18 14:55:58 -07002193function make()
2194{
2195 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002196 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002197 local ret=$?
2198 local end_time=$(date +"%s")
2199 local tdiff=$(($end_time-$start_time))
2200 local hours=$(($tdiff / 3600 ))
2201 local mins=$((($tdiff % 3600) / 60))
2202 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002203 local ncolors=$(tput colors 2>/dev/null)
2204 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2205 color_failed="\e[0;31m"
2206 color_success="\e[0;32m"
2207 color_reset="\e[00m"
2208 else
2209 color_failed=""
2210 color_success=""
2211 color_reset=""
2212 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002213 echo
2214 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002215 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002216 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002217 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002218 fi
2219 if [ $hours -gt 0 ] ; then
2220 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2221 elif [ $mins -gt 0 ] ; then
2222 printf "(%02g:%02g (mm:ss))" $mins $secs
2223 elif [ $secs -gt 0 ] ; then
2224 printf "(%s seconds)" $secs
2225 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002226 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002227 echo
2228 return $ret
2229}
2230
Raphael Moll70a86b02011-06-20 16:03:14 -07002231if [ "x$SHELL" != "x/bin/bash" ]; then
2232 case `ps -o command -p $$` in
2233 *bash*)
2234 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002235 *zsh*)
2236 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002237 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002238 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002239 ;;
2240 esac
2241fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002242
2243# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002244for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2245 `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 -08002246do
2247 echo "including $f"
2248 . $f
2249done
2250unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002251
2252addcompletions
Chirayu Desaie1466d62013-03-19 17:50:37 +05302253
2254export ANDROID_BUILD_TOP=$(gettop)