blob: f8b13b07b3ef73d2d24345590a787b2e69b6d613 [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
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800238 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700239 # TODO: fix the path
240 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
241}
242
243function printconfig()
244{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800245 T=$(gettop)
246 if [ ! "$T" ]; then
247 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
248 return
249 fi
250 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700251}
252
253function set_stuff_for_environment()
254{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800255 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500256 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800257 setpaths
258 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700259
Ben Chengaac3f812013-08-13 14:38:15 -0700260 # With this environment variable new GCC can apply colors to warnings/errors
261 export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
Dan Albert4ae5d4b2014-10-31 16:23:08 -0700262 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700263}
264
265function set_sequence_number()
266{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700267 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268}
269
270function settitle()
271{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800272 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700273 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700274 local product=$TARGET_PRODUCT
275 local variant=$TARGET_BUILD_VARIANT
276 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800277 if [ -z "$PROMPT_COMMAND" ]; then
278 # No prompts
279 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
280 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
281 # Prompts exist, but no hardstatus
282 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700283 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800284 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500285 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800286 fi
287
288 if [ -z "$apps" ]; then
289 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
290 else
291 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
292 fi
293 export ANDROID_PROMPT_PREFIX
294
295 # Inject build data into hardstatus
296 export PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/\\033]0;\(.*\)\\007/\\033]0;$ANDROID_PROMPT_PREFIX \1\\007/g')"
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800297 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700298}
299
Kyle Ladd031a0b62013-09-11 20:43:42 -0400300function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700301{
Kenny Root52aa81c2011-07-15 11:07:06 -0700302 # Keep us from trying to run in something that isn't bash.
303 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400304 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700305 fi
306
307 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200308 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400309 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700310 fi
311
Kyle Ladd031a0b62013-09-11 20:43:42 -0400312 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700313}
314
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700315function choosetype()
316{
317 echo "Build type choices are:"
318 echo " 1. release"
319 echo " 2. debug"
320 echo
321
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800322 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700323 DEFAULT_NUM=1
324 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700325
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800326 export TARGET_BUILD_TYPE=
327 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700328 while [ -z $TARGET_BUILD_TYPE ]
329 do
330 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 if [ -z "$1" ] ; then
332 read ANSWER
333 else
334 echo $1
335 ANSWER=$1
336 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700337 case $ANSWER in
338 "")
339 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
340 ;;
341 1)
342 export TARGET_BUILD_TYPE=release
343 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800344 release)
345 export TARGET_BUILD_TYPE=release
346 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700347 2)
348 export TARGET_BUILD_TYPE=debug
349 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800350 debug)
351 export TARGET_BUILD_TYPE=debug
352 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700353 *)
354 echo
355 echo "I didn't understand your response. Please try again."
356 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700357 ;;
358 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800359 if [ -n "$1" ] ; then
360 break
361 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 done
363
364 set_stuff_for_environment
365}
366
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800367#
368# This function isn't really right: It chooses a TARGET_PRODUCT
369# based on the list of boards. Usually, that gets you something
370# that kinda works with a generic product, but really, you should
371# pick a product by name.
372#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700373function chooseproduct()
374{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700375 if [ "x$TARGET_PRODUCT" != x ] ; then
376 default_value=$TARGET_PRODUCT
377 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700378 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700379 fi
380
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800381 export TARGET_PRODUCT=
382 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383 while [ -z "$TARGET_PRODUCT" ]
384 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700385 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800386 if [ -z "$1" ] ; then
387 read ANSWER
388 else
389 echo $1
390 ANSWER=$1
391 fi
392
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700393 if [ -z "$ANSWER" ] ; then
394 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800395 else
396 if check_product $ANSWER
397 then
398 export TARGET_PRODUCT=$ANSWER
399 else
400 echo "** Not a valid product: $ANSWER"
401 fi
402 fi
403 if [ -n "$1" ] ; then
404 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700405 fi
406 done
407
408 set_stuff_for_environment
409}
410
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800411function choosevariant()
412{
413 echo "Variant choices are:"
414 local index=1
415 local v
416 for v in ${VARIANT_CHOICES[@]}
417 do
418 # The product name is the name of the directory containing
419 # the makefile we found, above.
420 echo " $index. $v"
421 index=$(($index+1))
422 done
423
424 local default_value=eng
425 local ANSWER
426
427 export TARGET_BUILD_VARIANT=
428 while [ -z "$TARGET_BUILD_VARIANT" ]
429 do
430 echo -n "Which would you like? [$default_value] "
431 if [ -z "$1" ] ; then
432 read ANSWER
433 else
434 echo $1
435 ANSWER=$1
436 fi
437
438 if [ -z "$ANSWER" ] ; then
439 export TARGET_BUILD_VARIANT=$default_value
440 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
441 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800442 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800443 fi
444 else
445 if check_variant $ANSWER
446 then
447 export TARGET_BUILD_VARIANT=$ANSWER
448 else
449 echo "** Not a valid variant: $ANSWER"
450 fi
451 fi
452 if [ -n "$1" ] ; then
453 break
454 fi
455 done
456}
457
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700458function choosecombo()
459{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700460 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700461
462 echo
463 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700464 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700465
466 echo
467 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700468 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800469
470 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700471 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800472 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473}
474
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800475# Clear this variable. It will be built up again when the vendorsetup.sh
476# files are included at the end of this file.
477unset LUNCH_MENU_CHOICES
478function add_lunch_combo()
479{
480 local new_combo=$1
481 local c
482 for c in ${LUNCH_MENU_CHOICES[@]} ; do
483 if [ "$new_combo" = "$c" ] ; then
484 return
485 fi
486 done
487 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
488}
489
490# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700491add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800492add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000493add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800494add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000495add_lunch_combo aosp_x86-eng
496add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800497
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700498function print_lunch_menu()
499{
500 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700501 echo
502 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000503 if [ "$(uname)" = "Darwin" ] ; then
504 echo " (ohai, koush!)"
505 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000507 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
508 echo "Breakfast menu... pick a combo:"
509 else
510 echo "Lunch menu... pick a combo:"
511 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800512
513 local i=1
514 local choice
515 for choice in ${LUNCH_MENU_CHOICES[@]}
516 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100517 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800518 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100519 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000521 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
522 echo "... and don't forget the bacon!"
523 fi
524
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700525 echo
526}
527
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000528function brunch()
529{
530 breakfast $*
531 if [ $? -eq 0 ]; then
532 mka bacon
533 else
534 echo "No such item in brunch menu. Try 'breakfast'"
535 return 1
536 fi
537 return $?
538}
539
540function breakfast()
541{
542 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200543 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000544 CM_DEVICES_ONLY="true"
545 unset LUNCH_MENU_CHOICES
546 add_lunch_combo full-eng
547 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
548 do
549 echo "including $f"
550 . $f
551 done
552 unset f
553
554 if [ $# -eq 0 ]; then
555 # No arguments, so let's have the full menu
556 lunch
557 else
558 echo "z$target" | grep -q "-"
559 if [ $? -eq 0 ]; then
560 # A buildtype was specified, assume a full device name
561 lunch $target
562 else
563 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200564 if [ -z "$variant" ]; then
565 variant="userdebug"
566 fi
567 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000568 fi
569 fi
570 return $?
571}
572
573alias bib=breakfast
574
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700575function lunch()
576{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800577 local answer
Anthony King850627c2015-04-30 22:57:08 +0100578 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800579
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800581 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700582 else
583 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700584 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800585 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700586 fi
587
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800588 local selection=
589
590 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700592 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
594 then
595 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
596 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800597 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 fi
599 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
600 then
601 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700602 fi
603
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800604 if [ -z "$selection" ]
605 then
606 echo
607 echo "Invalid lunch combo: $answer"
608 return 1
609 fi
610
Joe Onoratoda12daf2010-06-09 18:18:31 -0700611 export TARGET_BUILD_APPS=
612
Jeff Browne33ba4c2011-07-11 22:11:46 -0700613 local product=$(echo -n $selection | sed -e "s/-.*$//")
614 check_product $product
615 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800616 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800617 # if we can't find a product, try to grab it off the CM github
618 T=$(gettop)
619 pushd $T > /dev/null
620 build/tools/roomservice.py $product
621 popd > /dev/null
622 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000623 else
624 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800625 fi
626 if [ $? -ne 0 ]
627 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700628 echo
629 echo "** Don't have a product spec for: '$product'"
630 echo "** Do you have the right repo manifest?"
631 product=
632 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800633
Jeff Browne33ba4c2011-07-11 22:11:46 -0700634 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
635 check_variant $variant
636 if [ $? -ne 0 ]
637 then
638 echo
639 echo "** Invalid variant: '$variant'"
640 echo "** Must be one of ${VARIANT_CHOICES[@]}"
641 variant=
642 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800643
Jeff Browne33ba4c2011-07-11 22:11:46 -0700644 if [ -z "$product" -o -z "$variant" ]
645 then
646 echo
647 return 1
648 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800649
Jeff Browne33ba4c2011-07-11 22:11:46 -0700650 export TARGET_PRODUCT=$product
651 export TARGET_BUILD_VARIANT=$variant
652 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700653
654 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800655
Chirayu Desaib89b3242013-06-30 10:04:25 +0530656 fixup_common_out_dir
657
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800659 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700660}
661
Jeff Davidson513d7a42010-08-02 10:00:44 -0700662# Tab completion for lunch.
663function _lunch()
664{
665 local cur prev opts
666 COMPREPLY=()
667 cur="${COMP_WORDS[COMP_CWORD]}"
668 prev="${COMP_WORDS[COMP_CWORD-1]}"
669
670 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
671 return 0
672}
Emilio López9ad6eea2013-11-03 13:02:13 -0300673complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700674
Joe Onoratoda12daf2010-06-09 18:18:31 -0700675# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700676# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700677function tapas()
678{
Ying Wangb541ab62014-05-29 17:57:40 -0700679 local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|armv5|arm64|x86_64|mips64)$' | xargs)"
Doug Zongker0d8179e2014-04-16 11:34:34 -0700680 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700681 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
682 local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|armv5|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700683
Ying Wang67f02922012-08-22 10:25:20 -0700684 if [ $(echo $arch | wc -w) -gt 1 ]; then
685 echo "tapas: Error: Multiple build archs supplied: $arch"
686 return
687 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700688 if [ $(echo $variant | wc -w) -gt 1 ]; then
689 echo "tapas: Error: Multiple build variants supplied: $variant"
690 return
691 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700692 if [ $(echo $density | wc -w) -gt 1 ]; then
693 echo "tapas: Error: Multiple densities supplied: $density"
694 return
695 fi
Ying Wang67f02922012-08-22 10:25:20 -0700696
697 local product=full
698 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700699 x86) product=full_x86;;
700 mips) product=full_mips;;
701 armv5) product=generic_armv5;;
702 arm64) product=aosp_arm64;;
703 x86_64) product=aosp_x86_64;;
704 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700705 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700706 if [ -z "$variant" ]; then
707 variant=eng
708 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700709 if [ -z "$apps" ]; then
710 apps=all
711 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600712 if [ -z "$density" ]; then
713 density=alldpi
714 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700715
Ying Wang67f02922012-08-22 10:25:20 -0700716 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700717 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700718 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700719 export TARGET_BUILD_TYPE=release
720 export TARGET_BUILD_APPS=$apps
721
722 set_stuff_for_environment
723 printconfig
724}
725
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100726function eat()
727{
728 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530729 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100730 ZIPFILE=cm-$MODVERSION.zip
731 ZIPPATH=$OUT/$ZIPFILE
732 if [ ! -f $ZIPPATH ] ; then
733 echo "Nothing to eat"
734 return 1
735 fi
736 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
737 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
738 echo "No device is online. Waiting for one..."
739 echo "Please connect USB and/or enable USB debugging"
740 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
741 sleep 1
742 done
743 echo "Device Found.."
744 fi
Steve Kondikec4627c2015-07-10 02:31:24 -0700745 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Chirayu Desai6dadb572012-12-26 10:53:58 +0530746 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100747 # if adbd isn't root we can't write to /cache/recovery/
748 adb root
749 sleep 1
750 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700751 cat << EOF > /tmp/command
752--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100753EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700754 if adb push /tmp/command /cache/recovery/ ; then
755 echo "Rebooting into recovery for sideload installation"
756 adb reboot recovery
757 adb wait-for-sideload
758 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100759 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700760 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100761 else
762 echo "Nothing to eat"
763 return 1
764 fi
765 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530766 else
767 echo "The connected device does not appear to be $CM_BUILD, run away!"
768 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100769}
770
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000771function omnom
772{
773 brunch $*
774 eat
775}
776
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700777function gettop
778{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800779 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700780 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700781 # The following circumlocution ensures we remove symlinks from TOP.
782 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700783 else
784 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800785 # The following circumlocution (repeated below as well) ensures
786 # that we record the true directory name and not one that is
787 # faked up with symlink names.
788 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700789 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800790 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 T=
792 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800793 \cd ..
synergyb112a402013-07-05 19:47:47 -0700794 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700795 done
Ying Wang9cd17642012-12-13 10:52:07 -0800796 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 if [ -f "$T/$TOPFILE" ]; then
798 echo $T
799 fi
800 fi
801 fi
802}
803
Andrew Hsieh906cb782013-09-10 17:37:14 +0800804# Return driver for "make", if any (eg. static analyzer)
805function getdriver()
806{
807 local T="$1"
808 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
809 if [ -n "$WITH_STATIC_ANALYZER" ]; then
810 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800811$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
812--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800813--status-bugs \
814--top=$T"
815 fi
816}
817
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700818function m()
819{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800820 local T=$(gettop)
821 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700822 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800823 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700824 else
825 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700826 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827 fi
828}
829
830function findmakefile()
831{
832 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800833 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700834 T=
835 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700836 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700837 if [ -f "$T/Android.mk" ]; then
838 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800839 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700840 return
841 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800842 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700843 done
Ying Wang9cd17642012-12-13 10:52:07 -0800844 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845}
846
847function mm()
848{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800849 local T=$(gettop)
850 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700851 # If we're sitting in the root of the build tree, just do a
852 # normal make.
853 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800854 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700855 else
856 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800857 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700858 local MODULES=
859 local GET_INSTALL_PATH=
860 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700861 # Remove the path to top as the makefilepath needs to be relative
862 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700863 if [ ! "$T" ]; then
864 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700865 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700866 elif [ ! "$M" ]; then
867 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700868 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700869 else
Ying Wanga7deb082013-08-16 13:24:47 -0700870 for ARG in $@; do
871 case $ARG in
872 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
873 esac
874 done
875 if [ -n "$GET_INSTALL_PATH" ]; then
876 MODULES=
877 ARGS=GET-INSTALL-PATH
878 else
879 MODULES=all_modules
880 ARGS=$@
881 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700882 ONE_SHOT_MAKEFILE=$M $DRV make -C $T -f build/core/main.mk $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700883 fi
884 fi
885}
886
887function mmm()
888{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800889 local T=$(gettop)
890 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700891 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800892 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800893 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800894 local ARGS=
895 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700896 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800897 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
898 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
899 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800900 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
901 if [ "$MODULES" = "" ]; then
902 MODULES=all_modules
903 fi
904 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700905 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700906 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
907 local TO_CHOP=`expr $TO_CHOP + 1`
908 local START=`PWD= /bin/pwd`
909 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700910 if [ "$MFILE" = "" ] ; then
911 MFILE=$DIR/Android.mk
912 else
913 MFILE=$MFILE/$DIR/Android.mk
914 fi
915 MAKEFILE="$MAKEFILE $MFILE"
916 else
Ying Wanga7deb082013-08-16 13:24:47 -0700917 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100918 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700919 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
920 *) echo "No Android.mk in $DIR."; return 1;;
921 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700922 fi
923 done
Ying Wanga7deb082013-08-16 13:24:47 -0700924 if [ -n "$GET_INSTALL_PATH" ]; then
925 ARGS=$GET_INSTALL_PATH
926 MODULES=
927 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800928 ONE_SHOT_MAKEFILE="$MAKEFILE" $DRV make -C $T -f build/core/main.mk $DASH_ARGS $MODULES $ARGS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700929 else
930 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700931 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 fi
933}
934
Ying Wangb607f7b2013-02-08 18:01:04 -0800935function mma()
936{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800937 local T=$(gettop)
938 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800939 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800940 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800941 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800942 if [ ! "$T" ]; then
943 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700944 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800945 fi
946 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800947 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800948 fi
949}
950
951function mmma()
952{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800953 local T=$(gettop)
954 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800955 if [ "$T" ]; then
956 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
957 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
958 local MY_PWD=`PWD= /bin/pwd`
959 if [ "$MY_PWD" = "$T" ]; then
960 MY_PWD=
961 else
962 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
963 fi
964 local DIR=
965 local MODULE_PATHS=
966 local ARGS=
967 for DIR in $DIRS ; do
968 if [ -d $DIR ]; then
969 if [ "$MY_PWD" = "" ]; then
970 MODULE_PATHS="$MODULE_PATHS $DIR"
971 else
972 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
973 fi
974 else
975 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100976 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800977 *) echo "Couldn't find directory $DIR"; return 1;;
978 esac
979 fi
980 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800981 $DRV make -C $T -f build/core/main.mk $DASH_ARGS $ARGS all_modules BUILD_MODULES_IN_PATHS="$MODULE_PATHS"
Ying Wangb607f7b2013-02-08 18:01:04 -0800982 else
983 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700984 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800985 fi
986}
987
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700988function croot()
989{
990 T=$(gettop)
991 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800992 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700993 else
994 echo "Couldn't locate the top of the tree. Try setting TOP."
995 fi
996}
997
nebkatfb67a1e2012-12-28 10:40:45 +0000998function cout()
999{
1000 if [ "$OUT" ]; then
1001 cd $OUT
1002 else
1003 echo "Couldn't locate out directory. Try setting OUT."
1004 fi
1005}
1006
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001007function cproj()
1008{
1009 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001010 local HERE=$PWD
1011 T=
1012 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1013 T=$PWD
1014 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001015 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001016 return
1017 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001018 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001019 done
Ying Wang9cd17642012-12-13 10:52:07 -08001020 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001021 echo "can't find Android.mk"
1022}
1023
Daniel Sandler47e0a882013-07-30 13:23:52 -04001024# simplified version of ps; output in the form
1025# <pid> <procname>
1026function qpid() {
1027 local prepend=''
1028 local append=''
1029 if [ "$1" = "--exact" ]; then
1030 prepend=' '
1031 append='$'
1032 shift
1033 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1034 echo "usage: qpid [[--exact] <process name|pid>"
1035 return 255
1036 fi
1037
1038 local EXE="$1"
1039 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001040 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001041 else
1042 adb shell ps \
1043 | tr -d '\r' \
1044 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1045 fi
1046}
1047
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001048function pid()
1049{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001050 local prepend=''
1051 local append=''
1052 if [ "$1" = "--exact" ]; then
1053 prepend=' '
1054 append='$'
1055 shift
1056 fi
1057 local EXE="$1"
1058 if [ "$EXE" ] ; then
1059 local PID=`adb shell ps \
1060 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001061 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001062 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1063 echo "$PID"
1064 else
1065 echo "usage: pid [--exact] <process name>"
1066 return 255
1067 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001068}
1069
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001070# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001071# that has the core-file-size limit set correctly
1072#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001073# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001074# if its core-file-size limit is not set already.
1075# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1076
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001077function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001078{
1079 echo "Getting root...";
1080 adb root;
1081 adb wait-for-device;
1082
1083 echo "Remounting root parition read-write...";
1084 adb shell mount -w -o remount -t rootfs rootfs;
1085 sleep 1;
1086 adb wait-for-device;
1087 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001088 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001089 adb shell chmod 0777 /cores;
1090
1091 echo "Granting SELinux permission to dump in /cores...";
1092 adb shell restorecon -R /cores;
1093
1094 echo "Set core pattern.";
1095 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1096
1097 echo "Done."
1098}
1099
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001100# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001101# $1 = PID of process (e.g., $(pid mediaserver))
1102#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001103# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001104# dump to actually be generated.
1105
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001106function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001107{
1108 local PID=$1;
1109 if [ -z "$PID" ]; then
1110 printf "Expecting a PID!\n";
1111 return;
1112 fi;
1113 echo "Setting core limit for $PID to infinite...";
1114 adb shell prlimit $PID 4 -1 -1
1115}
1116
1117# core - send SIGV and pull the core for process
1118# $1 = PID of process (e.g., $(pid mediaserver))
1119#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001120# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001121# enabled globally.
1122
1123function core()
1124{
1125 local PID=$1;
1126
1127 if [ -z "$PID" ]; then
1128 printf "Expecting a PID!\n";
1129 return;
1130 fi;
1131
1132 local CORENAME=core.$PID;
1133 local COREPATH=/cores/$CORENAME;
1134 local SIG=SEGV;
1135
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001136 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001137
1138 local done=0;
1139 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1140 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1141 adb shell kill -$SIG $PID;
1142 sleep 1;
1143 done;
1144
1145 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1146 echo "Done: core is under $COREPATH on device.";
1147}
1148
Christopher Tate744ee802009-11-12 15:33:08 -08001149# systemstack - dump the current stack trace of all threads in the system process
1150# to the usual ANR traces file
1151function systemstack()
1152{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001153 stacks system_server
1154}
1155
1156function stacks()
1157{
1158 if [[ $1 =~ ^[0-9]+$ ]] ; then
1159 local PID="$1"
1160 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001161 local PIDLIST="$(pid $1)"
1162 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1163 local PID="$PIDLIST"
1164 elif [ "$PIDLIST" ] ; then
1165 echo "more than one process: $1"
1166 else
1167 echo "no such process: $1"
1168 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001169 else
1170 echo "usage: stacks [pid|process name]"
1171 fi
1172
1173 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001174 # Determine whether the process is native
1175 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1176 # Dump stacks of Dalvik process
1177 local TRACES=/data/anr/traces.txt
1178 local ORIG=/data/anr/traces.orig
1179 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001180
Jeff Brownb12c2e52013-08-19 15:14:16 -07001181 # Keep original traces to avoid clobbering
1182 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001183
Jeff Brownb12c2e52013-08-19 15:14:16 -07001184 # Make sure we have a usable file
1185 adb shell touch $TRACES
1186 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001187
Jeff Brownb12c2e52013-08-19 15:14:16 -07001188 # Dump stacks and wait for dump to finish
1189 adb shell kill -3 $PID
1190 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001191
Jeff Brownb12c2e52013-08-19 15:14:16 -07001192 # Restore original stacks, and show current output
1193 adb shell mv $TRACES $TMP
1194 adb shell mv $ORIG $TRACES
1195 adb shell cat $TMP
1196 else
1197 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001198 local USE64BIT="$(is64bit $PID)"
1199 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001200 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001201 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001202}
1203
Michael Wrightaeed7212014-06-19 19:58:12 -07001204# Read the ELF header from /proc/$PID/exe to determine if the process is
1205# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001206function is64bit()
1207{
1208 local PID="$1"
1209 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001210 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001211 echo "64"
1212 else
1213 echo ""
1214 fi
1215 else
1216 echo ""
1217 fi
1218}
1219
Clark Scheff75b36a42014-12-23 13:30:51 -08001220function dddclient()
1221{
1222 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1223 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1224 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1225 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1226 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1227 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1228 local ARCH=$(get_build_var TARGET_ARCH)
1229 local GDB
1230 case "$ARCH" in
1231 arm) GDB=arm-linux-androideabi-gdb;;
1232 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1233 mips|mips64) GDB=mips64el-linux-android-gdb;;
1234 x86) GDB=x86_64-linux-android-gdb;;
1235 x86_64) GDB=x86_64-linux-android-gdb;;
1236 *) echo "Unknown arch $ARCH"; return 1;;
1237 esac
1238
1239 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1240 local EXE="$1"
1241 if [ "$EXE" ] ; then
1242 EXE=$1
1243 if [[ $EXE =~ ^[^/].* ]] ; then
1244 EXE="system/bin/"$EXE
1245 fi
1246 else
1247 EXE="app_process"
1248 fi
1249
1250 local PORT="$2"
1251 if [ "$PORT" ] ; then
1252 PORT=$2
1253 else
1254 PORT=":5039"
1255 fi
1256
1257 local PID="$3"
1258 if [ "$PID" ] ; then
1259 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1260 PID=`pid $3`
1261 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1262 # that likely didn't work because of returning multiple processes
1263 # try again, filtering by root processes (don't contain colon)
1264 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1265 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1266 then
1267 echo "Couldn't resolve '$3' to single PID"
1268 return 1
1269 else
1270 echo ""
1271 echo "WARNING: multiple processes matching '$3' observed, using root process"
1272 echo ""
1273 fi
1274 fi
1275 fi
1276 adb forward "tcp$PORT" "tcp$PORT"
1277 local USE64BIT="$(is64bit $PID)"
1278 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1279 sleep 2
1280 else
1281 echo ""
1282 echo "If you haven't done so already, do this first on the device:"
1283 echo " gdbserver $PORT /system/bin/$EXE"
1284 echo " or"
1285 echo " gdbserver $PORT --attach <PID>"
1286 echo ""
1287 fi
1288
1289 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1290 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1291
1292 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1293 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"
1294 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1295 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1296 # Enable special debugging for ART processes.
1297 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1298 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1299 fi
1300 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1301
1302 local WHICH_GDB=
1303 # 64-bit exe found
1304 if [ "$USE64BIT" != "" ] ; then
1305 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1306 # 32-bit exe / 32-bit platform
1307 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1308 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1309 # 32-bit exe / 64-bit platform
1310 else
1311 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1312 fi
1313
1314 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1315 else
1316 echo "Unable to determine build system output dir."
1317 fi
1318}
1319
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001320case `uname -s` in
1321 Darwin)
1322 function sgrep()
1323 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001324 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 -07001325 }
1326
1327 ;;
1328 *)
1329 function sgrep()
1330 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001331 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 -07001332 }
1333 ;;
1334esac
1335
Raghu Gandham8da43102012-07-25 19:57:22 -07001336function gettargetarch
1337{
1338 get_build_var TARGET_ARCH
1339}
1340
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001341function ggrep()
1342{
1343 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1344}
1345
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001346function jgrep()
1347{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001348 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 -07001349}
1350
1351function cgrep()
1352{
Dan Albert01961192014-11-22 10:16:01 -08001353 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 -07001354}
1355
1356function resgrep()
1357{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001358 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 -07001359}
1360
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001361function mangrep()
1362{
1363 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1364}
1365
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001366function sepgrep()
1367{
1368 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 "$@"
1369}
1370
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001371function rcgrep()
1372{
1373 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1374}
1375
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001376case `uname -s` in
1377 Darwin)
1378 function mgrep()
1379 {
Ying Wang324c2b22012-08-17 15:03:20 -07001380 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 -07001381 }
1382
1383 function treegrep()
1384 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001385 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 -07001386 }
1387
1388 ;;
1389 *)
1390 function mgrep()
1391 {
Ying Wang324c2b22012-08-17 15:03:20 -07001392 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 -07001393 }
1394
1395 function treegrep()
1396 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001397 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 -07001398 }
1399
1400 ;;
1401esac
1402
1403function getprebuilt
1404{
1405 get_abs_build_var ANDROID_PREBUILTS
1406}
1407
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001408function tracedmdump()
1409{
1410 T=$(gettop)
1411 if [ ! "$T" ]; then
1412 echo "Couldn't locate the top of the tree. Try setting TOP."
1413 return
1414 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001415 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001416 local arch=$(gettargetarch)
1417 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001418
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001419 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001420 if [ ! "$TRACE" ] ; then
1421 echo "usage: tracedmdump tracename"
1422 return
1423 fi
1424
Jack Veenstra60116fc2009-04-09 18:12:34 -07001425 if [ ! -r "$KERNEL" ] ; then
1426 echo "Error: cannot find kernel: '$KERNEL'"
1427 return
1428 fi
1429
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001430 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001431 if [ "$BASETRACE" = "$TRACE" ] ; then
1432 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1433 fi
1434
1435 echo "post-processing traces..."
1436 rm -f $TRACE/qtrace.dexlist
1437 post_trace $TRACE
1438 if [ $? -ne 0 ]; then
1439 echo "***"
1440 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1441 echo "***"
1442 return
1443 fi
1444 echo "generating dexlist output..."
1445 /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
1446 echo "generating dmtrace data..."
1447 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1448 echo "generating html file..."
1449 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1450 echo "done, see $TRACE/dmtrace.html for details"
1451 echo "or run:"
1452 echo " traceview $TRACE/dmtrace"
1453}
1454
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001455# communicate with a running device or emulator, set up necessary state,
1456# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001457function runhat()
1458{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001459 # process standard adb options
1460 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001461 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001462 adbTarget=$1
1463 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001464 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001465 adbTarget="$1 $2"
1466 shift 2
1467 fi
1468 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001469 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001470
1471 # runhat options
1472 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001473
1474 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001475 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001476 return
1477 fi
1478
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001479 # confirm hat is available
1480 if [ -z $(which hat) ]; then
1481 echo "hat is not available in this configuration."
1482 return
1483 fi
1484
Andy McFaddenb6289852010-07-12 08:00:19 -07001485 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001486 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001487 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001488 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001489 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001490 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001491 echo -n "> "
1492 read
1493
The Android Open Source Project88b60792009-03-03 19:28:42 -08001494 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001495
The Android Open Source Project88b60792009-03-03 19:28:42 -08001496 echo "Retrieving file $devFile..."
1497 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001498
The Android Open Source Project88b60792009-03-03 19:28:42 -08001499 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001500
The Android Open Source Project88b60792009-03-03 19:28:42 -08001501 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001502 echo "View the output by pointing your browser at http://localhost:7000/"
1503 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001504 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001505}
1506
1507function getbugreports()
1508{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001509 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001510
1511 if [ ! "$reports" ]; then
1512 echo "Could not locate any bugreports."
1513 return
1514 fi
1515
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001516 local report
1517 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001518 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001519 echo "/sdcard/bugreports/${report}"
1520 adb pull /sdcard/bugreports/${report} ${report}
1521 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001522 done
1523}
1524
Victoria Lease1b296b42012-08-21 15:44:06 -07001525function getsdcardpath()
1526{
1527 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1528}
1529
1530function getscreenshotpath()
1531{
1532 echo "$(getsdcardpath)/Pictures/Screenshots"
1533}
1534
1535function getlastscreenshot()
1536{
1537 local screenshot_path=$(getscreenshotpath)
1538 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1539 if [ "$screenshot" = "" ]; then
1540 echo "No screenshots found."
1541 return
1542 fi
1543 echo "${screenshot}"
1544 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1545}
1546
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001547function startviewserver()
1548{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001549 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001550 if [ $# -gt 0 ]; then
1551 port=$1
1552 fi
1553 adb shell service call window 1 i32 $port
1554}
1555
1556function stopviewserver()
1557{
1558 adb shell service call window 2
1559}
1560
1561function isviewserverstarted()
1562{
1563 adb shell service call window 3
1564}
1565
Romain Guyb84049a2010-10-04 16:56:11 -07001566function key_home()
1567{
1568 adb shell input keyevent 3
1569}
1570
1571function key_back()
1572{
1573 adb shell input keyevent 4
1574}
1575
1576function key_menu()
1577{
1578 adb shell input keyevent 82
1579}
1580
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001581function smoketest()
1582{
1583 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1584 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1585 return
1586 fi
1587 T=$(gettop)
1588 if [ ! "$T" ]; then
1589 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1590 return
1591 fi
1592
Ying Wang9cd17642012-12-13 10:52:07 -08001593 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001594 adb uninstall com.android.smoketest > /dev/null &&
1595 adb uninstall com.android.smoketest.tests > /dev/null &&
1596 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1597 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1598 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1599}
1600
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001601# simple shortcut to the runtest command
1602function runtest()
1603{
1604 T=$(gettop)
1605 if [ ! "$T" ]; then
1606 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1607 return
1608 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001609 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001610}
1611
The Android Open Source Project88b60792009-03-03 19:28:42 -08001612function godir () {
1613 if [[ -z "$1" ]]; then
1614 echo "Usage: godir <regex>"
1615 return
1616 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001617 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001618 if [[ ! -f $T/filelist ]]; then
1619 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001620 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001621 echo " Done"
1622 echo ""
1623 fi
1624 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001625 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001626 if [[ ${#lines[@]} = 0 ]]; then
1627 echo "Not found"
1628 return
1629 fi
1630 local pathname
1631 local choice
1632 if [[ ${#lines[@]} > 1 ]]; then
1633 while [[ -z "$pathname" ]]; do
1634 local index=1
1635 local line
1636 for line in ${lines[@]}; do
1637 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001638 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001639 done
1640 echo
1641 echo -n "Select one: "
1642 unset choice
1643 read choice
1644 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1645 echo "Invalid choice"
1646 continue
1647 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001648 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001649 done
1650 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001651 pathname=${lines[0]}
1652 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001653 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001654}
1655
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001656function cmremote()
1657{
1658 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301659 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001660 if [ -z "$GERRIT_REMOTE" ]
1661 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301662 echo Unable to set up the git remote, are you under a git repo?
1663 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001664 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301665 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001666 if [ -z "$CMUSER" ]
1667 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001668 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001669 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001670 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001671 fi
1672 echo You can now push to "cmremote".
1673}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001674
Steve Kondik873fa562012-09-17 11:33:18 -07001675function aospremote()
1676{
1677 git remote rm aosp 2> /dev/null
1678 if [ ! -d .git ]
1679 then
1680 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1681 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001682 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001683 if (echo $PROJECT | grep -qv "^device")
1684 then
1685 PFX="platform/"
1686 fi
1687 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1688 echo "Remote 'aosp' created"
1689}
Steve Kondik873fa562012-09-17 11:33:18 -07001690
Steve Kondik20c21d22013-10-27 13:34:36 -07001691function cafremote()
1692{
1693 git remote rm caf 2> /dev/null
1694 if [ ! -d .git ]
1695 then
1696 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1697 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001698 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001699 if (echo $PROJECT | grep -qv "^device")
1700 then
1701 PFX="platform/"
1702 fi
1703 git remote add caf git://codeaurora.org/$PFX$PROJECT
1704 echo "Remote 'caf' created"
1705}
Steve Kondik20c21d22013-10-27 13:34:36 -07001706
Steve Kondikf00e7d92012-09-23 23:46:55 -07001707function installboot()
1708{
1709 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1710 then
1711 echo "No recovery.fstab found. Build recovery first."
1712 return 1
1713 fi
1714 if [ ! -e "$OUT/boot.img" ];
1715 then
1716 echo "No boot.img found. Run make bootimage first."
1717 return 1
1718 fi
1719 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1720 if [ -z "$PARTITION" ];
1721 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001722 # Try for RECOVERY_FSTAB_VERSION = 2
1723 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1724 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1725 if [ -z "$PARTITION" ];
1726 then
1727 echo "Unable to determine boot partition."
1728 return 1
1729 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001730 fi
1731 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001732 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001733 adb root
1734 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001735 adb wait-for-online shell mount /system 2>&1 > /dev/null
1736 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001737 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondikf00e7d92012-09-23 23:46:55 -07001738 then
1739 adb push $OUT/boot.img /cache/
1740 for i in $OUT/system/lib/modules/*;
1741 do
1742 adb push $i /system/lib/modules/
1743 done
1744 adb shell dd if=/cache/boot.img of=$PARTITION
1745 adb shell chmod 644 /system/lib/modules/*
1746 echo "Installation complete."
1747 else
1748 echo "The connected device does not appear to be $CM_BUILD, run away!"
1749 fi
1750}
1751
Steve Kondik83c03d52012-10-24 16:40:42 -07001752function installrecovery()
1753{
1754 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1755 then
1756 echo "No recovery.fstab found. Build recovery first."
1757 return 1
1758 fi
1759 if [ ! -e "$OUT/recovery.img" ];
1760 then
1761 echo "No recovery.img found. Run make recoveryimage first."
1762 return 1
1763 fi
1764 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1765 if [ -z "$PARTITION" ];
1766 then
Steve Kondik75f10762013-08-09 21:03:42 -07001767 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001768 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1769 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001770 if [ -z "$PARTITION" ];
1771 then
1772 echo "Unable to determine recovery partition."
1773 return 1
1774 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001775 fi
1776 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001777 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001778 adb root
1779 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001780 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1781 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001782 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondik83c03d52012-10-24 16:40:42 -07001783 then
1784 adb push $OUT/recovery.img /cache/
1785 adb shell dd if=/cache/recovery.img of=$PARTITION
1786 echo "Installation complete."
1787 else
1788 echo "The connected device does not appear to be $CM_BUILD, run away!"
1789 fi
1790}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001791
Koushik Duttab55f13a2012-05-14 16:14:36 -07001792function makerecipe() {
1793 if [ -z "$1" ]
1794 then
1795 echo "No branch name provided."
1796 return 1
1797 fi
1798 cd android
1799 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1800 git commit -a -m "$1"
1801 cd ..
1802
1803 repo forall -c '
1804
1805 if [ "$REPO_REMOTE" == "github" ]
1806 then
1807 pwd
1808 cmremote
1809 git push cmremote HEAD:refs/heads/'$1'
1810 fi
1811 '
1812}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001813
1814function cmgerrit() {
1815 if [ $# -eq 0 ]; then
1816 $FUNCNAME help
1817 return 1
1818 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001819 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001820 local review=`git config --get remote.github.review`
1821 local project=`git config --get remote.github.projectname`
1822 local command=$1
1823 shift
1824 case $command in
1825 help)
1826 if [ $# -eq 0 ]; then
1827 cat <<EOF
1828Usage:
1829 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1830
1831Commands:
1832 fetch Just fetch the change as FETCH_HEAD
1833 help Show this help, or for a specific command
1834 pull Pull a change into current branch
1835 push Push HEAD or a local branch to Gerrit for a specific branch
1836
1837Any other Git commands that support refname would work as:
1838 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1839
1840See '$FUNCNAME help COMMAND' for more information on a specific command.
1841
1842Example:
1843 $FUNCNAME checkout -b topic 1234/5
1844works as:
1845 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1846 && git checkout -b topic FETCH_HEAD
1847will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1848Patch-set 1 will be fetched if omitted.
1849EOF
1850 return
1851 fi
1852 case $1 in
1853 __cmg_*) echo "For internal use only." ;;
1854 changes|for)
1855 if [ "$FUNCNAME" = "cmgerrit" ]; then
1856 echo "'$FUNCNAME $1' is deprecated."
1857 fi
1858 ;;
1859 help) $FUNCNAME help ;;
1860 fetch|pull) cat <<EOF
1861usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1862
1863works as:
1864 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1865 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1866
1867Example:
1868 $FUNCNAME $1 1234
1869will $1 patch-set 1 of change 1234
1870EOF
1871 ;;
1872 push) cat <<EOF
1873usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1874
1875works as:
1876 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1877 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1878
1879Example:
1880 $FUNCNAME push fix6789:gingerbread
1881will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1882HEAD will be pushed from local if omitted.
1883EOF
1884 ;;
1885 *)
1886 $FUNCNAME __cmg_err_not_supported $1 && return
1887 cat <<EOF
1888usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1889
1890works as:
1891 git fetch http://DOMAIN/p/PROJECT \\
1892 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1893 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1894EOF
1895 ;;
1896 esac
1897 ;;
1898 __cmg_get_ref)
1899 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1900 local change_id patchset_id hash
1901 case $1 in
1902 */*)
1903 change_id=${1%%/*}
1904 patchset_id=${1#*/}
1905 ;;
1906 *)
1907 change_id=$1
1908 patchset_id=1
1909 ;;
1910 esac
1911 hash=$(($change_id % 100))
1912 case $hash in
1913 [0-9]) hash="0$hash" ;;
1914 esac
1915 echo "refs/changes/$hash/$change_id/$patchset_id"
1916 ;;
1917 fetch|pull)
1918 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1919 $FUNCNAME __cmg_err_not_repo && return 1
1920 local change=$1
1921 shift
1922 git $command $@ http://$review/p/$project \
1923 $($FUNCNAME __cmg_get_ref $change) || return 1
1924 ;;
1925 push)
1926 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1927 $FUNCNAME __cmg_err_not_repo && return 1
1928 if [ -z "$user" ]; then
1929 echo >&2 "Gerrit username not found."
1930 return 1
1931 fi
1932 local local_branch remote_branch
1933 case $1 in
1934 *:*)
1935 local_branch=${1%:*}
1936 remote_branch=${1##*:}
1937 ;;
1938 *)
1939 local_branch=HEAD
1940 remote_branch=$1
1941 ;;
1942 esac
1943 shift
1944 git push $@ ssh://$user@$review:29418/$project \
1945 $local_branch:refs/for/$remote_branch || return 1
1946 ;;
1947 changes|for)
1948 if [ "$FUNCNAME" = "cmgerrit" ]; then
1949 echo >&2 "'$FUNCNAME $command' is deprecated."
1950 fi
1951 ;;
1952 __cmg_err_no_arg)
1953 if [ $# -lt 2 ]; then
1954 echo >&2 "'$FUNCNAME $command' missing argument."
1955 elif [ $2 -eq 0 ]; then
1956 if [ -n "$3" ]; then
1957 $FUNCNAME help $1
1958 else
1959 echo >&2 "'$FUNCNAME $1' missing argument."
1960 fi
1961 else
1962 return 1
1963 fi
1964 ;;
1965 __cmg_err_not_repo)
1966 if [ -z "$review" -o -z "$project" ]; then
1967 echo >&2 "Not currently in any reviewable repository."
1968 else
1969 return 1
1970 fi
1971 ;;
1972 __cmg_err_not_supported)
1973 $FUNCNAME __cmg_err_no_arg $command $# && return
1974 case $1 in
1975 #TODO: filter more git commands that don't use refname
1976 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1977 echo >&2 "'$FUNCNAME $1' is not supported."
1978 ;;
1979 *) return 1 ;;
1980 esac
1981 ;;
1982 #TODO: other special cases?
1983 *)
1984 $FUNCNAME __cmg_err_not_supported $command && return 1
1985 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1986 $FUNCNAME __cmg_err_not_repo && return 1
1987 local args="$@"
1988 local change pre_args refs_arg post_args
1989 case "$args" in
1990 *--\ *)
1991 pre_args=${args%%-- *}
1992 post_args="-- ${args#*-- }"
1993 ;;
1994 *) pre_args="$args" ;;
1995 esac
1996 args=($pre_args)
1997 pre_args=
1998 if [ ${#args[@]} -gt 0 ]; then
1999 change=${args[${#args[@]}-1]}
2000 fi
2001 if [ ${#args[@]} -gt 1 ]; then
2002 pre_args=${args[0]}
2003 for ((i=1; i<${#args[@]}-1; i++)); do
2004 pre_args="$pre_args ${args[$i]}"
2005 done
2006 fi
2007 while ((1)); do
2008 case $change in
2009 ""|--)
2010 $FUNCNAME help $command
2011 return 1
2012 ;;
2013 *@*)
2014 if [ -z "$refs_arg" ]; then
2015 refs_arg="@${change#*@}"
2016 change=${change%%@*}
2017 fi
2018 ;;
2019 *~*)
2020 if [ -z "$refs_arg" ]; then
2021 refs_arg="~${change#*~}"
2022 change=${change%%~*}
2023 fi
2024 ;;
2025 *^*)
2026 if [ -z "$refs_arg" ]; then
2027 refs_arg="^${change#*^}"
2028 change=${change%%^*}
2029 fi
2030 ;;
2031 *:*)
2032 if [ -z "$refs_arg" ]; then
2033 refs_arg=":${change#*:}"
2034 change=${change%%:*}
2035 fi
2036 ;;
2037 *) break ;;
2038 esac
2039 done
2040 $FUNCNAME fetch $change \
2041 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2042 || return 1
2043 ;;
2044 esac
2045}
2046
2047function cmrebase() {
2048 local repo=$1
2049 local refs=$2
2050 local pwd="$(pwd)"
2051 local dir="$(gettop)/$repo"
2052
2053 if [ -z $repo ] || [ -z $refs ]; then
2054 echo "CyanogenMod Gerrit Rebase Usage: "
2055 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2056 echo " The patch IDs appear on the Gerrit commands that are offered."
2057 echo " They consist on a series of numbers and slashes, after the text"
2058 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2059 echo ""
2060 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2061 echo ""
2062 return
2063 fi
2064
2065 if [ ! -d $dir ]; then
2066 echo "Directory $dir doesn't exist in tree."
2067 return
2068 fi
2069 cd $dir
2070 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2071 echo "Starting branch..."
2072 repo start tmprebase .
2073 echo "Bringing it up to date..."
2074 repo sync .
2075 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07002076 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002077 if [ "$?" != "0" ]; then
2078 echo "Error cherry-picking. Not uploading!"
2079 return
2080 fi
2081 echo "Uploading..."
2082 repo upload .
2083 echo "Cleaning up..."
2084 repo abandon tmprebase .
2085 cd $pwd
2086}
2087
2088function mka() {
2089 case `uname -s` in
2090 Darwin)
2091 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2092 ;;
2093 *)
Anthony King40b093f2015-04-30 22:19:48 +01002094 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 -06002095 ;;
2096 esac
2097}
2098
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302099function cmka() {
2100 if [ ! -z "$1" ]; then
2101 for i in "$@"; do
2102 case $i in
2103 bacon|otapackage|systemimage)
2104 mka installclean
2105 mka $i
2106 ;;
2107 *)
2108 mka clean-$i
2109 mka $i
2110 ;;
2111 esac
2112 done
2113 else
2114 mka clean
2115 mka
2116 fi
2117}
2118
Matt Mower8dacaed2013-12-29 12:57:20 -06002119function repolastsync() {
2120 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
2121 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
2122 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
2123 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
2124}
2125
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002126function reposync() {
2127 case `uname -s` in
2128 Darwin)
2129 repo sync -j 4 "$@"
2130 ;;
2131 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002132 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002133 ;;
2134 esac
2135}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002136
2137function repodiff() {
2138 if [ -z "$*" ]; then
2139 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2140 return
2141 fi
2142 diffopts=$* repo forall -c \
2143 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2144}
2145
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302146# Credit for color strip sed: http://goo.gl/BoIcm
2147function dopush()
2148{
2149 local func=$1
2150 shift
2151
2152 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2153 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2154 echo "No device is online. Waiting for one..."
2155 echo "Please connect USB and/or enable USB debugging"
2156 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2157 sleep 1
2158 done
2159 echo "Device Found."
2160 fi
2161
Steve Kondikec4627c2015-07-10 02:31:24 -07002162 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD") || [ "$FORCE_PUSH" == "true" ];
Chirayu Desai6dadb572012-12-26 10:53:58 +05302163 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002164 # retrieve IP and PORT info if we're using a TCP connection
2165 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2166 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302167 adb root &> /dev/null
2168 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002169 if [ -n "$TCPIPPORT" ]
2170 then
2171 # adb root just killed our connection
2172 # so reconnect...
2173 adb connect "$TCPIPPORT"
2174 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302175 adb wait-for-device &> /dev/null
2176 sleep 0.3
2177 adb remount &> /dev/null
2178
Matt Mower668ea262014-05-20 02:52:23 -05002179 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00002180 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2181 ret=$?;
2182 if [ $ret -ne 0 ]; then
2183 rm -f $OUT/.log;return $ret
2184 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302185
2186 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002187 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 +05302188
2189 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002190 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 +05302191
Matt Mower668ea262014-05-20 02:52:23 -05002192 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302193 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002194 # Make sure file is in $OUT/system
2195 case $FILE in
2196 $OUT/system/*)
2197 # Get target file name (i.e. /system/bin/adb)
2198 TARGET=$(echo $FILE | sed "s#$OUT##")
2199 ;;
2200 *) continue ;;
2201 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302202
Matt Mower668ea262014-05-20 02:52:23 -05002203 case $TARGET in
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002204 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002205 # Only need to stop services once
2206 if ! $stop_n_start; then
2207 adb shell stop
2208 stop_n_start=true
2209 fi
2210 echo "Pushing: $TARGET"
2211 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302212 ;;
2213 *)
Matt Mower668ea262014-05-20 02:52:23 -05002214 echo "Pushing: $TARGET"
2215 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302216 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002217 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302218 done
Matt Mower668ea262014-05-20 02:52:23 -05002219 if $stop_n_start; then
2220 adb shell start
2221 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302222 rm -f $OUT/.log
2223 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302224 else
2225 echo "The connected device does not appear to be $CM_BUILD, run away!"
2226 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302227}
2228
2229alias mmp='dopush mm'
2230alias mmmp='dopush mmm'
2231alias mkap='dopush mka'
2232alias cmkap='dopush cmka'
2233
Chirayu Desai4a319b82013-06-05 20:14:33 +05302234function repopick() {
2235 T=$(gettop)
2236 $T/build/tools/repopick.py $@
2237}
2238
Chirayu Desaib89b3242013-06-30 10:04:25 +05302239function fixup_common_out_dir() {
2240 common_out_dir=$(get_build_var OUT_DIR)/target/common
2241 target_device=$(get_build_var TARGET_DEVICE)
2242 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2243 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2244 mv ${common_out_dir} ${common_out_dir}-${target_device}
2245 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2246 else
2247 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2248 mkdir -p ${common_out_dir}-${target_device}
2249 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2250 fi
2251 else
2252 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2253 mkdir -p ${common_out_dir}
2254 fi
2255}
2256
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002257# 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 +00002258#
2259# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2260# For some reason, installing the JDK doesn't make it show up in the
2261# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002262function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002263 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002264 # we can reset it later, depending on the version of java the build
2265 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002266 #
2267 # If we don't do this, the JAVA_HOME value set by the first call to
2268 # build/envsetup.sh will persist forever.
2269 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2270 export JAVA_HOME=""
2271 fi
2272
Andy McFaddenbd960942010-06-24 12:52:51 -07002273 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002274 case `uname -s` in
2275 Darwin)
2276 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2277 ;;
2278 *)
2279 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2280 ;;
2281 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002282
2283 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2284 # we can change it on the next envsetup.sh, if required.
2285 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002286 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002287}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002288
Alex Rayf0d08eb2013-03-08 15:15:06 -08002289# Print colored exit condition
2290function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002291 "$@"
2292 local retval=$?
2293 if [ $retval -ne 0 ]
2294 then
2295 echo -e "\e[0;31mFAILURE\e[00m"
2296 else
2297 echo -e "\e[0;32mSUCCESS\e[00m"
2298 fi
2299 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002300}
2301
Ying Wanged21d4c2014-08-24 22:14:19 -07002302function get_make_command()
2303{
2304 echo command make
2305}
2306
Anthony King40b093f2015-04-30 22:19:48 +01002307function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002308{
2309 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002310 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002311 local ret=$?
2312 local end_time=$(date +"%s")
2313 local tdiff=$(($end_time-$start_time))
2314 local hours=$(($tdiff / 3600 ))
2315 local mins=$((($tdiff % 3600) / 60))
2316 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002317 local ncolors=$(tput colors 2>/dev/null)
2318 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2319 color_failed="\e[0;31m"
2320 color_success="\e[0;32m"
2321 color_reset="\e[00m"
2322 else
2323 color_failed=""
2324 color_success=""
2325 color_reset=""
2326 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002327 echo
2328 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002329 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002330 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002331 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002332 fi
2333 if [ $hours -gt 0 ] ; then
2334 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2335 elif [ $mins -gt 0 ] ; then
2336 printf "(%02g:%02g (mm:ss))" $mins $secs
2337 elif [ $secs -gt 0 ] ; then
2338 printf "(%s seconds)" $secs
2339 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002340 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002341 echo
2342 return $ret
2343}
2344
Anthony King40b093f2015-04-30 22:19:48 +01002345function make()
2346{
2347 mk_timer $(get_make_command) "$@"
2348}
2349
Raphael Moll70a86b02011-06-20 16:03:14 -07002350if [ "x$SHELL" != "x/bin/bash" ]; then
2351 case `ps -o command -p $$` in
2352 *bash*)
2353 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002354 *zsh*)
2355 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002356 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002357 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002358 ;;
2359 esac
2360fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002361
2362# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002363for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2364 `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 -08002365do
2366 echo "including $f"
2367 . $f
2368done
2369unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002370
Kyle Ladd031a0b62013-09-11 20:43:42 -04002371# Add completions
2372check_bash_version && {
2373 dirs="sdk/bash_completion vendor/cm/bash_completion"
2374 for dir in $dirs; do
2375 if [ -d ${dir} ]; then
2376 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2377 echo "including $f"
2378 . $f
2379 done
2380 fi
2381 done
2382}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302383
2384export ANDROID_BUILD_TOP=$(gettop)