blob: 01b657cbd3365d87f6d3ce2211713044eda9a6b9 [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.
7- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08008- mm: Builds all of the modules in the current directory, but not their dependencies.
9- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000010 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080011- mma: Builds all of the modules in the current directory, and their dependencies.
Daniel Bateman22185ba2012-08-04 03:48:09 -050012- mmp: Builds all of the modules in the current directory and pushes them to the device.
13- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080014- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070015- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070016- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070017- jgrep: Greps on all local Java files.
18- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000019- mangrep: Greps on all local AndroidManifest.xml files.
20- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070021- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080022- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060023- cmremote: Add git remote for CM Gerrit Review
24- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
25- cmrebase: Rebase a Gerrit change and push it again
Steve Kondik873fa562012-09-17 11:33:18 -070026- aospremote: Add git remote for matching AOSP repository
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060027- mka: Builds using SCHED_BATCH on all processors
28- reposync: Parallel repo sync using ionice and SCHED_BATCH
Steve Kondik83c03d52012-10-24 16:40:42 -070029- installboot: Installs a boot.img to the connected device.
30- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070031
Dan Albert4ae5d4b2014-10-31 16:23:08 -070032Environemnt options:
33- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
34 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
35 build is leak-check clean.
36
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070037Look at the source to view more functions. The complete list is:
38EOF
39 T=$(gettop)
40 local A
41 A=""
Jeff Brown46cbd202014-07-26 15:15:41 -070042 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 -070043 A="$A $i"
44 done
45 echo $A
46}
47
48# Get the value of a build variable as an absolute path.
49function get_abs_build_var()
50{
51 T=$(gettop)
52 if [ ! "$T" ]; then
53 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
54 return
55 fi
Ying Wang9cd17642012-12-13 10:52:07 -080056 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070057 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070058}
59
60# Get the exact value of a build variable.
61function get_build_var()
62{
63 T=$(gettop)
64 if [ ! "$T" ]; then
65 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
66 return
67 fi
Andrew Boie6905e212013-12-19 13:21:46 -080068 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070069 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080070}
71
72# check to see if the supplied product is one we can build
73function check_product()
74{
75 T=$(gettop)
76 if [ ! "$T" ]; then
77 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
78 return
79 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000080
81 if (echo -n $1 | grep -q -e "^cm_") ; then
82 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
83 else
84 CM_BUILD=
85 fi
86 export CM_BUILD
87
Jeff Browne33ba4c2011-07-11 22:11:46 -070088 TARGET_PRODUCT=$1 \
89 TARGET_BUILD_VARIANT= \
90 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070091 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080092 get_build_var TARGET_DEVICE > /dev/null
93 # hide successful answers, but allow the errors to show
94}
95
96VARIANT_CHOICES=(user userdebug eng)
97
98# check to see if the supplied variant is valid
99function check_variant()
100{
101 for v in ${VARIANT_CHOICES[@]}
102 do
103 if [ "$v" = "$1" ]
104 then
105 return 0
106 fi
107 done
108 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700109}
110
111function setpaths()
112{
113 T=$(gettop)
114 if [ ! "$T" ]; then
115 echo "Couldn't locate the top of the tree. Try setting TOP."
116 return
117 fi
118
119 ##################################################################
120 # #
121 # Read me before you modify this code #
122 # #
123 # This function sets ANDROID_BUILD_PATHS to what it is adding #
124 # to PATH, and the next time it is run, it removes that from #
125 # PATH. This is required so lunch can be run more than once #
126 # and still have working paths. #
127 # #
128 ##################################################################
129
Raphael Mollc639c782011-06-20 17:25:01 -0700130 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
131 # due to "C:\Program Files" being in the path.
132
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700133 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700134 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700135 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
136 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700137 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700138 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800139 # strip leading ':', if any
140 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500141 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700142
143 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700144 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700145 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700146
Ben Cheng8bc4c432012-11-16 13:29:13 -0800147 # defined in core/config.mk
148 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700149 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800150 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800151
Raphael Mollc639c782011-06-20 17:25:01 -0700152 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800153 export ANDROID_TOOLCHAIN=
154 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200155 local ARCH=$(get_build_var TARGET_ARCH)
156 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400157 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700158 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400159 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
160 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800161 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200162 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800163 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700164 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700165 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700166 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000167 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200168 *)
169 echo "Can't find toolchain for unknown architecture: $ARCH"
170 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700171 ;;
172 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700173 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800174 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700175 fi
Raphael732936d2011-06-22 14:35:32 -0700176
Ben Chengfba67bf2014-02-25 10:27:07 -0800177 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
178 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
179 fi
180
181 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700182 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700183 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800184 # Legacy toolchain configuration used for ARM kernel compilation
Ben Cheng8bc4c432012-11-16 13:29:13 -0800185 toolchaindir=arm/arm-eabi-$targetgccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700186 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100187 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
188 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700189 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700190 ;;
191 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700192 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700193 ;;
194 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700195
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700196 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700197 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 +0200198
199 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
200 # to ensure that the corresponding 'emulator' binaries are used.
201 case $(uname -s) in
202 Darwin)
203 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
204 ;;
205 Linux)
206 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
207 ;;
208 *)
209 ANDROID_EMULATOR_PREBUILTS=
210 ;;
211 esac
212 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700213 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200214 export ANDROID_EMULATOR_PREBUILTS
215 fi
216
Ying Wangaa1c9b52012-11-26 20:51:59 -0800217 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800218
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500219 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900220 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500221 if [ -n "$JAVA_HOME" ]; then
222 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900223 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
224 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500225 fi
226
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800227 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700228 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
229 export OUT=$ANDROID_PRODUCT_OUT
230
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700231 unset ANDROID_HOST_OUT
232 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
233
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800234 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700235 # TODO: fix the path
236 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
237}
238
239function printconfig()
240{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800241 T=$(gettop)
242 if [ ! "$T" ]; then
243 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
244 return
245 fi
246 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247}
248
249function set_stuff_for_environment()
250{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800251 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500252 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800253 setpaths
254 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800256 export ANDROID_BUILD_TOP=$(gettop)
Ben Chengaac3f812013-08-13 14:38:15 -0700257 # With this environment variable new GCC can apply colors to warnings/errors
258 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 -0700259 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700260}
261
262function set_sequence_number()
263{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700264 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700265}
266
267function settitle()
268{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800269 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700270 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700271 local product=$TARGET_PRODUCT
272 local variant=$TARGET_BUILD_VARIANT
273 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800274 if [ -z "$PROMPT_COMMAND" ]; then
275 # No prompts
276 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
277 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
278 # Prompts exist, but no hardstatus
279 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700280 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800281 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
282 PROMPT_COMMAND=$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')
283 fi
284
285 if [ -z "$apps" ]; then
286 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
287 else
288 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
289 fi
290 export ANDROID_PROMPT_PREFIX
291
292 # Inject build data into hardstatus
293 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 -0800294 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700295}
296
Kenny Root52aa81c2011-07-15 11:07:06 -0700297function addcompletions()
298{
299 local T dir f
300
301 # Keep us from trying to run in something that isn't bash.
302 if [ -z "${BASH_VERSION}" ]; then
303 return
304 fi
305
306 # Keep us from trying to run in bash that's too old.
307 if [ ${BASH_VERSINFO[0]} -lt 3 ]; then
308 return
309 fi
310
Chirayu Desai20a61372013-03-16 20:00:17 +0530311 dirs="sdk/bash_completion vendor/cm/bash_completion"
312 for dir in $dirs; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700313 if [ -d ${dir} ]; then
Kenny Root7546d612011-07-18 13:11:34 -0700314 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
Kenny Root52aa81c2011-07-15 11:07:06 -0700315 echo "including $f"
316 . $f
317 done
318 fi
Chirayu Desai20a61372013-03-16 20:00:17 +0530319 done
Kenny Root52aa81c2011-07-15 11:07:06 -0700320}
321
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700322function choosetype()
323{
324 echo "Build type choices are:"
325 echo " 1. release"
326 echo " 2. debug"
327 echo
328
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800329 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700330 DEFAULT_NUM=1
331 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800333 export TARGET_BUILD_TYPE=
334 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700335 while [ -z $TARGET_BUILD_TYPE ]
336 do
337 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800338 if [ -z "$1" ] ; then
339 read ANSWER
340 else
341 echo $1
342 ANSWER=$1
343 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700344 case $ANSWER in
345 "")
346 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
347 ;;
348 1)
349 export TARGET_BUILD_TYPE=release
350 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800351 release)
352 export TARGET_BUILD_TYPE=release
353 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700354 2)
355 export TARGET_BUILD_TYPE=debug
356 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800357 debug)
358 export TARGET_BUILD_TYPE=debug
359 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700360 *)
361 echo
362 echo "I didn't understand your response. Please try again."
363 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700364 ;;
365 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800366 if [ -n "$1" ] ; then
367 break
368 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700369 done
370
371 set_stuff_for_environment
372}
373
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800374#
375# This function isn't really right: It chooses a TARGET_PRODUCT
376# based on the list of boards. Usually, that gets you something
377# that kinda works with a generic product, but really, you should
378# pick a product by name.
379#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700380function chooseproduct()
381{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700382 if [ "x$TARGET_PRODUCT" != x ] ; then
383 default_value=$TARGET_PRODUCT
384 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700385 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700386 fi
387
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800388 export TARGET_PRODUCT=
389 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700390 while [ -z "$TARGET_PRODUCT" ]
391 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700392 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800393 if [ -z "$1" ] ; then
394 read ANSWER
395 else
396 echo $1
397 ANSWER=$1
398 fi
399
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700400 if [ -z "$ANSWER" ] ; then
401 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800402 else
403 if check_product $ANSWER
404 then
405 export TARGET_PRODUCT=$ANSWER
406 else
407 echo "** Not a valid product: $ANSWER"
408 fi
409 fi
410 if [ -n "$1" ] ; then
411 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700412 fi
413 done
414
415 set_stuff_for_environment
416}
417
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800418function choosevariant()
419{
420 echo "Variant choices are:"
421 local index=1
422 local v
423 for v in ${VARIANT_CHOICES[@]}
424 do
425 # The product name is the name of the directory containing
426 # the makefile we found, above.
427 echo " $index. $v"
428 index=$(($index+1))
429 done
430
431 local default_value=eng
432 local ANSWER
433
434 export TARGET_BUILD_VARIANT=
435 while [ -z "$TARGET_BUILD_VARIANT" ]
436 do
437 echo -n "Which would you like? [$default_value] "
438 if [ -z "$1" ] ; then
439 read ANSWER
440 else
441 echo $1
442 ANSWER=$1
443 fi
444
445 if [ -z "$ANSWER" ] ; then
446 export TARGET_BUILD_VARIANT=$default_value
447 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
448 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800449 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800450 fi
451 else
452 if check_variant $ANSWER
453 then
454 export TARGET_BUILD_VARIANT=$ANSWER
455 else
456 echo "** Not a valid variant: $ANSWER"
457 fi
458 fi
459 if [ -n "$1" ] ; then
460 break
461 fi
462 done
463}
464
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465function choosecombo()
466{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700467 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700468
469 echo
470 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700471 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700472
473 echo
474 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700475 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476
477 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700480}
481
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800482# Clear this variable. It will be built up again when the vendorsetup.sh
483# files are included at the end of this file.
484unset LUNCH_MENU_CHOICES
485function add_lunch_combo()
486{
487 local new_combo=$1
488 local c
489 for c in ${LUNCH_MENU_CHOICES[@]} ; do
490 if [ "$new_combo" = "$c" ] ; then
491 return
492 fi
493 done
494 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
495}
496
497# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700498add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800499add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000500add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800501add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000502add_lunch_combo aosp_x86-eng
503add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800504
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505function print_lunch_menu()
506{
507 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700508 echo
509 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000510 if [ "$(uname)" = "Darwin" ] ; then
511 echo " (ohai, koush!)"
512 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700513 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000514 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
515 echo "Breakfast menu... pick a combo:"
516 else
517 echo "Lunch menu... pick a combo:"
518 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800519
520 local i=1
521 local choice
522 for choice in ${LUNCH_MENU_CHOICES[@]}
523 do
524 echo " $i. $choice"
525 i=$(($i+1))
526 done
527
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000528 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
529 echo "... and don't forget the bacon!"
530 fi
531
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700532 echo
533}
534
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000535function brunch()
536{
537 breakfast $*
538 if [ $? -eq 0 ]; then
539 mka bacon
540 else
541 echo "No such item in brunch menu. Try 'breakfast'"
542 return 1
543 fi
544 return $?
545}
546
547function breakfast()
548{
549 target=$1
550 CM_DEVICES_ONLY="true"
551 unset LUNCH_MENU_CHOICES
552 add_lunch_combo full-eng
553 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
554 do
555 echo "including $f"
556 . $f
557 done
558 unset f
559
560 if [ $# -eq 0 ]; then
561 # No arguments, so let's have the full menu
562 lunch
563 else
564 echo "z$target" | grep -q "-"
565 if [ $? -eq 0 ]; then
566 # A buildtype was specified, assume a full device name
567 lunch $target
568 else
569 # This is probably just the CM model name
570 lunch cm_$target-userdebug
571 fi
572 fi
573 return $?
574}
575
576alias bib=breakfast
577
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700578function lunch()
579{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800580 local answer
581
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584 else
585 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700586 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588 fi
589
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 local selection=
591
592 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700593 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700594 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800595 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
596 then
597 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
598 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800599 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800600 fi
601 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
602 then
603 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700604 fi
605
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 if [ -z "$selection" ]
607 then
608 echo
609 echo "Invalid lunch combo: $answer"
610 return 1
611 fi
612
Joe Onoratoda12daf2010-06-09 18:18:31 -0700613 export TARGET_BUILD_APPS=
614
Jeff Browne33ba4c2011-07-11 22:11:46 -0700615 local product=$(echo -n $selection | sed -e "s/-.*$//")
616 check_product $product
617 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800618 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800619 # if we can't find a product, try to grab it off the CM github
620 T=$(gettop)
621 pushd $T > /dev/null
622 build/tools/roomservice.py $product
623 popd > /dev/null
624 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000625 else
626 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800627 fi
628 if [ $? -ne 0 ]
629 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700630 echo
631 echo "** Don't have a product spec for: '$product'"
632 echo "** Do you have the right repo manifest?"
633 product=
634 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800635
Jeff Browne33ba4c2011-07-11 22:11:46 -0700636 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
637 check_variant $variant
638 if [ $? -ne 0 ]
639 then
640 echo
641 echo "** Invalid variant: '$variant'"
642 echo "** Must be one of ${VARIANT_CHOICES[@]}"
643 variant=
644 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800645
Jeff Browne33ba4c2011-07-11 22:11:46 -0700646 if [ -z "$product" -o -z "$variant" ]
647 then
648 echo
649 return 1
650 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800651
Jeff Browne33ba4c2011-07-11 22:11:46 -0700652 export TARGET_PRODUCT=$product
653 export TARGET_BUILD_VARIANT=$variant
654 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700655
656 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800657
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660}
661
Jeff Davidson513d7a42010-08-02 10:00:44 -0700662# Tab completion for lunch.
663function _lunch()
664{
665 local cur prev opts
666 COMPREPLY=()
667 cur="${COMP_WORDS[COMP_CWORD]}"
668 prev="${COMP_WORDS[COMP_CWORD-1]}"
669
670 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
671 return 0
672}
673complete -F _lunch lunch
674
Joe Onoratoda12daf2010-06-09 18:18:31 -0700675# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700676# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677function tapas()
678{
Ying Wangb541ab62014-05-29 17:57:40 -0700679 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 -0700680 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700681 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
682 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 -0700683
Ying Wang67f02922012-08-22 10:25:20 -0700684 if [ $(echo $arch | wc -w) -gt 1 ]; then
685 echo "tapas: Error: Multiple build archs supplied: $arch"
686 return
687 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700688 if [ $(echo $variant | wc -w) -gt 1 ]; then
689 echo "tapas: Error: Multiple build variants supplied: $variant"
690 return
691 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700692 if [ $(echo $density | wc -w) -gt 1 ]; then
693 echo "tapas: Error: Multiple densities supplied: $density"
694 return
695 fi
Ying Wang67f02922012-08-22 10:25:20 -0700696
697 local product=full
698 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700699 x86) product=full_x86;;
700 mips) product=full_mips;;
701 armv5) product=generic_armv5;;
702 arm64) product=aosp_arm64;;
703 x86_64) product=aosp_x86_64;;
704 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700705 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700706 if [ -z "$variant" ]; then
707 variant=eng
708 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700709 if [ -z "$apps" ]; then
710 apps=all
711 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600712 if [ -z "$density" ]; then
713 density=alldpi
714 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700715
Ying Wang67f02922012-08-22 10:25:20 -0700716 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700717 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700718 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700719 export TARGET_BUILD_TYPE=release
720 export TARGET_BUILD_APPS=$apps
721
722 set_stuff_for_environment
723 printconfig
724}
725
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100726function eat()
727{
728 if [ "$OUT" ] ; then
729 MODVERSION=`sed -n -e'/ro\.cm\.version/s/.*=//p' $OUT/system/build.prop`
730 ZIPFILE=cm-$MODVERSION.zip
731 ZIPPATH=$OUT/$ZIPFILE
732 if [ ! -f $ZIPPATH ] ; then
733 echo "Nothing to eat"
734 return 1
735 fi
736 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
737 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
738 echo "No device is online. Waiting for one..."
739 echo "Please connect USB and/or enable USB debugging"
740 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
741 sleep 1
742 done
743 echo "Device Found.."
744 fi
Chirayu Desai6dadb572012-12-26 10:53:58 +0530745 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
746 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100747 # if adbd isn't root we can't write to /cache/recovery/
748 adb root
749 sleep 1
750 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700751 cat << EOF > /tmp/command
752--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100753EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700754 if adb push /tmp/command /cache/recovery/ ; then
755 echo "Rebooting into recovery for sideload installation"
756 adb reboot recovery
757 adb wait-for-sideload
758 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100759 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700760 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100761 else
762 echo "Nothing to eat"
763 return 1
764 fi
765 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530766 else
767 echo "The connected device does not appear to be $CM_BUILD, run away!"
768 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100769}
770
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000771function omnom
772{
773 brunch $*
774 eat
775}
776
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700777function gettop
778{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800779 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700780 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700781 # The following circumlocution ensures we remove symlinks from TOP.
782 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700783 else
784 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800785 # The following circumlocution (repeated below as well) ensures
786 # that we record the true directory name and not one that is
787 # faked up with symlink names.
788 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800790 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 T=
792 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800793 \cd ..
synergyb112a402013-07-05 19:47:47 -0700794 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700795 done
Ying Wang9cd17642012-12-13 10:52:07 -0800796 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 if [ -f "$T/$TOPFILE" ]; then
798 echo $T
799 fi
800 fi
801 fi
802}
803
Andrew Hsieh906cb782013-09-10 17:37:14 +0800804# Return driver for "make", if any (eg. static analyzer)
805function getdriver()
806{
807 local T="$1"
808 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
809 if [ -n "$WITH_STATIC_ANALYZER" ]; then
810 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800811$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
812--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800813--status-bugs \
814--top=$T"
815 fi
816}
817
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700818function m()
819{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800820 local T=$(gettop)
821 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800823 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824 else
825 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700826 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827 fi
828}
829
830function findmakefile()
831{
832 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800833 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834 T=
835 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700836 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700837 if [ -f "$T/Android.mk" ]; then
838 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800839 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700840 return
841 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800842 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700843 done
Ying Wang9cd17642012-12-13 10:52:07 -0800844 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845}
846
847function mm()
848{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800849 local T=$(gettop)
850 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700851 # If we're sitting in the root of the build tree, just do a
852 # normal make.
853 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800854 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855 else
856 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800857 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700858 local MODULES=
859 local GET_INSTALL_PATH=
860 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700861 # Remove the path to top as the makefilepath needs to be relative
862 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700863 if [ ! "$T" ]; then
864 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700865 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700866 elif [ ! "$M" ]; then
867 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700868 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700869 else
Ying Wanga7deb082013-08-16 13:24:47 -0700870 for ARG in $@; do
871 case $ARG in
872 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
873 esac
874 done
875 if [ -n "$GET_INSTALL_PATH" ]; then
876 MODULES=
877 ARGS=GET-INSTALL-PATH
878 else
879 MODULES=all_modules
880 ARGS=$@
881 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700882 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 -0700883 fi
884 fi
885}
886
887function mmm()
888{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800889 local T=$(gettop)
890 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700891 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800892 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800893 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800894 local ARGS=
895 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700896 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800897 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
898 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
899 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800900 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
901 if [ "$MODULES" = "" ]; then
902 MODULES=all_modules
903 fi
904 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700905 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700906 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
907 local TO_CHOP=`expr $TO_CHOP + 1`
908 local START=`PWD= /bin/pwd`
909 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700910 if [ "$MFILE" = "" ] ; then
911 MFILE=$DIR/Android.mk
912 else
913 MFILE=$MFILE/$DIR/Android.mk
914 fi
915 MAKEFILE="$MAKEFILE $MFILE"
916 else
Ying Wanga7deb082013-08-16 13:24:47 -0700917 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100918 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700919 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
920 *) echo "No Android.mk in $DIR."; return 1;;
921 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922 fi
923 done
Ying Wanga7deb082013-08-16 13:24:47 -0700924 if [ -n "$GET_INSTALL_PATH" ]; then
925 ARGS=$GET_INSTALL_PATH
926 MODULES=
927 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800928 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 -0700929 else
930 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700931 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 fi
933}
934
Ying Wangb607f7b2013-02-08 18:01:04 -0800935function mma()
936{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800937 local T=$(gettop)
938 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800939 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800940 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800941 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800942 if [ ! "$T" ]; then
943 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700944 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800945 fi
946 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800947 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800948 fi
949}
950
951function mmma()
952{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800953 local T=$(gettop)
954 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800955 if [ "$T" ]; then
956 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
957 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
958 local MY_PWD=`PWD= /bin/pwd`
959 if [ "$MY_PWD" = "$T" ]; then
960 MY_PWD=
961 else
962 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
963 fi
964 local DIR=
965 local MODULE_PATHS=
966 local ARGS=
967 for DIR in $DIRS ; do
968 if [ -d $DIR ]; then
969 if [ "$MY_PWD" = "" ]; then
970 MODULE_PATHS="$MODULE_PATHS $DIR"
971 else
972 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
973 fi
974 else
975 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100976 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800977 *) echo "Couldn't find directory $DIR"; return 1;;
978 esac
979 fi
980 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800981 $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 -0800982 else
983 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700984 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800985 fi
986}
987
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988function croot()
989{
990 T=$(gettop)
991 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800992 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700993 else
994 echo "Couldn't locate the top of the tree. Try setting TOP."
995 fi
996}
997
Joe Onorato2a5d4d82009-07-30 10:23:21 -0700998function cproj()
999{
1000 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001001 local HERE=$PWD
1002 T=
1003 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1004 T=$PWD
1005 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001006 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001007 return
1008 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001009 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001010 done
Ying Wang9cd17642012-12-13 10:52:07 -08001011 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001012 echo "can't find Android.mk"
1013}
1014
Daniel Sandler47e0a882013-07-30 13:23:52 -04001015# simplified version of ps; output in the form
1016# <pid> <procname>
1017function qpid() {
1018 local prepend=''
1019 local append=''
1020 if [ "$1" = "--exact" ]; then
1021 prepend=' '
1022 append='$'
1023 shift
1024 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1025 echo "usage: qpid [[--exact] <process name|pid>"
1026 return 255
1027 fi
1028
1029 local EXE="$1"
1030 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001031 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001032 else
1033 adb shell ps \
1034 | tr -d '\r' \
1035 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1036 fi
1037}
1038
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001039function pid()
1040{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001041 local prepend=''
1042 local append=''
1043 if [ "$1" = "--exact" ]; then
1044 prepend=' '
1045 append='$'
1046 shift
1047 fi
1048 local EXE="$1"
1049 if [ "$EXE" ] ; then
1050 local PID=`adb shell ps \
1051 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001052 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001053 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1054 echo "$PID"
1055 else
1056 echo "usage: pid [--exact] <process name>"
1057 return 255
1058 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001059}
1060
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001061# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001062# that has the core-file-size limit set correctly
1063#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001064# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001065# if its core-file-size limit is not set already.
1066# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1067
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001068function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001069{
1070 echo "Getting root...";
1071 adb root;
1072 adb wait-for-device;
1073
1074 echo "Remounting root parition read-write...";
1075 adb shell mount -w -o remount -t rootfs rootfs;
1076 sleep 1;
1077 adb wait-for-device;
1078 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001079 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001080 adb shell chmod 0777 /cores;
1081
1082 echo "Granting SELinux permission to dump in /cores...";
1083 adb shell restorecon -R /cores;
1084
1085 echo "Set core pattern.";
1086 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1087
1088 echo "Done."
1089}
1090
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001091# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001092# $1 = PID of process (e.g., $(pid mediaserver))
1093#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001094# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001095# dump to actually be generated.
1096
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001097function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001098{
1099 local PID=$1;
1100 if [ -z "$PID" ]; then
1101 printf "Expecting a PID!\n";
1102 return;
1103 fi;
1104 echo "Setting core limit for $PID to infinite...";
1105 adb shell prlimit $PID 4 -1 -1
1106}
1107
1108# core - send SIGV and pull the core for process
1109# $1 = PID of process (e.g., $(pid mediaserver))
1110#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001111# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001112# enabled globally.
1113
1114function core()
1115{
1116 local PID=$1;
1117
1118 if [ -z "$PID" ]; then
1119 printf "Expecting a PID!\n";
1120 return;
1121 fi;
1122
1123 local CORENAME=core.$PID;
1124 local COREPATH=/cores/$CORENAME;
1125 local SIG=SEGV;
1126
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001127 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001128
1129 local done=0;
1130 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1131 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1132 adb shell kill -$SIG $PID;
1133 sleep 1;
1134 done;
1135
1136 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1137 echo "Done: core is under $COREPATH on device.";
1138}
1139
Christopher Tate744ee802009-11-12 15:33:08 -08001140# systemstack - dump the current stack trace of all threads in the system process
1141# to the usual ANR traces file
1142function systemstack()
1143{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001144 stacks system_server
1145}
1146
1147function stacks()
1148{
1149 if [[ $1 =~ ^[0-9]+$ ]] ; then
1150 local PID="$1"
1151 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001152 local PIDLIST="$(pid $1)"
1153 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1154 local PID="$PIDLIST"
1155 elif [ "$PIDLIST" ] ; then
1156 echo "more than one process: $1"
1157 else
1158 echo "no such process: $1"
1159 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001160 else
1161 echo "usage: stacks [pid|process name]"
1162 fi
1163
1164 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001165 # Determine whether the process is native
1166 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1167 # Dump stacks of Dalvik process
1168 local TRACES=/data/anr/traces.txt
1169 local ORIG=/data/anr/traces.orig
1170 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001171
Jeff Brownb12c2e52013-08-19 15:14:16 -07001172 # Keep original traces to avoid clobbering
1173 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001174
Jeff Brownb12c2e52013-08-19 15:14:16 -07001175 # Make sure we have a usable file
1176 adb shell touch $TRACES
1177 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001178
Jeff Brownb12c2e52013-08-19 15:14:16 -07001179 # Dump stacks and wait for dump to finish
1180 adb shell kill -3 $PID
1181 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001182
Jeff Brownb12c2e52013-08-19 15:14:16 -07001183 # Restore original stacks, and show current output
1184 adb shell mv $TRACES $TMP
1185 adb shell mv $ORIG $TRACES
1186 adb shell cat $TMP
1187 else
1188 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001189 local USE64BIT="$(is64bit $PID)"
1190 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001191 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001192 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001193}
1194
Michael Wrightaeed7212014-06-19 19:58:12 -07001195# Read the ELF header from /proc/$PID/exe to determine if the process is
1196# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001197function is64bit()
1198{
1199 local PID="$1"
1200 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001201 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001202 echo "64"
1203 else
1204 echo ""
1205 fi
1206 else
1207 echo ""
1208 fi
1209}
1210
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001211case `uname -s` in
1212 Darwin)
1213 function sgrep()
1214 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001215 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 -07001216 }
1217
1218 ;;
1219 *)
1220 function sgrep()
1221 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001222 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 -07001223 }
1224 ;;
1225esac
1226
Raghu Gandham8da43102012-07-25 19:57:22 -07001227function gettargetarch
1228{
1229 get_build_var TARGET_ARCH
1230}
1231
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001232function ggrep()
1233{
1234 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1235}
1236
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001237function jgrep()
1238{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001239 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 -07001240}
1241
1242function cgrep()
1243{
Dan Albert01961192014-11-22 10:16:01 -08001244 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 -07001245}
1246
1247function resgrep()
1248{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001249 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 -07001250}
1251
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001252function mangrep()
1253{
1254 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1255}
1256
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001257function sepgrep()
1258{
1259 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 "$@"
1260}
1261
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001262function rcgrep()
1263{
1264 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1265}
1266
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001267case `uname -s` in
1268 Darwin)
1269 function mgrep()
1270 {
Ying Wang324c2b22012-08-17 15:03:20 -07001271 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 -07001272 }
1273
1274 function treegrep()
1275 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001276 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 -07001277 }
1278
1279 ;;
1280 *)
1281 function mgrep()
1282 {
Ying Wang324c2b22012-08-17 15:03:20 -07001283 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 -07001284 }
1285
1286 function treegrep()
1287 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001288 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 -07001289 }
1290
1291 ;;
1292esac
1293
1294function getprebuilt
1295{
1296 get_abs_build_var ANDROID_PREBUILTS
1297}
1298
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001299function tracedmdump()
1300{
1301 T=$(gettop)
1302 if [ ! "$T" ]; then
1303 echo "Couldn't locate the top of the tree. Try setting TOP."
1304 return
1305 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001306 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001307 local arch=$(gettargetarch)
1308 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001309
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001310 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001311 if [ ! "$TRACE" ] ; then
1312 echo "usage: tracedmdump tracename"
1313 return
1314 fi
1315
Jack Veenstra60116fc2009-04-09 18:12:34 -07001316 if [ ! -r "$KERNEL" ] ; then
1317 echo "Error: cannot find kernel: '$KERNEL'"
1318 return
1319 fi
1320
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001321 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001322 if [ "$BASETRACE" = "$TRACE" ] ; then
1323 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1324 fi
1325
1326 echo "post-processing traces..."
1327 rm -f $TRACE/qtrace.dexlist
1328 post_trace $TRACE
1329 if [ $? -ne 0 ]; then
1330 echo "***"
1331 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1332 echo "***"
1333 return
1334 fi
1335 echo "generating dexlist output..."
1336 /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
1337 echo "generating dmtrace data..."
1338 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1339 echo "generating html file..."
1340 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1341 echo "done, see $TRACE/dmtrace.html for details"
1342 echo "or run:"
1343 echo " traceview $TRACE/dmtrace"
1344}
1345
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001346# communicate with a running device or emulator, set up necessary state,
1347# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001348function runhat()
1349{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001350 # process standard adb options
1351 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001352 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001353 adbTarget=$1
1354 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001355 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001356 adbTarget="$1 $2"
1357 shift 2
1358 fi
1359 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001360 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001361
1362 # runhat options
1363 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001364
1365 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001366 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001367 return
1368 fi
1369
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001370 # confirm hat is available
1371 if [ -z $(which hat) ]; then
1372 echo "hat is not available in this configuration."
1373 return
1374 fi
1375
Andy McFaddenb6289852010-07-12 08:00:19 -07001376 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001377 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001378 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001379 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001380 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001381 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001382 echo -n "> "
1383 read
1384
The Android Open Source Project88b60792009-03-03 19:28:42 -08001385 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001386
The Android Open Source Project88b60792009-03-03 19:28:42 -08001387 echo "Retrieving file $devFile..."
1388 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001389
The Android Open Source Project88b60792009-03-03 19:28:42 -08001390 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001391
The Android Open Source Project88b60792009-03-03 19:28:42 -08001392 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001393 echo "View the output by pointing your browser at http://localhost:7000/"
1394 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001395 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001396}
1397
1398function getbugreports()
1399{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001400 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001401
1402 if [ ! "$reports" ]; then
1403 echo "Could not locate any bugreports."
1404 return
1405 fi
1406
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001407 local report
1408 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001409 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001410 echo "/sdcard/bugreports/${report}"
1411 adb pull /sdcard/bugreports/${report} ${report}
1412 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001413 done
1414}
1415
Victoria Lease1b296b42012-08-21 15:44:06 -07001416function getsdcardpath()
1417{
1418 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1419}
1420
1421function getscreenshotpath()
1422{
1423 echo "$(getsdcardpath)/Pictures/Screenshots"
1424}
1425
1426function getlastscreenshot()
1427{
1428 local screenshot_path=$(getscreenshotpath)
1429 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1430 if [ "$screenshot" = "" ]; then
1431 echo "No screenshots found."
1432 return
1433 fi
1434 echo "${screenshot}"
1435 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1436}
1437
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001438function startviewserver()
1439{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001440 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001441 if [ $# -gt 0 ]; then
1442 port=$1
1443 fi
1444 adb shell service call window 1 i32 $port
1445}
1446
1447function stopviewserver()
1448{
1449 adb shell service call window 2
1450}
1451
1452function isviewserverstarted()
1453{
1454 adb shell service call window 3
1455}
1456
Romain Guyb84049a2010-10-04 16:56:11 -07001457function key_home()
1458{
1459 adb shell input keyevent 3
1460}
1461
1462function key_back()
1463{
1464 adb shell input keyevent 4
1465}
1466
1467function key_menu()
1468{
1469 adb shell input keyevent 82
1470}
1471
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001472function smoketest()
1473{
1474 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1475 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1476 return
1477 fi
1478 T=$(gettop)
1479 if [ ! "$T" ]; then
1480 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1481 return
1482 fi
1483
Ying Wang9cd17642012-12-13 10:52:07 -08001484 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001485 adb uninstall com.android.smoketest > /dev/null &&
1486 adb uninstall com.android.smoketest.tests > /dev/null &&
1487 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1488 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1489 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1490}
1491
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001492# simple shortcut to the runtest command
1493function runtest()
1494{
1495 T=$(gettop)
1496 if [ ! "$T" ]; then
1497 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1498 return
1499 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001500 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001501}
1502
The Android Open Source Project88b60792009-03-03 19:28:42 -08001503function godir () {
1504 if [[ -z "$1" ]]; then
1505 echo "Usage: godir <regex>"
1506 return
1507 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001508 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001509 if [[ ! -f $T/filelist ]]; then
1510 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001511 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001512 echo " Done"
1513 echo ""
1514 fi
1515 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001516 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001517 if [[ ${#lines[@]} = 0 ]]; then
1518 echo "Not found"
1519 return
1520 fi
1521 local pathname
1522 local choice
1523 if [[ ${#lines[@]} > 1 ]]; then
1524 while [[ -z "$pathname" ]]; do
1525 local index=1
1526 local line
1527 for line in ${lines[@]}; do
1528 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001529 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001530 done
1531 echo
1532 echo -n "Select one: "
1533 unset choice
1534 read choice
1535 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1536 echo "Invalid choice"
1537 continue
1538 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001539 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001540 done
1541 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001542 pathname=${lines[0]}
1543 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001544 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001545}
1546
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001547function cmremote()
1548{
1549 git remote rm cmremote 2> /dev/null
1550 if [ ! -d .git ]
1551 then
1552 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1553 fi
1554 GERRIT_REMOTE=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1555 if [ -z "$GERRIT_REMOTE" ]
1556 then
Koushik Duttab55f13a2012-05-14 16:14:36 -07001557 GERRIT_REMOTE=$(cat .git/config | grep http://github.com | awk '{ print $NF }' | sed s#http://github.com/##g)
1558 if [ -z "$GERRIT_REMOTE" ]
1559 then
1560 echo Unable to set up the git remote, are you in the root of the repo?
1561 return 0
1562 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001563 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001564 CMUSER=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001565 if [ -z "$CMUSER" ]
1566 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001567 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001568 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001569 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001570 fi
1571 echo You can now push to "cmremote".
1572}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001573export -f cmremote
1574
Steve Kondik873fa562012-09-17 11:33:18 -07001575function aospremote()
1576{
1577 git remote rm aosp 2> /dev/null
1578 if [ ! -d .git ]
1579 then
1580 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1581 fi
1582 PROJECT=`pwd | sed s#$ANDROID_BUILD_TOP/##g`
1583 if (echo $PROJECT | grep -qv "^device")
1584 then
1585 PFX="platform/"
1586 fi
1587 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1588 echo "Remote 'aosp' created"
1589}
1590export -f aospremote
1591
Steve Kondikf00e7d92012-09-23 23:46:55 -07001592function installboot()
1593{
1594 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1595 then
1596 echo "No recovery.fstab found. Build recovery first."
1597 return 1
1598 fi
1599 if [ ! -e "$OUT/boot.img" ];
1600 then
1601 echo "No boot.img found. Run make bootimage first."
1602 return 1
1603 fi
1604 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1605 if [ -z "$PARTITION" ];
1606 then
1607 echo "Unable to determine boot partition."
1608 return 1
1609 fi
1610 adb start-server
1611 adb root
1612 sleep 1
1613 adb wait-for-device
1614 adb remount
1615 adb wait-for-device
1616 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1617 then
1618 adb push $OUT/boot.img /cache/
1619 for i in $OUT/system/lib/modules/*;
1620 do
1621 adb push $i /system/lib/modules/
1622 done
1623 adb shell dd if=/cache/boot.img of=$PARTITION
1624 adb shell chmod 644 /system/lib/modules/*
1625 echo "Installation complete."
1626 else
1627 echo "The connected device does not appear to be $CM_BUILD, run away!"
1628 fi
1629}
1630
Steve Kondik83c03d52012-10-24 16:40:42 -07001631function installrecovery()
1632{
1633 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1634 then
1635 echo "No recovery.fstab found. Build recovery first."
1636 return 1
1637 fi
1638 if [ ! -e "$OUT/recovery.img" ];
1639 then
1640 echo "No recovery.img found. Run make recoveryimage first."
1641 return 1
1642 fi
1643 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1644 if [ -z "$PARTITION" ];
1645 then
1646 echo "Unable to determine recovery partition."
1647 return 1
1648 fi
1649 adb start-server
1650 adb root
1651 sleep 1
1652 adb wait-for-device
1653 adb remount
1654 adb wait-for-device
1655 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
1656 then
1657 adb push $OUT/recovery.img /cache/
1658 adb shell dd if=/cache/recovery.img of=$PARTITION
1659 echo "Installation complete."
1660 else
1661 echo "The connected device does not appear to be $CM_BUILD, run away!"
1662 fi
1663}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001664
Koushik Duttab55f13a2012-05-14 16:14:36 -07001665function makerecipe() {
1666 if [ -z "$1" ]
1667 then
1668 echo "No branch name provided."
1669 return 1
1670 fi
1671 cd android
1672 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1673 git commit -a -m "$1"
1674 cd ..
1675
1676 repo forall -c '
1677
1678 if [ "$REPO_REMOTE" == "github" ]
1679 then
1680 pwd
1681 cmremote
1682 git push cmremote HEAD:refs/heads/'$1'
1683 fi
1684 '
1685}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001686
1687function cmgerrit() {
1688 if [ $# -eq 0 ]; then
1689 $FUNCNAME help
1690 return 1
1691 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001692 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001693 local review=`git config --get remote.github.review`
1694 local project=`git config --get remote.github.projectname`
1695 local command=$1
1696 shift
1697 case $command in
1698 help)
1699 if [ $# -eq 0 ]; then
1700 cat <<EOF
1701Usage:
1702 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1703
1704Commands:
1705 fetch Just fetch the change as FETCH_HEAD
1706 help Show this help, or for a specific command
1707 pull Pull a change into current branch
1708 push Push HEAD or a local branch to Gerrit for a specific branch
1709
1710Any other Git commands that support refname would work as:
1711 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1712
1713See '$FUNCNAME help COMMAND' for more information on a specific command.
1714
1715Example:
1716 $FUNCNAME checkout -b topic 1234/5
1717works as:
1718 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1719 && git checkout -b topic FETCH_HEAD
1720will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1721Patch-set 1 will be fetched if omitted.
1722EOF
1723 return
1724 fi
1725 case $1 in
1726 __cmg_*) echo "For internal use only." ;;
1727 changes|for)
1728 if [ "$FUNCNAME" = "cmgerrit" ]; then
1729 echo "'$FUNCNAME $1' is deprecated."
1730 fi
1731 ;;
1732 help) $FUNCNAME help ;;
1733 fetch|pull) cat <<EOF
1734usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1735
1736works as:
1737 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1738 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1739
1740Example:
1741 $FUNCNAME $1 1234
1742will $1 patch-set 1 of change 1234
1743EOF
1744 ;;
1745 push) cat <<EOF
1746usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1747
1748works as:
1749 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1750 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1751
1752Example:
1753 $FUNCNAME push fix6789:gingerbread
1754will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1755HEAD will be pushed from local if omitted.
1756EOF
1757 ;;
1758 *)
1759 $FUNCNAME __cmg_err_not_supported $1 && return
1760 cat <<EOF
1761usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1762
1763works as:
1764 git fetch http://DOMAIN/p/PROJECT \\
1765 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1766 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1767EOF
1768 ;;
1769 esac
1770 ;;
1771 __cmg_get_ref)
1772 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1773 local change_id patchset_id hash
1774 case $1 in
1775 */*)
1776 change_id=${1%%/*}
1777 patchset_id=${1#*/}
1778 ;;
1779 *)
1780 change_id=$1
1781 patchset_id=1
1782 ;;
1783 esac
1784 hash=$(($change_id % 100))
1785 case $hash in
1786 [0-9]) hash="0$hash" ;;
1787 esac
1788 echo "refs/changes/$hash/$change_id/$patchset_id"
1789 ;;
1790 fetch|pull)
1791 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1792 $FUNCNAME __cmg_err_not_repo && return 1
1793 local change=$1
1794 shift
1795 git $command $@ http://$review/p/$project \
1796 $($FUNCNAME __cmg_get_ref $change) || return 1
1797 ;;
1798 push)
1799 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1800 $FUNCNAME __cmg_err_not_repo && return 1
1801 if [ -z "$user" ]; then
1802 echo >&2 "Gerrit username not found."
1803 return 1
1804 fi
1805 local local_branch remote_branch
1806 case $1 in
1807 *:*)
1808 local_branch=${1%:*}
1809 remote_branch=${1##*:}
1810 ;;
1811 *)
1812 local_branch=HEAD
1813 remote_branch=$1
1814 ;;
1815 esac
1816 shift
1817 git push $@ ssh://$user@$review:29418/$project \
1818 $local_branch:refs/for/$remote_branch || return 1
1819 ;;
1820 changes|for)
1821 if [ "$FUNCNAME" = "cmgerrit" ]; then
1822 echo >&2 "'$FUNCNAME $command' is deprecated."
1823 fi
1824 ;;
1825 __cmg_err_no_arg)
1826 if [ $# -lt 2 ]; then
1827 echo >&2 "'$FUNCNAME $command' missing argument."
1828 elif [ $2 -eq 0 ]; then
1829 if [ -n "$3" ]; then
1830 $FUNCNAME help $1
1831 else
1832 echo >&2 "'$FUNCNAME $1' missing argument."
1833 fi
1834 else
1835 return 1
1836 fi
1837 ;;
1838 __cmg_err_not_repo)
1839 if [ -z "$review" -o -z "$project" ]; then
1840 echo >&2 "Not currently in any reviewable repository."
1841 else
1842 return 1
1843 fi
1844 ;;
1845 __cmg_err_not_supported)
1846 $FUNCNAME __cmg_err_no_arg $command $# && return
1847 case $1 in
1848 #TODO: filter more git commands that don't use refname
1849 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1850 echo >&2 "'$FUNCNAME $1' is not supported."
1851 ;;
1852 *) return 1 ;;
1853 esac
1854 ;;
1855 #TODO: other special cases?
1856 *)
1857 $FUNCNAME __cmg_err_not_supported $command && return 1
1858 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1859 $FUNCNAME __cmg_err_not_repo && return 1
1860 local args="$@"
1861 local change pre_args refs_arg post_args
1862 case "$args" in
1863 *--\ *)
1864 pre_args=${args%%-- *}
1865 post_args="-- ${args#*-- }"
1866 ;;
1867 *) pre_args="$args" ;;
1868 esac
1869 args=($pre_args)
1870 pre_args=
1871 if [ ${#args[@]} -gt 0 ]; then
1872 change=${args[${#args[@]}-1]}
1873 fi
1874 if [ ${#args[@]} -gt 1 ]; then
1875 pre_args=${args[0]}
1876 for ((i=1; i<${#args[@]}-1; i++)); do
1877 pre_args="$pre_args ${args[$i]}"
1878 done
1879 fi
1880 while ((1)); do
1881 case $change in
1882 ""|--)
1883 $FUNCNAME help $command
1884 return 1
1885 ;;
1886 *@*)
1887 if [ -z "$refs_arg" ]; then
1888 refs_arg="@${change#*@}"
1889 change=${change%%@*}
1890 fi
1891 ;;
1892 *~*)
1893 if [ -z "$refs_arg" ]; then
1894 refs_arg="~${change#*~}"
1895 change=${change%%~*}
1896 fi
1897 ;;
1898 *^*)
1899 if [ -z "$refs_arg" ]; then
1900 refs_arg="^${change#*^}"
1901 change=${change%%^*}
1902 fi
1903 ;;
1904 *:*)
1905 if [ -z "$refs_arg" ]; then
1906 refs_arg=":${change#*:}"
1907 change=${change%%:*}
1908 fi
1909 ;;
1910 *) break ;;
1911 esac
1912 done
1913 $FUNCNAME fetch $change \
1914 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
1915 || return 1
1916 ;;
1917 esac
1918}
1919
1920function cmrebase() {
1921 local repo=$1
1922 local refs=$2
1923 local pwd="$(pwd)"
1924 local dir="$(gettop)/$repo"
1925
1926 if [ -z $repo ] || [ -z $refs ]; then
1927 echo "CyanogenMod Gerrit Rebase Usage: "
1928 echo " cmrebase <path to project> <patch IDs on Gerrit>"
1929 echo " The patch IDs appear on the Gerrit commands that are offered."
1930 echo " They consist on a series of numbers and slashes, after the text"
1931 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
1932 echo ""
1933 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
1934 echo ""
1935 return
1936 fi
1937
1938 if [ ! -d $dir ]; then
1939 echo "Directory $dir doesn't exist in tree."
1940 return
1941 fi
1942 cd $dir
1943 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
1944 echo "Starting branch..."
1945 repo start tmprebase .
1946 echo "Bringing it up to date..."
1947 repo sync .
1948 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001949 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001950 if [ "$?" != "0" ]; then
1951 echo "Error cherry-picking. Not uploading!"
1952 return
1953 fi
1954 echo "Uploading..."
1955 repo upload .
1956 echo "Cleaning up..."
1957 repo abandon tmprebase .
1958 cd $pwd
1959}
1960
1961function mka() {
1962 case `uname -s` in
1963 Darwin)
1964 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
1965 ;;
1966 *)
Arnav Gupta3b909942012-11-23 10:47:44 -07001967 schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001968 ;;
1969 esac
1970}
1971
1972function reposync() {
1973 case `uname -s` in
1974 Darwin)
1975 repo sync -j 4 "$@"
1976 ;;
1977 *)
Alan Orthef363cd2012-09-07 11:44:27 +03001978 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001979 ;;
1980 esac
1981}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02001982
1983function repodiff() {
1984 if [ -z "$*" ]; then
1985 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
1986 return
1987 fi
1988 diffopts=$* repo forall -c \
1989 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
1990}
1991
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05301992# Credit for color strip sed: http://goo.gl/BoIcm
1993function dopush()
1994{
1995 local func=$1
1996 shift
1997
1998 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
1999 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2000 echo "No device is online. Waiting for one..."
2001 echo "Please connect USB and/or enable USB debugging"
2002 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2003 sleep 1
2004 done
2005 echo "Device Found."
2006 fi
2007
Chirayu Desai6dadb572012-12-26 10:53:58 +05302008 if (adb shell cat /system/build.prop | grep -q "ro.cm.device=$CM_BUILD");
2009 then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302010 adb root &> /dev/null
2011 sleep 0.3
2012 adb wait-for-device &> /dev/null
2013 sleep 0.3
2014 adb remount &> /dev/null
2015
2016 $func $* | tee $OUT/.log
2017
2018 # Install: <file>
2019 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)
2020
2021 # Copy: <file>
2022 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)
2023
2024 for FILE in $LOC; do
2025 # Get target file name (i.e. system/bin/adb)
2026 TARGET=$(echo $FILE | sed "s#$OUT/##")
2027
2028 # Don't send files that are not in /system.
2029 if ! echo $TARGET | egrep '^system\/' > /dev/null ; then
2030 continue
2031 else
2032 case $TARGET in
2033 system/app/SystemUI.apk|system/framework/*)
2034 stop_n_start=true
2035 ;;
2036 *)
2037 stop_n_start=false
2038 ;;
2039 esac
2040 if $stop_n_start ; then adb shell stop ; fi
2041 echo "Pushing: $TARGET"
2042 adb push $FILE $TARGET
2043 if $stop_n_start ; then adb shell start ; fi
2044 fi
2045 done
2046 rm -f $OUT/.log
2047 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302048 else
2049 echo "The connected device does not appear to be $CM_BUILD, run away!"
2050 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302051}
2052
2053alias mmp='dopush mm'
2054alias mmmp='dopush mmm'
2055alias mkap='dopush mka'
2056alias cmkap='dopush cmka'
2057
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002058# 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 +00002059#
2060# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2061# For some reason, installing the JDK doesn't make it show up in the
2062# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002063function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002064 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002065 # we can reset it later, depending on the version of java the build
2066 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002067 #
2068 # If we don't do this, the JAVA_HOME value set by the first call to
2069 # build/envsetup.sh will persist forever.
2070 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2071 export JAVA_HOME=""
2072 fi
2073
Andy McFaddenbd960942010-06-24 12:52:51 -07002074 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002075 case `uname -s` in
2076 Darwin)
2077 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2078 ;;
2079 *)
2080 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2081 ;;
2082 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002083
2084 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2085 # we can change it on the next envsetup.sh, if required.
2086 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002087 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002088}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002089
Alex Rayf0d08eb2013-03-08 15:15:06 -08002090# Print colored exit condition
2091function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002092 "$@"
2093 local retval=$?
2094 if [ $retval -ne 0 ]
2095 then
2096 echo -e "\e[0;31mFAILURE\e[00m"
2097 else
2098 echo -e "\e[0;32mSUCCESS\e[00m"
2099 fi
2100 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002101}
2102
Ying Wanged21d4c2014-08-24 22:14:19 -07002103function get_make_command()
2104{
2105 echo command make
2106}
2107
Ed Heylcc6be0a2014-06-18 14:55:58 -07002108function make()
2109{
2110 local start_time=$(date +"%s")
Ying Wanged21d4c2014-08-24 22:14:19 -07002111 $(get_make_command) "$@"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002112 local ret=$?
2113 local end_time=$(date +"%s")
2114 local tdiff=$(($end_time-$start_time))
2115 local hours=$(($tdiff / 3600 ))
2116 local mins=$((($tdiff % 3600) / 60))
2117 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002118 local ncolors=$(tput colors 2>/dev/null)
2119 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2120 color_failed="\e[0;31m"
2121 color_success="\e[0;32m"
2122 color_reset="\e[00m"
2123 else
2124 color_failed=""
2125 color_success=""
2126 color_reset=""
2127 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002128 echo
2129 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002130 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002131 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002132 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002133 fi
2134 if [ $hours -gt 0 ] ; then
2135 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2136 elif [ $mins -gt 0 ] ; then
2137 printf "(%02g:%02g (mm:ss))" $mins $secs
2138 elif [ $secs -gt 0 ] ; then
2139 printf "(%s seconds)" $secs
2140 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002141 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002142 echo
2143 return $ret
2144}
2145
Raphael Moll70a86b02011-06-20 16:03:14 -07002146if [ "x$SHELL" != "x/bin/bash" ]; then
2147 case `ps -o command -p $$` in
2148 *bash*)
2149 ;;
2150 *)
2151 echo "WARNING: Only bash is supported, use of other shell would lead to erroneous results"
2152 ;;
2153 esac
2154fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002155
2156# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002157for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2158 `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 -08002159do
2160 echo "including $f"
2161 . $f
2162done
2163unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002164
2165addcompletions