blob: 82b58e6e6a352f1958880d87660aa8b172de7554 [file] [log] [blame]
Scott Anderson1a5fc952012-03-07 17:15:06 -08001function hmm() {
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07002cat <<EOF
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08003Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
Ying Wang67f02922012-08-22 10:25:20 -07004- lunch: lunch <product_name>-<build_variant>
Ying Wangb541ab62014-05-29 17:57:40 -07005- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07006- croot: Changes directory to the top of the tree.
nebkatfb67a1e2012-12-28 10:40:45 +00007- cout: Changes directory to out.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07008- m: Makes from the top of the tree.
Ying Wangb607f7b2013-02-08 18:01:04 -08009- mm: Builds all of the modules in the current directory, but not their dependencies.
10- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
Primiano Tucci6a8069d2014-02-26 11:09:19 +000011 To limit the modules being built use the syntax: mmm dir/:target1,target2.
Ying Wangb607f7b2013-02-08 18:01:04 -080012- mma: Builds all of the modules in the current directory, and their dependencies.
Daniel Bateman22185ba2012-08-04 03:48:09 -050013- mmp: Builds all of the modules in the current directory and pushes them to the device.
14- mmmp: Builds all of the modules in the supplied directories and pushes them to the device.
Ying Wangb607f7b2013-02-08 18:01:04 -080015- mmma: Builds all of the modules in the supplied directories, and their dependencies.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070016- cgrep: Greps on all local C/C++ files.
Jon Boekenoogencbca56f2014-04-07 10:57:38 -070017- ggrep: Greps on all local Gradle files.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070018- jgrep: Greps on all local Java files.
19- resgrep: Greps on all local res/*.xml files.
Trevor Drake9c889762015-01-30 04:42:21 +000020- mangrep: Greps on all local AndroidManifest.xml files.
21- sepgrep: Greps on all local sepolicy files.
Jeff Brown46cbd202014-07-26 15:15:41 -070022- sgrep: Greps on all local source files.
The Android Open Source Project88b60792009-03-03 19:28:42 -080023- godir: Go to the directory containing a file.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060024- cmremote: Add git remote for CM Gerrit Review
25- cmgerrit: A Git wrapper that fetches/pushes patch from/to CM Gerrit Review
26- cmrebase: Rebase a Gerrit change and push it again
Steve Kondik873fa562012-09-17 11:33:18 -070027- aospremote: Add git remote for matching AOSP repository
Steve Kondik20c21d22013-10-27 13:34:36 -070028- cafremote: Add git remote for matching CodeAurora repository.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060029- mka: Builds using SCHED_BATCH on all processors
Chirayu Desaicf2bdb62012-09-28 11:56:02 +053030- mkap: Builds the module(s) using mka and pushes them to the device.
31- cmka: Cleans and builds using mka.
Matt Mower8dacaed2013-12-29 12:57:20 -060032- repolastsync: Prints date and time of last repo sync.
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -060033- reposync: Parallel repo sync using ionice and SCHED_BATCH
Chirayu Desai4a319b82013-06-05 20:14:33 +053034- repopick: Utility to fetch changes from Gerrit.
Steve Kondik83c03d52012-10-24 16:40:42 -070035- installboot: Installs a boot.img to the connected device.
36- installrecovery: Installs a recovery.img to the connected device.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070037
Dan Albert4ae5d4b2014-10-31 16:23:08 -070038Environemnt options:
39- SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that
40 ASAN_OPTIONS=detect_leaks=0 will be set by default until the
41 build is leak-check clean.
42
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070043Look at the source to view more functions. The complete list is:
44EOF
45 T=$(gettop)
Jeff Brown46cbd202014-07-26 15:15:41 -070046 for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do
Anthony King0780f2f2015-04-30 23:16:10 +010047 echo "$i"
48 done | column
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070049}
50
51# Get the value of a build variable as an absolute path.
52function get_abs_build_var()
53{
54 T=$(gettop)
55 if [ ! "$T" ]; then
56 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
57 return
58 fi
Ying Wang9cd17642012-12-13 10:52:07 -080059 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070060 command make --no-print-directory -f build/core/config.mk dumpvar-abs-$1)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -070061}
62
63# Get the exact value of a build variable.
64function get_build_var()
65{
66 T=$(gettop)
67 if [ ! "$T" ]; then
68 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
69 return
70 fi
Andrew Boie6905e212013-12-19 13:21:46 -080071 (\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
Ed Heylc6d11f82014-06-27 13:32:39 -070072 command make --no-print-directory -f build/core/config.mk dumpvar-$1)
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080073}
74
75# check to see if the supplied product is one we can build
76function check_product()
77{
78 T=$(gettop)
79 if [ ! "$T" ]; then
80 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
81 return
82 fi
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000083
84 if (echo -n $1 | grep -q -e "^cm_") ; then
85 CM_BUILD=$(echo -n $1 | sed -e 's/^cm_//g')
Ricardo Cerqueira34ae3232013-09-26 00:10:20 +010086 export BUILD_NUMBER=$((date +%s%N ; echo $CM_BUILD; hostname) | openssl sha1 | sed -e 's/.*=//g; s/ //g' | cut -c1-10)
Ricardo Cerqueira119d3bb2011-11-25 15:30:36 +000087 else
88 CM_BUILD=
89 fi
90 export CM_BUILD
91
Jeff Browne33ba4c2011-07-11 22:11:46 -070092 TARGET_PRODUCT=$1 \
93 TARGET_BUILD_VARIANT= \
94 TARGET_BUILD_TYPE= \
Joe Onoratoda12daf2010-06-09 18:18:31 -070095 TARGET_BUILD_APPS= \
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -080096 get_build_var TARGET_DEVICE > /dev/null
97 # hide successful answers, but allow the errors to show
98}
99
100VARIANT_CHOICES=(user userdebug eng)
101
102# check to see if the supplied variant is valid
103function check_variant()
104{
105 for v in ${VARIANT_CHOICES[@]}
106 do
107 if [ "$v" = "$1" ]
108 then
109 return 0
110 fi
111 done
112 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700113}
114
115function setpaths()
116{
117 T=$(gettop)
118 if [ ! "$T" ]; then
119 echo "Couldn't locate the top of the tree. Try setting TOP."
120 return
121 fi
122
123 ##################################################################
124 # #
125 # Read me before you modify this code #
126 # #
127 # This function sets ANDROID_BUILD_PATHS to what it is adding #
128 # to PATH, and the next time it is run, it removes that from #
129 # PATH. This is required so lunch can be run more than once #
130 # and still have working paths. #
131 # #
132 ##################################################################
133
Raphael Mollc639c782011-06-20 17:25:01 -0700134 # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces
135 # due to "C:\Program Files" being in the path.
136
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700137 # out with the old
Raphael Mollc639c782011-06-20 17:25:01 -0700138 if [ -n "$ANDROID_BUILD_PATHS" ] ; then
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700139 export PATH=${PATH/$ANDROID_BUILD_PATHS/}
140 fi
Raphael Mollc639c782011-06-20 17:25:01 -0700141 if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then
Doug Zongker29034982011-04-22 08:16:56 -0700142 export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/}
Ying Wangaa1c9b52012-11-26 20:51:59 -0800143 # strip leading ':', if any
144 export PATH=${PATH/:%/}
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500145 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700146
147 # and in with the new
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700148 prebuiltdir=$(getprebuilt)
Jing Yuf5172c72012-03-29 20:45:50 -0700149 gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS)
Raphael732936d2011-06-22 14:35:32 -0700150
Ben Cheng8bc4c432012-11-16 13:29:13 -0800151 # defined in core/config.mk
152 targetgccversion=$(get_build_var TARGET_GCC_VERSION)
Colin Cross03b424a2014-05-22 11:57:43 -0700153 targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION)
Brandon McAnshfaf35352015-10-10 10:20:38 -0400154 targetlegacygccversion=$(get_build_var TARGET_LEGACY_GCC_VERSION)
Ben Cheng15266702012-12-10 16:04:39 -0800155 export TARGET_GCC_VERSION=$targetgccversion
Ben Cheng8bc4c432012-11-16 13:29:13 -0800156
Raphael Mollc639c782011-06-20 17:25:01 -0700157 # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it.
Ben Chengfba67bf2014-02-25 10:27:07 -0800158 export ANDROID_TOOLCHAIN=
159 export ANDROID_TOOLCHAIN_2ND_ARCH=
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200160 local ARCH=$(get_build_var TARGET_ARCH)
161 case $ARCH in
Pavel Chupinc1a56642013-08-23 16:49:21 +0400162 x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
Mark D Horn7d0ede72012-03-14 14:20:30 -0700163 ;;
Pavel Chupinfd82a492012-11-26 09:50:07 +0400164 x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin
165 ;;
Ben Cheng8bc4c432012-11-16 13:29:13 -0800166 arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200167 ;;
Ben Chengfba67bf2014-02-25 10:27:07 -0800168 arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin;
Colin Cross03b424a2014-05-22 11:57:43 -0700169 toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin
Ben Chengdb4fc202013-10-04 16:02:59 -0700170 ;;
Duane Sand3c4fcd82014-07-22 14:34:00 -0700171 mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000172 ;;
David 'Digit' Turner2056c252012-04-17 14:50:47 +0200173 *)
174 echo "Can't find toolchain for unknown architecture: $ARCH"
175 toolchaindir=xxxxxxxxx
Mark D Horn7d0ede72012-03-14 14:20:30 -0700176 ;;
177 esac
Jing Yuf5172c72012-03-29 20:45:50 -0700178 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Ben Chengfba67bf2014-02-25 10:27:07 -0800179 export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir
Raphael Mollc639c782011-06-20 17:25:01 -0700180 fi
Raphael732936d2011-06-22 14:35:32 -0700181
Ben Chengfba67bf2014-02-25 10:27:07 -0800182 if [ -d "$gccprebuiltdir/$toolchaindir2" ]; then
183 export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2
184 fi
185
186 unset ANDROID_KERNEL_TOOLCHAIN_PATH
Ying Wang08f5e9a2012-04-17 18:10:11 -0700187 case $ARCH in
Bruce Beare42ced6d2012-07-17 21:40:01 -0700188 arm)
Ben Chengfba67bf2014-02-25 10:27:07 -0800189 # Legacy toolchain configuration used for ARM kernel compilation
Brandon McAnshfaf35352015-10-10 10:20:38 -0400190 toolchaindir=arm/arm-eabi-$targetlegacygccversion/bin
Bruce Beare42ced6d2012-07-17 21:40:01 -0700191 if [ -d "$gccprebuiltdir/$toolchaindir" ]; then
Torne (Richard Coles)f24c3562014-04-25 16:24:22 +0100192 export ARM_EABI_TOOLCHAIN="$gccprebuiltdir/$toolchaindir"
193 ANDROID_KERNEL_TOOLCHAIN_PATH="$ARM_EABI_TOOLCHAIN":
Bruce Beare42ced6d2012-07-17 21:40:01 -0700194 fi
Ying Wang08f5e9a2012-04-17 18:10:11 -0700195 ;;
196 *)
Bruce Beare42ced6d2012-07-17 21:40:01 -0700197 # No need to set ARM_EABI_TOOLCHAIN for other ARCHs
Ying Wang08f5e9a2012-04-17 18:10:11 -0700198 ;;
199 esac
Ying Wang08f5e9a2012-04-17 18:10:11 -0700200
Jeff Vander Stoep5aa68322015-06-12 09:56:39 -0700201 export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin
Ying Wang2a859d52014-06-30 10:25:33 -0700202 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 +0200203
204 # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
205 # to ensure that the corresponding 'emulator' binaries are used.
206 case $(uname -s) in
207 Darwin)
208 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
209 ;;
210 Linux)
211 ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
212 ;;
213 *)
214 ANDROID_EMULATOR_PREBUILTS=
215 ;;
216 esac
217 if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
Christopher Ferris7110f242014-05-20 13:56:00 -0700218 ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS:
David 'Digit' Turner94d16e52014-05-05 16:13:50 +0200219 export ANDROID_EMULATOR_PREBUILTS
220 fi
221
Ying Wangaa1c9b52012-11-26 20:51:59 -0800222 export PATH=$ANDROID_BUILD_PATHS$PATH
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800223
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500224 unset ANDROID_JAVA_TOOLCHAIN
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900225 unset ANDROID_PRE_BUILD_PATHS
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500226 if [ -n "$JAVA_HOME" ]; then
227 export ANDROID_JAVA_TOOLCHAIN=$JAVA_HOME/bin
Ji-Hwan Lee752ad062011-07-04 14:09:47 +0900228 export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN:
229 export PATH=$ANDROID_PRE_BUILD_PATHS$PATH
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500230 fi
231
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800232 unset ANDROID_PRODUCT_OUT
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700233 export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT)
234 export OUT=$ANDROID_PRODUCT_OUT
235
Jeff Brown8fd5cce2011-03-24 17:03:06 -0700236 unset ANDROID_HOST_OUT
237 export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT)
238
Matt Mowerf8ff73e2015-06-09 19:35:53 -0500239 if [ -n "$ANDROID_CCACHE_DIR" ]; then
240 export CCACHE_DIR=$ANDROID_CCACHE_DIR
241 fi
242
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800243 # needed for building linux on MacOS
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700244 # TODO: fix the path
245 #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include
246}
247
248function printconfig()
249{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800250 T=$(gettop)
251 if [ ! "$T" ]; then
252 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
253 return
254 fi
255 get_build_var report_config
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700256}
257
258function set_stuff_for_environment()
259{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800260 settitle
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -0500261 set_java_home
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800262 setpaths
263 set_sequence_number
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700264
Ben Chengaac3f812013-08-13 14:38:15 -0700265 # With this environment variable new GCC can apply colors to warnings/errors
266 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 -0700267 export ASAN_OPTIONS=detect_leaks=0
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700268}
269
270function set_sequence_number()
271{
Joe Onoratoaee4daa2010-06-23 14:03:13 -0700272 export BUILD_ENV_SEQUENCE_NUMBER=10
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700273}
274
275function settitle()
276{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800277 if [ "$STAY_OFF_MY_LAWN" = "" ]; then
Raghu Gandham8da43102012-07-25 19:57:22 -0700278 local arch=$(gettargetarch)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700279 local product=$TARGET_PRODUCT
280 local variant=$TARGET_BUILD_VARIANT
281 local apps=$TARGET_BUILD_APPS
Steve Kondikd6fba552012-12-27 15:28:34 -0800282 if [ -z "$PROMPT_COMMAND" ]; then
283 # No prompts
284 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\""
285 elif [ -z "$(echo $PROMPT_COMMAND | grep '033]0;')" ]; then
286 # Prompts exist, but no hardstatus
287 PROMPT_COMMAND="echo -ne \"\033]0;${USER}@${HOSTNAME}: ${PWD}\007\";${PROMPT_COMMAND}"
Joe Onoratoda12daf2010-06-09 18:18:31 -0700288 fi
Steve Kondikd6fba552012-12-27 15:28:34 -0800289 if [ ! -z "$ANDROID_PROMPT_PREFIX" ]; then
Christopher Laisfa8d9352013-06-03 15:15:39 -0500290 PROMPT_COMMAND="$(echo $PROMPT_COMMAND | sed -e 's/$ANDROID_PROMPT_PREFIX //g')"
Steve Kondikd6fba552012-12-27 15:28:34 -0800291 fi
292
293 if [ -z "$apps" ]; then
294 ANDROID_PROMPT_PREFIX="[${arch}-${product}-${variant}]"
295 else
296 ANDROID_PROMPT_PREFIX="[$arch $apps $variant]"
297 fi
298 export ANDROID_PROMPT_PREFIX
299
300 # Inject build data into hardstatus
301 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 -0800302 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700303}
304
Kyle Ladd031a0b62013-09-11 20:43:42 -0400305function check_bash_version()
Kenny Root52aa81c2011-07-15 11:07:06 -0700306{
Kenny Root52aa81c2011-07-15 11:07:06 -0700307 # Keep us from trying to run in something that isn't bash.
308 if [ -z "${BASH_VERSION}" ]; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400309 return 1
Kenny Root52aa81c2011-07-15 11:07:06 -0700310 fi
311
312 # Keep us from trying to run in bash that's too old.
James Roberts-Thomson24dd07d2013-04-16 15:53:39 +1200313 if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
Kyle Ladd031a0b62013-09-11 20:43:42 -0400314 return 2
Kenny Root52aa81c2011-07-15 11:07:06 -0700315 fi
316
Kyle Ladd031a0b62013-09-11 20:43:42 -0400317 return 0
Kenny Root52aa81c2011-07-15 11:07:06 -0700318}
319
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700320function choosetype()
321{
322 echo "Build type choices are:"
323 echo " 1. release"
324 echo " 2. debug"
325 echo
326
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800327 local DEFAULT_NUM DEFAULT_VALUE
Jeff Browne33ba4c2011-07-11 22:11:46 -0700328 DEFAULT_NUM=1
329 DEFAULT_VALUE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700330
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800331 export TARGET_BUILD_TYPE=
332 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700333 while [ -z $TARGET_BUILD_TYPE ]
334 do
335 echo -n "Which would you like? ["$DEFAULT_NUM"] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800336 if [ -z "$1" ] ; then
337 read ANSWER
338 else
339 echo $1
340 ANSWER=$1
341 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700342 case $ANSWER in
343 "")
344 export TARGET_BUILD_TYPE=$DEFAULT_VALUE
345 ;;
346 1)
347 export TARGET_BUILD_TYPE=release
348 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800349 release)
350 export TARGET_BUILD_TYPE=release
351 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700352 2)
353 export TARGET_BUILD_TYPE=debug
354 ;;
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800355 debug)
356 export TARGET_BUILD_TYPE=debug
357 ;;
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700358 *)
359 echo
360 echo "I didn't understand your response. Please try again."
361 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700362 ;;
363 esac
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800364 if [ -n "$1" ] ; then
365 break
366 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700367 done
368
369 set_stuff_for_environment
370}
371
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800372#
373# This function isn't really right: It chooses a TARGET_PRODUCT
374# based on the list of boards. Usually, that gets you something
375# that kinda works with a generic product, but really, you should
376# pick a product by name.
377#
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700378function chooseproduct()
379{
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700380 if [ "x$TARGET_PRODUCT" != x ] ; then
381 default_value=$TARGET_PRODUCT
382 else
Jeff Browne33ba4c2011-07-11 22:11:46 -0700383 default_value=full
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700384 fi
385
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800386 export TARGET_PRODUCT=
387 local ANSWER
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700388 while [ -z "$TARGET_PRODUCT" ]
389 do
Joe Onorato8849aed2009-04-29 15:56:47 -0700390 echo -n "Which product would you like? [$default_value] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800391 if [ -z "$1" ] ; then
392 read ANSWER
393 else
394 echo $1
395 ANSWER=$1
396 fi
397
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700398 if [ -z "$ANSWER" ] ; then
399 export TARGET_PRODUCT=$default_value
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800400 else
401 if check_product $ANSWER
402 then
403 export TARGET_PRODUCT=$ANSWER
404 else
405 echo "** Not a valid product: $ANSWER"
406 fi
407 fi
408 if [ -n "$1" ] ; then
409 break
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700410 fi
411 done
412
413 set_stuff_for_environment
414}
415
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800416function choosevariant()
417{
418 echo "Variant choices are:"
419 local index=1
420 local v
421 for v in ${VARIANT_CHOICES[@]}
422 do
423 # The product name is the name of the directory containing
424 # the makefile we found, above.
425 echo " $index. $v"
426 index=$(($index+1))
427 done
428
429 local default_value=eng
430 local ANSWER
431
432 export TARGET_BUILD_VARIANT=
433 while [ -z "$TARGET_BUILD_VARIANT" ]
434 do
435 echo -n "Which would you like? [$default_value] "
436 if [ -z "$1" ] ; then
437 read ANSWER
438 else
439 echo $1
440 ANSWER=$1
441 fi
442
443 if [ -z "$ANSWER" ] ; then
444 export TARGET_BUILD_VARIANT=$default_value
445 elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then
446 if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800447 export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800448 fi
449 else
450 if check_variant $ANSWER
451 then
452 export TARGET_BUILD_VARIANT=$ANSWER
453 else
454 echo "** Not a valid variant: $ANSWER"
455 fi
456 fi
457 if [ -n "$1" ] ; then
458 break
459 fi
460 done
461}
462
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700463function choosecombo()
464{
Jeff Browne33ba4c2011-07-11 22:11:46 -0700465 choosetype $1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700466
467 echo
468 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700469 chooseproduct $2
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700470
471 echo
472 echo
Jeff Browne33ba4c2011-07-11 22:11:46 -0700473 choosevariant $3
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800474
475 echo
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700476 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800477 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700478}
479
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800480# Clear this variable. It will be built up again when the vendorsetup.sh
481# files are included at the end of this file.
482unset LUNCH_MENU_CHOICES
483function add_lunch_combo()
484{
485 local new_combo=$1
486 local c
487 for c in ${LUNCH_MENU_CHOICES[@]} ; do
488 if [ "$new_combo" = "$c" ] ; then
489 return
490 fi
491 done
492 LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
493}
494
495# add the default one here
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700496add_lunch_combo aosp_arm-eng
Colin Cross4f0eb7d2014-01-21 19:35:38 -0800497add_lunch_combo aosp_arm64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000498add_lunch_combo aosp_mips-eng
Chris Dearman1efd9e42014-02-03 15:01:24 -0800499add_lunch_combo aosp_mips64-eng
Serban Constantinescu9b68fb22014-01-14 10:33:53 +0000500add_lunch_combo aosp_x86-eng
501add_lunch_combo aosp_x86_64-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800502
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700503function print_lunch_menu()
504{
505 local uname=$(uname)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700506 echo
507 echo "You're building on" $uname
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000508 if [ "$(uname)" = "Darwin" ] ; then
509 echo " (ohai, koush!)"
510 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700511 echo
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000512 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
513 echo "Breakfast menu... pick a combo:"
514 else
515 echo "Lunch menu... pick a combo:"
516 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800517
518 local i=1
519 local choice
520 for choice in ${LUNCH_MENU_CHOICES[@]}
521 do
cybojenixa5dd6ce2013-06-28 20:30:00 +0100522 echo " $i. $choice "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800523 i=$(($i+1))
cybojenixa5dd6ce2013-06-28 20:30:00 +0100524 done | column
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800525
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000526 if [ "z${CM_DEVICES_ONLY}" != "z" ]; then
527 echo "... and don't forget the bacon!"
528 fi
529
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700530 echo
531}
532
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000533function brunch()
534{
535 breakfast $*
536 if [ $? -eq 0 ]; then
537 mka bacon
538 else
539 echo "No such item in brunch menu. Try 'breakfast'"
540 return 1
541 fi
542 return $?
543}
544
545function breakfast()
546{
547 target=$1
JustArchif70c7e62014-06-22 14:37:30 +0200548 local variant=$2
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000549 CM_DEVICES_ONLY="true"
550 unset LUNCH_MENU_CHOICES
551 add_lunch_combo full-eng
552 for f in `/bin/ls vendor/cm/vendorsetup.sh 2> /dev/null`
553 do
554 echo "including $f"
555 . $f
556 done
557 unset f
558
559 if [ $# -eq 0 ]; then
560 # No arguments, so let's have the full menu
561 lunch
562 else
563 echo "z$target" | grep -q "-"
564 if [ $? -eq 0 ]; then
565 # A buildtype was specified, assume a full device name
566 lunch $target
567 else
568 # This is probably just the CM model name
JustArchif70c7e62014-06-22 14:37:30 +0200569 if [ -z "$variant" ]; then
570 variant="userdebug"
571 fi
572 lunch cm_$target-$variant
Ricardo Cerqueira8b2014d2011-01-31 00:49:49 +0000573 fi
574 fi
575 return $?
576}
577
578alias bib=breakfast
579
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700580function lunch()
581{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800582 local answer
Anthony King850627c2015-04-30 22:57:08 +0100583 LUNCH_MENU_CHOICES=($(for l in ${LUNCH_MENU_CHOICES[@]}; do echo "$l"; done | sort))
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800584
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700585 if [ "$1" ] ; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800586 answer=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700587 else
588 print_lunch_menu
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700589 echo -n "Which would you like? [aosp_arm-eng] "
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800590 read answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700591 fi
592
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800593 local selection=
594
595 if [ -z "$answer" ]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700596 then
Jean-Baptiste Queru324c1232013-03-22 15:53:54 -0700597 selection=aosp_arm-eng
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800598 elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
599 then
600 if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
601 then
Kan-Ru Chen07453762010-07-05 15:53:47 +0800602 selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800603 fi
604 elif (echo -n $answer | grep -q -e "^[^\-][^\-]*-[^\-][^\-]*$")
605 then
606 selection=$answer
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700607 fi
608
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800609 if [ -z "$selection" ]
610 then
611 echo
612 echo "Invalid lunch combo: $answer"
613 return 1
614 fi
615
Joe Onoratoda12daf2010-06-09 18:18:31 -0700616 export TARGET_BUILD_APPS=
617
Jeff Browne33ba4c2011-07-11 22:11:46 -0700618 local product=$(echo -n $selection | sed -e "s/-.*$//")
619 check_product $product
620 if [ $? -ne 0 ]
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800621 then
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800622 # if we can't find a product, try to grab it off the CM github
623 T=$(gettop)
624 pushd $T > /dev/null
625 build/tools/roomservice.py $product
626 popd > /dev/null
627 check_product $product
Diogo Ferreira0d109172012-03-18 21:18:29 +0000628 else
629 build/tools/roomservice.py $product true
Koushik Dutta780fb5f2011-11-26 18:51:42 -0800630 fi
631 if [ $? -ne 0 ]
632 then
Jeff Browne33ba4c2011-07-11 22:11:46 -0700633 echo
634 echo "** Don't have a product spec for: '$product'"
635 echo "** Do you have the right repo manifest?"
636 product=
637 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800638
Jeff Browne33ba4c2011-07-11 22:11:46 -0700639 local variant=$(echo -n $selection | sed -e "s/^[^\-]*-//")
640 check_variant $variant
641 if [ $? -ne 0 ]
642 then
643 echo
644 echo "** Invalid variant: '$variant'"
645 echo "** Must be one of ${VARIANT_CHOICES[@]}"
646 variant=
647 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800648
Jeff Browne33ba4c2011-07-11 22:11:46 -0700649 if [ -z "$product" -o -z "$variant" ]
650 then
651 echo
652 return 1
653 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800654
Jeff Browne33ba4c2011-07-11 22:11:46 -0700655 export TARGET_PRODUCT=$product
656 export TARGET_BUILD_VARIANT=$variant
657 export TARGET_BUILD_TYPE=release
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700658
659 echo
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800660
Chirayu Desaib89b3242013-06-30 10:04:25 +0530661 fixup_common_out_dir
662
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700663 set_stuff_for_environment
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800664 printconfig
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700665}
666
Jeff Davidson513d7a42010-08-02 10:00:44 -0700667# Tab completion for lunch.
668function _lunch()
669{
670 local cur prev opts
671 COMPREPLY=()
672 cur="${COMP_WORDS[COMP_CWORD]}"
673 prev="${COMP_WORDS[COMP_CWORD-1]}"
674
675 COMPREPLY=( $(compgen -W "${LUNCH_MENU_CHOICES[*]}" -- ${cur}) )
676 return 0
677}
Emilio López9ad6eea2013-11-03 13:02:13 -0300678complete -F _lunch lunch 2>/dev/null
Jeff Davidson513d7a42010-08-02 10:00:44 -0700679
Joe Onoratoda12daf2010-06-09 18:18:31 -0700680# Configures the build to build unbundled apps.
Doug Zongker0d8179e2014-04-16 11:34:34 -0700681# Run tapas with one or more app names (from LOCAL_PACKAGE_NAME)
Joe Onoratoda12daf2010-06-09 18:18:31 -0700682function tapas()
683{
Ying Wangb541ab62014-05-29 17:57:40 -0700684 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 -0700685 local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)"
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700686 local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)"
687 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 -0700688
Ying Wang67f02922012-08-22 10:25:20 -0700689 if [ $(echo $arch | wc -w) -gt 1 ]; then
690 echo "tapas: Error: Multiple build archs supplied: $arch"
691 return
692 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700693 if [ $(echo $variant | wc -w) -gt 1 ]; then
694 echo "tapas: Error: Multiple build variants supplied: $variant"
695 return
696 fi
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700697 if [ $(echo $density | wc -w) -gt 1 ]; then
698 echo "tapas: Error: Multiple densities supplied: $density"
699 return
700 fi
Ying Wang67f02922012-08-22 10:25:20 -0700701
702 local product=full
703 case $arch in
Ying Wangb541ab62014-05-29 17:57:40 -0700704 x86) product=full_x86;;
705 mips) product=full_mips;;
706 armv5) product=generic_armv5;;
707 arm64) product=aosp_arm64;;
708 x86_64) product=aosp_x86_64;;
709 mips64) product=aosp_mips64;;
Ying Wang67f02922012-08-22 10:25:20 -0700710 esac
Joe Onoratoda12daf2010-06-09 18:18:31 -0700711 if [ -z "$variant" ]; then
712 variant=eng
713 fi
Ying Wangc048c9b2010-06-24 15:08:33 -0700714 if [ -z "$apps" ]; then
715 apps=all
716 fi
Justin Morey29d225c2014-11-04 13:35:51 -0600717 if [ -z "$density" ]; then
718 density=alldpi
719 fi
Joe Onoratoda12daf2010-06-09 18:18:31 -0700720
Ying Wang67f02922012-08-22 10:25:20 -0700721 export TARGET_PRODUCT=$product
Joe Onoratoda12daf2010-06-09 18:18:31 -0700722 export TARGET_BUILD_VARIANT=$variant
Jeff Hamilton5069bd62014-09-04 21:28:00 -0700723 export TARGET_BUILD_DENSITY=$density
Joe Onoratoda12daf2010-06-09 18:18:31 -0700724 export TARGET_BUILD_TYPE=release
725 export TARGET_BUILD_APPS=$apps
726
727 set_stuff_for_environment
728 printconfig
729}
730
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100731function eat()
732{
733 if [ "$OUT" ] ; then
Chirayu Desai80a277d2013-05-04 17:59:18 +0530734 MODVERSION=$(get_build_var CM_VERSION)
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100735 ZIPFILE=cm-$MODVERSION.zip
736 ZIPPATH=$OUT/$ZIPFILE
737 if [ ! -f $ZIPPATH ] ; then
738 echo "Nothing to eat"
739 return 1
740 fi
741 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
742 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
743 echo "No device is online. Waiting for one..."
744 echo "Please connect USB and/or enable USB debugging"
745 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
746 sleep 1
747 done
748 echo "Device Found.."
749 fi
Steve Kondikec4627c2015-07-10 02:31:24 -0700750 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Chirayu Desai6dadb572012-12-26 10:53:58 +0530751 then
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100752 # if adbd isn't root we can't write to /cache/recovery/
753 adb root
754 sleep 1
755 adb wait-for-device
Steve Kondik464574f2013-04-13 07:19:52 -0700756 cat << EOF > /tmp/command
757--sideload
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100758EOF
Steve Kondik464574f2013-04-13 07:19:52 -0700759 if adb push /tmp/command /cache/recovery/ ; then
760 echo "Rebooting into recovery for sideload installation"
761 adb reboot recovery
762 adb wait-for-sideload
763 adb sideload $ZIPPATH
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100764 fi
Steve Kondik464574f2013-04-13 07:19:52 -0700765 rm /tmp/command
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100766 else
767 echo "Nothing to eat"
768 return 1
769 fi
770 return $?
Chirayu Desai6dadb572012-12-26 10:53:58 +0530771 else
772 echo "The connected device does not appear to be $CM_BUILD, run away!"
773 fi
Ricardo Cerqueiradbc3c4e2011-08-19 20:37:12 +0100774}
775
Nebojsa Cvetkovicd5c0c872012-11-09 23:02:54 +0000776function omnom
777{
778 brunch $*
779 eat
780}
781
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700782function gettop
783{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800784 local TOPFILE=build/core/envsetup.mk
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700785 if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
Brian Carlstroma5c4f172014-09-12 00:33:25 -0700786 # The following circumlocution ensures we remove symlinks from TOP.
787 (cd $TOP; PWD= /bin/pwd)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700788 else
789 if [ -f $TOPFILE ] ; then
Dan Bornsteind0b274d2009-11-24 15:48:50 -0800790 # The following circumlocution (repeated below as well) ensures
791 # that we record the true directory name and not one that is
792 # faked up with symlink names.
793 PWD= /bin/pwd
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700794 else
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800795 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700796 T=
797 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang9cd17642012-12-13 10:52:07 -0800798 \cd ..
synergyb112a402013-07-05 19:47:47 -0700799 T=`PWD= /bin/pwd -P`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700800 done
Ying Wang9cd17642012-12-13 10:52:07 -0800801 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700802 if [ -f "$T/$TOPFILE" ]; then
803 echo $T
804 fi
805 fi
806 fi
807}
808
Andrew Hsieh906cb782013-09-10 17:37:14 +0800809# Return driver for "make", if any (eg. static analyzer)
810function getdriver()
811{
812 local T="$1"
813 test "$WITH_STATIC_ANALYZER" = "0" && unset WITH_STATIC_ANALYZER
814 if [ -n "$WITH_STATIC_ANALYZER" ]; then
815 echo "\
Andrew Hsiehc4f7fba2014-03-03 16:53:17 +0800816$T/prebuilts/misc/linux-x86/analyzer/tools/scan-build/scan-build \
817--use-analyzer $T/prebuilts/misc/linux-x86/analyzer/bin/analyzer \
Andrew Hsieh906cb782013-09-10 17:37:14 +0800818--status-bugs \
819--top=$T"
820 fi
821}
822
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700823function m()
824{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800825 local T=$(gettop)
826 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700827 if [ "$T" ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800828 $DRV make -C $T -f build/core/main.mk $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700829 else
830 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700831 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700832 fi
833}
834
835function findmakefile()
836{
837 TOPFILE=build/core/envsetup.mk
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800838 local HERE=$PWD
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700839 T=
840 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
Ying Wang11b15b12012-10-11 15:05:07 -0700841 T=`PWD= /bin/pwd`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700842 if [ -f "$T/Android.mk" ]; then
843 echo $T/Android.mk
Ying Wang9cd17642012-12-13 10:52:07 -0800844 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700845 return
846 fi
Ying Wang9cd17642012-12-13 10:52:07 -0800847 \cd ..
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700848 done
Ying Wang9cd17642012-12-13 10:52:07 -0800849 \cd $HERE
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700850}
851
852function mm()
853{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800854 local T=$(gettop)
855 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700856 # If we're sitting in the root of the build tree, just do a
857 # normal make.
858 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800859 $DRV make $@
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700860 else
861 # Find the closest Android.mk file.
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800862 local M=$(findmakefile)
Ying Wanga7deb082013-08-16 13:24:47 -0700863 local MODULES=
864 local GET_INSTALL_PATH=
865 local ARGS=
Robert Greenwalt3c794d72009-07-15 15:07:44 -0700866 # Remove the path to top as the makefilepath needs to be relative
867 local M=`echo $M|sed 's:'$T'/::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700868 if [ ! "$T" ]; then
869 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700870 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700871 elif [ ! "$M" ]; then
872 echo "Couldn't locate a makefile from the current directory."
Ying Wang0c1374c2015-04-01 10:13:02 -0700873 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700874 else
Ying Wanga7deb082013-08-16 13:24:47 -0700875 for ARG in $@; do
876 case $ARG in
877 GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;;
878 esac
879 done
880 if [ -n "$GET_INSTALL_PATH" ]; then
881 MODULES=
882 ARGS=GET-INSTALL-PATH
883 else
884 MODULES=all_modules
885 ARGS=$@
886 fi
Andrew Hsieh246daf72013-09-10 18:07:23 -0700887 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 -0700888 fi
889 fi
890}
891
892function mmm()
893{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800894 local T=$(gettop)
895 local DRV=$(getdriver $T)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700896 if [ "$T" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800897 local MAKEFILE=
Alon Albert68895a92011-11-30 12:40:19 -0800898 local MODULES=
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -0800899 local ARGS=
900 local DIR TO_CHOP
Ying Wanga7deb082013-08-16 13:24:47 -0700901 local GET_INSTALL_PATH=
The Android Open Source Project88b60792009-03-03 19:28:42 -0800902 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
903 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
904 for DIR in $DIRS ; do
Alon Albert68895a92011-11-30 12:40:19 -0800905 MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'`
906 if [ "$MODULES" = "" ]; then
907 MODULES=all_modules
908 fi
909 DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700910 if [ -f $DIR/Android.mk ]; then
Ying Wanga7deb082013-08-16 13:24:47 -0700911 local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '`
912 local TO_CHOP=`expr $TO_CHOP + 1`
913 local START=`PWD= /bin/pwd`
914 local MFILE=`echo $START | cut -c${TO_CHOP}-`
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700915 if [ "$MFILE" = "" ] ; then
916 MFILE=$DIR/Android.mk
917 else
918 MFILE=$MFILE/$DIR/Android.mk
919 fi
920 MAKEFILE="$MAKEFILE $MFILE"
921 else
Ying Wanga7deb082013-08-16 13:24:47 -0700922 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100923 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wanga7deb082013-08-16 13:24:47 -0700924 GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;;
925 *) echo "No Android.mk in $DIR."; return 1;;
926 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700927 fi
928 done
Ying Wanga7deb082013-08-16 13:24:47 -0700929 if [ -n "$GET_INSTALL_PATH" ]; then
930 ARGS=$GET_INSTALL_PATH
931 MODULES=
932 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800933 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 -0700934 else
935 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700936 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700937 fi
938}
939
Ying Wangb607f7b2013-02-08 18:01:04 -0800940function mma()
941{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800942 local T=$(gettop)
943 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800944 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800945 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800946 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800947 if [ ! "$T" ]; then
948 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700949 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800950 fi
951 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800952 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800953 fi
954}
955
956function mmma()
957{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800958 local T=$(gettop)
959 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800960 if [ "$T" ]; then
961 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
962 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
963 local MY_PWD=`PWD= /bin/pwd`
964 if [ "$MY_PWD" = "$T" ]; then
965 MY_PWD=
966 else
967 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
968 fi
969 local DIR=
970 local MODULE_PATHS=
971 local ARGS=
972 for DIR in $DIRS ; do
973 if [ -d $DIR ]; then
974 if [ "$MY_PWD" = "" ]; then
975 MODULE_PATHS="$MODULE_PATHS $DIR"
976 else
977 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
978 fi
979 else
980 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100981 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800982 *) echo "Couldn't find directory $DIR"; return 1;;
983 esac
984 fi
985 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800986 $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 -0800987 else
988 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700989 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800990 fi
991}
992
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700993function croot()
994{
995 T=$(gettop)
996 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -0800997 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998 else
999 echo "Couldn't locate the top of the tree. Try setting TOP."
1000 fi
1001}
1002
nebkatfb67a1e2012-12-28 10:40:45 +00001003function cout()
1004{
1005 if [ "$OUT" ]; then
1006 cd $OUT
1007 else
1008 echo "Couldn't locate out directory. Try setting OUT."
1009 fi
1010}
1011
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001012function cproj()
1013{
1014 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001015 local HERE=$PWD
1016 T=
1017 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1018 T=$PWD
1019 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001020 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001021 return
1022 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001023 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001024 done
Ying Wang9cd17642012-12-13 10:52:07 -08001025 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001026 echo "can't find Android.mk"
1027}
1028
Daniel Sandler47e0a882013-07-30 13:23:52 -04001029# simplified version of ps; output in the form
1030# <pid> <procname>
1031function qpid() {
1032 local prepend=''
1033 local append=''
1034 if [ "$1" = "--exact" ]; then
1035 prepend=' '
1036 append='$'
1037 shift
1038 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1039 echo "usage: qpid [[--exact] <process name|pid>"
1040 return 255
1041 fi
1042
1043 local EXE="$1"
1044 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001045 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001046 else
1047 adb shell ps \
1048 | tr -d '\r' \
1049 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1050 fi
1051}
1052
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001053function pid()
1054{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001055 local prepend=''
1056 local append=''
1057 if [ "$1" = "--exact" ]; then
1058 prepend=' '
1059 append='$'
1060 shift
1061 fi
1062 local EXE="$1"
1063 if [ "$EXE" ] ; then
1064 local PID=`adb shell ps \
1065 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001066 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001067 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1068 echo "$PID"
1069 else
1070 echo "usage: pid [--exact] <process name>"
1071 return 255
1072 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001073}
1074
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001075# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001076# that has the core-file-size limit set correctly
1077#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001078# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001079# if its core-file-size limit is not set already.
1080# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1081
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001082function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001083{
1084 echo "Getting root...";
1085 adb root;
1086 adb wait-for-device;
1087
1088 echo "Remounting root parition read-write...";
1089 adb shell mount -w -o remount -t rootfs rootfs;
1090 sleep 1;
1091 adb wait-for-device;
1092 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001093 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001094 adb shell chmod 0777 /cores;
1095
1096 echo "Granting SELinux permission to dump in /cores...";
1097 adb shell restorecon -R /cores;
1098
1099 echo "Set core pattern.";
1100 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1101
1102 echo "Done."
1103}
1104
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001105# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001106# $1 = PID of process (e.g., $(pid mediaserver))
1107#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001108# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001109# dump to actually be generated.
1110
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001111function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001112{
1113 local PID=$1;
1114 if [ -z "$PID" ]; then
1115 printf "Expecting a PID!\n";
1116 return;
1117 fi;
1118 echo "Setting core limit for $PID to infinite...";
1119 adb shell prlimit $PID 4 -1 -1
1120}
1121
1122# core - send SIGV and pull the core for process
1123# $1 = PID of process (e.g., $(pid mediaserver))
1124#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001125# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001126# enabled globally.
1127
1128function core()
1129{
1130 local PID=$1;
1131
1132 if [ -z "$PID" ]; then
1133 printf "Expecting a PID!\n";
1134 return;
1135 fi;
1136
1137 local CORENAME=core.$PID;
1138 local COREPATH=/cores/$CORENAME;
1139 local SIG=SEGV;
1140
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001141 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001142
1143 local done=0;
1144 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1145 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1146 adb shell kill -$SIG $PID;
1147 sleep 1;
1148 done;
1149
1150 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1151 echo "Done: core is under $COREPATH on device.";
1152}
1153
Christopher Tate744ee802009-11-12 15:33:08 -08001154# systemstack - dump the current stack trace of all threads in the system process
1155# to the usual ANR traces file
1156function systemstack()
1157{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001158 stacks system_server
1159}
1160
1161function stacks()
1162{
1163 if [[ $1 =~ ^[0-9]+$ ]] ; then
1164 local PID="$1"
1165 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001166 local PIDLIST="$(pid $1)"
1167 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1168 local PID="$PIDLIST"
1169 elif [ "$PIDLIST" ] ; then
1170 echo "more than one process: $1"
1171 else
1172 echo "no such process: $1"
1173 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001174 else
1175 echo "usage: stacks [pid|process name]"
1176 fi
1177
1178 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001179 # Determine whether the process is native
1180 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1181 # Dump stacks of Dalvik process
1182 local TRACES=/data/anr/traces.txt
1183 local ORIG=/data/anr/traces.orig
1184 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001185
Jeff Brownb12c2e52013-08-19 15:14:16 -07001186 # Keep original traces to avoid clobbering
1187 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001188
Jeff Brownb12c2e52013-08-19 15:14:16 -07001189 # Make sure we have a usable file
1190 adb shell touch $TRACES
1191 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001192
Jeff Brownb12c2e52013-08-19 15:14:16 -07001193 # Dump stacks and wait for dump to finish
1194 adb shell kill -3 $PID
1195 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001196
Jeff Brownb12c2e52013-08-19 15:14:16 -07001197 # Restore original stacks, and show current output
1198 adb shell mv $TRACES $TMP
1199 adb shell mv $ORIG $TRACES
1200 adb shell cat $TMP
1201 else
1202 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001203 local USE64BIT="$(is64bit $PID)"
1204 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001205 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001206 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001207}
1208
Michael Wrightaeed7212014-06-19 19:58:12 -07001209# Read the ELF header from /proc/$PID/exe to determine if the process is
1210# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001211function is64bit()
1212{
1213 local PID="$1"
1214 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001215 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001216 echo "64"
1217 else
1218 echo ""
1219 fi
1220 else
1221 echo ""
1222 fi
1223}
1224
Clark Scheff75b36a42014-12-23 13:30:51 -08001225function dddclient()
1226{
1227 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1228 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1229 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1230 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1231 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1232 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1233 local ARCH=$(get_build_var TARGET_ARCH)
1234 local GDB
1235 case "$ARCH" in
1236 arm) GDB=arm-linux-androideabi-gdb;;
1237 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1238 mips|mips64) GDB=mips64el-linux-android-gdb;;
1239 x86) GDB=x86_64-linux-android-gdb;;
1240 x86_64) GDB=x86_64-linux-android-gdb;;
1241 *) echo "Unknown arch $ARCH"; return 1;;
1242 esac
1243
1244 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1245 local EXE="$1"
1246 if [ "$EXE" ] ; then
1247 EXE=$1
1248 if [[ $EXE =~ ^[^/].* ]] ; then
1249 EXE="system/bin/"$EXE
1250 fi
1251 else
1252 EXE="app_process"
1253 fi
1254
1255 local PORT="$2"
1256 if [ "$PORT" ] ; then
1257 PORT=$2
1258 else
1259 PORT=":5039"
1260 fi
1261
1262 local PID="$3"
1263 if [ "$PID" ] ; then
1264 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1265 PID=`pid $3`
1266 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1267 # that likely didn't work because of returning multiple processes
1268 # try again, filtering by root processes (don't contain colon)
1269 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1270 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1271 then
1272 echo "Couldn't resolve '$3' to single PID"
1273 return 1
1274 else
1275 echo ""
1276 echo "WARNING: multiple processes matching '$3' observed, using root process"
1277 echo ""
1278 fi
1279 fi
1280 fi
1281 adb forward "tcp$PORT" "tcp$PORT"
1282 local USE64BIT="$(is64bit $PID)"
1283 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1284 sleep 2
1285 else
1286 echo ""
1287 echo "If you haven't done so already, do this first on the device:"
1288 echo " gdbserver $PORT /system/bin/$EXE"
1289 echo " or"
1290 echo " gdbserver $PORT --attach <PID>"
1291 echo ""
1292 fi
1293
1294 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1295 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1296
1297 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1298 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"
1299 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1300 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1301 # Enable special debugging for ART processes.
1302 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1303 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1304 fi
1305 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1306
1307 local WHICH_GDB=
1308 # 64-bit exe found
1309 if [ "$USE64BIT" != "" ] ; then
1310 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1311 # 32-bit exe / 32-bit platform
1312 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1313 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1314 # 32-bit exe / 64-bit platform
1315 else
1316 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1317 fi
1318
1319 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1320 else
1321 echo "Unable to determine build system output dir."
1322 fi
1323}
1324
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001325case `uname -s` in
1326 Darwin)
1327 function sgrep()
1328 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001329 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 -07001330 }
1331
1332 ;;
1333 *)
1334 function sgrep()
1335 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001336 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 -07001337 }
1338 ;;
1339esac
1340
Raghu Gandham8da43102012-07-25 19:57:22 -07001341function gettargetarch
1342{
1343 get_build_var TARGET_ARCH
1344}
1345
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001346function ggrep()
1347{
1348 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1349}
1350
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001351function jgrep()
1352{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001353 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 -07001354}
1355
1356function cgrep()
1357{
Dan Albert01961192014-11-22 10:16:01 -08001358 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 -07001359}
1360
1361function resgrep()
1362{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001363 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 -07001364}
1365
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001366function mangrep()
1367{
1368 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1369}
1370
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001371function sepgrep()
1372{
1373 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 "$@"
1374}
1375
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001376function rcgrep()
1377{
1378 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1379}
1380
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001381case `uname -s` in
1382 Darwin)
1383 function mgrep()
1384 {
Ying Wang324c2b22012-08-17 15:03:20 -07001385 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 -07001386 }
1387
1388 function treegrep()
1389 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001390 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 -07001391 }
1392
1393 ;;
1394 *)
1395 function mgrep()
1396 {
Ying Wang324c2b22012-08-17 15:03:20 -07001397 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 -07001398 }
1399
1400 function treegrep()
1401 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001402 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 -07001403 }
1404
1405 ;;
1406esac
1407
1408function getprebuilt
1409{
1410 get_abs_build_var ANDROID_PREBUILTS
1411}
1412
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001413function tracedmdump()
1414{
1415 T=$(gettop)
1416 if [ ! "$T" ]; then
1417 echo "Couldn't locate the top of the tree. Try setting TOP."
1418 return
1419 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001420 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001421 local arch=$(gettargetarch)
1422 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001423
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001424 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001425 if [ ! "$TRACE" ] ; then
1426 echo "usage: tracedmdump tracename"
1427 return
1428 fi
1429
Jack Veenstra60116fc2009-04-09 18:12:34 -07001430 if [ ! -r "$KERNEL" ] ; then
1431 echo "Error: cannot find kernel: '$KERNEL'"
1432 return
1433 fi
1434
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001435 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001436 if [ "$BASETRACE" = "$TRACE" ] ; then
1437 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1438 fi
1439
1440 echo "post-processing traces..."
1441 rm -f $TRACE/qtrace.dexlist
1442 post_trace $TRACE
1443 if [ $? -ne 0 ]; then
1444 echo "***"
1445 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1446 echo "***"
1447 return
1448 fi
1449 echo "generating dexlist output..."
1450 /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
1451 echo "generating dmtrace data..."
1452 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1453 echo "generating html file..."
1454 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1455 echo "done, see $TRACE/dmtrace.html for details"
1456 echo "or run:"
1457 echo " traceview $TRACE/dmtrace"
1458}
1459
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001460# communicate with a running device or emulator, set up necessary state,
1461# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001462function runhat()
1463{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001464 # process standard adb options
1465 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001466 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001467 adbTarget=$1
1468 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001469 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001470 adbTarget="$1 $2"
1471 shift 2
1472 fi
1473 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001474 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001475
1476 # runhat options
1477 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001478
1479 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001480 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001481 return
1482 fi
1483
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001484 # confirm hat is available
1485 if [ -z $(which hat) ]; then
1486 echo "hat is not available in this configuration."
1487 return
1488 fi
1489
Andy McFaddenb6289852010-07-12 08:00:19 -07001490 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001491 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001492 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001493 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001494 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001495 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001496 echo -n "> "
1497 read
1498
The Android Open Source Project88b60792009-03-03 19:28:42 -08001499 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001500
The Android Open Source Project88b60792009-03-03 19:28:42 -08001501 echo "Retrieving file $devFile..."
1502 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001503
The Android Open Source Project88b60792009-03-03 19:28:42 -08001504 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001505
The Android Open Source Project88b60792009-03-03 19:28:42 -08001506 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001507 echo "View the output by pointing your browser at http://localhost:7000/"
1508 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001509 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001510}
1511
1512function getbugreports()
1513{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001514 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001515
1516 if [ ! "$reports" ]; then
1517 echo "Could not locate any bugreports."
1518 return
1519 fi
1520
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001521 local report
1522 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001523 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001524 echo "/sdcard/bugreports/${report}"
1525 adb pull /sdcard/bugreports/${report} ${report}
1526 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001527 done
1528}
1529
Victoria Lease1b296b42012-08-21 15:44:06 -07001530function getsdcardpath()
1531{
1532 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1533}
1534
1535function getscreenshotpath()
1536{
1537 echo "$(getsdcardpath)/Pictures/Screenshots"
1538}
1539
1540function getlastscreenshot()
1541{
1542 local screenshot_path=$(getscreenshotpath)
1543 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1544 if [ "$screenshot" = "" ]; then
1545 echo "No screenshots found."
1546 return
1547 fi
1548 echo "${screenshot}"
1549 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1550}
1551
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001552function startviewserver()
1553{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001554 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001555 if [ $# -gt 0 ]; then
1556 port=$1
1557 fi
1558 adb shell service call window 1 i32 $port
1559}
1560
1561function stopviewserver()
1562{
1563 adb shell service call window 2
1564}
1565
1566function isviewserverstarted()
1567{
1568 adb shell service call window 3
1569}
1570
Romain Guyb84049a2010-10-04 16:56:11 -07001571function key_home()
1572{
1573 adb shell input keyevent 3
1574}
1575
1576function key_back()
1577{
1578 adb shell input keyevent 4
1579}
1580
1581function key_menu()
1582{
1583 adb shell input keyevent 82
1584}
1585
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001586function smoketest()
1587{
1588 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1589 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1590 return
1591 fi
1592 T=$(gettop)
1593 if [ ! "$T" ]; then
1594 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1595 return
1596 fi
1597
Ying Wang9cd17642012-12-13 10:52:07 -08001598 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001599 adb uninstall com.android.smoketest > /dev/null &&
1600 adb uninstall com.android.smoketest.tests > /dev/null &&
1601 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1602 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1603 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1604}
1605
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001606# simple shortcut to the runtest command
1607function runtest()
1608{
1609 T=$(gettop)
1610 if [ ! "$T" ]; then
1611 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1612 return
1613 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001614 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001615}
1616
The Android Open Source Project88b60792009-03-03 19:28:42 -08001617function godir () {
1618 if [[ -z "$1" ]]; then
1619 echo "Usage: godir <regex>"
1620 return
1621 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001622 T=$(gettop)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001623 if [[ ! -f $T/filelist ]]; then
1624 echo -n "Creating index..."
Ying Wang9cd17642012-12-13 10:52:07 -08001625 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > filelist)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001626 echo " Done"
1627 echo ""
1628 fi
1629 local lines
Jeff Hamilton293f9392011-11-18 17:15:25 -06001630 lines=($(\grep "$1" $T/filelist | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001631 if [[ ${#lines[@]} = 0 ]]; then
1632 echo "Not found"
1633 return
1634 fi
1635 local pathname
1636 local choice
1637 if [[ ${#lines[@]} > 1 ]]; then
1638 while [[ -z "$pathname" ]]; do
1639 local index=1
1640 local line
1641 for line in ${lines[@]}; do
1642 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001643 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001644 done
1645 echo
1646 echo -n "Select one: "
1647 unset choice
1648 read choice
1649 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1650 echo "Invalid choice"
1651 continue
1652 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001653 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001654 done
1655 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001656 pathname=${lines[0]}
1657 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001658 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001659}
1660
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001661function cmremote()
1662{
1663 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301664 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001665 if [ -z "$GERRIT_REMOTE" ]
1666 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301667 echo Unable to set up the git remote, are you under a git repo?
1668 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001669 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301670 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001671 if [ -z "$CMUSER" ]
1672 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001673 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001674 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001675 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001676 fi
1677 echo You can now push to "cmremote".
1678}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001679
Steve Kondik873fa562012-09-17 11:33:18 -07001680function aospremote()
1681{
1682 git remote rm aosp 2> /dev/null
1683 if [ ! -d .git ]
1684 then
1685 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1686 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001687 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001688 if (echo $PROJECT | grep -qv "^device")
1689 then
1690 PFX="platform/"
1691 fi
1692 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1693 echo "Remote 'aosp' created"
1694}
Steve Kondik873fa562012-09-17 11:33:18 -07001695
Steve Kondik20c21d22013-10-27 13:34:36 -07001696function cafremote()
1697{
1698 git remote rm caf 2> /dev/null
1699 if [ ! -d .git ]
1700 then
1701 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1702 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001703 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001704 if (echo $PROJECT | grep -qv "^device")
1705 then
1706 PFX="platform/"
1707 fi
1708 git remote add caf git://codeaurora.org/$PFX$PROJECT
1709 echo "Remote 'caf' created"
1710}
Steve Kondik20c21d22013-10-27 13:34:36 -07001711
Steve Kondikf00e7d92012-09-23 23:46:55 -07001712function installboot()
1713{
1714 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1715 then
1716 echo "No recovery.fstab found. Build recovery first."
1717 return 1
1718 fi
1719 if [ ! -e "$OUT/boot.img" ];
1720 then
1721 echo "No boot.img found. Run make bootimage first."
1722 return 1
1723 fi
1724 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1725 if [ -z "$PARTITION" ];
1726 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001727 # Try for RECOVERY_FSTAB_VERSION = 2
1728 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1729 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1730 if [ -z "$PARTITION" ];
1731 then
1732 echo "Unable to determine boot partition."
1733 return 1
1734 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001735 fi
1736 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001737 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001738 adb root
1739 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001740 adb wait-for-online shell mount /system 2>&1 > /dev/null
1741 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001742 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondikf00e7d92012-09-23 23:46:55 -07001743 then
1744 adb push $OUT/boot.img /cache/
1745 for i in $OUT/system/lib/modules/*;
1746 do
1747 adb push $i /system/lib/modules/
1748 done
1749 adb shell dd if=/cache/boot.img of=$PARTITION
1750 adb shell chmod 644 /system/lib/modules/*
1751 echo "Installation complete."
1752 else
1753 echo "The connected device does not appear to be $CM_BUILD, run away!"
1754 fi
1755}
1756
Steve Kondik83c03d52012-10-24 16:40:42 -07001757function installrecovery()
1758{
1759 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1760 then
1761 echo "No recovery.fstab found. Build recovery first."
1762 return 1
1763 fi
1764 if [ ! -e "$OUT/recovery.img" ];
1765 then
1766 echo "No recovery.img found. Run make recoveryimage first."
1767 return 1
1768 fi
1769 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1770 if [ -z "$PARTITION" ];
1771 then
Steve Kondik75f10762013-08-09 21:03:42 -07001772 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001773 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1774 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001775 if [ -z "$PARTITION" ];
1776 then
1777 echo "Unable to determine recovery partition."
1778 return 1
1779 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001780 fi
1781 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001782 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001783 adb root
1784 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001785 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1786 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001787 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondik83c03d52012-10-24 16:40:42 -07001788 then
1789 adb push $OUT/recovery.img /cache/
1790 adb shell dd if=/cache/recovery.img of=$PARTITION
1791 echo "Installation complete."
1792 else
1793 echo "The connected device does not appear to be $CM_BUILD, run away!"
1794 fi
1795}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001796
Koushik Duttab55f13a2012-05-14 16:14:36 -07001797function makerecipe() {
1798 if [ -z "$1" ]
1799 then
1800 echo "No branch name provided."
1801 return 1
1802 fi
1803 cd android
1804 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1805 git commit -a -m "$1"
1806 cd ..
1807
1808 repo forall -c '
1809
1810 if [ "$REPO_REMOTE" == "github" ]
1811 then
1812 pwd
1813 cmremote
1814 git push cmremote HEAD:refs/heads/'$1'
1815 fi
1816 '
1817}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001818
1819function cmgerrit() {
1820 if [ $# -eq 0 ]; then
1821 $FUNCNAME help
1822 return 1
1823 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001824 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001825 local review=`git config --get remote.github.review`
1826 local project=`git config --get remote.github.projectname`
1827 local command=$1
1828 shift
1829 case $command in
1830 help)
1831 if [ $# -eq 0 ]; then
1832 cat <<EOF
1833Usage:
1834 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1835
1836Commands:
1837 fetch Just fetch the change as FETCH_HEAD
1838 help Show this help, or for a specific command
1839 pull Pull a change into current branch
1840 push Push HEAD or a local branch to Gerrit for a specific branch
1841
1842Any other Git commands that support refname would work as:
1843 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1844
1845See '$FUNCNAME help COMMAND' for more information on a specific command.
1846
1847Example:
1848 $FUNCNAME checkout -b topic 1234/5
1849works as:
1850 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1851 && git checkout -b topic FETCH_HEAD
1852will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1853Patch-set 1 will be fetched if omitted.
1854EOF
1855 return
1856 fi
1857 case $1 in
1858 __cmg_*) echo "For internal use only." ;;
1859 changes|for)
1860 if [ "$FUNCNAME" = "cmgerrit" ]; then
1861 echo "'$FUNCNAME $1' is deprecated."
1862 fi
1863 ;;
1864 help) $FUNCNAME help ;;
1865 fetch|pull) cat <<EOF
1866usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1867
1868works as:
1869 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1870 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1871
1872Example:
1873 $FUNCNAME $1 1234
1874will $1 patch-set 1 of change 1234
1875EOF
1876 ;;
1877 push) cat <<EOF
1878usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1879
1880works as:
1881 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1882 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1883
1884Example:
1885 $FUNCNAME push fix6789:gingerbread
1886will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1887HEAD will be pushed from local if omitted.
1888EOF
1889 ;;
1890 *)
1891 $FUNCNAME __cmg_err_not_supported $1 && return
1892 cat <<EOF
1893usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1894
1895works as:
1896 git fetch http://DOMAIN/p/PROJECT \\
1897 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1898 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1899EOF
1900 ;;
1901 esac
1902 ;;
1903 __cmg_get_ref)
1904 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1905 local change_id patchset_id hash
1906 case $1 in
1907 */*)
1908 change_id=${1%%/*}
1909 patchset_id=${1#*/}
1910 ;;
1911 *)
1912 change_id=$1
1913 patchset_id=1
1914 ;;
1915 esac
1916 hash=$(($change_id % 100))
1917 case $hash in
1918 [0-9]) hash="0$hash" ;;
1919 esac
1920 echo "refs/changes/$hash/$change_id/$patchset_id"
1921 ;;
1922 fetch|pull)
1923 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1924 $FUNCNAME __cmg_err_not_repo && return 1
1925 local change=$1
1926 shift
1927 git $command $@ http://$review/p/$project \
1928 $($FUNCNAME __cmg_get_ref $change) || return 1
1929 ;;
1930 push)
1931 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1932 $FUNCNAME __cmg_err_not_repo && return 1
1933 if [ -z "$user" ]; then
1934 echo >&2 "Gerrit username not found."
1935 return 1
1936 fi
1937 local local_branch remote_branch
1938 case $1 in
1939 *:*)
1940 local_branch=${1%:*}
1941 remote_branch=${1##*:}
1942 ;;
1943 *)
1944 local_branch=HEAD
1945 remote_branch=$1
1946 ;;
1947 esac
1948 shift
1949 git push $@ ssh://$user@$review:29418/$project \
1950 $local_branch:refs/for/$remote_branch || return 1
1951 ;;
1952 changes|for)
1953 if [ "$FUNCNAME" = "cmgerrit" ]; then
1954 echo >&2 "'$FUNCNAME $command' is deprecated."
1955 fi
1956 ;;
1957 __cmg_err_no_arg)
1958 if [ $# -lt 2 ]; then
1959 echo >&2 "'$FUNCNAME $command' missing argument."
1960 elif [ $2 -eq 0 ]; then
1961 if [ -n "$3" ]; then
1962 $FUNCNAME help $1
1963 else
1964 echo >&2 "'$FUNCNAME $1' missing argument."
1965 fi
1966 else
1967 return 1
1968 fi
1969 ;;
1970 __cmg_err_not_repo)
1971 if [ -z "$review" -o -z "$project" ]; then
1972 echo >&2 "Not currently in any reviewable repository."
1973 else
1974 return 1
1975 fi
1976 ;;
1977 __cmg_err_not_supported)
1978 $FUNCNAME __cmg_err_no_arg $command $# && return
1979 case $1 in
1980 #TODO: filter more git commands that don't use refname
1981 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1982 echo >&2 "'$FUNCNAME $1' is not supported."
1983 ;;
1984 *) return 1 ;;
1985 esac
1986 ;;
1987 #TODO: other special cases?
1988 *)
1989 $FUNCNAME __cmg_err_not_supported $command && return 1
1990 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1991 $FUNCNAME __cmg_err_not_repo && return 1
1992 local args="$@"
1993 local change pre_args refs_arg post_args
1994 case "$args" in
1995 *--\ *)
1996 pre_args=${args%%-- *}
1997 post_args="-- ${args#*-- }"
1998 ;;
1999 *) pre_args="$args" ;;
2000 esac
2001 args=($pre_args)
2002 pre_args=
2003 if [ ${#args[@]} -gt 0 ]; then
2004 change=${args[${#args[@]}-1]}
2005 fi
2006 if [ ${#args[@]} -gt 1 ]; then
2007 pre_args=${args[0]}
2008 for ((i=1; i<${#args[@]}-1; i++)); do
2009 pre_args="$pre_args ${args[$i]}"
2010 done
2011 fi
2012 while ((1)); do
2013 case $change in
2014 ""|--)
2015 $FUNCNAME help $command
2016 return 1
2017 ;;
2018 *@*)
2019 if [ -z "$refs_arg" ]; then
2020 refs_arg="@${change#*@}"
2021 change=${change%%@*}
2022 fi
2023 ;;
2024 *~*)
2025 if [ -z "$refs_arg" ]; then
2026 refs_arg="~${change#*~}"
2027 change=${change%%~*}
2028 fi
2029 ;;
2030 *^*)
2031 if [ -z "$refs_arg" ]; then
2032 refs_arg="^${change#*^}"
2033 change=${change%%^*}
2034 fi
2035 ;;
2036 *:*)
2037 if [ -z "$refs_arg" ]; then
2038 refs_arg=":${change#*:}"
2039 change=${change%%:*}
2040 fi
2041 ;;
2042 *) break ;;
2043 esac
2044 done
2045 $FUNCNAME fetch $change \
2046 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2047 || return 1
2048 ;;
2049 esac
2050}
2051
2052function cmrebase() {
2053 local repo=$1
2054 local refs=$2
2055 local pwd="$(pwd)"
2056 local dir="$(gettop)/$repo"
2057
2058 if [ -z $repo ] || [ -z $refs ]; then
2059 echo "CyanogenMod Gerrit Rebase Usage: "
2060 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2061 echo " The patch IDs appear on the Gerrit commands that are offered."
2062 echo " They consist on a series of numbers and slashes, after the text"
2063 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2064 echo ""
2065 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2066 echo ""
2067 return
2068 fi
2069
2070 if [ ! -d $dir ]; then
2071 echo "Directory $dir doesn't exist in tree."
2072 return
2073 fi
2074 cd $dir
2075 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2076 echo "Starting branch..."
2077 repo start tmprebase .
2078 echo "Bringing it up to date..."
2079 repo sync .
2080 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07002081 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002082 if [ "$?" != "0" ]; then
2083 echo "Error cherry-picking. Not uploading!"
2084 return
2085 fi
2086 echo "Uploading..."
2087 repo upload .
2088 echo "Cleaning up..."
2089 repo abandon tmprebase .
2090 cd $pwd
2091}
2092
2093function mka() {
2094 case `uname -s` in
2095 Darwin)
2096 make -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2097 ;;
2098 *)
Anthony King40b093f2015-04-30 22:19:48 +01002099 mk_timer schedtool -B -n 1 -e ionice -n 1 make -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002100 ;;
2101 esac
2102}
2103
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302104function cmka() {
2105 if [ ! -z "$1" ]; then
2106 for i in "$@"; do
2107 case $i in
2108 bacon|otapackage|systemimage)
2109 mka installclean
2110 mka $i
2111 ;;
2112 *)
2113 mka clean-$i
2114 mka $i
2115 ;;
2116 esac
2117 done
2118 else
2119 mka clean
2120 mka
2121 fi
2122}
2123
Matt Mower8dacaed2013-12-29 12:57:20 -06002124function repolastsync() {
2125 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
2126 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
2127 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
2128 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
2129}
2130
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002131function reposync() {
2132 case `uname -s` in
2133 Darwin)
2134 repo sync -j 4 "$@"
2135 ;;
2136 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002137 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002138 ;;
2139 esac
2140}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002141
2142function repodiff() {
2143 if [ -z "$*" ]; then
2144 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2145 return
2146 fi
2147 diffopts=$* repo forall -c \
2148 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2149}
2150
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302151# Credit for color strip sed: http://goo.gl/BoIcm
2152function dopush()
2153{
2154 local func=$1
2155 shift
2156
2157 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2158 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2159 echo "No device is online. Waiting for one..."
2160 echo "Please connect USB and/or enable USB debugging"
2161 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2162 sleep 1
2163 done
2164 echo "Device Found."
2165 fi
2166
Steve Kondikec4627c2015-07-10 02:31:24 -07002167 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD") || [ "$FORCE_PUSH" == "true" ];
Chirayu Desai6dadb572012-12-26 10:53:58 +05302168 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002169 # retrieve IP and PORT info if we're using a TCP connection
2170 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2171 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302172 adb root &> /dev/null
2173 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002174 if [ -n "$TCPIPPORT" ]
2175 then
2176 # adb root just killed our connection
2177 # so reconnect...
2178 adb connect "$TCPIPPORT"
2179 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302180 adb wait-for-device &> /dev/null
2181 sleep 0.3
2182 adb remount &> /dev/null
2183
Matt Mower668ea262014-05-20 02:52:23 -05002184 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00002185 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2186 ret=$?;
2187 if [ $ret -ne 0 ]; then
2188 rm -f $OUT/.log;return $ret
2189 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302190
2191 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002192 LOC="$(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep '^Install: ' | cut -d ':' -f 2)"
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302193
2194 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002195 LOC="$LOC $(cat $OUT/.log | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | grep '^Copy: ' | cut -d ':' -f 2)"
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302196
Matt Mower668ea262014-05-20 02:52:23 -05002197 stop_n_start=false
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302198 for FILE in $LOC; do
Matt Mower668ea262014-05-20 02:52:23 -05002199 # Make sure file is in $OUT/system
2200 case $FILE in
2201 $OUT/system/*)
2202 # Get target file name (i.e. /system/bin/adb)
2203 TARGET=$(echo $FILE | sed "s#$OUT##")
2204 ;;
2205 *) continue ;;
2206 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302207
Matt Mower668ea262014-05-20 02:52:23 -05002208 case $TARGET in
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002209 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002210 # Only need to stop services once
2211 if ! $stop_n_start; then
2212 adb shell stop
2213 stop_n_start=true
2214 fi
2215 echo "Pushing: $TARGET"
2216 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302217 ;;
2218 *)
Matt Mower668ea262014-05-20 02:52:23 -05002219 echo "Pushing: $TARGET"
2220 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302221 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002222 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302223 done
Matt Mower668ea262014-05-20 02:52:23 -05002224 if $stop_n_start; then
2225 adb shell start
2226 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302227 rm -f $OUT/.log
2228 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302229 else
2230 echo "The connected device does not appear to be $CM_BUILD, run away!"
2231 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302232}
2233
2234alias mmp='dopush mm'
2235alias mmmp='dopush mmm'
2236alias mkap='dopush mka'
2237alias cmkap='dopush cmka'
2238
Chirayu Desai4a319b82013-06-05 20:14:33 +05302239function repopick() {
2240 T=$(gettop)
2241 $T/build/tools/repopick.py $@
2242}
2243
Chirayu Desaib89b3242013-06-30 10:04:25 +05302244function fixup_common_out_dir() {
2245 common_out_dir=$(get_build_var OUT_DIR)/target/common
2246 target_device=$(get_build_var TARGET_DEVICE)
2247 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2248 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2249 mv ${common_out_dir} ${common_out_dir}-${target_device}
2250 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2251 else
2252 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2253 mkdir -p ${common_out_dir}-${target_device}
2254 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2255 fi
2256 else
2257 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2258 mkdir -p ${common_out_dir}
2259 fi
2260}
2261
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002262# Force JAVA_HOME to point to java 1.7 or java 1.6 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002263#
2264# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2265# For some reason, installing the JDK doesn't make it show up in the
2266# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002267function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002268 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002269 # we can reset it later, depending on the version of java the build
2270 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002271 #
2272 # If we don't do this, the JAVA_HOME value set by the first call to
2273 # build/envsetup.sh will persist forever.
2274 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2275 export JAVA_HOME=""
2276 fi
2277
Andy McFaddenbd960942010-06-24 12:52:51 -07002278 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002279 case `uname -s` in
2280 Darwin)
2281 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2282 ;;
2283 *)
2284 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2285 ;;
2286 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002287
2288 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2289 # we can change it on the next envsetup.sh, if required.
2290 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002291 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002292}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002293
Alex Rayf0d08eb2013-03-08 15:15:06 -08002294# Print colored exit condition
2295function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002296 "$@"
2297 local retval=$?
2298 if [ $retval -ne 0 ]
2299 then
2300 echo -e "\e[0;31mFAILURE\e[00m"
2301 else
2302 echo -e "\e[0;32mSUCCESS\e[00m"
2303 fi
2304 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002305}
2306
Ying Wanged21d4c2014-08-24 22:14:19 -07002307function get_make_command()
2308{
2309 echo command make
2310}
2311
Anthony King40b093f2015-04-30 22:19:48 +01002312function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002313{
2314 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002315 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002316 local ret=$?
2317 local end_time=$(date +"%s")
2318 local tdiff=$(($end_time-$start_time))
2319 local hours=$(($tdiff / 3600 ))
2320 local mins=$((($tdiff % 3600) / 60))
2321 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002322 local ncolors=$(tput colors 2>/dev/null)
2323 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2324 color_failed="\e[0;31m"
2325 color_success="\e[0;32m"
2326 color_reset="\e[00m"
2327 else
2328 color_failed=""
2329 color_success=""
2330 color_reset=""
2331 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002332 echo
2333 if [ $ret -eq 0 ] ; then
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002334 echo -n -e "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002335 else
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002336 echo -n -e "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002337 fi
2338 if [ $hours -gt 0 ] ; then
2339 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2340 elif [ $mins -gt 0 ] ; then
2341 printf "(%02g:%02g (mm:ss))" $mins $secs
2342 elif [ $secs -gt 0 ] ; then
2343 printf "(%s seconds)" $secs
2344 fi
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002345 echo -e " ####${color_reset}"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002346 echo
2347 return $ret
2348}
2349
Anthony King40b093f2015-04-30 22:19:48 +01002350function make()
2351{
2352 mk_timer $(get_make_command) "$@"
2353}
2354
Raphael Moll70a86b02011-06-20 16:03:14 -07002355if [ "x$SHELL" != "x/bin/bash" ]; then
2356 case `ps -o command -p $$` in
2357 *bash*)
2358 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002359 *zsh*)
2360 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002361 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002362 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002363 ;;
2364 esac
2365fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002366
2367# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002368for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2369 `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 -08002370do
2371 echo "including $f"
2372 . $f
2373done
2374unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002375
Kyle Ladd031a0b62013-09-11 20:43:42 -04002376# Add completions
2377check_bash_version && {
2378 dirs="sdk/bash_completion vendor/cm/bash_completion"
2379 for dir in $dirs; do
2380 if [ -d ${dir} ]; then
2381 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2382 echo "including $f"
2383 . $f
2384 done
2385 fi
2386 done
2387}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302388
2389export ANDROID_BUILD_TOP=$(gettop)