blob: 3605a59ee76c5a98a4e32b8e96e1207e7254b0b6 [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -07005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
nebkatfb67a1e2012-12-28 10:40:45 +00007- cout: Changes directory to out.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07008- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08009- mm: Builds all of the modules in the current directory, but not their dependencies.
10- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000011 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080012- mma: Builds all of the modules in the current directory, and their dependencies.
Daniel Bateman22185ba2012-08-04 03:48:09 -050013- mmp: Builds all of the modules in the current directory and pushes them to the device.
14- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080015- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070016- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070017- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070018- jgrep: Greps on all local Java files.
19- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000020- mangrep: Greps on all local AndroidManifest.xml files.
21- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070022- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080023- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060024- cmremote: Add git remote for CM Gerrit Review
25- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
26- cmrebase: Rebase a Gerrit change and push it again
Steve Kondik873fa562012-09-17 11:33:18 -070027- aospremote: Add git remote for matching AOSP repository
Steve Kondik20c21d22013-10-27 13:34:36 -070028- cafremote: Add git remote for matching CodeAurora repository.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060029- mka: Builds using SCHED_BATCH on all processors
Chirayu Desaicf2bdb62012-09-28 11:56:02 +053030- mkap: Builds the module(s) using mka and pushes them to the device.
31- cmka: Cleans and builds using mka.
Matt Mower8dacaed2013-12-29 12:57:20 -060032- repolastsync: Prints date and time of last repo sync.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060033- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053034- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070035- installboot: Installs a boot.img to the connected device.
36- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070037
Dan Albert4ae5d4b2014-10-31 16:23:08 -070038Environemnt options:
39- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
40 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
41 build is leak-check clean.
42
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070043Look at the source to view more functions. The complete list is:
44EOF
45 T=$(gettop)
Jeff Brown46cbd202014-07-26 15:15:41 -070046 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
Anthony King0780f2f2015-04-30 23:16:10 +010047 echo "$i"
48 done | column
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070049}
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
Matt Mowerf8ff73e2015-06-09 19:35:53 -0500238 if [ -n "$ANDROID_CCACHE_DIR" ]; then
239 export CCACHE_DIR=$ANDROID_CCACHE_DIR
240 fi
241
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800242 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700243 # TODO: fix the path
244 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
245}
246
247function printconfig()
248{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800249 T=$(gettop)
250 if [ ! "$T" ]; then
251 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
252 return
253 fi
254 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700255}
256
257function set_stuff_for_environment()
258{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800259 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500260 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800261 setpaths
262 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263
Ben Chengaac3f812013-08-13 14:38:15 -0700264 # With this environment variable new GCC can apply colors to warnings/errors
265 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 -0700266 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267}
268
269function set_sequence_number()
270{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700271 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700272}
273
274function settitle()
275{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800276 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700277 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700278 local product=$TARGET_PRODUCT
279 local variant=$TARGET_BUILD_VARIANT
280 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800281 if [ -z "$PROMPT_COMMAND" ]; then
282 # No prompts
283 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
284 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
285 # Prompts exist, but no hardstatus
286 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700287 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800288 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500289 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800290 fi
291
292 if [ -z "$apps" ]; then
293 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
294 else
295 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
296 fi
297 export ANDROID_PROMPT_PREFIX
298
299 # Inject build data into hardstatus
300 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 -0800301 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700302}
303
Kyle Ladd031a0b62013-09-11 20:43:42 -0400304function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700305{
Kenny Root52aa81c2011-07-15 11:07:06 -0700306 # Keep us from trying to run in something that isn't bash.
307 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400308 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700309 fi
310
311 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200312 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400313 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700314 fi
315
Kyle Ladd031a0b62013-09-11 20:43:42 -0400316 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700317}
318
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700319function choosetype()
320{
321 echo "Build type choices are:"
322 echo " 1. release"
323 echo " 2. debug"
324 echo
325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700327 DEFAULT_NUM=1
328 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700329
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 export TARGET_BUILD_TYPE=
331 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700332 while [ -z $TARGET_BUILD_TYPE ]
333 do
334 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800335 if [ -z "$1" ] ; then
336 read ANSWER
337 else
338 echo $1
339 ANSWER=$1
340 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700341 case $ANSWER in
342 "")
343 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
344 ;;
345 1)
346 export TARGET_BUILD_TYPE=release
347 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800348 release)
349 export TARGET_BUILD_TYPE=release
350 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700351 2)
352 export TARGET_BUILD_TYPE=debug
353 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800354 debug)
355 export TARGET_BUILD_TYPE=debug
356 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357 *)
358 echo
359 echo "I didn't understand your response. Please try again."
360 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361 ;;
362 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800363 if [ -n "$1" ] ; then
364 break
365 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700366 done
367
368 set_stuff_for_environment
369}
370
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800371#
372# This function isn't really right: It chooses a TARGET_PRODUCT
373# based on the list of boards. Usually, that gets you something
374# that kinda works with a generic product, but really, you should
375# pick a product by name.
376#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700377function chooseproduct()
378{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700379 if [ "x$TARGET_PRODUCT" != x ] ; then
380 default_value=$TARGET_PRODUCT
381 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700382 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383 fi
384
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800385 export TARGET_PRODUCT=
386 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700387 while [ -z "$TARGET_PRODUCT" ]
388 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700389 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800390 if [ -z "$1" ] ; then
391 read ANSWER
392 else
393 echo $1
394 ANSWER=$1
395 fi
396
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700397 if [ -z "$ANSWER" ] ; then
398 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800399 else
400 if check_product $ANSWER
401 then
402 export TARGET_PRODUCT=$ANSWER
403 else
404 echo "** Not a valid product: $ANSWER"
405 fi
406 fi
407 if [ -n "$1" ] ; then
408 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700409 fi
410 done
411
412 set_stuff_for_environment
413}
414
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800415function choosevariant()
416{
417 echo "Variant choices are:"
418 local index=1
419 local v
420 for v in ${VARIANT_CHOICES[@]}
421 do
422 # The product name is the name of the directory containing
423 # the makefile we found, above.
424 echo " $index. $v"
425 index=$(($index+1))
426 done
427
428 local default_value=eng
429 local ANSWER
430
431 export TARGET_BUILD_VARIANT=
432 while [ -z "$TARGET_BUILD_VARIANT" ]
433 do
434 echo -n "Which would you like? [$default_value] "
435 if [ -z "$1" ] ; then
436 read ANSWER
437 else
438 echo $1
439 ANSWER=$1
440 fi
441
442 if [ -z "$ANSWER" ] ; then
443 export TARGET_BUILD_VARIANT=$default_value
444 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
445 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800446 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800447 fi
448 else
449 if check_variant $ANSWER
450 then
451 export TARGET_BUILD_VARIANT=$ANSWER
452 else
453 echo "** Not a valid variant: $ANSWER"
454 fi
455 fi
456 if [ -n "$1" ] ; then
457 break
458 fi
459 done
460}
461
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700462function choosecombo()
463{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700464 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465
466 echo
467 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700468 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700469
470 echo
471 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700472 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800473
474 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700475 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800476 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700477}
478
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800479# Clear this variable. It will be built up again when the vendorsetup.sh
480# files are included at the end of this file.
481unset LUNCH_MENU_CHOICES
482function add_lunch_combo()
483{
484 local new_combo=$1
485 local c
486 for c in ${LUNCH_MENU_CHOICES[@]} ; do
487 if [ "$new_combo" = "$c" ] ; then
488 return
489 fi
490 done
491 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
492}
493
494# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700495add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800496add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000497add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800498add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000499add_lunch_combo aosp_x86-eng
500add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800501
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700502function print_lunch_menu()
503{
504 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700505 echo
506 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000507 if [ "$(uname)" = "Darwin" ] ; then
508 echo " (ohai, koush!)"
509 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700510 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000511 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
512 echo "Breakfast menu... pick a combo:"
513 else
514 echo "Lunch menu... pick a combo:"
515 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800516
517 local i=1
518 local choice
519 for choice in ${LUNCH_MENU_CHOICES[@]}
520 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100521 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800522 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100523 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800524
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000525 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
526 echo "... and don't forget the bacon!"
527 fi
528
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700529 echo
530}
531
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000532function brunch()
533{
534 breakfast $*
535 if [ $? -eq 0 ]; then
536 mka bacon
537 else
538 echo "No such item in brunch menu. Try 'breakfast'"
539 return 1
540 fi
541 return $?
542}
543
544function breakfast()
545{
546 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200547 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000548 CM_DEVICES_ONLY="true"
549 unset LUNCH_MENU_CHOICES
550 add_lunch_combo full-eng
551 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
552 do
553 echo "including $f"
554 . $f
555 done
556 unset f
557
558 if [ $# -eq 0 ]; then
559 # No arguments, so let's have the full menu
560 lunch
561 else
562 echo "z$target" | grep -q "-"
563 if [ $? -eq 0 ]; then
564 # A buildtype was specified, assume a full device name
565 lunch $target
566 else
567 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200568 if [ -z "$variant" ]; then
569 variant="userdebug"
570 fi
571 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000572 fi
573 fi
574 return $?
575}
576
577alias bib=breakfast
578
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700579function lunch()
580{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 local answer
Anthony King850627c2015-04-30 22:57:08 +0100582 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800583
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700584 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800585 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586 else
587 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700588 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 fi
591
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800592 local selection=
593
594 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700595 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700596 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800597 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
598 then
599 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
600 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800601 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800602 fi
603 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
604 then
605 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700606 fi
607
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800608 if [ -z "$selection" ]
609 then
610 echo
611 echo "Invalid lunch combo: $answer"
612 return 1
613 fi
614
Joe Onoratoda12daf2010-06-09 18:18:31 -0700615 export TARGET_BUILD_APPS=
616
Jeff Browne33ba4c2011-07-11 22:11:46 -0700617 local product=$(echo -n $selection | sed -e "s/-.*$//")
618 check_product $product
619 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800620 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800621 # if we can't find a product, try to grab it off the CM github
622 T=$(gettop)
623 pushd $T > /dev/null
624 build/tools/roomservice.py $product
625 popd > /dev/null
626 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000627 else
628 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800629 fi
630 if [ $? -ne 0 ]
631 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700632 echo
633 echo "** Don't have a product spec for: '$product'"
634 echo "** Do you have the right repo manifest?"
635 product=
636 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800637
Jeff Browne33ba4c2011-07-11 22:11:46 -0700638 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
639 check_variant $variant
640 if [ $? -ne 0 ]
641 then
642 echo
643 echo "** Invalid variant: '$variant'"
644 echo "** Must be one of ${VARIANT_CHOICES[@]}"
645 variant=
646 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800647
Jeff Browne33ba4c2011-07-11 22:11:46 -0700648 if [ -z "$product" -o -z "$variant" ]
649 then
650 echo
651 return 1
652 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800653
Jeff Browne33ba4c2011-07-11 22:11:46 -0700654 export TARGET_PRODUCT=$product
655 export TARGET_BUILD_VARIANT=$variant
656 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700657
658 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659
Chirayu Desaib89b3242013-06-30 10:04:25 +0530660 fixup_common_out_dir
661
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700662 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800663 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700664}
665
Jeff Davidson513d7a42010-08-02 10:00:44 -0700666# Tab completion for lunch.
667function _lunch()
668{
669 local cur prev opts
670 COMPREPLY=()
671 cur="${COMP_WORDS[COMP_CWORD]}"
672 prev="${COMP_WORDS[COMP_CWORD-1]}"
673
674 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
675 return 0
676}
Emilio López9ad6eea2013-11-03 13:02:13 -0300677complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700678
Joe Onoratoda12daf2010-06-09 18:18:31 -0700679# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700680# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700681function tapas()
682{
Ying Wangb541ab62014-05-29 17:57:40 -0700683 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 -0700684 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700685 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
686 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 -0700687
Ying Wang67f02922012-08-22 10:25:20 -0700688 if [ $(echo $arch | wc -w) -gt 1 ]; then
689 echo "tapas: Error: Multiple build archs supplied: $arch"
690 return
691 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700692 if [ $(echo $variant | wc -w) -gt 1 ]; then
693 echo "tapas: Error: Multiple build variants supplied: $variant"
694 return
695 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700696 if [ $(echo $density | wc -w) -gt 1 ]; then
697 echo "tapas: Error: Multiple densities supplied: $density"
698 return
699 fi
Ying Wang67f02922012-08-22 10:25:20 -0700700
701 local product=full
702 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700703 x86) product=full_x86;;
704 mips) product=full_mips;;
705 armv5) product=generic_armv5;;
706 arm64) product=aosp_arm64;;
707 x86_64) product=aosp_x86_64;;
708 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700709 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700710 if [ -z "$variant" ]; then
711 variant=eng
712 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700713 if [ -z "$apps" ]; then
714 apps=all
715 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600716 if [ -z "$density" ]; then
717 density=alldpi
718 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700719
Ying Wang67f02922012-08-22 10:25:20 -0700720 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700721 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700722 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700723 export TARGET_BUILD_TYPE=release
724 export TARGET_BUILD_APPS=$apps
725
726 set_stuff_for_environment
727 printconfig
728}
729
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100730function eat()
731{
732 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530733 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100734 ZIPFILE=cm-$MODVERSION.zip
735 ZIPPATH=$OUT/$ZIPFILE
736 if [ ! -f $ZIPPATH ] ; then
737 echo "Nothing to eat"
738 return 1
739 fi
740 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
741 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
742 echo "No device is online. Waiting for one..."
743 echo "Please connect USB and/or enable USB debugging"
744 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
745 sleep 1
746 done
747 echo "Device Found.."
748 fi
Steve Kondikec4627c2015-07-10 02:31:24 -0700749 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Chirayu Desai6dadb572012-12-26 10:53:58 +0530750 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100751 # if adbd isn't root we can't write to /cache/recovery/
752 adb root
753 sleep 1
754 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700755 cat << EOF > /tmp/command
756--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100757EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700758 if adb push /tmp/command /cache/recovery/ ; then
759 echo "Rebooting into recovery for sideload installation"
760 adb reboot recovery
761 adb wait-for-sideload
762 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100763 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700764 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100765 else
766 echo "Nothing to eat"
767 return 1
768 fi
769 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530770 else
771 echo "The connected device does not appear to be $CM_BUILD, run away!"
772 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100773}
774
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000775function omnom
776{
777 brunch $*
778 eat
779}
780
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700781function gettop
782{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800783 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700784 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700785 # The following circumlocution ensures we remove symlinks from TOP.
786 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700787 else
788 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800789 # The following circumlocution (repeated below as well) ensures
790 # that we record the true directory name and not one that is
791 # faked up with symlink names.
792 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700793 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800794 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700795 T=
796 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800797 \cd ..
synergyb112a402013-07-05 19:47:47 -0700798 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799 done
Ying Wang9cd17642012-12-13 10:52:07 -0800800 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700801 if [ -f "$T/$TOPFILE" ]; then
802 echo $T
803 fi
804 fi
805 fi
806}
807
Andrew Hsieh906cb782013-09-10 17:37:14 +0800808# Return driver for "make", if any (eg. static analyzer)
809function getdriver()
810{
811 local T="$1"
812 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
813 if [ -n "$WITH_STATIC_ANALYZER" ]; then
814 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800815$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
816--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800817--status-bugs \
818--top=$T"
819 fi
820}
821
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822function m()
823{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800824 local T=$(gettop)
825 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700826 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800827 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700828 else
829 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700830 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700831 fi
832}
833
834function findmakefile()
835{
836 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800837 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700838 T=
839 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700840 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700841 if [ -f "$T/Android.mk" ]; then
842 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800843 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700844 return
845 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800846 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700847 done
Ying Wang9cd17642012-12-13 10:52:07 -0800848 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700849}
850
851function mm()
852{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800853 local T=$(gettop)
854 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855 # If we're sitting in the root of the build tree, just do a
856 # normal make.
857 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800858 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700859 else
860 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800861 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700862 local MODULES=
863 local GET_INSTALL_PATH=
864 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700865 # Remove the path to top as the makefilepath needs to be relative
866 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700867 if [ ! "$T" ]; then
868 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700869 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700870 elif [ ! "$M" ]; then
871 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700872 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700873 else
Ying Wanga7deb082013-08-16 13:24:47 -0700874 for ARG in $@; do
875 case $ARG in
876 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
877 esac
878 done
879 if [ -n "$GET_INSTALL_PATH" ]; then
880 MODULES=
881 ARGS=GET-INSTALL-PATH
882 else
883 MODULES=all_modules
884 ARGS=$@
885 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700886 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 -0700887 fi
888 fi
889}
890
891function mmm()
892{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800893 local T=$(gettop)
894 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700895 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800896 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800897 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800898 local ARGS=
899 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700900 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800901 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
902 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
903 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800904 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
905 if [ "$MODULES" = "" ]; then
906 MODULES=all_modules
907 fi
908 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700909 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700910 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
911 local TO_CHOP=`expr $TO_CHOP + 1`
912 local START=`PWD= /bin/pwd`
913 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700914 if [ "$MFILE" = "" ] ; then
915 MFILE=$DIR/Android.mk
916 else
917 MFILE=$MFILE/$DIR/Android.mk
918 fi
919 MAKEFILE="$MAKEFILE $MFILE"
920 else
Ying Wanga7deb082013-08-16 13:24:47 -0700921 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100922 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700923 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
924 *) echo "No Android.mk in $DIR."; return 1;;
925 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700926 fi
927 done
Ying Wanga7deb082013-08-16 13:24:47 -0700928 if [ -n "$GET_INSTALL_PATH" ]; then
929 ARGS=$GET_INSTALL_PATH
930 MODULES=
931 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800932 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 -0700933 else
934 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700935 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700936 fi
937}
938
Ying Wangb607f7b2013-02-08 18:01:04 -0800939function mma()
940{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800941 local T=$(gettop)
942 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800943 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800944 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800945 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800946 if [ ! "$T" ]; then
947 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700948 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800949 fi
950 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800951 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800952 fi
953}
954
955function mmma()
956{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800957 local T=$(gettop)
958 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800959 if [ "$T" ]; then
960 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
961 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
962 local MY_PWD=`PWD= /bin/pwd`
963 if [ "$MY_PWD" = "$T" ]; then
964 MY_PWD=
965 else
966 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
967 fi
968 local DIR=
969 local MODULE_PATHS=
970 local ARGS=
971 for DIR in $DIRS ; do
972 if [ -d $DIR ]; then
973 if [ "$MY_PWD" = "" ]; then
974 MODULE_PATHS="$MODULE_PATHS $DIR"
975 else
976 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
977 fi
978 else
979 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100980 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800981 *) echo "Couldn't find directory $DIR"; return 1;;
982 esac
983 fi
984 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800985 $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 -0800986 else
987 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700988 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800989 fi
990}
991
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700992function croot()
993{
994 T=$(gettop)
995 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800996 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700997 else
998 echo "Couldn't locate the top of the tree. Try setting TOP."
999 fi
1000}
1001
nebkatfb67a1e2012-12-28 10:40:45 +00001002function cout()
1003{
1004 if [ "$OUT" ]; then
1005 cd $OUT
1006 else
1007 echo "Couldn't locate out directory. Try setting OUT."
1008 fi
1009}
1010
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001011function cproj()
1012{
1013 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001014 local HERE=$PWD
1015 T=
1016 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1017 T=$PWD
1018 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001019 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 return
1021 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001022 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001023 done
Ying Wang9cd17642012-12-13 10:52:07 -08001024 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001025 echo "can't find Android.mk"
1026}
1027
Daniel Sandler47e0a882013-07-30 13:23:52 -04001028# simplified version of ps; output in the form
1029# <pid> <procname>
1030function qpid() {
1031 local prepend=''
1032 local append=''
1033 if [ "$1" = "--exact" ]; then
1034 prepend=' '
1035 append='$'
1036 shift
1037 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1038 echo "usage: qpid [[--exact] <process name|pid>"
1039 return 255
1040 fi
1041
1042 local EXE="$1"
1043 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001044 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001045 else
1046 adb shell ps \
1047 | tr -d '\r' \
1048 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1049 fi
1050}
1051
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001052function pid()
1053{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001054 local prepend=''
1055 local append=''
1056 if [ "$1" = "--exact" ]; then
1057 prepend=' '
1058 append='$'
1059 shift
1060 fi
1061 local EXE="$1"
1062 if [ "$EXE" ] ; then
1063 local PID=`adb shell ps \
1064 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001065 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001066 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1067 echo "$PID"
1068 else
1069 echo "usage: pid [--exact] <process name>"
1070 return 255
1071 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001072}
1073
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001074# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001075# that has the core-file-size limit set correctly
1076#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001077# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001078# if its core-file-size limit is not set already.
1079# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1080
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001081function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001082{
1083 echo "Getting root...";
1084 adb root;
1085 adb wait-for-device;
1086
1087 echo "Remounting root parition read-write...";
1088 adb shell mount -w -o remount -t rootfs rootfs;
1089 sleep 1;
1090 adb wait-for-device;
1091 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001092 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001093 adb shell chmod 0777 /cores;
1094
1095 echo "Granting SELinux permission to dump in /cores...";
1096 adb shell restorecon -R /cores;
1097
1098 echo "Set core pattern.";
1099 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1100
1101 echo "Done."
1102}
1103
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001104# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001105# $1 = PID of process (e.g., $(pid mediaserver))
1106#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001107# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001108# dump to actually be generated.
1109
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001110function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001111{
1112 local PID=$1;
1113 if [ -z "$PID" ]; then
1114 printf "Expecting a PID!\n";
1115 return;
1116 fi;
1117 echo "Setting core limit for $PID to infinite...";
1118 adb shell prlimit $PID 4 -1 -1
1119}
1120
1121# core - send SIGV and pull the core for process
1122# $1 = PID of process (e.g., $(pid mediaserver))
1123#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001124# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001125# enabled globally.
1126
1127function core()
1128{
1129 local PID=$1;
1130
1131 if [ -z "$PID" ]; then
1132 printf "Expecting a PID!\n";
1133 return;
1134 fi;
1135
1136 local CORENAME=core.$PID;
1137 local COREPATH=/cores/$CORENAME;
1138 local SIG=SEGV;
1139
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001140 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001141
1142 local done=0;
1143 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1144 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1145 adb shell kill -$SIG $PID;
1146 sleep 1;
1147 done;
1148
1149 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1150 echo "Done: core is under $COREPATH on device.";
1151}
1152
Christopher Tate744ee802009-11-12 15:33:08 -08001153# systemstack - dump the current stack trace of all threads in the system process
1154# to the usual ANR traces file
1155function systemstack()
1156{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001157 stacks system_server
1158}
1159
1160function stacks()
1161{
1162 if [[ $1 =~ ^[0-9]+$ ]] ; then
1163 local PID="$1"
1164 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001165 local PIDLIST="$(pid $1)"
1166 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1167 local PID="$PIDLIST"
1168 elif [ "$PIDLIST" ] ; then
1169 echo "more than one process: $1"
1170 else
1171 echo "no such process: $1"
1172 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001173 else
1174 echo "usage: stacks [pid|process name]"
1175 fi
1176
1177 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001178 # Determine whether the process is native
1179 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1180 # Dump stacks of Dalvik process
1181 local TRACES=/data/anr/traces.txt
1182 local ORIG=/data/anr/traces.orig
1183 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001184
Jeff Brownb12c2e52013-08-19 15:14:16 -07001185 # Keep original traces to avoid clobbering
1186 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001187
Jeff Brownb12c2e52013-08-19 15:14:16 -07001188 # Make sure we have a usable file
1189 adb shell touch $TRACES
1190 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001191
Jeff Brownb12c2e52013-08-19 15:14:16 -07001192 # Dump stacks and wait for dump to finish
1193 adb shell kill -3 $PID
1194 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001195
Jeff Brownb12c2e52013-08-19 15:14:16 -07001196 # Restore original stacks, and show current output
1197 adb shell mv $TRACES $TMP
1198 adb shell mv $ORIG $TRACES
1199 adb shell cat $TMP
1200 else
1201 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001202 local USE64BIT="$(is64bit $PID)"
1203 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001204 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001205 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001206}
1207
Michael Wrightaeed7212014-06-19 19:58:12 -07001208# Read the ELF header from /proc/$PID/exe to determine if the process is
1209# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001210function is64bit()
1211{
1212 local PID="$1"
1213 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001214 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001215 echo "64"
1216 else
1217 echo ""
1218 fi
1219 else
1220 echo ""
1221 fi
1222}
1223
Clark Scheff75b36a42014-12-23 13:30:51 -08001224function dddclient()
1225{
1226 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1227 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1228 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1229 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1230 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1231 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1232 local ARCH=$(get_build_var TARGET_ARCH)
1233 local GDB
1234 case "$ARCH" in
1235 arm) GDB=arm-linux-androideabi-gdb;;
1236 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1237 mips|mips64) GDB=mips64el-linux-android-gdb;;
1238 x86) GDB=x86_64-linux-android-gdb;;
1239 x86_64) GDB=x86_64-linux-android-gdb;;
1240 *) echo "Unknown arch $ARCH"; return 1;;
1241 esac
1242
1243 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1244 local EXE="$1"
1245 if [ "$EXE" ] ; then
1246 EXE=$1
1247 if [[ $EXE =~ ^[^/].* ]] ; then
1248 EXE="system/bin/"$EXE
1249 fi
1250 else
1251 EXE="app_process"
1252 fi
1253
1254 local PORT="$2"
1255 if [ "$PORT" ] ; then
1256 PORT=$2
1257 else
1258 PORT=":5039"
1259 fi
1260
1261 local PID="$3"
1262 if [ "$PID" ] ; then
1263 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1264 PID=`pid $3`
1265 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1266 # that likely didn't work because of returning multiple processes
1267 # try again, filtering by root processes (don't contain colon)
1268 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1269 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1270 then
1271 echo "Couldn't resolve '$3' to single PID"
1272 return 1
1273 else
1274 echo ""
1275 echo "WARNING: multiple processes matching '$3' observed, using root process"
1276 echo ""
1277 fi
1278 fi
1279 fi
1280 adb forward "tcp$PORT" "tcp$PORT"
1281 local USE64BIT="$(is64bit $PID)"
1282 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1283 sleep 2
1284 else
1285 echo ""
1286 echo "If you haven't done so already, do this first on the device:"
1287 echo " gdbserver $PORT /system/bin/$EXE"
1288 echo " or"
1289 echo " gdbserver $PORT --attach <PID>"
1290 echo ""
1291 fi
1292
1293 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1294 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1295
1296 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1297 echo >>"$OUT_ROOT/gdbclient.cmds" "set solib-search-path $OUT_SO_SYMBOLS:$OUT_SO_SYMBOLS/hw:$OUT_SO_SYMBOLS/ssl/engines:$OUT_SO_SYMBOLS/drm:$OUT_SO_SYMBOLS/egl:$OUT_SO_SYMBOLS/soundfx:$OUT_VENDOR_SO_SYMBOLS:$OUT_VENDOR_SO_SYMBOLS/hw:$OUT_VENDOR_SO_SYMBOLS/egl"
1298 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1299 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1300 # Enable special debugging for ART processes.
1301 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1302 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1303 fi
1304 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1305
1306 local WHICH_GDB=
1307 # 64-bit exe found
1308 if [ "$USE64BIT" != "" ] ; then
1309 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1310 # 32-bit exe / 32-bit platform
1311 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1312 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1313 # 32-bit exe / 64-bit platform
1314 else
1315 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1316 fi
1317
1318 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1319 else
1320 echo "Unable to determine build system output dir."
1321 fi
1322}
1323
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001324case `uname -s` in
1325 Darwin)
1326 function sgrep()
1327 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001328 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 -07001329 }
1330
1331 ;;
1332 *)
1333 function sgrep()
1334 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001335 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 -07001336 }
1337 ;;
1338esac
1339
Raghu Gandham8da43102012-07-25 19:57:22 -07001340function gettargetarch
1341{
1342 get_build_var TARGET_ARCH
1343}
1344
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001345function ggrep()
1346{
1347 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1348}
1349
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001350function jgrep()
1351{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001352 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 -07001353}
1354
1355function cgrep()
1356{
Dan Albert01961192014-11-22 10:16:01 -08001357 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 -07001358}
1359
1360function resgrep()
1361{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001362 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 -07001363}
1364
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001365function mangrep()
1366{
1367 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1368}
1369
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001370function sepgrep()
1371{
1372 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 "$@"
1373}
1374
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001375function rcgrep()
1376{
1377 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1378}
1379
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001380case `uname -s` in
1381 Darwin)
1382 function mgrep()
1383 {
Ying Wang324c2b22012-08-17 15:03:20 -07001384 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 -07001385 }
1386
1387 function treegrep()
1388 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001389 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 -07001390 }
1391
1392 ;;
1393 *)
1394 function mgrep()
1395 {
Ying Wang324c2b22012-08-17 15:03:20 -07001396 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 -07001397 }
1398
1399 function treegrep()
1400 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001401 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 -07001402 }
1403
1404 ;;
1405esac
1406
1407function getprebuilt
1408{
1409 get_abs_build_var ANDROID_PREBUILTS
1410}
1411
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001412function tracedmdump()
1413{
1414 T=$(gettop)
1415 if [ ! "$T" ]; then
1416 echo "Couldn't locate the top of the tree. Try setting TOP."
1417 return
1418 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001419 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001420 local arch=$(gettargetarch)
1421 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001422
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001423 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001424 if [ ! "$TRACE" ] ; then
1425 echo "usage: tracedmdump tracename"
1426 return
1427 fi
1428
Jack Veenstra60116fc2009-04-09 18:12:34 -07001429 if [ ! -r "$KERNEL" ] ; then
1430 echo "Error: cannot find kernel: '$KERNEL'"
1431 return
1432 fi
1433
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001434 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001435 if [ "$BASETRACE" = "$TRACE" ] ; then
1436 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1437 fi
1438
1439 echo "post-processing traces..."
1440 rm -f $TRACE/qtrace.dexlist
1441 post_trace $TRACE
1442 if [ $? -ne 0 ]; then
1443 echo "***"
1444 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1445 echo "***"
1446 return
1447 fi
1448 echo "generating dexlist output..."
1449 /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
1450 echo "generating dmtrace data..."
1451 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1452 echo "generating html file..."
1453 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1454 echo "done, see $TRACE/dmtrace.html for details"
1455 echo "or run:"
1456 echo " traceview $TRACE/dmtrace"
1457}
1458
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001459# communicate with a running device or emulator, set up necessary state,
1460# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001461function runhat()
1462{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001463 # process standard adb options
1464 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001465 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001466 adbTarget=$1
1467 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001468 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001469 adbTarget="$1 $2"
1470 shift 2
1471 fi
1472 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001473 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001474
1475 # runhat options
1476 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001477
1478 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001479 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001480 return
1481 fi
1482
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001483 # confirm hat is available
1484 if [ -z $(which hat) ]; then
1485 echo "hat is not available in this configuration."
1486 return
1487 fi
1488
Andy McFaddenb6289852010-07-12 08:00:19 -07001489 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001490 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001491 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001492 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001493 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001494 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001495 echo -n "> "
1496 read
1497
The Android Open Source Project88b60792009-03-03 19:28:42 -08001498 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001499
The Android Open Source Project88b60792009-03-03 19:28:42 -08001500 echo "Retrieving file $devFile..."
1501 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001502
The Android Open Source Project88b60792009-03-03 19:28:42 -08001503 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001504
The Android Open Source Project88b60792009-03-03 19:28:42 -08001505 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001506 echo "View the output by pointing your browser at http://localhost:7000/"
1507 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001508 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001509}
1510
1511function getbugreports()
1512{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001513 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001514
1515 if [ ! "$reports" ]; then
1516 echo "Could not locate any bugreports."
1517 return
1518 fi
1519
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001520 local report
1521 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001522 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001523 echo "/sdcard/bugreports/${report}"
1524 adb pull /sdcard/bugreports/${report} ${report}
1525 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001526 done
1527}
1528
Victoria Lease1b296b42012-08-21 15:44:06 -07001529function getsdcardpath()
1530{
1531 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1532}
1533
1534function getscreenshotpath()
1535{
1536 echo "$(getsdcardpath)/Pictures/Screenshots"
1537}
1538
1539function getlastscreenshot()
1540{
1541 local screenshot_path=$(getscreenshotpath)
1542 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1543 if [ "$screenshot" = "" ]; then
1544 echo "No screenshots found."
1545 return
1546 fi
1547 echo "${screenshot}"
1548 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1549}
1550
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001551function startviewserver()
1552{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001553 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001554 if [ $# -gt 0 ]; then
1555 port=$1
1556 fi
1557 adb shell service call window 1 i32 $port
1558}
1559
1560function stopviewserver()
1561{
1562 adb shell service call window 2
1563}
1564
1565function isviewserverstarted()
1566{
1567 adb shell service call window 3
1568}
1569
Romain Guyb84049a2010-10-04 16:56:11 -07001570function key_home()
1571{
1572 adb shell input keyevent 3
1573}
1574
1575function key_back()
1576{
1577 adb shell input keyevent 4
1578}
1579
1580function key_menu()
1581{
1582 adb shell input keyevent 82
1583}
1584
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001585function smoketest()
1586{
1587 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1588 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1589 return
1590 fi
1591 T=$(gettop)
1592 if [ ! "$T" ]; then
1593 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1594 return
1595 fi
1596
Ying Wang9cd17642012-12-13 10:52:07 -08001597 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001598 adb uninstall com.android.smoketest > /dev/null &&
1599 adb uninstall com.android.smoketest.tests > /dev/null &&
1600 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1601 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1602 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1603}
1604
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001605# simple shortcut to the runtest command
1606function runtest()
1607{
1608 T=$(gettop)
1609 if [ ! "$T" ]; then
1610 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1611 return
1612 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001613 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001614}
1615
The Android Open Source Project88b60792009-03-03 19:28:42 -08001616function godir () {
1617 if [[ -z "$1" ]]; then
1618 echo "Usage: godir <regex>"
1619 return
1620 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001621 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001622 if [[ ! -f $T/filelist ]]; then
1623 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001624 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001625 echo " Done"
1626 echo ""
1627 fi
1628 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001629 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001630 if [[ ${#lines[@]} = 0 ]]; then
1631 echo "Not found"
1632 return
1633 fi
1634 local pathname
1635 local choice
1636 if [[ ${#lines[@]} > 1 ]]; then
1637 while [[ -z "$pathname" ]]; do
1638 local index=1
1639 local line
1640 for line in ${lines[@]}; do
1641 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001642 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001643 done
1644 echo
1645 echo -n "Select one: "
1646 unset choice
1647 read choice
1648 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1649 echo "Invalid choice"
1650 continue
1651 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001652 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001653 done
1654 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001655 pathname=${lines[0]}
1656 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001657 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001658}
1659
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001660function cmremote()
1661{
1662 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301663 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001664 if [ -z "$GERRIT_REMOTE" ]
1665 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301666 echo Unable to set up the git remote, are you under a git repo?
1667 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001668 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301669 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001670 if [ -z "$CMUSER" ]
1671 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001672 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001673 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001674 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001675 fi
1676 echo You can now push to "cmremote".
1677}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001678
Steve Kondik873fa562012-09-17 11:33:18 -07001679function aospremote()
1680{
1681 git remote rm aosp 2> /dev/null
1682 if [ ! -d .git ]
1683 then
1684 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1685 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001686 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001687 if (echo $PROJECT | grep -qv "^device")
1688 then
1689 PFX="platform/"
1690 fi
1691 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1692 echo "Remote 'aosp' created"
1693}
Steve Kondik873fa562012-09-17 11:33:18 -07001694
Steve Kondik20c21d22013-10-27 13:34:36 -07001695function cafremote()
1696{
1697 git remote rm caf 2> /dev/null
1698 if [ ! -d .git ]
1699 then
1700 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1701 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001702 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001703 if (echo $PROJECT | grep -qv "^device")
1704 then
1705 PFX="platform/"
1706 fi
1707 git remote add caf git://codeaurora.org/$PFX$PROJECT
1708 echo "Remote 'caf' created"
1709}
Steve Kondik20c21d22013-10-27 13:34:36 -07001710
Steve Kondikf00e7d92012-09-23 23:46:55 -07001711function installboot()
1712{
1713 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1714 then
1715 echo "No recovery.fstab found. Build recovery first."
1716 return 1
1717 fi
1718 if [ ! -e "$OUT/boot.img" ];
1719 then
1720 echo "No boot.img found. Run make bootimage first."
1721 return 1
1722 fi
1723 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1724 if [ -z "$PARTITION" ];
1725 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001726 # Try for RECOVERY_FSTAB_VERSION = 2
1727 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1728 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1729 if [ -z "$PARTITION" ];
1730 then
1731 echo "Unable to determine boot partition."
1732 return 1
1733 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001734 fi
1735 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001736 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001737 adb root
1738 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001739 adb wait-for-online shell mount /system 2>&1 > /dev/null
1740 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001741 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondikf00e7d92012-09-23 23:46:55 -07001742 then
1743 adb push $OUT/boot.img /cache/
1744 for i in $OUT/system/lib/modules/*;
1745 do
1746 adb push $i /system/lib/modules/
1747 done
1748 adb shell dd if=/cache/boot.img of=$PARTITION
1749 adb shell chmod 644 /system/lib/modules/*
1750 echo "Installation complete."
1751 else
1752 echo "The connected device does not appear to be $CM_BUILD, run away!"
1753 fi
1754}
1755
Steve Kondik83c03d52012-10-24 16:40:42 -07001756function installrecovery()
1757{
1758 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1759 then
1760 echo "No recovery.fstab found. Build recovery first."
1761 return 1
1762 fi
1763 if [ ! -e "$OUT/recovery.img" ];
1764 then
1765 echo "No recovery.img found. Run make recoveryimage first."
1766 return 1
1767 fi
1768 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1769 if [ -z "$PARTITION" ];
1770 then
Steve Kondik75f10762013-08-09 21:03:42 -07001771 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001772 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1773 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001774 if [ -z "$PARTITION" ];
1775 then
1776 echo "Unable to determine recovery partition."
1777 return 1
1778 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001779 fi
1780 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001781 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001782 adb root
1783 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001784 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1785 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001786 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondik83c03d52012-10-24 16:40:42 -07001787 then
1788 adb push $OUT/recovery.img /cache/
1789 adb shell dd if=/cache/recovery.img of=$PARTITION
1790 echo "Installation complete."
1791 else
1792 echo "The connected device does not appear to be $CM_BUILD, run away!"
1793 fi
1794}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001795
Koushik Duttab55f13a2012-05-14 16:14:36 -07001796function makerecipe() {
1797 if [ -z "$1" ]
1798 then
1799 echo "No branch name provided."
1800 return 1
1801 fi
1802 cd android
1803 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1804 git commit -a -m "$1"
1805 cd ..
1806
1807 repo forall -c '
1808
1809 if [ "$REPO_REMOTE" == "github" ]
1810 then
1811 pwd
1812 cmremote
1813 git push cmremote HEAD:refs/heads/'$1'
1814 fi
1815 '
1816}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001817
1818function cmgerrit() {
1819 if [ $# -eq 0 ]; then
1820 $FUNCNAME help
1821 return 1
1822 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001823 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001824 local review=`git config --get remote.github.review`
1825 local project=`git config --get remote.github.projectname`
1826 local command=$1
1827 shift
1828 case $command in
1829 help)
1830 if [ $# -eq 0 ]; then
1831 cat <<EOF
1832Usage:
1833 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1834
1835Commands:
1836 fetch Just fetch the change as FETCH_HEAD
1837 help Show this help, or for a specific command
1838 pull Pull a change into current branch
1839 push Push HEAD or a local branch to Gerrit for a specific branch
1840
1841Any other Git commands that support refname would work as:
1842 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1843
1844See '$FUNCNAME help COMMAND' for more information on a specific command.
1845
1846Example:
1847 $FUNCNAME checkout -b topic 1234/5
1848works as:
1849 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1850 && git checkout -b topic FETCH_HEAD
1851will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1852Patch-set 1 will be fetched if omitted.
1853EOF
1854 return
1855 fi
1856 case $1 in
1857 __cmg_*) echo "For internal use only." ;;
1858 changes|for)
1859 if [ "$FUNCNAME" = "cmgerrit" ]; then
1860 echo "'$FUNCNAME $1' is deprecated."
1861 fi
1862 ;;
1863 help) $FUNCNAME help ;;
1864 fetch|pull) cat <<EOF
1865usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1866
1867works as:
1868 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1869 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1870
1871Example:
1872 $FUNCNAME $1 1234
1873will $1 patch-set 1 of change 1234
1874EOF
1875 ;;
1876 push) cat <<EOF
1877usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1878
1879works as:
1880 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1881 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1882
1883Example:
1884 $FUNCNAME push fix6789:gingerbread
1885will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1886HEAD will be pushed from local if omitted.
1887EOF
1888 ;;
1889 *)
1890 $FUNCNAME __cmg_err_not_supported $1 && return
1891 cat <<EOF
1892usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1893
1894works as:
1895 git fetch http://DOMAIN/p/PROJECT \\
1896 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1897 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1898EOF
1899 ;;
1900 esac
1901 ;;
1902 __cmg_get_ref)
1903 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1904 local change_id patchset_id hash
1905 case $1 in
1906 */*)
1907 change_id=${1%%/*}
1908 patchset_id=${1#*/}
1909 ;;
1910 *)
1911 change_id=$1
1912 patchset_id=1
1913 ;;
1914 esac
1915 hash=$(($change_id % 100))
1916 case $hash in
1917 [0-9]) hash="0$hash" ;;
1918 esac
1919 echo "refs/changes/$hash/$change_id/$patchset_id"
1920 ;;
1921 fetch|pull)
1922 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1923 $FUNCNAME __cmg_err_not_repo && return 1
1924 local change=$1
1925 shift
1926 git $command $@ http://$review/p/$project \
1927 $($FUNCNAME __cmg_get_ref $change) || return 1
1928 ;;
1929 push)
1930 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1931 $FUNCNAME __cmg_err_not_repo && return 1
1932 if [ -z "$user" ]; then
1933 echo >&2 "Gerrit username not found."
1934 return 1
1935 fi
1936 local local_branch remote_branch
1937 case $1 in
1938 *:*)
1939 local_branch=${1%:*}
1940 remote_branch=${1##*:}
1941 ;;
1942 *)
1943 local_branch=HEAD
1944 remote_branch=$1
1945 ;;
1946 esac
1947 shift
1948 git push $@ ssh://$user@$review:29418/$project \
1949 $local_branch:refs/for/$remote_branch || return 1
1950 ;;
1951 changes|for)
1952 if [ "$FUNCNAME" = "cmgerrit" ]; then
1953 echo >&2 "'$FUNCNAME $command' is deprecated."
1954 fi
1955 ;;
1956 __cmg_err_no_arg)
1957 if [ $# -lt 2 ]; then
1958 echo >&2 "'$FUNCNAME $command' missing argument."
1959 elif [ $2 -eq 0 ]; then
1960 if [ -n "$3" ]; then
1961 $FUNCNAME help $1
1962 else
1963 echo >&2 "'$FUNCNAME $1' missing argument."
1964 fi
1965 else
1966 return 1
1967 fi
1968 ;;
1969 __cmg_err_not_repo)
1970 if [ -z "$review" -o -z "$project" ]; then
1971 echo >&2 "Not currently in any reviewable repository."
1972 else
1973 return 1
1974 fi
1975 ;;
1976 __cmg_err_not_supported)
1977 $FUNCNAME __cmg_err_no_arg $command $# && return
1978 case $1 in
1979 #TODO: filter more git commands that don't use refname
1980 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1981 echo >&2 "'$FUNCNAME $1' is not supported."
1982 ;;
1983 *) return 1 ;;
1984 esac
1985 ;;
1986 #TODO: other special cases?
1987 *)
1988 $FUNCNAME __cmg_err_not_supported $command && return 1
1989 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1990 $FUNCNAME __cmg_err_not_repo && return 1
1991 local args="$@"
1992 local change pre_args refs_arg post_args
1993 case "$args" in
1994 *--\ *)
1995 pre_args=${args%%-- *}
1996 post_args="-- ${args#*-- }"
1997 ;;
1998 *) pre_args="$args" ;;
1999 esac
2000 args=($pre_args)
2001 pre_args=
2002 if [ ${#args[@]} -gt 0 ]; then
2003 change=${args[${#args[@]}-1]}
2004 fi
2005 if [ ${#args[@]} -gt 1 ]; then
2006 pre_args=${args[0]}
2007 for ((i=1; i<${#args[@]}-1; i++)); do
2008 pre_args="$pre_args ${args[$i]}"
2009 done
2010 fi
2011 while ((1)); do
2012 case $change in
2013 ""|--)
2014 $FUNCNAME help $command
2015 return 1
2016 ;;
2017 *@*)
2018 if [ -z "$refs_arg" ]; then
2019 refs_arg="@${change#*@}"
2020 change=${change%%@*}
2021 fi
2022 ;;
2023 *~*)
2024 if [ -z "$refs_arg" ]; then
2025 refs_arg="~${change#*~}"
2026 change=${change%%~*}
2027 fi
2028 ;;
2029 *^*)
2030 if [ -z "$refs_arg" ]; then
2031 refs_arg="^${change#*^}"
2032 change=${change%%^*}
2033 fi
2034 ;;
2035 *:*)
2036 if [ -z "$refs_arg" ]; then
2037 refs_arg=":${change#*:}"
2038 change=${change%%:*}
2039 fi
2040 ;;
2041 *) break ;;
2042 esac
2043 done
2044 $FUNCNAME fetch $change \
2045 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2046 || return 1
2047 ;;
2048 esac
2049}
2050
2051function cmrebase() {
2052 local repo=$1
2053 local refs=$2
2054 local pwd="$(pwd)"
2055 local dir="$(gettop)/$repo"
2056
2057 if [ -z $repo ] || [ -z $refs ]; then
2058 echo "CyanogenMod Gerrit Rebase Usage: "
2059 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2060 echo " The patch IDs appear on the Gerrit commands that are offered."
2061 echo " They consist on a series of numbers and slashes, after the text"
2062 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2063 echo ""
2064 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2065 echo ""
2066 return
2067 fi
2068
2069 if [ ! -d $dir ]; then
2070 echo "Directory $dir doesn't exist in tree."
2071 return
2072 fi
2073 cd $dir
2074 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2075 echo "Starting branch..."
2076 repo start tmprebase .
2077 echo "Bringing it up to date..."
2078 repo sync .
2079 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07002080 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002081 if [ "$?" != "0" ]; then
2082 echo "Error cherry-picking. Not uploading!"
2083 return
2084 fi
2085 echo "Uploading..."
2086 repo upload .
2087 echo "Cleaning up..."
2088 repo abandon tmprebase .
2089 cd $pwd
2090}
2091
2092function mka() {
2093 case `uname -s` in
2094 Darwin)
2095 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2096 ;;
2097 *)
Anthony King40b093f2015-04-30 22:19:48 +01002098 mk_timer schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002099 ;;
2100 esac
2101}
2102
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302103function cmka() {
2104 if [ ! -z "$1" ]; then
2105 for i in "$@"; do
2106 case $i in
2107 bacon|otapackage|systemimage)
2108 mka installclean
2109 mka $i
2110 ;;
2111 *)
2112 mka clean-$i
2113 mka $i
2114 ;;
2115 esac
2116 done
2117 else
2118 mka clean
2119 mka
2120 fi
2121}
2122
Matt Mower8dacaed2013-12-29 12:57:20 -06002123function repolastsync() {
2124 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
2125 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
2126 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
2127 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
2128}
2129
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002130function reposync() {
2131 case `uname -s` in
2132 Darwin)
2133 repo sync -j 4 "$@"
2134 ;;
2135 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002136 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002137 ;;
2138 esac
2139}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002140
2141function repodiff() {
2142 if [ -z "$*" ]; then
2143 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2144 return
2145 fi
2146 diffopts=$* repo forall -c \
2147 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2148}
2149
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302150# Credit for color strip sed: http://goo.gl/BoIcm
2151function dopush()
2152{
2153 local func=$1
2154 shift
2155
2156 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2157 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2158 echo "No device is online. Waiting for one..."
2159 echo "Please connect USB and/or enable USB debugging"
2160 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2161 sleep 1
2162 done
2163 echo "Device Found."
2164 fi
2165
Steve Kondikec4627c2015-07-10 02:31:24 -07002166 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD") || [ "$FORCE_PUSH" == "true" ];
Chirayu Desai6dadb572012-12-26 10:53:58 +05302167 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002168 # retrieve IP and PORT info if we're using a TCP connection
2169 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2170 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302171 adb root &> /dev/null
2172 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002173 if [ -n "$TCPIPPORT" ]
2174 then
2175 # adb root just killed our connection
2176 # so reconnect...
2177 adb connect "$TCPIPPORT"
2178 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302179 adb wait-for-device &> /dev/null
2180 sleep 0.3
2181 adb remount &> /dev/null
2182
Matt Mower668ea262014-05-20 02:52:23 -05002183 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00002184 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2185 ret=$?;
2186 if [ $ret -ne 0 ]; then
2187 rm -f $OUT/.log;return $ret
2188 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302189
2190 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002191 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 +05302192
2193 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002194 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 +05302195
Matt Mower668ea262014-05-20 02:52:23 -05002196 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302197 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002198 # Make sure file is in $OUT/system
2199 case $FILE in
2200 $OUT/system/*)
2201 # Get target file name (i.e. /system/bin/adb)
2202 TARGET=$(echo $FILE | sed "s#$OUT##")
2203 ;;
2204 *) continue ;;
2205 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302206
Matt Mower668ea262014-05-20 02:52:23 -05002207 case $TARGET in
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002208 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002209 # Only need to stop services once
2210 if ! $stop_n_start; then
2211 adb shell stop
2212 stop_n_start=true
2213 fi
2214 echo "Pushing: $TARGET"
2215 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302216 ;;
2217 *)
Matt Mower668ea262014-05-20 02:52:23 -05002218 echo "Pushing: $TARGET"
2219 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302220 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002221 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302222 done
Matt Mower668ea262014-05-20 02:52:23 -05002223 if $stop_n_start; then
2224 adb shell start
2225 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302226 rm -f $OUT/.log
2227 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302228 else
2229 echo "The connected device does not appear to be $CM_BUILD, run away!"
2230 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302231}
2232
2233alias mmp='dopush mm'
2234alias mmmp='dopush mmm'
2235alias mkap='dopush mka'
2236alias cmkap='dopush cmka'
2237
Chirayu Desai4a319b82013-06-05 20:14:33 +05302238function repopick() {
2239 T=$(gettop)
2240 $T/build/tools/repopick.py $@
2241}
2242
Chirayu Desaib89b3242013-06-30 10:04:25 +05302243function fixup_common_out_dir() {
2244 common_out_dir=$(get_build_var OUT_DIR)/target/common
2245 target_device=$(get_build_var TARGET_DEVICE)
2246 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2247 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2248 mv ${common_out_dir} ${common_out_dir}-${target_device}
2249 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2250 else
2251 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2252 mkdir -p ${common_out_dir}-${target_device}
2253 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2254 fi
2255 else
2256 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2257 mkdir -p ${common_out_dir}
2258 fi
2259}
2260
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002261# 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 +00002262#
2263# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2264# For some reason, installing the JDK doesn't make it show up in the
2265# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002266function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002267 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002268 # we can reset it later, depending on the version of java the build
2269 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002270 #
2271 # If we don't do this, the JAVA_HOME value set by the first call to
2272 # build/envsetup.sh will persist forever.
2273 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2274 export JAVA_HOME=""
2275 fi
2276
Andy McFaddenbd960942010-06-24 12:52:51 -07002277 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002278 case `uname -s` in
2279 Darwin)
2280 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2281 ;;
2282 *)
2283 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2284 ;;
2285 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002286
2287 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2288 # we can change it on the next envsetup.sh, if required.
2289 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002290 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002291}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002292
Alex Rayf0d08eb2013-03-08 15:15:06 -08002293# Print colored exit condition
2294function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002295 "$@"
2296 local retval=$?
2297 if [ $retval -ne 0 ]
2298 then
2299 echo -e "\e[0;31mFAILURE\e[00m"
2300 else
2301 echo -e "\e[0;32mSUCCESS\e[00m"
2302 fi
2303 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002304}
2305
Ying Wanged21d4c2014-08-24 22:14:19 -07002306function get_make_command()
2307{
2308 echo command make
2309}
2310
Anthony King40b093f2015-04-30 22:19:48 +01002311function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002312{
2313 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002314 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002315 local ret=$?
2316 local end_time=$(date +"%s")
2317 local tdiff=$(($end_time-$start_time))
2318 local hours=$(($tdiff / 3600 ))
2319 local mins=$((($tdiff % 3600) / 60))
2320 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002321 local ncolors=$(tput colors 2>/dev/null)
2322 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2323 color_failed="\e[0;31m"
2324 color_success="\e[0;32m"
2325 color_reset="\e[00m"
2326 else
2327 color_failed=""
2328 color_success=""
2329 color_reset=""
2330 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002331 echo
2332 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002333 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002334 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002335 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002336 fi
2337 if [ $hours -gt 0 ] ; then
2338 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2339 elif [ $mins -gt 0 ] ; then
2340 printf "(%02g:%02g (mm:ss))" $mins $secs
2341 elif [ $secs -gt 0 ] ; then
2342 printf "(%s seconds)" $secs
2343 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002344 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002345 echo
2346 return $ret
2347}
2348
Anthony King40b093f2015-04-30 22:19:48 +01002349function make()
2350{
2351 mk_timer $(get_make_command) "$@"
2352}
2353
Raphael Moll70a86b02011-06-20 16:03:14 -07002354if [ "x$SHELL" != "x/bin/bash" ]; then
2355 case `ps -o command -p $$` in
2356 *bash*)
2357 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002358 *zsh*)
2359 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002360 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002361 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002362 ;;
2363 esac
2364fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002365
2366# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002367for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2368 `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 -08002369do
2370 echo "including $f"
2371 . $f
2372done
2373unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002374
Kyle Ladd031a0b62013-09-11 20:43:42 -04002375# Add completions
2376check_bash_version && {
2377 dirs="sdk/bash_completion vendor/cm/bash_completion"
2378 for dir in $dirs; do
2379 if [ -d ${dir} ]; then
2380 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2381 echo "including $f"
2382 . $f
2383 done
2384 fi
2385 done
2386}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302387
2388export ANDROID_BUILD_TOP=$(gettop)