blob: 5f0e9fe9e0535138e4f0ee498322d1e467bdfc97 [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
Steve Kondike9f828c2015-11-10 23:51:21 +0100757--sideload_auto_reboot
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;;
Abhinav1997c3eb1072015-10-18 19:49:13 +0200925 *) if [ -d $DIR ]; then
926 echo "No Android.mk in $DIR.";
927 else
928 echo "Couldn't locate the directory $DIR";
929 fi
930 return 1;;
Ying Wanga7deb082013-08-16 13:24:47 -0700931 esac
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700932 fi
933 done
Ying Wanga7deb082013-08-16 13:24:47 -0700934 if [ -n "$GET_INSTALL_PATH" ]; then
935 ARGS=$GET_INSTALL_PATH
936 MODULES=
937 fi
Andrew Hsieh906cb782013-09-10 17:37:14 +0800938 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 -0700939 else
940 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700941 return 1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700942 fi
943}
944
Ying Wangb607f7b2013-02-08 18:01:04 -0800945function mma()
946{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800947 local T=$(gettop)
948 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800949 if [ -f build/core/envsetup.mk -a -f Makefile ]; then
Andrew Hsieh906cb782013-09-10 17:37:14 +0800950 $DRV make $@
Ying Wangb607f7b2013-02-08 18:01:04 -0800951 else
Ying Wangb607f7b2013-02-08 18:01:04 -0800952 if [ ! "$T" ]; then
953 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700954 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800955 fi
956 local MY_PWD=`PWD= /bin/pwd|sed 's:'$T'/::'`
Andrew Hsieh906cb782013-09-10 17:37:14 +0800957 $DRV make -C $T -f build/core/main.mk $@ all_modules BUILD_MODULES_IN_PATHS="$MY_PWD"
Ying Wangb607f7b2013-02-08 18:01:04 -0800958 fi
959}
960
961function mmma()
962{
Andrew Hsieh906cb782013-09-10 17:37:14 +0800963 local T=$(gettop)
964 local DRV=$(getdriver $T)
Ying Wangb607f7b2013-02-08 18:01:04 -0800965 if [ "$T" ]; then
966 local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/')
967 local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/')
968 local MY_PWD=`PWD= /bin/pwd`
969 if [ "$MY_PWD" = "$T" ]; then
970 MY_PWD=
971 else
972 MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'`
973 fi
974 local DIR=
975 local MODULE_PATHS=
976 local ARGS=
977 for DIR in $DIRS ; do
978 if [ -d $DIR ]; then
979 if [ "$MY_PWD" = "" ]; then
980 MODULE_PATHS="$MODULE_PATHS $DIR"
981 else
982 MODULE_PATHS="$MODULE_PATHS $MY_PWD/$DIR"
983 fi
984 else
985 case $DIR in
Adrian Roosafa958f2015-03-05 19:52:55 +0100986 showcommands | snod | dist | incrementaljavac | *=*) ARGS="$ARGS $DIR";;
Ying Wangb607f7b2013-02-08 18:01:04 -0800987 *) echo "Couldn't find directory $DIR"; return 1;;
988 esac
989 fi
990 done
Andrew Hsieh906cb782013-09-10 17:37:14 +0800991 $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 -0800992 else
993 echo "Couldn't locate the top of the tree. Try setting TOP."
Ying Wang0c1374c2015-04-01 10:13:02 -0700994 return 1
Ying Wangb607f7b2013-02-08 18:01:04 -0800995 fi
996}
997
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -0700998function croot()
999{
1000 T=$(gettop)
1001 if [ "$T" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001002 \cd $(gettop)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001003 else
1004 echo "Couldn't locate the top of the tree. Try setting TOP."
1005 fi
1006}
1007
nebkatfb67a1e2012-12-28 10:40:45 +00001008function cout()
1009{
1010 if [ "$OUT" ]; then
1011 cd $OUT
1012 else
1013 echo "Couldn't locate out directory. Try setting OUT."
1014 fi
1015}
1016
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001017function cproj()
1018{
1019 TOPFILE=build/core/envsetup.mk
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001020 local HERE=$PWD
1021 T=
1022 while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
1023 T=$PWD
1024 if [ -f "$T/Android.mk" ]; then
Ying Wang9cd17642012-12-13 10:52:07 -08001025 \cd $T
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001026 return
1027 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001028 \cd ..
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001029 done
Ying Wang9cd17642012-12-13 10:52:07 -08001030 \cd $HERE
Joe Onorato2a5d4d82009-07-30 10:23:21 -07001031 echo "can't find Android.mk"
1032}
1033
Daniel Sandler47e0a882013-07-30 13:23:52 -04001034# simplified version of ps; output in the form
1035# <pid> <procname>
1036function qpid() {
1037 local prepend=''
1038 local append=''
1039 if [ "$1" = "--exact" ]; then
1040 prepend=' '
1041 append='$'
1042 shift
1043 elif [ "$1" = "--help" -o "$1" = "-h" ]; then
1044 echo "usage: qpid [[--exact] <process name|pid>"
1045 return 255
1046 fi
1047
1048 local EXE="$1"
1049 if [ "$EXE" ] ; then
Mathias Agopian44583272013-08-27 14:15:50 -07001050 qpid | \grep "$prepend$EXE$append"
Daniel Sandler47e0a882013-07-30 13:23:52 -04001051 else
1052 adb shell ps \
1053 | tr -d '\r' \
1054 | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/'
1055 fi
1056}
1057
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001058function pid()
1059{
Daniel Sandler47e0a882013-07-30 13:23:52 -04001060 local prepend=''
1061 local append=''
1062 if [ "$1" = "--exact" ]; then
1063 prepend=' '
1064 append='$'
1065 shift
1066 fi
1067 local EXE="$1"
1068 if [ "$EXE" ] ; then
1069 local PID=`adb shell ps \
1070 | tr -d '\r' \
Mathias Agopian44583272013-08-27 14:15:50 -07001071 | \grep "$prepend$EXE$append" \
Daniel Sandler47e0a882013-07-30 13:23:52 -04001072 | sed -e 's/^[^ ]* *\([0-9]*\).*$/\1/'`
1073 echo "$PID"
1074 else
1075 echo "usage: pid [--exact] <process name>"
1076 return 255
1077 fi
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001078}
1079
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001080# coredump_setup - enable core dumps globally for any process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001081# that has the core-file-size limit set correctly
1082#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001083# NOTE: You must call also coredump_enable for a specific process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001084# if its core-file-size limit is not set already.
1085# NOTE: Core dumps are written to ramdisk; they will not survive a reboot!
1086
Iliyan Malcheve675cfb2014-11-03 17:04:47 -08001087function coredump_setup()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001088{
1089 echo "Getting root...";
1090 adb root;
1091 adb wait-for-device;
1092
1093 echo "Remounting root parition read-write...";
1094 adb shell mount -w -o remount -t rootfs rootfs;
1095 sleep 1;
1096 adb wait-for-device;
1097 adb shell mkdir -p /cores;
Nick Kralevicha94282c2014-11-04 11:17:20 -08001098 adb shell mount -t tmpfs tmpfs /cores;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001099 adb shell chmod 0777 /cores;
1100
1101 echo "Granting SELinux permission to dump in /cores...";
1102 adb shell restorecon -R /cores;
1103
1104 echo "Set core pattern.";
1105 adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern';
1106
1107 echo "Done."
1108}
1109
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001110# coredump_enable - enable core dumps for the specified process
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001111# $1 = PID of process (e.g., $(pid mediaserver))
1112#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001113# NOTE: coredump_setup must have been called as well for a core
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001114# dump to actually be generated.
1115
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001116function coredump_enable()
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001117{
1118 local PID=$1;
1119 if [ -z "$PID" ]; then
1120 printf "Expecting a PID!\n";
1121 return;
1122 fi;
1123 echo "Setting core limit for $PID to infinite...";
1124 adb shell prlimit $PID 4 -1 -1
1125}
1126
1127# core - send SIGV and pull the core for process
1128# $1 = PID of process (e.g., $(pid mediaserver))
1129#
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001130# NOTE: coredump_setup must be called once per boot for core dumps to be
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001131# enabled globally.
1132
1133function core()
1134{
1135 local PID=$1;
1136
1137 if [ -z "$PID" ]; then
1138 printf "Expecting a PID!\n";
1139 return;
1140 fi;
1141
1142 local CORENAME=core.$PID;
1143 local COREPATH=/cores/$CORENAME;
1144 local SIG=SEGV;
1145
Iliyan Malchevaf5de972014-11-04 20:57:37 -08001146 coredump_enable $1;
Iliyan Malchev248f4d52014-10-28 18:00:42 -07001147
1148 local done=0;
1149 while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do
1150 printf "\tSending SIG%s to %d...\n" $SIG $PID;
1151 adb shell kill -$SIG $PID;
1152 sleep 1;
1153 done;
1154
1155 adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done"
1156 echo "Done: core is under $COREPATH on device.";
1157}
1158
Christopher Tate744ee802009-11-12 15:33:08 -08001159# systemstack - dump the current stack trace of all threads in the system process
1160# to the usual ANR traces file
1161function systemstack()
1162{
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001163 stacks system_server
1164}
1165
1166function stacks()
1167{
1168 if [[ $1 =~ ^[0-9]+$ ]] ; then
1169 local PID="$1"
1170 elif [ "$1" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001171 local PIDLIST="$(pid $1)"
1172 if [[ $PIDLIST =~ ^[0-9]+$ ]] ; then
1173 local PID="$PIDLIST"
1174 elif [ "$PIDLIST" ] ; then
1175 echo "more than one process: $1"
1176 else
1177 echo "no such process: $1"
1178 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001179 else
1180 echo "usage: stacks [pid|process name]"
1181 fi
1182
1183 if [ "$PID" ] ; then
Jeff Brownb12c2e52013-08-19 15:14:16 -07001184 # Determine whether the process is native
1185 if adb shell ls -l /proc/$PID/exe | grep -q /system/bin/app_process ; then
1186 # Dump stacks of Dalvik process
1187 local TRACES=/data/anr/traces.txt
1188 local ORIG=/data/anr/traces.orig
1189 local TMP=/data/anr/traces.tmp
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001190
Jeff Brownb12c2e52013-08-19 15:14:16 -07001191 # Keep original traces to avoid clobbering
1192 adb shell mv $TRACES $ORIG
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001193
Jeff Brownb12c2e52013-08-19 15:14:16 -07001194 # Make sure we have a usable file
1195 adb shell touch $TRACES
1196 adb shell chmod 666 $TRACES
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001197
Jeff Brownb12c2e52013-08-19 15:14:16 -07001198 # Dump stacks and wait for dump to finish
1199 adb shell kill -3 $PID
1200 adb shell notify $TRACES >/dev/null
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001201
Jeff Brownb12c2e52013-08-19 15:14:16 -07001202 # Restore original stacks, and show current output
1203 adb shell mv $TRACES $TMP
1204 adb shell mv $ORIG $TRACES
1205 adb shell cat $TMP
1206 else
1207 # Dump stacks of native process
Michael Wrightaeed7212014-06-19 19:58:12 -07001208 local USE64BIT="$(is64bit $PID)"
1209 adb shell debuggerd$USE64BIT -b $PID
Jeff Brownb12c2e52013-08-19 15:14:16 -07001210 fi
Jeff Sharkeyf5824372013-02-19 17:00:46 -08001211 fi
Christopher Tate744ee802009-11-12 15:33:08 -08001212}
1213
Michael Wrightaeed7212014-06-19 19:58:12 -07001214# Read the ELF header from /proc/$PID/exe to determine if the process is
1215# 64-bit.
Ben Chengfba67bf2014-02-25 10:27:07 -08001216function is64bit()
1217{
1218 local PID="$1"
1219 if [ "$PID" ] ; then
Michael Wrightaeed7212014-06-19 19:58:12 -07001220 if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -ps)" -eq "02" ]] ; then
Ben Chengfba67bf2014-02-25 10:27:07 -08001221 echo "64"
1222 else
1223 echo ""
1224 fi
1225 else
1226 echo ""
1227 fi
1228}
1229
Clark Scheff75b36a42014-12-23 13:30:51 -08001230function dddclient()
1231{
1232 local OUT_ROOT=$(get_abs_build_var PRODUCT_OUT)
1233 local OUT_SYMBOLS=$(get_abs_build_var TARGET_OUT_UNSTRIPPED)
1234 local OUT_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_SHARED_LIBRARIES_UNSTRIPPED)
1235 local OUT_VENDOR_SO_SYMBOLS=$(get_abs_build_var TARGET_OUT_VENDOR_SHARED_LIBRARIES_UNSTRIPPED)
1236 local OUT_EXE_SYMBOLS=$(get_symbols_directory)
1237 local PREBUILTS=$(get_abs_build_var ANDROID_PREBUILTS)
1238 local ARCH=$(get_build_var TARGET_ARCH)
1239 local GDB
1240 case "$ARCH" in
1241 arm) GDB=arm-linux-androideabi-gdb;;
1242 arm64) GDB=arm-linux-androideabi-gdb; GDB64=aarch64-linux-android-gdb;;
1243 mips|mips64) GDB=mips64el-linux-android-gdb;;
1244 x86) GDB=x86_64-linux-android-gdb;;
1245 x86_64) GDB=x86_64-linux-android-gdb;;
1246 *) echo "Unknown arch $ARCH"; return 1;;
1247 esac
1248
1249 if [ "$OUT_ROOT" -a "$PREBUILTS" ]; then
1250 local EXE="$1"
1251 if [ "$EXE" ] ; then
1252 EXE=$1
1253 if [[ $EXE =~ ^[^/].* ]] ; then
1254 EXE="system/bin/"$EXE
1255 fi
1256 else
1257 EXE="app_process"
1258 fi
1259
1260 local PORT="$2"
1261 if [ "$PORT" ] ; then
1262 PORT=$2
1263 else
1264 PORT=":5039"
1265 fi
1266
1267 local PID="$3"
1268 if [ "$PID" ] ; then
1269 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1270 PID=`pid $3`
1271 if [[ ! "$PID" =~ ^[0-9]+$ ]] ; then
1272 # that likely didn't work because of returning multiple processes
1273 # try again, filtering by root processes (don't contain colon)
1274 PID=`adb shell ps | \grep $3 | \grep -v ":" | awk '{print $2}'`
1275 if [[ ! "$PID" =~ ^[0-9]+$ ]]
1276 then
1277 echo "Couldn't resolve '$3' to single PID"
1278 return 1
1279 else
1280 echo ""
1281 echo "WARNING: multiple processes matching '$3' observed, using root process"
1282 echo ""
1283 fi
1284 fi
1285 fi
1286 adb forward "tcp$PORT" "tcp$PORT"
1287 local USE64BIT="$(is64bit $PID)"
1288 adb shell gdbserver$USE64BIT $PORT --attach $PID &
1289 sleep 2
1290 else
1291 echo ""
1292 echo "If you haven't done so already, do this first on the device:"
1293 echo " gdbserver $PORT /system/bin/$EXE"
1294 echo " or"
1295 echo " gdbserver $PORT --attach <PID>"
1296 echo ""
1297 fi
1298
1299 OUT_SO_SYMBOLS=$OUT_SO_SYMBOLS$USE64BIT
1300 OUT_VENDOR_SO_SYMBOLS=$OUT_VENDOR_SO_SYMBOLS$USE64BIT
1301
1302 echo >|"$OUT_ROOT/gdbclient.cmds" "set solib-absolute-prefix $OUT_SYMBOLS"
1303 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"
1304 echo >>"$OUT_ROOT/gdbclient.cmds" "source $ANDROID_BUILD_TOP/development/scripts/gdb/dalvik.gdb"
1305 echo >>"$OUT_ROOT/gdbclient.cmds" "target remote $PORT"
1306 # Enable special debugging for ART processes.
1307 if [[ $EXE =~ (^|/)(app_process|dalvikvm)(|32|64)$ ]]; then
1308 echo >> "$OUT_ROOT/gdbclient.cmds" "art-on"
1309 fi
1310 echo >>"$OUT_ROOT/gdbclient.cmds" ""
1311
1312 local WHICH_GDB=
1313 # 64-bit exe found
1314 if [ "$USE64BIT" != "" ] ; then
1315 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB64
1316 # 32-bit exe / 32-bit platform
1317 elif [ "$(get_build_var TARGET_2ND_ARCH)" = "" ]; then
1318 WHICH_GDB=$ANDROID_TOOLCHAIN/$GDB
1319 # 32-bit exe / 64-bit platform
1320 else
1321 WHICH_GDB=$ANDROID_TOOLCHAIN_2ND_ARCH/$GDB
1322 fi
1323
1324 ddd --debugger $WHICH_GDB -x "$OUT_ROOT/gdbclient.cmds" "$OUT_EXE_SYMBOLS/$EXE"
1325 else
1326 echo "Unable to determine build system output dir."
1327 fi
1328}
1329
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001330case `uname -s` in
1331 Darwin)
1332 function sgrep()
1333 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001334 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 -07001335 }
1336
1337 ;;
1338 *)
1339 function sgrep()
1340 {
Jeff Brown46cbd202014-07-26 15:15:41 -07001341 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 -07001342 }
1343 ;;
1344esac
1345
Raghu Gandham8da43102012-07-25 19:57:22 -07001346function gettargetarch
1347{
1348 get_build_var TARGET_ARCH
1349}
1350
Jon Boekenoogencbca56f2014-04-07 10:57:38 -07001351function ggrep()
1352{
1353 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" -print0 | xargs -0 grep --color -n "$@"
1354}
1355
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001356function jgrep()
1357{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001358 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 -07001359}
1360
1361function cgrep()
1362{
Dan Albert01961192014-11-22 10:16:01 -08001363 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 -07001364}
1365
1366function resgrep()
1367{
Anatolii Shuba91c72d22013-07-05 16:09:25 +03001368 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 -07001369}
1370
Jeff Sharkey50b61e92013-03-08 10:20:47 -08001371function mangrep()
1372{
1373 find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' -print0 | xargs -0 grep --color -n "$@"
1374}
1375
Alex Klyubinba5fc8e2013-05-06 14:11:48 -07001376function sepgrep()
1377{
1378 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 "$@"
1379}
1380
Jeff Sharkeyea0068a2015-02-26 14:13:46 -08001381function rcgrep()
1382{
1383 find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" -print0 | xargs -0 grep --color -n "$@"
1384}
1385
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001386case `uname -s` in
1387 Darwin)
1388 function mgrep()
1389 {
Ying Wang324c2b22012-08-17 15:03:20 -07001390 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 -07001391 }
1392
1393 function treegrep()
1394 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001395 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 -07001396 }
1397
1398 ;;
1399 *)
1400 function mgrep()
1401 {
Ying Wang324c2b22012-08-17 15:03:20 -07001402 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 -07001403 }
1404
1405 function treegrep()
1406 {
Joe Onoratof50e84b2011-03-15 14:15:46 -07001407 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 -07001408 }
1409
1410 ;;
1411esac
1412
1413function getprebuilt
1414{
1415 get_abs_build_var ANDROID_PREBUILTS
1416}
1417
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001418function tracedmdump()
1419{
1420 T=$(gettop)
1421 if [ ! "$T" ]; then
1422 echo "Couldn't locate the top of the tree. Try setting TOP."
1423 return
1424 fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001425 local prebuiltdir=$(getprebuilt)
Raghu Gandham8da43102012-07-25 19:57:22 -07001426 local arch=$(gettargetarch)
1427 local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001428
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001429 local TRACE=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001430 if [ ! "$TRACE" ] ; then
1431 echo "usage: tracedmdump tracename"
1432 return
1433 fi
1434
Jack Veenstra60116fc2009-04-09 18:12:34 -07001435 if [ ! -r "$KERNEL" ] ; then
1436 echo "Error: cannot find kernel: '$KERNEL'"
1437 return
1438 fi
1439
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001440 local BASETRACE=$(basename $TRACE)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001441 if [ "$BASETRACE" = "$TRACE" ] ; then
1442 TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE
1443 fi
1444
1445 echo "post-processing traces..."
1446 rm -f $TRACE/qtrace.dexlist
1447 post_trace $TRACE
1448 if [ $? -ne 0 ]; then
1449 echo "***"
1450 echo "*** Error: malformed trace. Did you remember to exit the emulator?"
1451 echo "***"
1452 return
1453 fi
1454 echo "generating dexlist output..."
1455 /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
1456 echo "generating dmtrace data..."
1457 q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return
1458 echo "generating html file..."
1459 dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return
1460 echo "done, see $TRACE/dmtrace.html for details"
1461 echo "or run:"
1462 echo " traceview $TRACE/dmtrace"
1463}
1464
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001465# communicate with a running device or emulator, set up necessary state,
1466# and run the hat command.
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001467function runhat()
1468{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001469 # process standard adb options
1470 local adbTarget=""
Andy McFaddenb6289852010-07-12 08:00:19 -07001471 if [ "$1" = "-d" -o "$1" = "-e" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001472 adbTarget=$1
1473 shift 1
Andy McFaddenb6289852010-07-12 08:00:19 -07001474 elif [ "$1" = "-s" ]; then
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001475 adbTarget="$1 $2"
1476 shift 2
1477 fi
1478 local adbOptions=${adbTarget}
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001479 #echo adbOptions = ${adbOptions}
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001480
1481 # runhat options
1482 local targetPid=$1
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001483
1484 if [ "$targetPid" = "" ]; then
Andy McFaddenb6289852010-07-12 08:00:19 -07001485 echo "Usage: runhat [ -d | -e | -s serial ] target-pid"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001486 return
1487 fi
1488
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001489 # confirm hat is available
1490 if [ -z $(which hat) ]; then
1491 echo "hat is not available in this configuration."
1492 return
1493 fi
1494
Andy McFaddenb6289852010-07-12 08:00:19 -07001495 # issue "am" command to cause the hprof dump
Nick Kralevich9948b1e2014-07-18 15:45:38 -07001496 local devFile=/data/local/tmp/hprof-$targetPid
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001497 echo "Poking $targetPid and waiting for data..."
Dianne Hackborn6b9549f2012-09-26 15:00:59 -07001498 echo "Storing data at $devFile"
Andy McFaddenb6289852010-07-12 08:00:19 -07001499 adb ${adbOptions} shell am dumpheap $targetPid $devFile
The Android Open Source Project88b60792009-03-03 19:28:42 -08001500 echo "Press enter when logcat shows \"hprof: heap dump completed\""
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001501 echo -n "> "
1502 read
1503
The Android Open Source Project88b60792009-03-03 19:28:42 -08001504 local localFile=/tmp/$$-hprof
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001505
The Android Open Source Project88b60792009-03-03 19:28:42 -08001506 echo "Retrieving file $devFile..."
1507 adb ${adbOptions} pull $devFile $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001508
The Android Open Source Project88b60792009-03-03 19:28:42 -08001509 adb ${adbOptions} shell rm $devFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001510
The Android Open Source Project88b60792009-03-03 19:28:42 -08001511 echo "Running hat on $localFile"
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001512 echo "View the output by pointing your browser at http://localhost:7000/"
1513 echo ""
Dianne Hackborn6e4e1bb2011-11-10 15:19:51 -08001514 hat -JXmx512m $localFile
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001515}
1516
1517function getbugreports()
1518{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001519 local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`)
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001520
1521 if [ ! "$reports" ]; then
1522 echo "Could not locate any bugreports."
1523 return
1524 fi
1525
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001526 local report
1527 for report in ${reports[@]}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001528 do
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001529 echo "/sdcard/bugreports/${report}"
1530 adb pull /sdcard/bugreports/${report} ${report}
1531 gunzip ${report}
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001532 done
1533}
1534
Victoria Lease1b296b42012-08-21 15:44:06 -07001535function getsdcardpath()
1536{
1537 adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\}
1538}
1539
1540function getscreenshotpath()
1541{
1542 echo "$(getsdcardpath)/Pictures/Screenshots"
1543}
1544
1545function getlastscreenshot()
1546{
1547 local screenshot_path=$(getscreenshotpath)
1548 local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1`
1549 if [ "$screenshot" = "" ]; then
1550 echo "No screenshots found."
1551 return
1552 fi
1553 echo "${screenshot}"
1554 adb ${adbOptions} pull ${screenshot_path}/${screenshot}
1555}
1556
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001557function startviewserver()
1558{
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001559 local port=4939
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001560 if [ $# -gt 0 ]; then
1561 port=$1
1562 fi
1563 adb shell service call window 1 i32 $port
1564}
1565
1566function stopviewserver()
1567{
1568 adb shell service call window 2
1569}
1570
1571function isviewserverstarted()
1572{
1573 adb shell service call window 3
1574}
1575
Romain Guyb84049a2010-10-04 16:56:11 -07001576function key_home()
1577{
1578 adb shell input keyevent 3
1579}
1580
1581function key_back()
1582{
1583 adb shell input keyevent 4
1584}
1585
1586function key_menu()
1587{
1588 adb shell input keyevent 82
1589}
1590
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001591function smoketest()
1592{
1593 if [ ! "$ANDROID_PRODUCT_OUT" ]; then
1594 echo "Couldn't locate output files. Try running 'lunch' first." >&2
1595 return
1596 fi
1597 T=$(gettop)
1598 if [ ! "$T" ]; then
1599 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1600 return
1601 fi
1602
Ying Wang9cd17642012-12-13 10:52:07 -08001603 (\cd "$T" && mmm tests/SmokeTest) &&
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001604 adb uninstall com.android.smoketest > /dev/null &&
1605 adb uninstall com.android.smoketest.tests > /dev/null &&
1606 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk &&
1607 adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk &&
1608 adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner
1609}
1610
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08001611# simple shortcut to the runtest command
1612function runtest()
1613{
1614 T=$(gettop)
1615 if [ ! "$T" ]; then
1616 echo "Couldn't locate the top of the tree. Try setting TOP." >&2
1617 return
1618 fi
Brett Chabot3fb149d2009-10-21 20:05:26 -07001619 ("$T"/development/testrunner/runtest.py $@)
Brett Chabot762748c2009-03-27 10:25:11 -07001620}
1621
The Android Open Source Project88b60792009-03-03 19:28:42 -08001622function godir () {
1623 if [[ -z "$1" ]]; then
1624 echo "Usage: godir <regex>"
1625 return
1626 fi
Brian Carlstromb9915a62010-01-29 16:39:32 -08001627 T=$(gettop)
Brian Carlstromf2257422015-09-30 20:28:54 -07001628 if [ ! "$OUT_DIR" = "" ]; then
1629 mkdir -p $OUT_DIR
1630 FILELIST=$OUT_DIR/filelist
1631 else
1632 FILELIST=$T/filelist
1633 fi
1634 if [[ ! -f $FILELIST ]]; then
The Android Open Source Project88b60792009-03-03 19:28:42 -08001635 echo -n "Creating index..."
Brian Carlstromf2257422015-09-30 20:28:54 -07001636 (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST)
The Android Open Source Project88b60792009-03-03 19:28:42 -08001637 echo " Done"
1638 echo ""
1639 fi
1640 local lines
Brian Carlstromf2257422015-09-30 20:28:54 -07001641 lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001642 if [[ ${#lines[@]} = 0 ]]; then
1643 echo "Not found"
1644 return
1645 fi
1646 local pathname
1647 local choice
1648 if [[ ${#lines[@]} > 1 ]]; then
1649 while [[ -z "$pathname" ]]; do
1650 local index=1
1651 local line
1652 for line in ${lines[@]}; do
1653 printf "%6s %s\n" "[$index]" $line
Doug Zongker29034982011-04-22 08:16:56 -07001654 index=$(($index + 1))
The Android Open Source Project88b60792009-03-03 19:28:42 -08001655 done
1656 echo
1657 echo -n "Select one: "
1658 unset choice
1659 read choice
1660 if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
1661 echo "Invalid choice"
1662 continue
1663 fi
Kan-Ru Chen07453762010-07-05 15:53:47 +08001664 pathname=${lines[$(($choice-1))]}
The Android Open Source Project88b60792009-03-03 19:28:42 -08001665 done
1666 else
The Android Open Source Project88b60792009-03-03 19:28:42 -08001667 pathname=${lines[0]}
1668 fi
Ying Wang9cd17642012-12-13 10:52:07 -08001669 \cd $T/$pathname
The Android Open Source Project88b60792009-03-03 19:28:42 -08001670}
1671
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001672function cmremote()
1673{
1674 git remote rm cmremote 2> /dev/null
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301675 GERRIT_REMOTE=$(git config --get remote.github.projectname)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001676 if [ -z "$GERRIT_REMOTE" ]
1677 then
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301678 echo Unable to set up the git remote, are you under a git repo?
1679 return 0
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001680 fi
Chirayu Desaif2f15f12014-12-16 18:22:55 +05301681 CMUSER=$(git config --get review.review.cyanogenmod.org.username)
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001682 if [ -z "$CMUSER" ]
1683 then
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001684 git remote add cmremote ssh://review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001685 else
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001686 git remote add cmremote ssh://$CMUSER@review.cyanogenmod.org:29418/$GERRIT_REMOTE
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001687 fi
1688 echo You can now push to "cmremote".
1689}
Koushik Duttab55f13a2012-05-14 16:14:36 -07001690
Steve Kondik873fa562012-09-17 11:33:18 -07001691function aospremote()
1692{
1693 git remote rm aosp 2> /dev/null
1694 if [ ! -d .git ]
1695 then
1696 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1697 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001698 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik873fa562012-09-17 11:33:18 -07001699 if (echo $PROJECT | grep -qv "^device")
1700 then
1701 PFX="platform/"
1702 fi
1703 git remote add aosp https://android.googlesource.com/$PFX$PROJECT
1704 echo "Remote 'aosp' created"
1705}
Steve Kondik873fa562012-09-17 11:33:18 -07001706
Steve Kondik20c21d22013-10-27 13:34:36 -07001707function cafremote()
1708{
1709 git remote rm caf 2> /dev/null
1710 if [ ! -d .git ]
1711 then
1712 echo .git directory not found. Please run this from the root directory of the Android repository you wish to set up.
1713 fi
Steve Kondike917827b2013-11-16 03:48:30 -08001714 PROJECT=`pwd -P | sed s#$ANDROID_BUILD_TOP/##g`
Steve Kondik20c21d22013-10-27 13:34:36 -07001715 if (echo $PROJECT | grep -qv "^device")
1716 then
1717 PFX="platform/"
1718 fi
1719 git remote add caf git://codeaurora.org/$PFX$PROJECT
1720 echo "Remote 'caf' created"
1721}
Steve Kondik20c21d22013-10-27 13:34:36 -07001722
Steve Kondikf00e7d92012-09-23 23:46:55 -07001723function installboot()
1724{
1725 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1726 then
1727 echo "No recovery.fstab found. Build recovery first."
1728 return 1
1729 fi
1730 if [ ! -e "$OUT/boot.img" ];
1731 then
1732 echo "No boot.img found. Run make bootimage first."
1733 return 1
1734 fi
1735 PARTITION=`grep "^\/boot" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1736 if [ -z "$PARTITION" ];
1737 then
Ricardo Cerqueira9e4c4a72013-07-27 13:51:56 +01001738 # Try for RECOVERY_FSTAB_VERSION = 2
1739 PARTITION=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1740 PARTITION_TYPE=`grep "[[:space:]]\/boot[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1741 if [ -z "$PARTITION" ];
1742 then
1743 echo "Unable to determine boot partition."
1744 return 1
1745 fi
Steve Kondikf00e7d92012-09-23 23:46:55 -07001746 fi
1747 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001748 adb wait-for-online
Steve Kondikf00e7d92012-09-23 23:46:55 -07001749 adb root
1750 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001751 adb wait-for-online shell mount /system 2>&1 > /dev/null
1752 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001753 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondikf00e7d92012-09-23 23:46:55 -07001754 then
1755 adb push $OUT/boot.img /cache/
1756 for i in $OUT/system/lib/modules/*;
1757 do
1758 adb push $i /system/lib/modules/
1759 done
1760 adb shell dd if=/cache/boot.img of=$PARTITION
1761 adb shell chmod 644 /system/lib/modules/*
1762 echo "Installation complete."
1763 else
1764 echo "The connected device does not appear to be $CM_BUILD, run away!"
1765 fi
1766}
1767
Steve Kondik83c03d52012-10-24 16:40:42 -07001768function installrecovery()
1769{
1770 if [ ! -e "$OUT/recovery/root/etc/recovery.fstab" ];
1771 then
1772 echo "No recovery.fstab found. Build recovery first."
1773 return 1
1774 fi
1775 if [ ! -e "$OUT/recovery.img" ];
1776 then
1777 echo "No recovery.img found. Run make recoveryimage first."
1778 return 1
1779 fi
1780 PARTITION=`grep "^\/recovery" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
1781 if [ -z "$PARTITION" ];
1782 then
Steve Kondik75f10762013-08-09 21:03:42 -07001783 # Try for RECOVERY_FSTAB_VERSION = 2
Steve Kondikd8b510a2013-08-10 21:02:09 -07001784 PARTITION=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $1'}`
1785 PARTITION_TYPE=`grep "[[:space:]]\/recovery[[:space:]]" $OUT/recovery/root/etc/recovery.fstab | awk {'print $3'}`
Steve Kondik75f10762013-08-09 21:03:42 -07001786 if [ -z "$PARTITION" ];
1787 then
1788 echo "Unable to determine recovery partition."
1789 return 1
1790 fi
Steve Kondik83c03d52012-10-24 16:40:42 -07001791 fi
1792 adb start-server
Steve Kondik3bc5cfd2013-08-30 17:34:37 -07001793 adb wait-for-online
Steve Kondik83c03d52012-10-24 16:40:42 -07001794 adb root
1795 sleep 1
Steve Kondik21e4f7f2013-04-13 13:23:35 -07001796 adb wait-for-online shell mount /system 2>&1 >> /dev/null
1797 adb wait-for-online remount
Steve Kondikec4627c2015-07-10 02:31:24 -07001798 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD");
Steve Kondik83c03d52012-10-24 16:40:42 -07001799 then
1800 adb push $OUT/recovery.img /cache/
1801 adb shell dd if=/cache/recovery.img of=$PARTITION
1802 echo "Installation complete."
1803 else
1804 echo "The connected device does not appear to be $CM_BUILD, run away!"
1805 fi
1806}
Steve Kondikf00e7d92012-09-23 23:46:55 -07001807
Koushik Duttab55f13a2012-05-14 16:14:36 -07001808function makerecipe() {
1809 if [ -z "$1" ]
1810 then
1811 echo "No branch name provided."
1812 return 1
1813 fi
1814 cd android
1815 sed -i s/'default revision=.*'/'default revision="refs\/heads\/'$1'"'/ default.xml
1816 git commit -a -m "$1"
1817 cd ..
1818
1819 repo forall -c '
1820
1821 if [ "$REPO_REMOTE" == "github" ]
1822 then
1823 pwd
1824 cmremote
1825 git push cmremote HEAD:refs/heads/'$1'
1826 fi
1827 '
1828}
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001829
1830function cmgerrit() {
1831 if [ $# -eq 0 ]; then
1832 $FUNCNAME help
1833 return 1
1834 fi
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07001835 local user=`git config --get review.review.cyanogenmod.org.username`
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06001836 local review=`git config --get remote.github.review`
1837 local project=`git config --get remote.github.projectname`
1838 local command=$1
1839 shift
1840 case $command in
1841 help)
1842 if [ $# -eq 0 ]; then
1843 cat <<EOF
1844Usage:
1845 $FUNCNAME COMMAND [OPTIONS] [CHANGE-ID[/PATCH-SET]][{@|^|~|:}ARG] [-- ARGS]
1846
1847Commands:
1848 fetch Just fetch the change as FETCH_HEAD
1849 help Show this help, or for a specific command
1850 pull Pull a change into current branch
1851 push Push HEAD or a local branch to Gerrit for a specific branch
1852
1853Any other Git commands that support refname would work as:
1854 git fetch URL CHANGE && git COMMAND OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1855
1856See '$FUNCNAME help COMMAND' for more information on a specific command.
1857
1858Example:
1859 $FUNCNAME checkout -b topic 1234/5
1860works as:
1861 git fetch http://DOMAIN/p/PROJECT refs/changes/34/1234/5 \\
1862 && git checkout -b topic FETCH_HEAD
1863will checkout a new branch 'topic' base on patch-set 5 of change 1234.
1864Patch-set 1 will be fetched if omitted.
1865EOF
1866 return
1867 fi
1868 case $1 in
1869 __cmg_*) echo "For internal use only." ;;
1870 changes|for)
1871 if [ "$FUNCNAME" = "cmgerrit" ]; then
1872 echo "'$FUNCNAME $1' is deprecated."
1873 fi
1874 ;;
1875 help) $FUNCNAME help ;;
1876 fetch|pull) cat <<EOF
1877usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET]
1878
1879works as:
1880 git $1 OPTIONS http://DOMAIN/p/PROJECT \\
1881 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1}
1882
1883Example:
1884 $FUNCNAME $1 1234
1885will $1 patch-set 1 of change 1234
1886EOF
1887 ;;
1888 push) cat <<EOF
1889usage: $FUNCNAME push [OPTIONS] [LOCAL_BRANCH:]REMOTE_BRANCH
1890
1891works as:
1892 git push OPTIONS ssh://USER@DOMAIN:29418/PROJECT \\
1893 {LOCAL_BRANCH|HEAD}:refs/for/REMOTE_BRANCH
1894
1895Example:
1896 $FUNCNAME push fix6789:gingerbread
1897will push local branch 'fix6789' to Gerrit for branch 'gingerbread'.
1898HEAD will be pushed from local if omitted.
1899EOF
1900 ;;
1901 *)
1902 $FUNCNAME __cmg_err_not_supported $1 && return
1903 cat <<EOF
1904usage: $FUNCNAME $1 [OPTIONS] CHANGE-ID[/PATCH-SET][{@|^|~|:}ARG] [-- ARGS]
1905
1906works as:
1907 git fetch http://DOMAIN/p/PROJECT \\
1908 refs/changes/HASH/CHANGE-ID/{PATCH-SET|1} \\
1909 && git $1 OPTIONS FETCH_HEAD{@|^|~|:}ARG -- ARGS
1910EOF
1911 ;;
1912 esac
1913 ;;
1914 __cmg_get_ref)
1915 $FUNCNAME __cmg_err_no_arg $command $# && return 1
1916 local change_id patchset_id hash
1917 case $1 in
1918 */*)
1919 change_id=${1%%/*}
1920 patchset_id=${1#*/}
1921 ;;
1922 *)
1923 change_id=$1
1924 patchset_id=1
1925 ;;
1926 esac
1927 hash=$(($change_id % 100))
1928 case $hash in
1929 [0-9]) hash="0$hash" ;;
1930 esac
1931 echo "refs/changes/$hash/$change_id/$patchset_id"
1932 ;;
1933 fetch|pull)
1934 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1935 $FUNCNAME __cmg_err_not_repo && return 1
1936 local change=$1
1937 shift
1938 git $command $@ http://$review/p/$project \
1939 $($FUNCNAME __cmg_get_ref $change) || return 1
1940 ;;
1941 push)
1942 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
1943 $FUNCNAME __cmg_err_not_repo && return 1
1944 if [ -z "$user" ]; then
1945 echo >&2 "Gerrit username not found."
1946 return 1
1947 fi
1948 local local_branch remote_branch
1949 case $1 in
1950 *:*)
1951 local_branch=${1%:*}
1952 remote_branch=${1##*:}
1953 ;;
1954 *)
1955 local_branch=HEAD
1956 remote_branch=$1
1957 ;;
1958 esac
1959 shift
1960 git push $@ ssh://$user@$review:29418/$project \
1961 $local_branch:refs/for/$remote_branch || return 1
1962 ;;
1963 changes|for)
1964 if [ "$FUNCNAME" = "cmgerrit" ]; then
1965 echo >&2 "'$FUNCNAME $command' is deprecated."
1966 fi
1967 ;;
1968 __cmg_err_no_arg)
1969 if [ $# -lt 2 ]; then
1970 echo >&2 "'$FUNCNAME $command' missing argument."
1971 elif [ $2 -eq 0 ]; then
1972 if [ -n "$3" ]; then
1973 $FUNCNAME help $1
1974 else
1975 echo >&2 "'$FUNCNAME $1' missing argument."
1976 fi
1977 else
1978 return 1
1979 fi
1980 ;;
1981 __cmg_err_not_repo)
1982 if [ -z "$review" -o -z "$project" ]; then
1983 echo >&2 "Not currently in any reviewable repository."
1984 else
1985 return 1
1986 fi
1987 ;;
1988 __cmg_err_not_supported)
1989 $FUNCNAME __cmg_err_no_arg $command $# && return
1990 case $1 in
1991 #TODO: filter more git commands that don't use refname
1992 init|add|rm|mv|status|clone|remote|bisect|config|stash)
1993 echo >&2 "'$FUNCNAME $1' is not supported."
1994 ;;
1995 *) return 1 ;;
1996 esac
1997 ;;
1998 #TODO: other special cases?
1999 *)
2000 $FUNCNAME __cmg_err_not_supported $command && return 1
2001 $FUNCNAME __cmg_err_no_arg $command $# help && return 1
2002 $FUNCNAME __cmg_err_not_repo && return 1
2003 local args="$@"
2004 local change pre_args refs_arg post_args
2005 case "$args" in
2006 *--\ *)
2007 pre_args=${args%%-- *}
2008 post_args="-- ${args#*-- }"
2009 ;;
2010 *) pre_args="$args" ;;
2011 esac
2012 args=($pre_args)
2013 pre_args=
2014 if [ ${#args[@]} -gt 0 ]; then
2015 change=${args[${#args[@]}-1]}
2016 fi
2017 if [ ${#args[@]} -gt 1 ]; then
2018 pre_args=${args[0]}
2019 for ((i=1; i<${#args[@]}-1; i++)); do
2020 pre_args="$pre_args ${args[$i]}"
2021 done
2022 fi
2023 while ((1)); do
2024 case $change in
2025 ""|--)
2026 $FUNCNAME help $command
2027 return 1
2028 ;;
2029 *@*)
2030 if [ -z "$refs_arg" ]; then
2031 refs_arg="@${change#*@}"
2032 change=${change%%@*}
2033 fi
2034 ;;
2035 *~*)
2036 if [ -z "$refs_arg" ]; then
2037 refs_arg="~${change#*~}"
2038 change=${change%%~*}
2039 fi
2040 ;;
2041 *^*)
2042 if [ -z "$refs_arg" ]; then
2043 refs_arg="^${change#*^}"
2044 change=${change%%^*}
2045 fi
2046 ;;
2047 *:*)
2048 if [ -z "$refs_arg" ]; then
2049 refs_arg=":${change#*:}"
2050 change=${change%%:*}
2051 fi
2052 ;;
2053 *) break ;;
2054 esac
2055 done
2056 $FUNCNAME fetch $change \
2057 && git $command $pre_args FETCH_HEAD$refs_arg $post_args \
2058 || return 1
2059 ;;
2060 esac
2061}
2062
2063function cmrebase() {
2064 local repo=$1
2065 local refs=$2
2066 local pwd="$(pwd)"
2067 local dir="$(gettop)/$repo"
2068
2069 if [ -z $repo ] || [ -z $refs ]; then
2070 echo "CyanogenMod Gerrit Rebase Usage: "
2071 echo " cmrebase <path to project> <patch IDs on Gerrit>"
2072 echo " The patch IDs appear on the Gerrit commands that are offered."
2073 echo " They consist on a series of numbers and slashes, after the text"
2074 echo " refs/changes. For example, the ID in the following command is 26/8126/2"
2075 echo ""
2076 echo " git[...]ges_apps_Camera refs/changes/26/8126/2 && git cherry-pick FETCH_HEAD"
2077 echo ""
2078 return
2079 fi
2080
2081 if [ ! -d $dir ]; then
2082 echo "Directory $dir doesn't exist in tree."
2083 return
2084 fi
2085 cd $dir
2086 repo=$(cat .git/config | grep git://github.com | awk '{ print $NF }' | sed s#git://github.com/##g)
2087 echo "Starting branch..."
2088 repo start tmprebase .
2089 echo "Bringing it up to date..."
2090 repo sync .
2091 echo "Fetching change..."
Pawit Pornkitprasan7bef61f2012-12-11 16:41:07 +07002092 git fetch "http://review.cyanogenmod.org/p/$repo" "refs/changes/$refs" && git cherry-pick FETCH_HEAD
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002093 if [ "$?" != "0" ]; then
2094 echo "Error cherry-picking. Not uploading!"
2095 return
2096 fi
2097 echo "Uploading..."
2098 repo upload .
2099 echo "Cleaning up..."
2100 repo abandon tmprebase .
2101 cd $pwd
2102}
2103
2104function mka() {
Khalid Zubairabcd1942015-10-06 11:00:55 -07002105 local T=$(gettop)
2106 if [ "$T" ]; then
2107 case `uname -s` in
2108 Darwin)
2109 make -C $T -j `sysctl hw.ncpu|cut -d" " -f2` "$@"
2110 ;;
2111 *)
2112 mk_timer schedtool -B -n 1 -e ionice -n 1 make -C $T -j$(cat /proc/cpuinfo | grep "^processor" | wc -l) "$@"
2113 ;;
2114 esac
2115
2116 else
2117 echo "Couldn't locate the top of the tree. Try setting TOP."
2118 fi
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002119}
2120
Chirayu Desaicf2bdb62012-09-28 11:56:02 +05302121function cmka() {
2122 if [ ! -z "$1" ]; then
2123 for i in "$@"; do
2124 case $i in
2125 bacon|otapackage|systemimage)
2126 mka installclean
2127 mka $i
2128 ;;
2129 *)
2130 mka clean-$i
2131 mka $i
2132 ;;
2133 esac
2134 done
2135 else
2136 mka clean
2137 mka
2138 fi
2139}
2140
Matt Mower8dacaed2013-12-29 12:57:20 -06002141function repolastsync() {
2142 RLSPATH="$ANDROID_BUILD_TOP/.repo/.repo_fetchtimes.json"
2143 RLSLOCAL=$(date -d "$(stat -c %z $RLSPATH)" +"%e %b %Y, %T %Z")
2144 RLSUTC=$(date -d "$(stat -c %z $RLSPATH)" -u +"%e %b %Y, %T %Z")
2145 echo "Last repo sync: $RLSLOCAL / $RLSUTC"
2146}
2147
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002148function reposync() {
2149 case `uname -s` in
2150 Darwin)
2151 repo sync -j 4 "$@"
2152 ;;
2153 *)
Alan Orthef363cd2012-09-07 11:44:27 +03002154 schedtool -B -n 1 -e ionice -n 1 `which repo` sync -j 4 "$@"
Andrew Sutherlandd6bd0652011-11-18 00:45:55 -06002155 ;;
2156 esac
2157}
Tanguy Pruvot2192fd22012-06-06 21:39:23 +02002158
2159function repodiff() {
2160 if [ -z "$*" ]; then
2161 echo "Usage: repodiff <ref-from> [[ref-to] [--numstat]]"
2162 return
2163 fi
2164 diffopts=$* repo forall -c \
2165 'echo "$REPO_PATH ($REPO_REMOTE)"; git diff ${diffopts} 2>/dev/null ;'
2166}
2167
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302168# Credit for color strip sed: http://goo.gl/BoIcm
2169function dopush()
2170{
2171 local func=$1
2172 shift
2173
2174 adb start-server # Prevent unexpected starting server message from adb get-state in the next line
2175 if [ $(adb get-state) != device -a $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) != 0 ] ; then
2176 echo "No device is online. Waiting for one..."
2177 echo "Please connect USB and/or enable USB debugging"
2178 until [ $(adb get-state) = device -o $(adb shell busybox test -e /sbin/recovery 2> /dev/null; echo $?) = 0 ];do
2179 sleep 1
2180 done
2181 echo "Device Found."
2182 fi
2183
Steve Kondikec4627c2015-07-10 02:31:24 -07002184 if (adb shell getprop ro.cm.device | grep -q "$CM_BUILD") || [ "$FORCE_PUSH" == "true" ];
Chirayu Desai6dadb572012-12-26 10:53:58 +05302185 then
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002186 # retrieve IP and PORT info if we're using a TCP connection
2187 TCPIPPORT=$(adb devices | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+[^0-9]+' \
2188 | head -1 | awk '{print $1}')
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302189 adb root &> /dev/null
2190 sleep 0.3
Sam Mortimer9e0a3f72013-08-10 22:57:08 -07002191 if [ -n "$TCPIPPORT" ]
2192 then
2193 # adb root just killed our connection
2194 # so reconnect...
2195 adb connect "$TCPIPPORT"
2196 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302197 adb wait-for-device &> /dev/null
2198 sleep 0.3
2199 adb remount &> /dev/null
2200
Matt Mower668ea262014-05-20 02:52:23 -05002201 mkdir -p $OUT
Marcos Marado37e92c22015-01-13 15:14:28 +00002202 ($func $*|tee $OUT/.log;return ${PIPESTATUS[0]})
2203 ret=$?;
2204 if [ $ret -ne 0 ]; then
2205 rm -f $OUT/.log;return $ret
2206 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302207
2208 # Install: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002209 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 +05302210
2211 # Copy: <file>
Matt Mower668ea262014-05-20 02:52:23 -05002212 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 +05302213
Matt Mowerdfd4c082014-05-20 02:52:23 -05002214 # If any files are going to /data, push an octal file permissions reader to device
2215 if [ -n "$(echo $LOC | egrep '(^|\s)/data')" ]; then
2216 CHKPERM="/data/local/tmp/chkfileperm.sh"
2217(
2218cat <<'EOF'
2219#!/system/xbin/sh
2220FILE=$@
2221if [ -e $FILE ]; then
2222 ls -l $FILE | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' | cut -d ' ' -f1
2223fi
2224EOF
2225) > $OUT/.chkfileperm.sh
2226 echo "Pushing file permissions checker to device"
2227 adb push $OUT/.chkfileperm.sh $CHKPERM
2228 adb shell chmod 755 $CHKPERM
2229 rm -f $OUT/.chkfileperm.sh
2230 fi
2231
Matt Mower668ea262014-05-20 02:52:23 -05002232 stop_n_start=false
Luca Stefani406c2af2015-11-02 05:33:10 -08002233 for FILE in $(echo $LOC | tr " " "\n"); do
Matt Mowerdfd4c082014-05-20 02:52:23 -05002234 # Make sure file is in $OUT/system or $OUT/data
Matt Mower668ea262014-05-20 02:52:23 -05002235 case $FILE in
Matt Mowerdfd4c082014-05-20 02:52:23 -05002236 $OUT/system/*|$OUT/data/*)
Matt Mower668ea262014-05-20 02:52:23 -05002237 # Get target file name (i.e. /system/bin/adb)
2238 TARGET=$(echo $FILE | sed "s#$OUT##")
2239 ;;
2240 *) continue ;;
2241 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302242
Matt Mower668ea262014-05-20 02:52:23 -05002243 case $TARGET in
Matt Mowerdfd4c082014-05-20 02:52:23 -05002244 /data/*)
2245 # fs_config only sets permissions and se labels for files pushed to /system
2246 if [ -n "$CHKPERM" ]; then
2247 OLDPERM=$(adb shell $CHKPERM $TARGET)
2248 OLDPERM=$(echo $OLDPERM | tr -d '\r' | tr -d '\n')
2249 OLDOWN=$(adb shell ls -al $TARGET | awk '{print $2}')
2250 OLDGRP=$(adb shell ls -al $TARGET | awk '{print $3}')
2251 fi
2252 echo "Pushing: $TARGET"
2253 adb push $FILE $TARGET
2254 if [ -n "$OLDPERM" ]; then
2255 echo "Setting file permissions: $OLDPERM, $OLDOWN":"$OLDGRP"
2256 adb shell chown "$OLDOWN":"$OLDGRP" $TARGET
2257 adb shell chmod "$OLDPERM" $TARGET
2258 else
2259 echo "$TARGET did not exist previously, you should set file permissions manually"
2260 fi
2261 adb shell restorecon "$TARGET"
2262 ;;
Pawit Pornkitprasan1822ad02014-12-22 20:11:47 +07002263 /system/priv-app/SystemUI/SystemUI.apk|/system/framework/*)
Matt Mower668ea262014-05-20 02:52:23 -05002264 # Only need to stop services once
2265 if ! $stop_n_start; then
2266 adb shell stop
2267 stop_n_start=true
2268 fi
2269 echo "Pushing: $TARGET"
2270 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302271 ;;
2272 *)
Matt Mower668ea262014-05-20 02:52:23 -05002273 echo "Pushing: $TARGET"
2274 adb push $FILE $TARGET
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302275 ;;
Matt Mower668ea262014-05-20 02:52:23 -05002276 esac
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302277 done
Matt Mowerdfd4c082014-05-20 02:52:23 -05002278 if [ -n "$CHKPERM" ]; then
2279 adb shell rm $CHKPERM
2280 fi
Matt Mower668ea262014-05-20 02:52:23 -05002281 if $stop_n_start; then
2282 adb shell start
2283 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302284 rm -f $OUT/.log
2285 return 0
Chirayu Desai6dadb572012-12-26 10:53:58 +05302286 else
2287 echo "The connected device does not appear to be $CM_BUILD, run away!"
2288 fi
Chirayu Desaiae7a4d02012-10-16 19:40:18 +05302289}
2290
2291alias mmp='dopush mm'
2292alias mmmp='dopush mmm'
2293alias mkap='dopush mka'
2294alias cmkap='dopush cmka'
2295
Chirayu Desai4a319b82013-06-05 20:14:33 +05302296function repopick() {
2297 T=$(gettop)
2298 $T/build/tools/repopick.py $@
2299}
2300
Chirayu Desaib89b3242013-06-30 10:04:25 +05302301function fixup_common_out_dir() {
2302 common_out_dir=$(get_build_var OUT_DIR)/target/common
2303 target_device=$(get_build_var TARGET_DEVICE)
2304 if [ ! -z $CM_FIXUP_COMMON_OUT ]; then
2305 if [ -d ${common_out_dir} ] && [ ! -L ${common_out_dir} ]; then
2306 mv ${common_out_dir} ${common_out_dir}-${target_device}
2307 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2308 else
2309 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2310 mkdir -p ${common_out_dir}-${target_device}
2311 ln -s ${common_out_dir}-${target_device} ${common_out_dir}
2312 fi
2313 else
2314 [ -L ${common_out_dir} ] && rm ${common_out_dir}
2315 mkdir -p ${common_out_dir}
2316 fi
2317}
2318
Michael Bestas163381a2015-10-23 20:36:47 +03002319# Force JAVA_HOME to point to java 1.7 if it isn't already set.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002320#
2321# Note that the MacOS path for java 1.7 includes a minor revision number (sigh).
2322# For some reason, installing the JDK doesn't make it show up in the
2323# JavaVM.framework/Versions/1.7/ folder.
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002324function set_java_home() {
Narayan Kamath9260bba2014-01-17 10:05:25 +00002325 # Clear the existing JAVA_HOME value if we set it ourselves, so that
Narayan Kamathc84889b2014-04-01 14:16:26 +01002326 # we can reset it later, depending on the version of java the build
2327 # system needs.
Narayan Kamath9260bba2014-01-17 10:05:25 +00002328 #
2329 # If we don't do this, the JAVA_HOME value set by the first call to
2330 # build/envsetup.sh will persist forever.
2331 if [ -n "$ANDROID_SET_JAVA_HOME" ]; then
2332 export JAVA_HOME=""
2333 fi
2334
Andy McFaddenbd960942010-06-24 12:52:51 -07002335 if [ ! "$JAVA_HOME" ]; then
Neil Fuller46e00ea2014-10-16 10:23:03 +01002336 case `uname -s` in
2337 Darwin)
2338 export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
2339 ;;
2340 *)
2341 export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
2342 ;;
2343 esac
Narayan Kamath9260bba2014-01-17 10:05:25 +00002344
2345 # Keep track of the fact that we set JAVA_HOME ourselves, so that
2346 # we can change it on the next envsetup.sh, if required.
2347 export ANDROID_SET_JAVA_HOME=true
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002348 fi
Jeff Hamilton4a1c70e2010-06-21 18:26:38 -05002349}
Jeff Hamilton04be0d82010-06-07 15:03:54 -05002350
Alex Rayf0d08eb2013-03-08 15:15:06 -08002351# Print colored exit condition
2352function pez {
Michael Wrighteb733842013-03-08 17:34:02 -08002353 "$@"
2354 local retval=$?
2355 if [ $retval -ne 0 ]
2356 then
Roman Birgead9a5c2015-10-16 10:29:06 -07002357 printf "\e[0;31mFAILURE\e[00m\n"
Michael Wrighteb733842013-03-08 17:34:02 -08002358 else
Roman Birgead9a5c2015-10-16 10:29:06 -07002359 printf "\e[0;32mSUCCESS\e[00m\n"
Michael Wrighteb733842013-03-08 17:34:02 -08002360 fi
2361 return $retval
Alex Rayf0d08eb2013-03-08 15:15:06 -08002362}
2363
Ying Wanged21d4c2014-08-24 22:14:19 -07002364function get_make_command()
2365{
2366 echo command make
2367}
2368
Anthony King40b093f2015-04-30 22:19:48 +01002369function mk_timer()
Ed Heylcc6be0a2014-06-18 14:55:58 -07002370{
2371 local start_time=$(date +"%s")
Anthony King40b093f2015-04-30 22:19:48 +01002372 $@
Ed Heylcc6be0a2014-06-18 14:55:58 -07002373 local ret=$?
2374 local end_time=$(date +"%s")
2375 local tdiff=$(($end_time-$start_time))
2376 local hours=$(($tdiff / 3600 ))
2377 local mins=$((($tdiff % 3600) / 60))
2378 local secs=$(($tdiff % 60))
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002379 local ncolors=$(tput colors 2>/dev/null)
2380 if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then
2381 color_failed="\e[0;31m"
2382 color_success="\e[0;32m"
Roman Birgead9a5c2015-10-16 10:29:06 -07002383 color_reset="\e[0m"
Greg Hackmannd95c7f72014-06-23 14:05:06 -07002384 else
2385 color_failed=""
2386 color_success=""
2387 color_reset=""
2388 fi
Ed Heylcc6be0a2014-06-18 14:55:58 -07002389 echo
2390 if [ $ret -eq 0 ] ; then
Roman Birgead9a5c2015-10-16 10:29:06 -07002391 printf "${color_success}#### make completed successfully "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002392 else
Roman Birgead9a5c2015-10-16 10:29:06 -07002393 printf "${color_failed}#### make failed to build some targets "
Ed Heylcc6be0a2014-06-18 14:55:58 -07002394 fi
2395 if [ $hours -gt 0 ] ; then
2396 printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs
2397 elif [ $mins -gt 0 ] ; then
2398 printf "(%02g:%02g (mm:ss))" $mins $secs
2399 elif [ $secs -gt 0 ] ; then
2400 printf "(%s seconds)" $secs
2401 fi
Roman Birgead9a5c2015-10-16 10:29:06 -07002402 printf " ####${color_reset}\n\n"
Ed Heylcc6be0a2014-06-18 14:55:58 -07002403 return $ret
2404}
2405
Anthony King40b093f2015-04-30 22:19:48 +01002406function make()
2407{
2408 mk_timer $(get_make_command) "$@"
2409}
2410
Raphael Moll70a86b02011-06-20 16:03:14 -07002411if [ "x$SHELL" != "x/bin/bash" ]; then
2412 case `ps -o command -p $$` in
2413 *bash*)
2414 ;;
Emilio López7ff9caa2013-11-03 13:05:43 -03002415 *zsh*)
2416 ;;
Raphael Moll70a86b02011-06-20 16:03:14 -07002417 *)
Emilio López7ff9caa2013-11-03 13:05:43 -03002418 echo "WARNING: Only bash and zsh are supported, use of other shell may lead to erroneous results"
Raphael Moll70a86b02011-06-20 16:03:14 -07002419 ;;
2420 esac
2421fi
The Android Open Source Projectdcc08f02008-12-17 18:03:49 -08002422
2423# Execute the contents of any vendorsetup.sh files we can find.
Oleksiy Avramchenko15760a82014-10-06 18:51:58 +02002424for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
2425 `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 -08002426do
2427 echo "including $f"
2428 . $f
2429done
2430unset f
Kenny Root52aa81c2011-07-15 11:07:06 -07002431
Kyle Ladd031a0b62013-09-11 20:43:42 -04002432# Add completions
2433check_bash_version && {
2434 dirs="sdk/bash_completion vendor/cm/bash_completion"
2435 for dir in $dirs; do
2436 if [ -d ${dir} ]; then
2437 for f in `/bin/ls ${dir}/[a-z]*.bash 2> /dev/null`; do
2438 echo "including $f"
2439 . $f
2440 done
2441 fi
2442 done
2443}
Chirayu Desaie1466d62013-03-19 17:50:37 +05302444
2445export ANDROID_BUILD_TOP=$(gettop)