blob: c62a57f9ca8cd913efe9c516b0f48abc7cb387cd [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.
Martin Brabhamb77db582016-02-05 15:59:21 -050014- mmap: Builds all of the modules in the current directory, and its dependencies, then pushes the package to the device.
Daniel Bateman22185ba2012-08-04 03:48:09 -050015- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080016- mmma: Builds all of the modules in the supplied directories, and their dependencies.
Khalid Zubairfdc26cd2015-10-21 12:43:14 -070017- mms: Short circuit builder. Quickly re-build the kernel, rootfs, boot and system images
18 without deep dependencies. Requires the full build to have run before.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070019- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070020- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070021- jgrep: Greps on all local Java files.
22- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000023- mangrep: Greps on all local AndroidManifest.xml files.
24- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070025- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080026- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060027- cmremote: Add git remote for CM Gerrit Review
28- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
29- cmrebase: Rebase a Gerrit change and push it again
Steve Kondik873fa562012-09-17 11:33:18 -070030- aospremote: Add git remote for matching AOSP repository
Steve Kondik20c21d22013-10-27 13:34:36 -070031- cafremote: Add git remote for matching CodeAurora repository.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060032- mka: Builds using SCHED_BATCH on all processors
Chirayu Desaicf2bdb62012-09-28 11:56:02 +053033- mkap: Builds the module(s) using mka and pushes them to the device.
34- cmka: Cleans and builds using mka.
Matt Mower8dacaed2013-12-29 12:57:20 -060035- repolastsync: Prints date and time of last repo sync.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060036- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053037- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070038- installboot: Installs a boot.img to the connected device.
39- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070040
Dan Albert4ae5d4b2014-10-31 16:23:08 -070041Environemnt options:
42- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
43 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
44 build is leak-check clean.
45
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070046Look at the source to view more functions. The complete list is:
47EOF
48 T=$(gettop)
Jeff Brown46cbd202014-07-26 15:15:41 -070049 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 +010050 echo "$i"
51 done | column
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070052}
53
54# Get the value of a build variable as an absolute path.
55function get_abs_build_var()
56{
57 T=$(gettop)
58 if [ ! "$T" ]; then
59 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
60 return
61 fi
Ying Wang9cd17642012-12-13 10:52:07 -080062 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070063 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070064}
65
66# Get the exact value of a build variable.
67function get_build_var()
68{
69 T=$(gettop)
70 if [ ! "$T" ]; then
71 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
72 return
73 fi
Andrew Boie6905e212013-12-19 13:21:46 -080074 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070075 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080076}
77
78# check to see if the supplied product is one we can build
79function check_product()
80{
81 T=$(gettop)
82 if [ ! "$T" ]; then
83 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
84 return
85 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000086
87 if (echo -n $1 | grep -q -e "^cm_") ; then
88 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
Ricardo Cerqueira34ae3232013-09-26 00:10:20 +010089 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 +000090 else
91 CM_BUILD=
92 fi
93 export CM_BUILD
94
Jeff Browne33ba4c2011-07-11 22:11:46 -070095 TARGET_PRODUCT=$1 \
96 TARGET_BUILD_VARIANT= \
97 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070098 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080099 get_build_var TARGET_DEVICE > /dev/null
100 # hide successful answers, but allow the errors to show
101}
102
103VARIANT_CHOICES=(user userdebug eng)
104
105# check to see if the supplied variant is valid
106function check_variant()
107{
108 for v in ${VARIANT_CHOICES[@]}
109 do
110 if [ "$v" = "$1" ]
111 then
112 return 0
113 fi
114 done
115 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700116}
117
118function setpaths()
119{
120 T=$(gettop)
121 if [ ! "$T" ]; then
122 echo "Couldn't locate the top of the tree. Try setting TOP."
123 return
124 fi
125
126 ##################################################################
127 # #
128 # Read me before you modify this code #
129 # #
130 # This function sets ANDROID_BUILD_PATHS to what it is adding #
131 # to PATH, and the next time it is run, it removes that from #
132 # PATH. This is required so lunch can be run more than once #
133 # and still have working paths. #
134 # #
135 ##################################################################
136
Raphael Mollc639c782011-06-20 17:25:01 -0700137 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
138 # due to "C:\Program Files" being in the path.
139
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700140 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700141 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700142 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
143 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700144 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700145 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800146 # strip leading ':', if any
147 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500148 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700149
150 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700151 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700152 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700153
Ben Cheng8bc4c432012-11-16 13:29:13 -0800154 # defined in core/config.mk
155 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700156 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Brandon McAnshfaf35352015-10-10 10:20:38 -0400157 targetlegacygccversion=$(get_build_var TARGET_LEGACY_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800158 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800159
Raphael Mollc639c782011-06-20 17:25:01 -0700160 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800161 export ANDROID_TOOLCHAIN=
162 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200163 local ARCH=$(get_build_var TARGET_ARCH)
164 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400165 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700166 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400167 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
168 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800169 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200170 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800171 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700172 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700173 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700174 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000175 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200176 *)
177 echo "Can't find toolchain for unknown architecture: $ARCH"
178 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700179 ;;
180 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700181 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800182 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700183 fi
Raphael732936d2011-06-22 14:35:32 -0700184
Ben Chengfba67bf2014-02-25 10:27:07 -0800185 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
186 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
187 fi
188
189 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700190 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700191 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800192 # Legacy toolchain configuration used for ARM kernel compilation
Brandon McAnshfaf35352015-10-10 10:20:38 -0400193 toolchaindir=arm/arm-eabi-$targetlegacygccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700194 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100195 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
196 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700197 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700198 ;;
199 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700200 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700201 ;;
202 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700203
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700204 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700205 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 +0200206
207 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
208 # to ensure that the corresponding 'emulator' binaries are used.
209 case $(uname -s) in
210 Darwin)
211 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
212 ;;
213 Linux)
214 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
215 ;;
216 *)
217 ANDROID_EMULATOR_PREBUILTS=
218 ;;
219 esac
220 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700221 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200222 export ANDROID_EMULATOR_PREBUILTS
223 fi
224
Ying Wangaa1c9b52012-11-26 20:51:59 -0800225 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800226
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500227 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900228 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500229 if [ -n "$JAVA_HOME" ]; then
230 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900231 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
232 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500233 fi
234
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800235 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700236 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
237 export OUT=$ANDROID_PRODUCT_OUT
238
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700239 unset ANDROID_HOST_OUT
240 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
241
Matt Mowerf8ff73e2015-06-09 19:35:53 -0500242 if [ -n "$ANDROID_CCACHE_DIR" ]; then
243 export CCACHE_DIR=$ANDROID_CCACHE_DIR
244 fi
245
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800246 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700247 # TODO: fix the path
248 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
249}
250
251function printconfig()
252{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800253 T=$(gettop)
254 if [ ! "$T" ]; then
255 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
256 return
257 fi
258 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700259}
260
261function set_stuff_for_environment()
262{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800263 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500264 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800265 setpaths
266 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700267
Ben Chengaac3f812013-08-13 14:38:15 -0700268 # With this environment variable new GCC can apply colors to warnings/errors
269 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 -0700270 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700271}
272
273function set_sequence_number()
274{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700275 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700276}
277
278function settitle()
279{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800280 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700281 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700282 local product=$TARGET_PRODUCT
283 local variant=$TARGET_BUILD_VARIANT
284 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800285 if [ -z "$PROMPT_COMMAND" ]; then
286 # No prompts
287 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
288 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
289 # Prompts exist, but no hardstatus
290 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700291 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800292 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500293 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800294 fi
295
296 if [ -z "$apps" ]; then
297 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
298 else
299 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
300 fi
301 export ANDROID_PROMPT_PREFIX
302
303 # Inject build data into hardstatus
304 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 -0800305 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700306}
307
Kyle Ladd031a0b62013-09-11 20:43:42 -0400308function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700309{
Kenny Root52aa81c2011-07-15 11:07:06 -0700310 # Keep us from trying to run in something that isn't bash.
311 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400312 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700313 fi
314
315 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200316 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400317 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700318 fi
319
Kyle Ladd031a0b62013-09-11 20:43:42 -0400320 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700321}
322
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700323function choosetype()
324{
325 echo "Build type choices are:"
326 echo " 1. release"
327 echo " 2. debug"
328 echo
329
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800330 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700331 DEFAULT_NUM=1
332 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800334 export TARGET_BUILD_TYPE=
335 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700336 while [ -z $TARGET_BUILD_TYPE ]
337 do
338 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800339 if [ -z "$1" ] ; then
340 read ANSWER
341 else
342 echo $1
343 ANSWER=$1
344 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700345 case $ANSWER in
346 "")
347 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
348 ;;
349 1)
350 export TARGET_BUILD_TYPE=release
351 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800352 release)
353 export TARGET_BUILD_TYPE=release
354 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700355 2)
356 export TARGET_BUILD_TYPE=debug
357 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800358 debug)
359 export TARGET_BUILD_TYPE=debug
360 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700361 *)
362 echo
363 echo "I didn't understand your response. Please try again."
364 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700365 ;;
366 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800367 if [ -n "$1" ] ; then
368 break
369 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700370 done
371
372 set_stuff_for_environment
373}
374
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800375#
376# This function isn't really right: It chooses a TARGET_PRODUCT
377# based on the list of boards. Usually, that gets you something
378# that kinda works with a generic product, but really, you should
379# pick a product by name.
380#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700381function chooseproduct()
382{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700383 if [ "x$TARGET_PRODUCT" != x ] ; then
384 default_value=$TARGET_PRODUCT
385 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700386 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700387 fi
388
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800389 export TARGET_PRODUCT=
390 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700391 while [ -z "$TARGET_PRODUCT" ]
392 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700393 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800394 if [ -z "$1" ] ; then
395 read ANSWER
396 else
397 echo $1
398 ANSWER=$1
399 fi
400
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700401 if [ -z "$ANSWER" ] ; then
402 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800403 else
404 if check_product $ANSWER
405 then
406 export TARGET_PRODUCT=$ANSWER
407 else
408 echo "** Not a valid product: $ANSWER"
409 fi
410 fi
411 if [ -n "$1" ] ; then
412 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700413 fi
414 done
415
416 set_stuff_for_environment
417}
418
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800419function choosevariant()
420{
421 echo "Variant choices are:"
422 local index=1
423 local v
424 for v in ${VARIANT_CHOICES[@]}
425 do
426 # The product name is the name of the directory containing
427 # the makefile we found, above.
428 echo " $index. $v"
429 index=$(($index+1))
430 done
431
432 local default_value=eng
433 local ANSWER
434
435 export TARGET_BUILD_VARIANT=
436 while [ -z "$TARGET_BUILD_VARIANT" ]
437 do
438 echo -n "Which would you like? [$default_value] "
439 if [ -z "$1" ] ; then
440 read ANSWER
441 else
442 echo $1
443 ANSWER=$1
444 fi
445
446 if [ -z "$ANSWER" ] ; then
447 export TARGET_BUILD_VARIANT=$default_value
448 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
449 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800450 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800451 fi
452 else
453 if check_variant $ANSWER
454 then
455 export TARGET_BUILD_VARIANT=$ANSWER
456 else
457 echo "** Not a valid variant: $ANSWER"
458 fi
459 fi
460 if [ -n "$1" ] ; then
461 break
462 fi
463 done
464}
465
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466function choosecombo()
467{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700468 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700469
470 echo
471 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700472 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700473
474 echo
475 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700476 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477
478 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700479 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700481}
482
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800483# Clear this variable. It will be built up again when the vendorsetup.sh
484# files are included at the end of this file.
485unset LUNCH_MENU_CHOICES
486function add_lunch_combo()
487{
488 local new_combo=$1
489 local c
490 for c in ${LUNCH_MENU_CHOICES[@]} ; do
491 if [ "$new_combo" = "$c" ] ; then
492 return
493 fi
494 done
495 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
496}
497
498# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700499add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800500add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000501add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800502add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000503add_lunch_combo aosp_x86-eng
504add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800505
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506function print_lunch_menu()
507{
508 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700509 echo
510 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000511 if [ "$(uname)" = "Darwin" ] ; then
512 echo " (ohai, koush!)"
513 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700514 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000515 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
516 echo "Breakfast menu... pick a combo:"
517 else
518 echo "Lunch menu... pick a combo:"
519 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800520
521 local i=1
522 local choice
523 for choice in ${LUNCH_MENU_CHOICES[@]}
524 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100525 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800526 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100527 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800528
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000529 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
530 echo "... and don't forget the bacon!"
531 fi
532
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700533 echo
534}
535
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000536function brunch()
537{
538 breakfast $*
539 if [ $? -eq 0 ]; then
540 mka bacon
541 else
542 echo "No such item in brunch menu. Try 'breakfast'"
543 return 1
544 fi
545 return $?
546}
547
548function breakfast()
549{
550 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200551 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000552 CM_DEVICES_ONLY="true"
553 unset LUNCH_MENU_CHOICES
554 add_lunch_combo full-eng
555 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
556 do
557 echo "including $f"
558 . $f
559 done
560 unset f
561
562 if [ $# -eq 0 ]; then
563 # No arguments, so let's have the full menu
564 lunch
565 else
566 echo "z$target" | grep -q "-"
567 if [ $? -eq 0 ]; then
568 # A buildtype was specified, assume a full device name
569 lunch $target
570 else
571 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200572 if [ -z "$variant" ]; then
573 variant="userdebug"
574 fi
575 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000576 fi
577 fi
578 return $?
579}
580
581alias bib=breakfast
582
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700583function lunch()
584{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800585 local answer
Anthony King850627c2015-04-30 22:57:08 +0100586 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800587
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700588 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800589 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700590 else
591 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700592 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700594 fi
595
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800596 local selection=
597
598 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700599 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700600 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800601 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
602 then
603 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
604 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800605 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800606 fi
607 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
608 then
609 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700610 fi
611
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800612 if [ -z "$selection" ]
613 then
614 echo
615 echo "Invalid lunch combo: $answer"
616 return 1
617 fi
618
Joe Onoratoda12daf2010-06-09 18:18:31 -0700619 export TARGET_BUILD_APPS=
620
Jeff Browne33ba4c2011-07-11 22:11:46 -0700621 local product=$(echo -n $selection | sed -e "s/-.*$//")
622 check_product $product
623 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800624 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800625 # if we can't find a product, try to grab it off the CM github
626 T=$(gettop)
627 pushd $T > /dev/null
628 build/tools/roomservice.py $product
629 popd > /dev/null
630 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000631 else
632 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800633 fi
634 if [ $? -ne 0 ]
635 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700636 echo
637 echo "** Don't have a product spec for: '$product'"
638 echo "** Do you have the right repo manifest?"
639 product=
640 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800641
Jeff Browne33ba4c2011-07-11 22:11:46 -0700642 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
643 check_variant $variant
644 if [ $? -ne 0 ]
645 then
646 echo
647 echo "** Invalid variant: '$variant'"
648 echo "** Must be one of ${VARIANT_CHOICES[@]}"
649 variant=
650 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800651
Jeff Browne33ba4c2011-07-11 22:11:46 -0700652 if [ -z "$product" -o -z "$variant" ]
653 then
654 echo
655 return 1
656 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800657
Jeff Browne33ba4c2011-07-11 22:11:46 -0700658 export TARGET_PRODUCT=$product
659 export TARGET_BUILD_VARIANT=$variant
660 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700661
662 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800663
Chirayu Desaib89b3242013-06-30 10:04:25 +0530664 fixup_common_out_dir
665
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700666 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800667 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700668}
669
Jeff Davidson513d7a42010-08-02 10:00:44 -0700670# Tab completion for lunch.
671function _lunch()
672{
673 local cur prev opts
674 COMPREPLY=()
675 cur="${COMP_WORDS[COMP_CWORD]}"
676 prev="${COMP_WORDS[COMP_CWORD-1]}"
677
678 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
679 return 0
680}
Emilio López9ad6eea2013-11-03 13:02:13 -0300681complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700682
Joe Onoratoda12daf2010-06-09 18:18:31 -0700683# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700684# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700685function tapas()
686{
Ying Wangb541ab62014-05-29 17:57:40 -0700687 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 -0700688 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700689 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
690 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 -0700691
Ying Wang67f02922012-08-22 10:25:20 -0700692 if [ $(echo $arch | wc -w) -gt 1 ]; then
693 echo "tapas: Error: Multiple build archs supplied: $arch"
694 return
695 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700696 if [ $(echo $variant | wc -w) -gt 1 ]; then
697 echo "tapas: Error: Multiple build variants supplied: $variant"
698 return
699 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700700 if [ $(echo $density | wc -w) -gt 1 ]; then
701 echo "tapas: Error: Multiple densities supplied: $density"
702 return
703 fi
Ying Wang67f02922012-08-22 10:25:20 -0700704
705 local product=full
706 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700707 x86) product=full_x86;;
708 mips) product=full_mips;;
709 armv5) product=generic_armv5;;
710 arm64) product=aosp_arm64;;
711 x86_64) product=aosp_x86_64;;
712 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700713 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700714 if [ -z "$variant" ]; then
715 variant=eng
716 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700717 if [ -z "$apps" ]; then
718 apps=all
719 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600720 if [ -z "$density" ]; then
721 density=alldpi
722 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700723
Ying Wang67f02922012-08-22 10:25:20 -0700724 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700725 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700726 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700727 export TARGET_BUILD_TYPE=release
728 export TARGET_BUILD_APPS=$apps
729
730 set_stuff_for_environment
731 printconfig
732}
733
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100734function eat()
735{
736 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530737 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100738 ZIPFILE=cm-$MODVERSION.zip
739 ZIPPATH=$OUT/$ZIPFILE
740 if [ ! -f $ZIPPATH ] ; then
741 echo "Nothing to eat"
742 return 1
743 fi
744 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
Steve Kondik58fa7162015-11-15 18:47:58 -0800745 if [ $(adb get-state) != device -a $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100746 echo "No device is online. Waiting for one..."
747 echo "Please connect USB and/or enable USB debugging"
Steve Kondik58fa7162015-11-15 18:47:58 -0800748 until [ $(adb get-state) = device -o $(adb shell test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100749 sleep 1
750 done
751 echo "Device Found.."
752 fi
Steve Kondikec4627c2015-07-10 02:31:24 -0700753 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Chirayu Desai6dadb572012-12-26 10:53:58 +0530754 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100755 # if adbd isn't root we can't write to /cache/recovery/
756 adb root
757 sleep 1
758 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700759 cat << EOF > /tmp/command
Steve Kondike9f828c2015-11-10 23:51:21 +0100760--sideload_auto_reboot
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100761EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700762 if adb push /tmp/command /cache/recovery/ ; then
763 echo "Rebooting into recovery for sideload installation"
764 adb reboot recovery
765 adb wait-for-sideload
766 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100767 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700768 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100769 else
770 echo "Nothing to eat"
771 return 1
772 fi
773 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530774 else
775 echo "The connected device does not appear to be $CM_BUILD, run away!"
776 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100777}
778
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000779function omnom
780{
781 brunch $*
782 eat
783}
784
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785function gettop
786{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800787 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700789 # The following circumlocution ensures we remove symlinks from TOP.
790 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700791 else
792 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800793 # The following circumlocution (repeated below as well) ensures
794 # that we record the true directory name and not one that is
795 # faked up with symlink names.
796 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700797 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800798 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700799 T=
800 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800801 \cd ..
synergyb112a402013-07-05 19:47:47 -0700802 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700803 done
Ying Wang9cd17642012-12-13 10:52:07 -0800804 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700805 if [ -f "$T/$TOPFILE" ]; then
806 echo $T
807 fi
808 fi
809 fi
810}
811
Andrew Hsieh906cb782013-09-10 17:37:14 +0800812# Return driver for "make", if any (eg. static analyzer)
813function getdriver()
814{
815 local T="$1"
816 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
817 if [ -n "$WITH_STATIC_ANALYZER" ]; then
818 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800819$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
820--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800821--status-bugs \
822--top=$T"
823 fi
824}
825
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700826function m()
827{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800828 local T=$(gettop)
829 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700830 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800831 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700832 else
833 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700834 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700835 fi
836}
837
838function findmakefile()
839{
840 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800841 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842 T=
843 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700844 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 if [ -f "$T/Android.mk" ]; then
846 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800847 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848 return
849 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800850 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700851 done
Ying Wang9cd17642012-12-13 10:52:07 -0800852 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700853}
854
855function mm()
856{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800857 local T=$(gettop)
858 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700859 # If we're sitting in the root of the build tree, just do a
860 # normal make.
861 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800862 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700863 else
864 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800865 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700866 local MODULES=
867 local GET_INSTALL_PATH=
868 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700869 # Remove the path to top as the makefilepath needs to be relative
870 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871 if [ ! "$T" ]; then
872 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700873 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700874 elif [ ! "$M" ]; then
875 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700876 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700877 else
Ying Wanga7deb082013-08-16 13:24:47 -0700878 for ARG in $@; do
879 case $ARG in
880 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
881 esac
882 done
883 if [ -n "$GET_INSTALL_PATH" ]; then
884 MODULES=
885 ARGS=GET-INSTALL-PATH
886 else
887 MODULES=all_modules
888 ARGS=$@
889 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700890 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 -0700891 fi
892 fi
893}
894
895function mmm()
896{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800897 local T=$(gettop)
898 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700899 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800900 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800901 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800902 local ARGS=
903 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700904 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800905 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
906 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
907 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800908 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
909 if [ "$MODULES" = "" ]; then
910 MODULES=all_modules
911 fi
912 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700913 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700914 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
915 local TO_CHOP=`expr $TO_CHOP + 1`
916 local START=`PWD= /bin/pwd`
917 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700918 if [ "$MFILE" = "" ] ; then
919 MFILE=$DIR/Android.mk
920 else
921 MFILE=$MFILE/$DIR/Android.mk
922 fi
923 MAKEFILE="$MAKEFILE $MFILE"
924 else
Ying Wanga7deb082013-08-16 13:24:47 -0700925 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100926 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700927 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
Abhinav1997c3eb1072015-10-18 19:49:13 +0200928 *) if [ -d $DIR ]; then
929 echo "No Android.mk in $DIR.";
930 else
931 echo "Couldn't locate the directory $DIR";
932 fi
933 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700934 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700935 fi
936 done
Ying Wanga7deb082013-08-16 13:24:47 -0700937 if [ -n "$GET_INSTALL_PATH" ]; then
938 ARGS=$GET_INSTALL_PATH
939 MODULES=
940 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800941 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 -0700942 else
943 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700944 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700945 fi
946}
947
Ying Wangb607f7b2013-02-08 18:01:04 -0800948function mma()
949{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800950 local T=$(gettop)
951 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800952 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800953 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800954 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800955 if [ ! "$T" ]; then
956 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700957 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800958 fi
959 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800960 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800961 fi
962}
963
964function mmma()
965{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800966 local T=$(gettop)
967 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800968 if [ "$T" ]; then
969 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
970 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
971 local MY_PWD=`PWD= /bin/pwd`
972 if [ "$MY_PWD" = "$T" ]; then
973 MY_PWD=
974 else
975 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
976 fi
977 local DIR=
978 local MODULE_PATHS=
979 local ARGS=
980 for DIR in $DIRS ; do
981 if [ -d $DIR ]; then
982 if [ "$MY_PWD" = "" ]; then
983 MODULE_PATHS="$MODULE_PATHS $DIR"
984 else
985 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
986 fi
987 else
988 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100989 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800990 *) echo "Couldn't find directory $DIR"; return 1;;
991 esac
992 fi
993 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800994 $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 -0800995 else
996 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700997 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800998 fi
999}
1000
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001001function croot()
1002{
1003 T=$(gettop)
1004 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001005 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001006 else
1007 echo "Couldn't locate the top of the tree. Try setting TOP."
1008 fi
1009}
1010
nebkatfb67a1e2012-12-28 10:40:45 +00001011function cout()
1012{
1013 if [ "$OUT" ]; then
1014 cd $OUT
1015 else
1016 echo "Couldn't locate out directory. Try setting OUT."
1017 fi
1018}
1019
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020function cproj()
1021{
1022 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001023 local HERE=$PWD
1024 T=
1025 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1026 T=$PWD
1027 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001028 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001029 return
1030 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001031 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001032 done
Ying Wang9cd17642012-12-13 10:52:07 -08001033 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001034 echo "can't find Android.mk"
1035}
1036
Daniel Sandler47e0a882013-07-30 13:23:52 -04001037# simplified version of ps; output in the form
1038# <pid> <procname>
1039function qpid() {
1040 local prepend=''
1041 local append=''
1042 if [ "$1" = "--exact" ]; then
1043 prepend=' '
1044 append='$'
1045 shift
1046 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1047 echo "usage: qpid [[--exact] <process name|pid>"
1048 return 255
1049 fi
1050
1051 local EXE="$1"
1052 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001053 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001054 else
1055 adb shell ps \
1056 | tr -d '\r' \
1057 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1058 fi
1059}
1060
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001061function pid()
1062{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001063 local prepend=''
1064 local append=''
1065 if [ "$1" = "--exact" ]; then
1066 prepend=' '
1067 append='$'
1068 shift
1069 fi
1070 local EXE="$1"
1071 if [ "$EXE" ] ; then
1072 local PID=`adb shell ps \
1073 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001074 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001075 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1076 echo "$PID"
1077 else
1078 echo "usage: pid [--exact] <process name>"
1079 return 255
1080 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001081}
1082
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001083# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001084# that has the core-file-size limit set correctly
1085#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001086# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001087# if its core-file-size limit is not set already.
1088# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1089
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001090function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001091{
1092 echo "Getting root...";
1093 adb root;
1094 adb wait-for-device;
1095
1096 echo "Remounting root parition read-write...";
1097 adb shell mount -w -o remount -t rootfs rootfs;
1098 sleep 1;
1099 adb wait-for-device;
1100 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001101 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001102 adb shell chmod 0777 /cores;
1103
1104 echo "Granting SELinux permission to dump in /cores...";
1105 adb shell restorecon -R /cores;
1106
1107 echo "Set core pattern.";
1108 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1109
1110 echo "Done."
1111}
1112
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001113# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001114# $1 = PID of process (e.g., $(pid mediaserver))
1115#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001116# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001117# dump to actually be generated.
1118
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001119function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001120{
1121 local PID=$1;
1122 if [ -z "$PID" ]; then
1123 printf "Expecting a PID!\n";
1124 return;
1125 fi;
1126 echo "Setting core limit for $PID to infinite...";
1127 adb shell prlimit $PID 4 -1 -1
1128}
1129
1130# core - send SIGV and pull the core for process
1131# $1 = PID of process (e.g., $(pid mediaserver))
1132#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001133# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001134# enabled globally.
1135
1136function core()
1137{
1138 local PID=$1;
1139
1140 if [ -z "$PID" ]; then
1141 printf "Expecting a PID!\n";
1142 return;
1143 fi;
1144
1145 local CORENAME=core.$PID;
1146 local COREPATH=/cores/$CORENAME;
1147 local SIG=SEGV;
1148
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001149 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001150
1151 local done=0;
1152 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1153 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1154 adb shell kill -$SIG $PID;
1155 sleep 1;
1156 done;
1157
1158 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1159 echo "Done: core is under $COREPATH on device.";
1160}
1161
Christopher Tate744ee802009-11-12 15:33:08 -08001162# systemstack - dump the current stack trace of all threads in the system process
1163# to the usual ANR traces file
1164function systemstack()
1165{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001166 stacks system_server
1167}
1168
1169function stacks()
1170{
1171 if [[ $1 =~ ^[0-9]+$ ]] ; then
1172 local PID="$1"
1173 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001174 local PIDLIST="$(pid $1)"
1175 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1176 local PID="$PIDLIST"
1177 elif [ "$PIDLIST" ] ; then
1178 echo "more than one process: $1"
1179 else
1180 echo "no such process: $1"
1181 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001182 else
1183 echo "usage: stacks [pid|process name]"
1184 fi
1185
1186 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001187 # Determine whether the process is native
1188 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1189 # Dump stacks of Dalvik process
1190 local TRACES=/data/anr/traces.txt
1191 local ORIG=/data/anr/traces.orig
1192 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001193
Jeff Brownb12c2e52013-08-19 15:14:16 -07001194 # Keep original traces to avoid clobbering
1195 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001196
Jeff Brownb12c2e52013-08-19 15:14:16 -07001197 # Make sure we have a usable file
1198 adb shell touch $TRACES
1199 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001200
Jeff Brownb12c2e52013-08-19 15:14:16 -07001201 # Dump stacks and wait for dump to finish
1202 adb shell kill -3 $PID
1203 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001204
Jeff Brownb12c2e52013-08-19 15:14:16 -07001205 # Restore original stacks, and show current output
1206 adb shell mv $TRACES $TMP
1207 adb shell mv $ORIG $TRACES
1208 adb shell cat $TMP
1209 else
1210 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001211 local USE64BIT="$(is64bit $PID)"
1212 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001213 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001214 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001215}
1216
Michael Wrightaeed7212014-06-19 19:58:12 -07001217# Read the ELF header from /proc/$PID/exe to determine if the process is
1218# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001219function is64bit()
1220{
1221 local PID="$1"
1222 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001223 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001224 echo "64"
1225 else
1226 echo ""
1227 fi
1228 else
1229 echo ""
1230 fi
1231}
1232
Clark Scheff75b36a42014-12-23 13:30:51 -08001233function dddclient()
1234{
1235 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1236 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1237 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1238 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1239 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1240 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1241 local ARCH=$(get_build_var TARGET_ARCH)
1242 local GDB
1243 case "$ARCH" in
1244 arm) GDB=arm-linux-androideabi-gdb;;
1245 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1246 mips|mips64) GDB=mips64el-linux-android-gdb;;
1247 x86) GDB=x86_64-linux-android-gdb;;
1248 x86_64) GDB=x86_64-linux-android-gdb;;
1249 *) echo "Unknown arch $ARCH"; return 1;;
1250 esac
1251
1252 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1253 local EXE="$1"
1254 if [ "$EXE" ] ; then
1255 EXE=$1
1256 if [[ $EXE =~ ^[^/].* ]] ; then
1257 EXE="system/bin/"$EXE
1258 fi
1259 else
1260 EXE="app_process"
1261 fi
1262
1263 local PORT="$2"
1264 if [ "$PORT" ] ; then
1265 PORT=$2
1266 else
1267 PORT=":5039"
1268 fi
1269
1270 local PID="$3"
1271 if [ "$PID" ] ; then
1272 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1273 PID=`pid $3`
1274 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1275 # that likely didn't work because of returning multiple processes
1276 # try again, filtering by root processes (don't contain colon)
1277 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1278 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1279 then
1280 echo "Couldn't resolve '$3' to single PID"
1281 return 1
1282 else
1283 echo ""
1284 echo "WARNING: multiple processes matching '$3' observed, using root process"
1285 echo ""
1286 fi
1287 fi
1288 fi
1289 adb forward "tcp$PORT" "tcp$PORT"
1290 local USE64BIT="$(is64bit $PID)"
1291 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1292 sleep 2
1293 else
1294 echo ""
1295 echo "If you haven't done so already, do this first on the device:"
1296 echo " gdbserver $PORT /system/bin/$EXE"
1297 echo " or"
1298 echo " gdbserver $PORT --attach <PID>"
1299 echo ""
1300 fi
1301
1302 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1303 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1304
1305 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1306 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"
1307 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1308 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1309 # Enable special debugging for ART processes.
1310 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1311 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1312 fi
1313 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1314
1315 local WHICH_GDB=
1316 # 64-bit exe found
1317 if [ "$USE64BIT" != "" ] ; then
1318 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1319 # 32-bit exe / 32-bit platform
1320 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1321 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1322 # 32-bit exe / 64-bit platform
1323 else
1324 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1325 fi
1326
1327 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1328 else
1329 echo "Unable to determine build system output dir."
1330 fi
1331}
1332
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001333case `uname -s` in
1334 Darwin)
1335 function sgrep()
1336 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001337 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 -07001338 }
1339
1340 ;;
1341 *)
1342 function sgrep()
1343 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001344 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 -07001345 }
1346 ;;
1347esac
1348
Raghu Gandham8da43102012-07-25 19:57:22 -07001349function gettargetarch
1350{
1351 get_build_var TARGET_ARCH
1352}
1353
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001354function ggrep()
1355{
1356 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1357}
1358
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001359function jgrep()
1360{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001361 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 -07001362}
1363
1364function cgrep()
1365{
Dan Albert01961192014-11-22 10:16:01 -08001366 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 -07001367}
1368
1369function resgrep()
1370{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001371 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 -07001372}
1373
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001374function mangrep()
1375{
1376 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1377}
1378
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001379function sepgrep()
1380{
1381 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 "$@"
1382}
1383
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001384function rcgrep()
1385{
1386 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1387}
1388
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001389case `uname -s` in
1390 Darwin)
1391 function mgrep()
1392 {
Ying Wang324c2b22012-08-17 15:03:20 -07001393 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 -07001394 }
1395
1396 function treegrep()
1397 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001398 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 -07001399 }
1400
1401 ;;
1402 *)
1403 function mgrep()
1404 {
Ying Wang324c2b22012-08-17 15:03:20 -07001405 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 -07001406 }
1407
1408 function treegrep()
1409 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001410 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 -07001411 }
1412
1413 ;;
1414esac
1415
1416function getprebuilt
1417{
1418 get_abs_build_var ANDROID_PREBUILTS
1419}
1420
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001421function tracedmdump()
1422{
1423 T=$(gettop)
1424 if [ ! "$T" ]; then
1425 echo "Couldn't locate the top of the tree. Try setting TOP."
1426 return
1427 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001428 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001429 local arch=$(gettargetarch)
1430 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001431
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001432 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001433 if [ ! "$TRACE" ] ; then
1434 echo "usage: tracedmdump tracename"
1435 return
1436 fi
1437
Jack Veenstra60116fc2009-04-09 18:12:34 -07001438 if [ ! -r "$KERNEL" ] ; then
1439 echo "Error: cannot find kernel: '$KERNEL'"
1440 return
1441 fi
1442
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001443 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001444 if [ "$BASETRACE" = "$TRACE" ] ; then
1445 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1446 fi
1447
1448 echo "post-processing traces..."
1449 rm -f $TRACE/qtrace.dexlist
1450 post_trace $TRACE
1451 if [ $? -ne 0 ]; then
1452 echo "***"
1453 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1454 echo "***"
1455 return
1456 fi
1457 echo "generating dexlist output..."
1458 /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
1459 echo "generating dmtrace data..."
1460 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1461 echo "generating html file..."
1462 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1463 echo "done, see $TRACE/dmtrace.html for details"
1464 echo "or run:"
1465 echo " traceview $TRACE/dmtrace"
1466}
1467
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001468# communicate with a running device or emulator, set up necessary state,
1469# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001470function runhat()
1471{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001472 # process standard adb options
1473 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001474 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001475 adbTarget=$1
1476 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001477 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001478 adbTarget="$1 $2"
1479 shift 2
1480 fi
1481 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001482 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001483
1484 # runhat options
1485 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001486
1487 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001488 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001489 return
1490 fi
1491
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001492 # confirm hat is available
1493 if [ -z $(which hat) ]; then
1494 echo "hat is not available in this configuration."
1495 return
1496 fi
1497
Andy McFaddenb6289852010-07-12 08:00:19 -07001498 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001499 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001500 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001501 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001502 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001503 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001504 echo -n "> "
1505 read
1506
The Android Open Source Project88b60792009-03-03 19:28:42 -08001507 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001508
The Android Open Source Project88b60792009-03-03 19:28:42 -08001509 echo "Retrieving file $devFile..."
1510 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001511
The Android Open Source Project88b60792009-03-03 19:28:42 -08001512 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001513
The Android Open Source Project88b60792009-03-03 19:28:42 -08001514 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001515 echo "View the output by pointing your browser at http://localhost:7000/"
1516 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001517 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001518}
1519
1520function getbugreports()
1521{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001522 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001523
1524 if [ ! "$reports" ]; then
1525 echo "Could not locate any bugreports."
1526 return
1527 fi
1528
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001529 local report
1530 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001531 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001532 echo "/sdcard/bugreports/${report}"
1533 adb pull /sdcard/bugreports/${report} ${report}
1534 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001535 done
1536}
1537
Victoria Lease1b296b42012-08-21 15:44:06 -07001538function getsdcardpath()
1539{
1540 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1541}
1542
1543function getscreenshotpath()
1544{
1545 echo "$(getsdcardpath)/Pictures/Screenshots"
1546}
1547
1548function getlastscreenshot()
1549{
1550 local screenshot_path=$(getscreenshotpath)
1551 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1552 if [ "$screenshot" = "" ]; then
1553 echo "No screenshots found."
1554 return
1555 fi
1556 echo "${screenshot}"
1557 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1558}
1559
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001560function startviewserver()
1561{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001562 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001563 if [ $# -gt 0 ]; then
1564 port=$1
1565 fi
1566 adb shell service call window 1 i32 $port
1567}
1568
1569function stopviewserver()
1570{
1571 adb shell service call window 2
1572}
1573
1574function isviewserverstarted()
1575{
1576 adb shell service call window 3
1577}
1578
Romain Guyb84049a2010-10-04 16:56:11 -07001579function key_home()
1580{
1581 adb shell input keyevent 3
1582}
1583
1584function key_back()
1585{
1586 adb shell input keyevent 4
1587}
1588
1589function key_menu()
1590{
1591 adb shell input keyevent 82
1592}
1593
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001594function smoketest()
1595{
1596 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1597 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1598 return
1599 fi
1600 T=$(gettop)
1601 if [ ! "$T" ]; then
1602 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1603 return
1604 fi
1605
Ying Wang9cd17642012-12-13 10:52:07 -08001606 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001607 adb uninstall com.android.smoketest > /dev/null &&
1608 adb uninstall com.android.smoketest.tests > /dev/null &&
1609 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1610 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1611 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1612}
1613
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001614# simple shortcut to the runtest command
1615function runtest()
1616{
1617 T=$(gettop)
1618 if [ ! "$T" ]; then
1619 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1620 return
1621 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001622 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001623}
1624
The Android Open Source Project88b60792009-03-03 19:28:42 -08001625function godir () {
1626 if [[ -z "$1" ]]; then
1627 echo "Usage: godir <regex>"
1628 return
1629 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001630 T=$(gettop)
Brian Carlstromf2257422015-09-30 20:28:54 -07001631 if [ ! "$OUT_DIR" = "" ]; then
1632 mkdir -p $OUT_DIR
1633 FILELIST=$OUT_DIR/filelist
1634 else
1635 FILELIST=$T/filelist
1636 fi
1637 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001638 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001639 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001640 echo " Done"
1641 echo ""
1642 fi
1643 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001644 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001645 if [[ ${#lines[@]} = 0 ]]; then
1646 echo "Not found"
1647 return
1648 fi
1649 local pathname
1650 local choice
1651 if [[ ${#lines[@]} > 1 ]]; then
1652 while [[ -z "$pathname" ]]; do
1653 local index=1
1654 local line
1655 for line in ${lines[@]}; do
1656 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001657 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001658 done
1659 echo
1660 echo -n "Select one: "
1661 unset choice
1662 read choice
1663 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1664 echo "Invalid choice"
1665 continue
1666 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001667 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001668 done
1669 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001670 pathname=${lines[0]}
1671 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001672 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001673}
1674
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001675function cmremote()
1676{
1677 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301678 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001679 if [ -z "$GERRIT_REMOTE" ]
1680 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301681 echo Unable to set up the git remote, are you under a git repo?
1682 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001683 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301684 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001685 if [ -z "$CMUSER" ]
1686 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001687 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001688 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001689 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001690 fi
1691 echo You can now push to "cmremote".
1692}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001693
Steve Kondik873fa562012-09-17 11:33:18 -07001694function aospremote()
1695{
1696 git remote rm aosp 2> /dev/null
1697 if [ ! -d .git ]
1698 then
1699 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1700 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001701 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001702 if (echo $PROJECT | grep -qv "^device")
1703 then
1704 PFX="platform/"
1705 fi
1706 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1707 echo "Remote 'aosp' created"
1708}
Steve Kondik873fa562012-09-17 11:33:18 -07001709
Steve Kondik20c21d22013-10-27 13:34:36 -07001710function cafremote()
1711{
1712 git remote rm caf 2> /dev/null
1713 if [ ! -d .git ]
1714 then
1715 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1716 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001717 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001718 if (echo $PROJECT | grep -qv "^device")
1719 then
1720 PFX="platform/"
1721 fi
1722 git remote add caf git://codeaurora.org/$PFX$PROJECT
1723 echo "Remote 'caf' created"
1724}
Steve Kondik20c21d22013-10-27 13:34:36 -07001725
Steve Kondikf00e7d92012-09-23 23:46:55 -07001726function installboot()
1727{
1728 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1729 then
1730 echo "No recovery.fstab found. Build recovery first."
1731 return 1
1732 fi
1733 if [ ! -e "$OUT/boot.img" ];
1734 then
1735 echo "No boot.img found. Run make bootimage first."
1736 return 1
1737 fi
1738 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1739 if [ -z "$PARTITION" ];
1740 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001741 # Try for RECOVERY_FSTAB_VERSION = 2
1742 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1743 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1744 if [ -z "$PARTITION" ];
1745 then
1746 echo "Unable to determine boot partition."
1747 return 1
1748 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001749 fi
1750 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001751 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001752 adb root
1753 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001754 adb wait-for-online shell mount /system 2>&1 > /dev/null
1755 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001756 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondikf00e7d92012-09-23 23:46:55 -07001757 then
1758 adb push $OUT/boot.img /cache/
1759 for i in $OUT/system/lib/modules/*;
1760 do
1761 adb push $i /system/lib/modules/
1762 done
1763 adb shell dd if=/cache/boot.img of=$PARTITION
1764 adb shell chmod 644 /system/lib/modules/*
1765 echo "Installation complete."
1766 else
1767 echo "The connected device does not appear to be $CM_BUILD, run away!"
1768 fi
1769}
1770
Steve Kondik83c03d52012-10-24 16:40:42 -07001771function installrecovery()
1772{
1773 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1774 then
1775 echo "No recovery.fstab found. Build recovery first."
1776 return 1
1777 fi
1778 if [ ! -e "$OUT/recovery.img" ];
1779 then
1780 echo "No recovery.img found. Run make recoveryimage first."
1781 return 1
1782 fi
1783 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1784 if [ -z "$PARTITION" ];
1785 then
Steve Kondik75f10762013-08-09 21:03:42 -07001786 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001787 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1788 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001789 if [ -z "$PARTITION" ];
1790 then
1791 echo "Unable to determine recovery partition."
1792 return 1
1793 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001794 fi
1795 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001796 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001797 adb root
1798 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001799 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1800 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001801 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondik83c03d52012-10-24 16:40:42 -07001802 then
1803 adb push $OUT/recovery.img /cache/
1804 adb shell dd if=/cache/recovery.img of=$PARTITION
1805 echo "Installation complete."
1806 else
1807 echo "The connected device does not appear to be $CM_BUILD, run away!"
1808 fi
1809}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001810
Koushik Duttab55f13a2012-05-14 16:14:36 -07001811function makerecipe() {
1812 if [ -z "$1" ]
1813 then
1814 echo "No branch name provided."
1815 return 1
1816 fi
1817 cd android
1818 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1819 git commit -a -m "$1"
1820 cd ..
1821
1822 repo forall -c '
1823
1824 if [ "$REPO_REMOTE" == "github" ]
1825 then
1826 pwd
1827 cmremote
1828 git push cmremote HEAD:refs/heads/'$1'
1829 fi
1830 '
1831}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001832
1833function cmgerrit() {
1834 if [ $# -eq 0 ]; then
1835 $FUNCNAME help
1836 return 1
1837 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001838 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001839 local review=`git config --get remote.github.review`
1840 local project=`git config --get remote.github.projectname`
1841 local command=$1
1842 shift
1843 case $command in
1844 help)
1845 if [ $# -eq 0 ]; then
1846 cat <<EOF
1847Usage:
1848 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1849
1850Commands:
1851 fetch Just fetch the change as FETCH_HEAD
1852 help Show this help, or for a specific command
1853 pull Pull a change into current branch
1854 push Push HEAD or a local branch to Gerrit for a specific branch
1855
1856Any other Git commands that support refname would work as:
1857 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1858
1859See '$FUNCNAME help COMMAND' for more information on a specific command.
1860
1861Example:
1862 $FUNCNAME checkout -b topic 1234/5
1863works as:
1864 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1865 && git checkout -b topic FETCH_HEAD
1866will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1867Patch-set 1 will be fetched if omitted.
1868EOF
1869 return
1870 fi
1871 case $1 in
1872 __cmg_*) echo "For internal use only." ;;
1873 changes|for)
1874 if [ "$FUNCNAME" = "cmgerrit" ]; then
1875 echo "'$FUNCNAME $1' is deprecated."
1876 fi
1877 ;;
1878 help) $FUNCNAME help ;;
1879 fetch|pull) cat <<EOF
1880usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1881
1882works as:
1883 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1884 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1885
1886Example:
1887 $FUNCNAME $1 1234
1888will $1 patch-set 1 of change 1234
1889EOF
1890 ;;
1891 push) cat <<EOF
1892usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1893
1894works as:
1895 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1896 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1897
1898Example:
1899 $FUNCNAME push fix6789:gingerbread
1900will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1901HEAD will be pushed from local if omitted.
1902EOF
1903 ;;
1904 *)
1905 $FUNCNAME __cmg_err_not_supported $1 && return
1906 cat <<EOF
1907usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1908
1909works as:
1910 git fetch http://DOMAIN/p/PROJECT \\
1911 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1912 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1913EOF
1914 ;;
1915 esac
1916 ;;
1917 __cmg_get_ref)
1918 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1919 local change_id patchset_id hash
1920 case $1 in
1921 */*)
1922 change_id=${1%%/*}
1923 patchset_id=${1#*/}
1924 ;;
1925 *)
1926 change_id=$1
1927 patchset_id=1
1928 ;;
1929 esac
1930 hash=$(($change_id % 100))
1931 case $hash in
1932 [0-9]) hash="0$hash" ;;
1933 esac
1934 echo "refs/changes/$hash/$change_id/$patchset_id"
1935 ;;
1936 fetch|pull)
1937 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1938 $FUNCNAME __cmg_err_not_repo && return 1
1939 local change=$1
1940 shift
1941 git $command $@ http://$review/p/$project \
1942 $($FUNCNAME __cmg_get_ref $change) || return 1
1943 ;;
1944 push)
1945 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1946 $FUNCNAME __cmg_err_not_repo && return 1
1947 if [ -z "$user" ]; then
1948 echo >&2 "Gerrit username not found."
1949 return 1
1950 fi
1951 local local_branch remote_branch
1952 case $1 in
1953 *:*)
1954 local_branch=${1%:*}
1955 remote_branch=${1##*:}
1956 ;;
1957 *)
1958 local_branch=HEAD
1959 remote_branch=$1
1960 ;;
1961 esac
1962 shift
1963 git push $@ ssh://$user@$review:29418/$project \
1964 $local_branch:refs/for/$remote_branch || return 1
1965 ;;
1966 changes|for)
1967 if [ "$FUNCNAME" = "cmgerrit" ]; then
1968 echo >&2 "'$FUNCNAME $command' is deprecated."
1969 fi
1970 ;;
1971 __cmg_err_no_arg)
1972 if [ $# -lt 2 ]; then
1973 echo >&2 "'$FUNCNAME $command' missing argument."
1974 elif [ $2 -eq 0 ]; then
1975 if [ -n "$3" ]; then
1976 $FUNCNAME help $1
1977 else
1978 echo >&2 "'$FUNCNAME $1' missing argument."
1979 fi
1980 else
1981 return 1
1982 fi
1983 ;;
1984 __cmg_err_not_repo)
1985 if [ -z "$review" -o -z "$project" ]; then
1986 echo >&2 "Not currently in any reviewable repository."
1987 else
1988 return 1
1989 fi
1990 ;;
1991 __cmg_err_not_supported)
1992 $FUNCNAME __cmg_err_no_arg $command $# && return
1993 case $1 in
1994 #TODO: filter more git commands that don't use refname
1995 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1996 echo >&2 "'$FUNCNAME $1' is not supported."
1997 ;;
1998 *) return 1 ;;
1999 esac
2000 ;;
2001 #TODO: other special cases?
2002 *)
2003 $FUNCNAME __cmg_err_not_supported $command && return 1
2004 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
2005 $FUNCNAME __cmg_err_not_repo && return 1
2006 local args="$@"
2007 local change pre_args refs_arg post_args
2008 case "$args" in
2009 *--\ *)
2010 pre_args=${args%%-- *}
2011 post_args="-- ${args#*-- }"
2012 ;;
2013 *) pre_args="$args" ;;
2014 esac
2015 args=($pre_args)
2016 pre_args=
2017 if [ ${#args[@]} -gt 0 ]; then
2018 change=${args[${#args[@]}-1]}
2019 fi
2020 if [ ${#args[@]} -gt 1 ]; then
2021 pre_args=${args[0]}
2022 for ((i=1; i<${#args[@]}-1; i++)); do
2023 pre_args="$pre_args ${args[$i]}"
2024 done
2025 fi
2026 while ((1)); do
2027 case $change in
2028 ""|--)
2029 $FUNCNAME help $command
2030 return 1
2031 ;;
2032 *@*)
2033 if [ -z "$refs_arg" ]; then
2034 refs_arg="@${change#*@}"
2035 change=${change%%@*}
2036 fi
2037 ;;
2038 *~*)
2039 if [ -z "$refs_arg" ]; then
2040 refs_arg="~${change#*~}"
2041 change=${change%%~*}
2042 fi
2043 ;;
2044 *^*)
2045 if [ -z "$refs_arg" ]; then
2046 refs_arg="^${change#*^}"
2047 change=${change%%^*}
2048 fi
2049 ;;
2050 *:*)
2051 if [ -z "$refs_arg" ]; then
2052 refs_arg=":${change#*:}"
2053 change=${change%%:*}
2054 fi
2055 ;;
2056 *) break ;;
2057 esac
2058 done
2059 $FUNCNAME fetch $change \
2060 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2061 || return 1
2062 ;;
2063 esac
2064}
2065
2066function cmrebase() {
2067 local repo=$1
2068 local refs=$2
2069 local pwd="$(pwd)"
2070 local dir="$(gettop)/$repo"
2071
2072 if [ -z $repo ] || [ -z $refs ]; then
2073 echo "CyanogenMod Gerrit Rebase Usage: "
2074 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2075 echo " The patch IDs appear on the Gerrit commands that are offered."
2076 echo " They consist on a series of numbers and slashes, after the text"
2077 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2078 echo ""
2079 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2080 echo ""
2081 return
2082 fi
2083
2084 if [ ! -d $dir ]; then
2085 echo "Directory $dir doesn't exist in tree."
2086 return
2087 fi
2088 cd $dir
2089 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2090 echo "Starting branch..."
2091 repo start tmprebase .
2092 echo "Bringing it up to date..."
2093 repo sync .
2094 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07002095 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002096 if [ "$?" != "0" ]; then
2097 echo "Error cherry-picking. Not uploading!"
2098 return
2099 fi
2100 echo "Uploading..."
2101 repo upload .
2102 echo "Cleaning up..."
2103 repo abandon tmprebase .
2104 cd $pwd
2105}
2106
2107function mka() {
Khalid Zubairabcd1942015-10-06 11:00:55 -07002108 local T=$(gettop)
2109 if [ "$T" ]; then
2110 case `uname -s` in
2111 Darwin)
2112 make -C $T -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2113 ;;
2114 *)
2115 mk_timer schedtool -B -n 1 -e ionice -n 1 make -C $T -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
2116 ;;
2117 esac
2118
2119 else
2120 echo "Couldn't locate the top of the tree. Try setting TOP."
2121 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002122}
2123
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302124function cmka() {
2125 if [ ! -z "$1" ]; then
2126 for i in "$@"; do
2127 case $i in
2128 bacon|otapackage|systemimage)
2129 mka installclean
2130 mka $i
2131 ;;
2132 *)
2133 mka clean-$i
2134 mka $i
2135 ;;
2136 esac
2137 done
2138 else
2139 mka clean
2140 mka
2141 fi
2142}
2143
Khalid Zubairfdc26cd2015-10-21 12:43:14 -07002144function mms() {
2145 local T=$(gettop)
2146 if [ -z "$T" ]
2147 then
2148 echo "Couldn't locate the top of the tree. Try setting TOP."
2149 return 1
2150 fi
2151
2152 case `uname -s` in
2153 Darwin)
2154 local NUM_CPUS=$(sysctl hw.ncpu|cut -d" " -f2)
2155 ONE_SHOT_MAKEFILE="__none__" \
2156 make -C $T -j $NUM_CPUS "$@"
2157 ;;
2158 *)
2159 local NUM_CPUS=$(cat /proc/cpuinfo | grep "^processor" | wc -l)
2160 ONE_SHOT_MAKEFILE="__none__" \
2161 mk_timer schedtool -B -n 1 -e ionice -n 1 \
2162 make -C $T -j $NUM_CPUS "$@"
2163 ;;
2164 esac
2165}
2166
2167
Matt Mower8dacaed2013-12-29 12:57:20 -06002168function repolastsync() {
2169 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
2170 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
2171 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
2172 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
2173}
2174
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002175function reposync() {
2176 case `uname -s` in
2177 Darwin)
2178 repo sync -j 4 "$@"
2179 ;;
2180 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002181 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002182 ;;
2183 esac
2184}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002185
2186function repodiff() {
2187 if [ -z "$*" ]; then
2188 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2189 return
2190 fi
2191 diffopts=$* repo forall -c \
2192 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2193}
2194
Khalid Zubair63eabff2016-02-02 12:00:14 -08002195# Return success if adb is up and not in recovery
2196function _adb_connected {
2197 {
2198 if [[ "$(adb get-state)" == device &&
2199 "$(adb shell test -e /sbin/recovery; echo $?)" == 0 ]]
2200 then
2201 return 0
2202 fi
2203 } 2>/dev/null
2204
2205 return 1
2206};
2207
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302208# Credit for color strip sed: http://goo.gl/BoIcm
2209function dopush()
2210{
2211 local func=$1
2212 shift
2213
2214 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
Khalid Zubair63eabff2016-02-02 12:00:14 -08002215 if ! _adb_connected; then
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302216 echo "No device is online. Waiting for one..."
2217 echo "Please connect USB and/or enable USB debugging"
Khalid Zubair63eabff2016-02-02 12:00:14 -08002218 until _adb_connected; do
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302219 sleep 1
2220 done
2221 echo "Device Found."
2222 fi
2223
Steve Kondikec4627c2015-07-10 02:31:24 -07002224 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD") || [ "$FORCE_PUSH" == "true" ];
Chirayu Desai6dadb572012-12-26 10:53:58 +05302225 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002226 # retrieve IP and PORT info if we're using a TCP connection
2227 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2228 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302229 adb root &> /dev/null
2230 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002231 if [ -n "$TCPIPPORT" ]
2232 then
2233 # adb root just killed our connection
2234 # so reconnect...
2235 adb connect "$TCPIPPORT"
2236 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302237 adb wait-for-device &> /dev/null
2238 sleep 0.3
2239 adb remount &> /dev/null
2240
Matt Mower668ea262014-05-20 02:52:23 -05002241 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00002242 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2243 ret=$?;
2244 if [ $ret -ne 0 ]; then
2245 rm -f $OUT/.log;return $ret
2246 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302247
2248 # Install: <file>
LuK133756041e72015-12-01 14:53:23 +01002249 if [ `uname` = "Linux" ]; then
2250 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)"
2251 else
2252 LOC="$(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" | grep '^Install: ' | cut -d ':' -f 2)"
2253 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302254
2255 # Copy: <file>
LuK133756041e72015-12-01 14:53:23 +01002256 if [ `uname` = "Linux" ]; then
2257 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)"
2258 else
2259 LOC="$LOC $(cat $OUT/.log | sed -E "s/"$'\E'"\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g" | grep '^Copy: ' | cut -d ':' -f 2)"
2260 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302261
Matt Mowerdfd4c082014-05-20 02:52:23 -05002262 # If any files are going to /data, push an octal file permissions reader to device
2263 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
2264 CHKPERM="/data/local/tmp/chkfileperm.sh"
2265(
2266cat <<'EOF'
2267#!/system/xbin/sh
2268FILE=$@
2269if [ -e $FILE ]; then
2270 ls -l $FILE | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' | cut -d ' ' -f1
2271fi
2272EOF
2273) > $OUT/.chkfileperm.sh
2274 echo "Pushing file permissions checker to device"
2275 adb push $OUT/.chkfileperm.sh $CHKPERM
2276 adb shell chmod 755 $CHKPERM
2277 rm -f $OUT/.chkfileperm.sh
2278 fi
2279
Matt Mower668ea262014-05-20 02:52:23 -05002280 stop_n_start=false
Luca Stefani406c2af2015-11-02 05:33:10 -08002281 for FILE in $(echo $LOC | tr " " "\n"); do
Matt Mowerdfd4c082014-05-20 02:52:23 -05002282 # Make sure file is in $OUT/system or $OUT/data
Matt Mower668ea262014-05-20 02:52:23 -05002283 case $FILE in
Matt Mowerdfd4c082014-05-20 02:52:23 -05002284 $OUT/system/*|$OUT/data/*)
Matt Mower668ea262014-05-20 02:52:23 -05002285 # Get target file name (i.e. /system/bin/adb)
2286 TARGET=$(echo $FILE | sed "s#$OUT##")
2287 ;;
2288 *) continue ;;
2289 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302290
Matt Mower668ea262014-05-20 02:52:23 -05002291 case $TARGET in
Matt Mowerdfd4c082014-05-20 02:52:23 -05002292 /data/*)
2293 # fs_config only sets permissions and se labels for files pushed to /system
2294 if [ -n "$CHKPERM" ]; then
2295 OLDPERM=$(adb shell $CHKPERM $TARGET)
2296 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
2297 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
2298 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
2299 fi
2300 echo "Pushing: $TARGET"
2301 adb push $FILE $TARGET
2302 if [ -n "$OLDPERM" ]; then
2303 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
2304 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
2305 adb shell chmod "$OLDPERM" $TARGET
2306 else
2307 echo "$TARGET did not exist previously, you should set file permissions manually"
2308 fi
2309 adb shell restorecon "$TARGET"
2310 ;;
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002311 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002312 # Only need to stop services once
2313 if ! $stop_n_start; then
2314 adb shell stop
2315 stop_n_start=true
2316 fi
2317 echo "Pushing: $TARGET"
2318 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302319 ;;
2320 *)
Matt Mower668ea262014-05-20 02:52:23 -05002321 echo "Pushing: $TARGET"
2322 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302323 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002324 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302325 done
Matt Mowerdfd4c082014-05-20 02:52:23 -05002326 if [ -n "$CHKPERM" ]; then
2327 adb shell rm $CHKPERM
2328 fi
Matt Mower668ea262014-05-20 02:52:23 -05002329 if $stop_n_start; then
2330 adb shell start
2331 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302332 rm -f $OUT/.log
2333 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302334 else
2335 echo "The connected device does not appear to be $CM_BUILD, run away!"
2336 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302337}
2338
2339alias mmp='dopush mm'
2340alias mmmp='dopush mmm'
Martin Brabhamb77db582016-02-05 15:59:21 -05002341alias mmap='dopush mma'
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302342alias mkap='dopush mka'
2343alias cmkap='dopush cmka'
2344
Chirayu Desai4a319b82013-06-05 20:14:33 +05302345function repopick() {
2346 T=$(gettop)
2347 $T/build/tools/repopick.py $@
2348}
2349
Chirayu Desaib89b3242013-06-30 10:04:25 +05302350function fixup_common_out_dir() {
2351 common_out_dir=$(get_build_var OUT_DIR)/target/common
2352 target_device=$(get_build_var TARGET_DEVICE)
2353 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2354 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2355 mv ${common_out_dir} ${common_out_dir}-${target_device}
2356 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2357 else
2358 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2359 mkdir -p ${common_out_dir}-${target_device}
2360 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2361 fi
2362 else
2363 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2364 mkdir -p ${common_out_dir}
2365 fi
2366}
2367
Michael Bestas163381a2015-10-23 20:36:47 +03002368# Force JAVA_HOME to point to java 1.7 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002369#
2370# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2371# For some reason, installing the JDK doesn't make it show up in the
2372# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002373function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002374 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002375 # we can reset it later, depending on the version of java the build
2376 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002377 #
2378 # If we don't do this, the JAVA_HOME value set by the first call to
2379 # build/envsetup.sh will persist forever.
2380 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2381 export JAVA_HOME=""
2382 fi
2383
Andy McFaddenbd960942010-06-24 12:52:51 -07002384 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002385 case `uname -s` in
2386 Darwin)
2387 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2388 ;;
2389 *)
2390 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2391 ;;
2392 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002393
2394 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2395 # we can change it on the next envsetup.sh, if required.
2396 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002397 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002398}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002399
Alex Rayf0d08eb2013-03-08 15:15:06 -08002400# Print colored exit condition
2401function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002402 "$@"
2403 local retval=$?
2404 if [ $retval -ne 0 ]
2405 then
Roman Birgead9a5c2015-10-16 10:29:06 -07002406 printf "\e[0;31mFAILURE\e[00m\n"
Michael Wrighteb733842013-03-08 17:34:02 -08002407 else
Roman Birgead9a5c2015-10-16 10:29:06 -07002408 printf "\e[0;32mSUCCESS\e[00m\n"
Michael Wrighteb733842013-03-08 17:34:02 -08002409 fi
2410 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002411}
2412
Ying Wanged21d4c2014-08-24 22:14:19 -07002413function get_make_command()
2414{
2415 echo command make
2416}
2417
Anthony King40b093f2015-04-30 22:19:48 +01002418function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002419{
2420 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002421 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002422 local ret=$?
2423 local end_time=$(date +"%s")
2424 local tdiff=$(($end_time-$start_time))
2425 local hours=$(($tdiff / 3600 ))
2426 local mins=$((($tdiff % 3600) / 60))
2427 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002428 local ncolors=$(tput colors 2>/dev/null)
2429 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2430 color_failed="\e[0;31m"
2431 color_success="\e[0;32m"
Roman Birgead9a5c2015-10-16 10:29:06 -07002432 color_reset="\e[0m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002433 else
2434 color_failed=""
2435 color_success=""
2436 color_reset=""
2437 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002438 echo
2439 if [ $ret -eq 0 ] ; then
Roman Birgead9a5c2015-10-16 10:29:06 -07002440 printf "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002441 else
Roman Birgead9a5c2015-10-16 10:29:06 -07002442 printf "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002443 fi
2444 if [ $hours -gt 0 ] ; then
2445 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2446 elif [ $mins -gt 0 ] ; then
2447 printf "(%02g:%02g (mm:ss))" $mins $secs
2448 elif [ $secs -gt 0 ] ; then
2449 printf "(%s seconds)" $secs
2450 fi
Roman Birgead9a5c2015-10-16 10:29:06 -07002451 printf " ####${color_reset}\n\n"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002452 return $ret
2453}
2454
Anthony King40b093f2015-04-30 22:19:48 +01002455function make()
2456{
2457 mk_timer $(get_make_command) "$@"
2458}
2459
Raphael Moll70a86b02011-06-20 16:03:14 -07002460if [ "x$SHELL" != "x/bin/bash" ]; then
2461 case `ps -o command -p $$` in
2462 *bash*)
2463 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002464 *zsh*)
2465 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002466 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002467 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002468 ;;
2469 esac
2470fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002471
2472# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002473for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2474 `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 -08002475do
2476 echo "including $f"
2477 . $f
2478done
2479unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002480
Kyle Ladd031a0b62013-09-11 20:43:42 -04002481# Add completions
2482check_bash_version && {
2483 dirs="sdk/bash_completion vendor/cm/bash_completion"
2484 for dir in $dirs; do
2485 if [ -d ${dir} ]; then
2486 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2487 echo "including $f"
2488 . $f
2489 done
2490 fi
2491 done
2492}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302493
2494export ANDROID_BUILD_TOP=$(gettop)