Scott Anderson | 1a5fc95 | 2012-03-07 17:15:06 -0800 | [diff] [blame] | 1 | function hmm() { |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 2 | cat <<EOF |
Jeff Gaston | c6dfc4e | 2017-05-30 17:12:37 -0700 | [diff] [blame] | 3 | |
| 4 | Run "m help" for help with the build system itself. |
| 5 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 6 | Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment: |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 7 | - lunch: lunch <product_name>-<build_variant> |
| 8 | Selects <product_name> as the product to build, and <build_variant> as the variant to |
| 9 | build, and stores those selections in the environment to be read by subsequent |
| 10 | invocations of 'm' etc. |
| 11 | - tapas: tapas [<App1> <App2> ...] [arm|x86|mips|arm64|x86_64|mips64] [eng|userdebug|user] |
| 12 | - croot: Changes directory to the top of the tree. |
| 13 | - m: Makes from the top of the tree. |
| 14 | - mm: Builds all of the modules in the current directory, but not their dependencies. |
| 15 | - mmm: Builds all of the modules in the supplied directories, but not their dependencies. |
| 16 | To limit the modules being built use the syntax: mmm dir/:target1,target2. |
| 17 | - mma: Builds all of the modules in the current directory, and their dependencies. |
| 18 | - mmma: Builds all of the modules in the supplied directories, and their dependencies. |
| 19 | - provision: Flash device with all required partitions. Options will be passed on to fastboot. |
| 20 | - cgrep: Greps on all local C/C++ files. |
| 21 | - ggrep: Greps on all local Gradle files. |
| 22 | - jgrep: Greps on all local Java files. |
| 23 | - resgrep: Greps on all local res/*.xml files. |
| 24 | - mangrep: Greps on all local AndroidManifest.xml files. |
| 25 | - mgrep: Greps on all local Makefiles files. |
| 26 | - sepgrep: Greps on all local sepolicy files. |
| 27 | - sgrep: Greps on all local source files. |
| 28 | - godir: Go to the directory containing a file. |
| 29 | - allmod: List all modules. |
| 30 | - gomod: Go to the directory containing a module. |
| 31 | - refreshmod: Refresh list of modules for allmod/gomod. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | |
Roland Levillain | 3934192 | 2015-10-20 12:48:19 +0100 | [diff] [blame] | 33 | Environment options: |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 34 | - SANITIZE_HOST: Set to 'true' to use ASAN for all host modules. Note that |
| 35 | ASAN_OPTIONS=detect_leaks=0 will be set by default until the |
| 36 | build is leak-check clean. |
| 37 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 38 | Look at the source to view more functions. The complete list is: |
| 39 | EOF |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 40 | local T=$(gettop) |
| 41 | local A="" |
| 42 | local i |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 43 | for i in `cat $T/build/envsetup.sh | sed -n "/^[[:blank:]]*function /s/function \([a-z_]*\).*/\1/p" | sort | uniq`; do |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 44 | A="$A $i" |
| 45 | done |
| 46 | echo $A |
| 47 | } |
| 48 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 49 | # Get all the build variables needed by this script in a single call to the build system. |
| 50 | function build_build_var_cache() |
| 51 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 52 | local T=$(gettop) |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 53 | # Grep out the variable names from the script. |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 54 | cached_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`) |
| 55 | cached_abs_vars=(`cat $T/build/envsetup.sh | tr '()' ' ' | awk '{for(i=1;i<=NF;i++) if($i~/get_abs_build_var/) print $(i+1)}' | sort -u | tr '\n' ' '`) |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 56 | # Call the build system to dump the "<val>=<value>" pairs as a shell script. |
Steven Moreland | 0540296 | 2018-01-05 12:13:11 -0800 | [diff] [blame] | 57 | build_dicts_script=`\builtin cd $T; build/soong/soong_ui.bash --dumpvars-mode \ |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 58 | --vars="${cached_vars[*]}" \ |
| 59 | --abs-vars="${cached_abs_vars[*]}" \ |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 60 | --var-prefix=var_cache_ \ |
| 61 | --abs-var-prefix=abs_var_cache_` |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 62 | local ret=$? |
| 63 | if [ $ret -ne 0 ] |
| 64 | then |
| 65 | unset build_dicts_script |
| 66 | return $ret |
| 67 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 68 | # Execute the script to store the "<val>=<value>" pairs as shell variables. |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 69 | eval "$build_dicts_script" |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 70 | ret=$? |
Ying Wang | f0cb397 | 2016-03-04 13:56:23 -0800 | [diff] [blame] | 71 | unset build_dicts_script |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 72 | if [ $ret -ne 0 ] |
| 73 | then |
| 74 | return $ret |
| 75 | fi |
| 76 | BUILD_VAR_CACHE_READY="true" |
| 77 | } |
| 78 | |
Ying Wang | f0cb397 | 2016-03-04 13:56:23 -0800 | [diff] [blame] | 79 | # Delete the build var cache, so that we can still call into the build system |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 80 | # to get build variables not listed in this script. |
| 81 | function destroy_build_var_cache() |
| 82 | { |
| 83 | unset BUILD_VAR_CACHE_READY |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 84 | local v |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 85 | for v in $cached_vars; do |
| 86 | unset var_cache_$v |
| 87 | done |
| 88 | unset cached_vars |
| 89 | for v in $cached_abs_vars; do |
| 90 | unset abs_var_cache_$v |
| 91 | done |
| 92 | unset cached_abs_vars |
| 93 | } |
| 94 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 95 | # Get the value of a build variable as an absolute path. |
| 96 | function get_abs_build_var() |
| 97 | { |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 98 | if [ "$BUILD_VAR_CACHE_READY" = "true" ] |
| 99 | then |
Vishwath Mohan | 7d35f00 | 2016-03-11 10:00:40 -0800 | [diff] [blame] | 100 | eval "echo \"\${abs_var_cache_$1}\"" |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 101 | return |
| 102 | fi |
| 103 | |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 104 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 105 | if [ ! "$T" ]; then |
| 106 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 107 | return |
| 108 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 109 | (\cd $T; build/soong/soong_ui.bash --dumpvar-mode --abs $1) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | # Get the exact value of a build variable. |
| 113 | function get_build_var() |
| 114 | { |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 115 | if [ "$BUILD_VAR_CACHE_READY" = "true" ] |
| 116 | then |
Vishwath Mohan | 7d35f00 | 2016-03-11 10:00:40 -0800 | [diff] [blame] | 117 | eval "echo \"\${var_cache_$1}\"" |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 118 | return |
| 119 | fi |
| 120 | |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 121 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | if [ ! "$T" ]; then |
| 123 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 124 | return |
| 125 | fi |
Dan Willemsen | af88c41 | 2017-07-14 11:29:44 -0700 | [diff] [blame] | 126 | (\cd $T; build/soong/soong_ui.bash --dumpvar-mode $1) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | # check to see if the supplied product is one we can build |
| 130 | function check_product() |
| 131 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 132 | local T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 133 | if [ ! "$T" ]; then |
| 134 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 135 | return |
| 136 | fi |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 137 | TARGET_PRODUCT=$1 \ |
| 138 | TARGET_BUILD_VARIANT= \ |
| 139 | TARGET_BUILD_TYPE= \ |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 140 | TARGET_BUILD_APPS= \ |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 141 | get_build_var TARGET_DEVICE > /dev/null |
| 142 | # hide successful answers, but allow the errors to show |
| 143 | } |
| 144 | |
| 145 | VARIANT_CHOICES=(user userdebug eng) |
| 146 | |
| 147 | # check to see if the supplied variant is valid |
| 148 | function check_variant() |
| 149 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 150 | local v |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 151 | for v in ${VARIANT_CHOICES[@]} |
| 152 | do |
| 153 | if [ "$v" = "$1" ] |
| 154 | then |
| 155 | return 0 |
| 156 | fi |
| 157 | done |
| 158 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | function setpaths() |
| 162 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 163 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 164 | if [ ! "$T" ]; then |
| 165 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 166 | return |
| 167 | fi |
| 168 | |
| 169 | ################################################################## |
| 170 | # # |
| 171 | # Read me before you modify this code # |
| 172 | # # |
| 173 | # This function sets ANDROID_BUILD_PATHS to what it is adding # |
| 174 | # to PATH, and the next time it is run, it removes that from # |
| 175 | # PATH. This is required so lunch can be run more than once # |
| 176 | # and still have working paths. # |
| 177 | # # |
| 178 | ################################################################## |
| 179 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 180 | # Note: on windows/cygwin, ANDROID_BUILD_PATHS will contain spaces |
| 181 | # due to "C:\Program Files" being in the path. |
| 182 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 183 | # out with the old |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 184 | if [ -n "$ANDROID_BUILD_PATHS" ] ; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 185 | export PATH=${PATH/$ANDROID_BUILD_PATHS/} |
| 186 | fi |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 187 | if [ -n "$ANDROID_PRE_BUILD_PATHS" ] ; then |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 188 | export PATH=${PATH/$ANDROID_PRE_BUILD_PATHS/} |
Ying Wang | aa1c9b5 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 189 | # strip leading ':', if any |
| 190 | export PATH=${PATH/:%/} |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 191 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 192 | |
| 193 | # and in with the new |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 194 | local prebuiltdir=$(getprebuilt) |
| 195 | local gccprebuiltdir=$(get_abs_build_var ANDROID_GCC_PREBUILTS) |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 196 | |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 197 | # defined in core/config.mk |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 198 | local targetgccversion=$(get_build_var TARGET_GCC_VERSION) |
| 199 | local targetgccversion2=$(get_build_var 2ND_TARGET_GCC_VERSION) |
Ben Cheng | 1526670 | 2012-12-10 16:04:39 -0800 | [diff] [blame] | 200 | export TARGET_GCC_VERSION=$targetgccversion |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 201 | |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 202 | # The gcc toolchain does not exists for windows/cygwin. In this case, do not reference it. |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 203 | export ANDROID_TOOLCHAIN= |
| 204 | export ANDROID_TOOLCHAIN_2ND_ARCH= |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 205 | local ARCH=$(get_build_var TARGET_ARCH) |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 206 | local toolchaindir toolchaindir2= |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 207 | case $ARCH in |
Pavel Chupin | c1a5664 | 2013-08-23 16:49:21 +0400 | [diff] [blame] | 208 | x86) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 209 | ;; |
Pavel Chupin | fd82a49 | 2012-11-26 09:50:07 +0400 | [diff] [blame] | 210 | x86_64) toolchaindir=x86/x86_64-linux-android-$targetgccversion/bin |
| 211 | ;; |
Ben Cheng | 8bc4c43 | 2012-11-16 13:29:13 -0800 | [diff] [blame] | 212 | arm) toolchaindir=arm/arm-linux-androideabi-$targetgccversion/bin |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 213 | ;; |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 214 | arm64) toolchaindir=aarch64/aarch64-linux-android-$targetgccversion/bin; |
Colin Cross | 03b424a | 2014-05-22 11:57:43 -0700 | [diff] [blame] | 215 | toolchaindir2=arm/arm-linux-androideabi-$targetgccversion2/bin |
Ben Cheng | db4fc20 | 2013-10-04 16:02:59 -0700 | [diff] [blame] | 216 | ;; |
Duane Sand | 3c4fcd8 | 2014-07-22 14:34:00 -0700 | [diff] [blame] | 217 | mips|mips64) toolchaindir=mips/mips64el-linux-android-$targetgccversion/bin |
Serban Constantinescu | 9b68fb2 | 2014-01-14 10:33:53 +0000 | [diff] [blame] | 218 | ;; |
David 'Digit' Turner | 2056c25 | 2012-04-17 14:50:47 +0200 | [diff] [blame] | 219 | *) |
| 220 | echo "Can't find toolchain for unknown architecture: $ARCH" |
| 221 | toolchaindir=xxxxxxxxx |
Mark D Horn | 7d0ede7 | 2012-03-14 14:20:30 -0700 | [diff] [blame] | 222 | ;; |
| 223 | esac |
Jing Yu | f5172c7 | 2012-03-29 20:45:50 -0700 | [diff] [blame] | 224 | if [ -d "$gccprebuiltdir/$toolchaindir" ]; then |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 225 | export ANDROID_TOOLCHAIN=$gccprebuiltdir/$toolchaindir |
Raphael Moll | c639c78 | 2011-06-20 17:25:01 -0700 | [diff] [blame] | 226 | fi |
Raphael | 732936d | 2011-06-22 14:35:32 -0700 | [diff] [blame] | 227 | |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 228 | if [ "$toolchaindir2" -a -d "$gccprebuiltdir/$toolchaindir2" ]; then |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 229 | export ANDROID_TOOLCHAIN_2ND_ARCH=$gccprebuiltdir/$toolchaindir2 |
| 230 | fi |
| 231 | |
Jeff Vander Stoep | 5f50f05 | 2015-06-12 09:56:39 -0700 | [diff] [blame] | 232 | export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools:$T/external/selinux/prebuilts/bin |
Yueyao Zhu | efc786a | 2017-04-07 14:11:54 -0700 | [diff] [blame] | 233 | |
| 234 | # add kernel specific binaries |
| 235 | case $(uname -s) in |
| 236 | Linux) |
| 237 | export ANDROID_DEV_SCRIPTS=$ANDROID_DEV_SCRIPTS:$T/prebuilts/misc/linux-x86/dtc:$T/prebuilts/misc/linux-x86/libufdt |
| 238 | ;; |
| 239 | *) |
| 240 | ;; |
| 241 | esac |
| 242 | |
Torne (Richard Coles) | 0091bae | 2017-10-03 16:31:18 -0400 | [diff] [blame] | 243 | ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_TOOLCHAIN |
| 244 | if [ -n "$ANDROID_TOOLCHAIN_2ND_ARCH" ]; then |
| 245 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_TOOLCHAIN_2ND_ARCH |
| 246 | fi |
| 247 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS:$ANDROID_DEV_SCRIPTS: |
| 248 | export ANDROID_BUILD_PATHS |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 249 | |
| 250 | # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH |
| 251 | # to ensure that the corresponding 'emulator' binaries are used. |
| 252 | case $(uname -s) in |
| 253 | Darwin) |
| 254 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64 |
| 255 | ;; |
| 256 | Linux) |
| 257 | ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64 |
| 258 | ;; |
| 259 | *) |
| 260 | ANDROID_EMULATOR_PREBUILTS= |
| 261 | ;; |
| 262 | esac |
| 263 | if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then |
Christopher Ferris | 7110f24 | 2014-05-20 13:56:00 -0700 | [diff] [blame] | 264 | ANDROID_BUILD_PATHS=$ANDROID_BUILD_PATHS$ANDROID_EMULATOR_PREBUILTS: |
David 'Digit' Turner | 94d16e5 | 2014-05-05 16:13:50 +0200 | [diff] [blame] | 265 | export ANDROID_EMULATOR_PREBUILTS |
| 266 | fi |
| 267 | |
Ying Wang | aa1c9b5 | 2012-11-26 20:51:59 -0800 | [diff] [blame] | 268 | export PATH=$ANDROID_BUILD_PATHS$PATH |
Dan Albert | f5caa3d | 2015-09-18 13:23:56 -0700 | [diff] [blame] | 269 | export PYTHONPATH=$T/development/python-packages:$PYTHONPATH |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 270 | |
Colin Cross | e97e693 | 2017-06-30 16:01:45 -0700 | [diff] [blame] | 271 | export ANDROID_JAVA_HOME=$(get_abs_build_var ANDROID_JAVA_HOME) |
| 272 | export JAVA_HOME=$ANDROID_JAVA_HOME |
| 273 | export ANDROID_JAVA_TOOLCHAIN=$(get_abs_build_var ANDROID_JAVA_TOOLCHAIN) |
| 274 | export ANDROID_PRE_BUILD_PATHS=$ANDROID_JAVA_TOOLCHAIN: |
| 275 | export PATH=$ANDROID_PRE_BUILD_PATHS$PATH |
Jeff Hamilton | 4a1c70e | 2010-06-21 18:26:38 -0500 | [diff] [blame] | 276 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 277 | unset ANDROID_PRODUCT_OUT |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 278 | export ANDROID_PRODUCT_OUT=$(get_abs_build_var PRODUCT_OUT) |
| 279 | export OUT=$ANDROID_PRODUCT_OUT |
| 280 | |
Jeff Brown | 8fd5cce | 2011-03-24 17:03:06 -0700 | [diff] [blame] | 281 | unset ANDROID_HOST_OUT |
| 282 | export ANDROID_HOST_OUT=$(get_abs_build_var HOST_OUT) |
| 283 | |
Simran Basi | dd050ed | 2017-02-13 13:46:48 -0800 | [diff] [blame] | 284 | unset ANDROID_HOST_OUT_TESTCASES |
| 285 | export ANDROID_HOST_OUT_TESTCASES=$(get_abs_build_var HOST_OUT_TESTCASES) |
| 286 | |
| 287 | unset ANDROID_TARGET_OUT_TESTCASES |
| 288 | export ANDROID_TARGET_OUT_TESTCASES=$(get_abs_build_var TARGET_OUT_TESTCASES) |
| 289 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 290 | # needed for building linux on MacOS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 291 | # TODO: fix the path |
| 292 | #export HOST_EXTRACFLAGS="-I "$T/system/kernel_headers/host_include |
| 293 | } |
| 294 | |
| 295 | function printconfig() |
| 296 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 297 | local T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 298 | if [ ! "$T" ]; then |
| 299 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 300 | return |
| 301 | fi |
| 302 | get_build_var report_config |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | function set_stuff_for_environment() |
| 306 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 307 | setpaths |
| 308 | set_sequence_number |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 309 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 310 | export ANDROID_BUILD_TOP=$(gettop) |
Ben Cheng | aac3f81 | 2013-08-13 14:38:15 -0700 | [diff] [blame] | 311 | # With this environment variable new GCC can apply colors to warnings/errors |
| 312 | export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 313 | export ASAN_OPTIONS=detect_leaks=0 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | function set_sequence_number() |
| 317 | { |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 318 | export BUILD_ENV_SEQUENCE_NUMBER=13 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 321 | # Takes a command name, and check if it's in ENVSETUP_NO_COMPLETION or not. |
| 322 | function should_add_completion() { |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 323 | local cmd="$(basename $1| sed 's/_completion//' |sed 's/\.\(.*\)*sh$//')" |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 324 | case :"$ENVSETUP_NO_COMPLETION": in |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 325 | *:"$cmd":*) |
| 326 | return 1 |
| 327 | ;; |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 328 | esac |
| 329 | return 0 |
| 330 | } |
| 331 | |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 332 | function addcompletions() |
| 333 | { |
| 334 | local T dir f |
| 335 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 336 | # Keep us from trying to run in something that's neither bash nor zsh. |
| 337 | if [ -z "$BASH_VERSION" -a -z "$ZSH_VERSION" ]; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 338 | return |
| 339 | fi |
| 340 | |
| 341 | # Keep us from trying to run in bash that's too old. |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 342 | if [ -n "$BASH_VERSION" -a ${BASH_VERSINFO[0]} -lt 3 ]; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 343 | return |
| 344 | fi |
| 345 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 346 | local completion_files=( |
| 347 | system/core/adb/adb.bash |
| 348 | system/core/fastboot/fastboot.bash |
| 349 | tools/tradefederation/core/atest/atest_completion.sh |
| 350 | ) |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 351 | # Completion can be disabled selectively to allow users to use non-standard completion. |
| 352 | # e.g. |
| 353 | # ENVSETUP_NO_COMPLETION=adb # -> disable adb completion |
| 354 | # ENVSETUP_NO_COMPLETION=adb:bit # -> disable adb and bit completion |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 355 | for f in ${completion_files[*]}; do |
| 356 | if [ -f "$f" ] && should_add_completion "$f"; then |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 357 | . $f |
Elliott Hughes | ce18dd4 | 2018-04-03 13:49:48 -0700 | [diff] [blame] | 358 | fi |
| 359 | done |
Joe Onorato | 002a6c7 | 2016-10-20 16:39:49 -0700 | [diff] [blame] | 360 | |
Makoto Onuki | da97106 | 2018-06-18 10:15:19 -0700 | [diff] [blame] | 361 | if should_add_completion bit ; then |
| 362 | complete -C "bit --tab" bit |
| 363 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 364 | complete -F _lunch lunch |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 365 | |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame^] | 366 | complete -F _complete_android_module_names gomod |
| 367 | complete -F _complete_android_module_names m |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 368 | } |
| 369 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 370 | function choosetype() |
| 371 | { |
| 372 | echo "Build type choices are:" |
| 373 | echo " 1. release" |
| 374 | echo " 2. debug" |
| 375 | echo |
| 376 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 377 | local DEFAULT_NUM DEFAULT_VALUE |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 378 | DEFAULT_NUM=1 |
| 379 | DEFAULT_VALUE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 380 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 381 | export TARGET_BUILD_TYPE= |
| 382 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 383 | while [ -z $TARGET_BUILD_TYPE ] |
| 384 | do |
| 385 | echo -n "Which would you like? ["$DEFAULT_NUM"] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 386 | if [ -z "$1" ] ; then |
| 387 | read ANSWER |
| 388 | else |
| 389 | echo $1 |
| 390 | ANSWER=$1 |
| 391 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 392 | case $ANSWER in |
| 393 | "") |
| 394 | export TARGET_BUILD_TYPE=$DEFAULT_VALUE |
| 395 | ;; |
| 396 | 1) |
| 397 | export TARGET_BUILD_TYPE=release |
| 398 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 399 | release) |
| 400 | export TARGET_BUILD_TYPE=release |
| 401 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 402 | 2) |
| 403 | export TARGET_BUILD_TYPE=debug |
| 404 | ;; |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 405 | debug) |
| 406 | export TARGET_BUILD_TYPE=debug |
| 407 | ;; |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 408 | *) |
| 409 | echo |
| 410 | echo "I didn't understand your response. Please try again." |
| 411 | echo |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 412 | ;; |
| 413 | esac |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 414 | if [ -n "$1" ] ; then |
| 415 | break |
| 416 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 417 | done |
| 418 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 419 | build_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 420 | set_stuff_for_environment |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 421 | destroy_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 422 | } |
| 423 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 424 | # |
| 425 | # This function isn't really right: It chooses a TARGET_PRODUCT |
| 426 | # based on the list of boards. Usually, that gets you something |
| 427 | # that kinda works with a generic product, but really, you should |
| 428 | # pick a product by name. |
| 429 | # |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 430 | function chooseproduct() |
| 431 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 432 | local default_value |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 433 | if [ "x$TARGET_PRODUCT" != x ] ; then |
| 434 | default_value=$TARGET_PRODUCT |
| 435 | else |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 436 | default_value=aosp_arm |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 437 | fi |
| 438 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 439 | export TARGET_BUILD_APPS= |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 440 | export TARGET_PRODUCT= |
| 441 | local ANSWER |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 442 | while [ -z "$TARGET_PRODUCT" ] |
| 443 | do |
Joe Onorato | 8849aed | 2009-04-29 15:56:47 -0700 | [diff] [blame] | 444 | echo -n "Which product would you like? [$default_value] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 445 | if [ -z "$1" ] ; then |
| 446 | read ANSWER |
| 447 | else |
| 448 | echo $1 |
| 449 | ANSWER=$1 |
| 450 | fi |
| 451 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 452 | if [ -z "$ANSWER" ] ; then |
| 453 | export TARGET_PRODUCT=$default_value |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 454 | else |
| 455 | if check_product $ANSWER |
| 456 | then |
| 457 | export TARGET_PRODUCT=$ANSWER |
| 458 | else |
| 459 | echo "** Not a valid product: $ANSWER" |
| 460 | fi |
| 461 | fi |
| 462 | if [ -n "$1" ] ; then |
| 463 | break |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 464 | fi |
| 465 | done |
| 466 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 467 | build_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 468 | set_stuff_for_environment |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 469 | destroy_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 470 | } |
| 471 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 472 | function choosevariant() |
| 473 | { |
| 474 | echo "Variant choices are:" |
| 475 | local index=1 |
| 476 | local v |
| 477 | for v in ${VARIANT_CHOICES[@]} |
| 478 | do |
| 479 | # The product name is the name of the directory containing |
| 480 | # the makefile we found, above. |
| 481 | echo " $index. $v" |
| 482 | index=$(($index+1)) |
| 483 | done |
| 484 | |
| 485 | local default_value=eng |
| 486 | local ANSWER |
| 487 | |
| 488 | export TARGET_BUILD_VARIANT= |
| 489 | while [ -z "$TARGET_BUILD_VARIANT" ] |
| 490 | do |
| 491 | echo -n "Which would you like? [$default_value] " |
| 492 | if [ -z "$1" ] ; then |
| 493 | read ANSWER |
| 494 | else |
| 495 | echo $1 |
| 496 | ANSWER=$1 |
| 497 | fi |
| 498 | |
| 499 | if [ -z "$ANSWER" ] ; then |
| 500 | export TARGET_BUILD_VARIANT=$default_value |
| 501 | elif (echo -n $ANSWER | grep -q -e "^[0-9][0-9]*$") ; then |
| 502 | if [ "$ANSWER" -le "${#VARIANT_CHOICES[@]}" ] ; then |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 503 | export TARGET_BUILD_VARIANT=${VARIANT_CHOICES[$(($ANSWER-1))]} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 504 | fi |
| 505 | else |
| 506 | if check_variant $ANSWER |
| 507 | then |
| 508 | export TARGET_BUILD_VARIANT=$ANSWER |
| 509 | else |
| 510 | echo "** Not a valid variant: $ANSWER" |
| 511 | fi |
| 512 | fi |
| 513 | if [ -n "$1" ] ; then |
| 514 | break |
| 515 | fi |
| 516 | done |
| 517 | } |
| 518 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 519 | function choosecombo() |
| 520 | { |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 521 | choosetype $1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 522 | |
| 523 | echo |
| 524 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 525 | chooseproduct $2 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 526 | |
| 527 | echo |
| 528 | echo |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 529 | choosevariant $3 |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 530 | |
| 531 | echo |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 532 | build_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 533 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 534 | printconfig |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 535 | destroy_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 536 | } |
| 537 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 538 | # Clear this variable. It will be built up again when the vendorsetup.sh |
| 539 | # files are included at the end of this file. |
| 540 | unset LUNCH_MENU_CHOICES |
| 541 | function add_lunch_combo() |
| 542 | { |
| 543 | local new_combo=$1 |
| 544 | local c |
| 545 | for c in ${LUNCH_MENU_CHOICES[@]} ; do |
| 546 | if [ "$new_combo" = "$c" ] ; then |
| 547 | return |
| 548 | fi |
| 549 | done |
| 550 | LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) |
| 551 | } |
| 552 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 553 | function print_lunch_menu() |
| 554 | { |
| 555 | local uname=$(uname) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 556 | echo |
| 557 | echo "You're building on" $uname |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 558 | echo |
| 559 | echo "Lunch menu... pick a combo:" |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 560 | |
| 561 | local i=1 |
| 562 | local choice |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 563 | for choice in $(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 564 | do |
| 565 | echo " $i. $choice" |
| 566 | i=$(($i+1)) |
| 567 | done |
| 568 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 569 | echo |
| 570 | } |
| 571 | |
| 572 | function lunch() |
| 573 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 574 | local answer |
| 575 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 576 | if [ "$1" ] ; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 577 | answer=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 578 | else |
| 579 | print_lunch_menu |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 580 | echo -n "Which would you like? [aosp_arm-eng] " |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 581 | read answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 582 | fi |
| 583 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 584 | local selection= |
| 585 | |
| 586 | if [ -z "$answer" ] |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 587 | then |
Jean-Baptiste Queru | 324c123 | 2013-03-22 15:53:54 -0700 | [diff] [blame] | 588 | selection=aosp_arm-eng |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 589 | elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$") |
| 590 | then |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 591 | local choices=($(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES)) |
| 592 | if [ $answer -le ${#choices[@]} ] |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 593 | then |
Jim Tang | 0e3397b | 2018-10-03 18:25:50 +0800 | [diff] [blame] | 594 | # array in zsh starts from 1 instead of 0. |
| 595 | if [ -n "$ZSH_VERSION" ] |
| 596 | then |
| 597 | selection=${choices[$(($answer))]} |
| 598 | else |
| 599 | selection=${choices[$(($answer-1))]} |
| 600 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 601 | fi |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 602 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 603 | selection=$answer |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 604 | fi |
| 605 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 606 | export TARGET_BUILD_APPS= |
| 607 | |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 608 | local product variant_and_version variant version |
| 609 | |
| 610 | product=${selection%%-*} # Trim everything after first dash |
| 611 | variant_and_version=${selection#*-} # Trim everything up to first dash |
| 612 | if [ "$variant_and_version" != "$selection" ]; then |
| 613 | variant=${variant_and_version%%-*} |
| 614 | if [ "$variant" != "$variant_and_version" ]; then |
| 615 | version=${variant_and_version#*-} |
| 616 | fi |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 617 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 618 | |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 619 | if [ -z "$product" ] |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 620 | then |
| 621 | echo |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 622 | echo "Invalid lunch combo: $selection" |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 623 | return 1 |
| 624 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 625 | |
Colin Cross | 8873713 | 2017-03-21 17:41:03 -0700 | [diff] [blame] | 626 | TARGET_PRODUCT=$product \ |
| 627 | TARGET_BUILD_VARIANT=$variant \ |
| 628 | TARGET_PLATFORM_VERSION=$version \ |
| 629 | build_build_var_cache |
| 630 | if [ $? -ne 0 ] |
| 631 | then |
| 632 | return 1 |
| 633 | fi |
| 634 | |
| 635 | export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT) |
| 636 | export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT) |
Colin Cross | b105e36 | 2017-05-01 14:21:28 -0700 | [diff] [blame] | 637 | if [ -n "$version" ]; then |
| 638 | export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION) |
| 639 | else |
| 640 | unset TARGET_PLATFORM_VERSION |
| 641 | fi |
Jeff Brown | e33ba4c | 2011-07-11 22:11:46 -0700 | [diff] [blame] | 642 | export TARGET_BUILD_TYPE=release |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 643 | |
| 644 | echo |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 645 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 646 | set_stuff_for_environment |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 647 | printconfig |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 648 | destroy_build_var_cache |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 651 | unset COMMON_LUNCH_CHOICES_CACHE |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 652 | # Tab completion for lunch. |
| 653 | function _lunch() |
| 654 | { |
| 655 | local cur prev opts |
| 656 | COMPREPLY=() |
| 657 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 658 | prev="${COMP_WORDS[COMP_CWORD-1]}" |
| 659 | |
Dan Willemsen | af2e1f8 | 2018-04-04 15:41:41 -0700 | [diff] [blame] | 660 | if [ -z "$COMMON_LUNCH_CHOICES_CACHE" ]; then |
| 661 | COMMON_LUNCH_CHOICES_CACHE=$(TARGET_BUILD_APPS= LUNCH_MENU_CHOICES="${LUNCH_MENU_CHOICES[@]}" get_build_var COMMON_LUNCH_CHOICES) |
| 662 | fi |
| 663 | |
| 664 | COMPREPLY=( $(compgen -W "${COMMON_LUNCH_CHOICES_CACHE}" -- ${cur}) ) |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 665 | return 0 |
| 666 | } |
Jeff Davidson | 513d7a4 | 2010-08-02 10:00:44 -0700 | [diff] [blame] | 667 | |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 668 | # Configures the build to build unbundled apps. |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 669 | # Run tapas with one or more app names (from LOCAL_PACKAGE_NAME) |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 670 | function tapas() |
| 671 | { |
Jeff Gaston | 9fb05d8 | 2017-08-21 18:27:00 -0700 | [diff] [blame] | 672 | local showHelp="$(echo $* | xargs -n 1 echo | \grep -E '^(help)$' | xargs)" |
Dan Willemsen | dd3a273 | 2018-01-08 15:26:16 -0800 | [diff] [blame] | 673 | local arch="$(echo $* | xargs -n 1 echo | \grep -E '^(arm|x86|mips|arm64|x86_64|mips64)$' | xargs)" |
Doug Zongker | 0d8179e | 2014-04-16 11:34:34 -0700 | [diff] [blame] | 674 | local variant="$(echo $* | xargs -n 1 echo | \grep -E '^(user|userdebug|eng)$' | xargs)" |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 675 | local density="$(echo $* | xargs -n 1 echo | \grep -E '^(ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)" |
Dan Willemsen | dd3a273 | 2018-01-08 15:26:16 -0800 | [diff] [blame] | 676 | local apps="$(echo $* | xargs -n 1 echo | \grep -E -v '^(user|userdebug|eng|arm|x86|mips|arm64|x86_64|mips64|ldpi|mdpi|tvdpi|hdpi|xhdpi|xxhdpi|xxxhdpi|alldpi)$' | xargs)" |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 677 | |
Jeff Gaston | 9fb05d8 | 2017-08-21 18:27:00 -0700 | [diff] [blame] | 678 | if [ "$showHelp" != "" ]; then |
| 679 | $(gettop)/build/make/tapasHelp.sh |
| 680 | return |
| 681 | fi |
| 682 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 683 | if [ $(echo $arch | wc -w) -gt 1 ]; then |
| 684 | echo "tapas: Error: Multiple build archs supplied: $arch" |
| 685 | return |
| 686 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 687 | if [ $(echo $variant | wc -w) -gt 1 ]; then |
| 688 | echo "tapas: Error: Multiple build variants supplied: $variant" |
| 689 | return |
| 690 | fi |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 691 | if [ $(echo $density | wc -w) -gt 1 ]; then |
| 692 | echo "tapas: Error: Multiple densities supplied: $density" |
| 693 | return |
| 694 | fi |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 695 | |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 696 | local product=aosp_arm |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 697 | case $arch in |
Ying Wang | 0a76df5 | 2015-06-08 11:57:26 -0700 | [diff] [blame] | 698 | x86) product=aosp_x86;; |
| 699 | mips) product=aosp_mips;; |
Ying Wang | b541ab6 | 2014-05-29 17:57:40 -0700 | [diff] [blame] | 700 | arm64) product=aosp_arm64;; |
| 701 | x86_64) product=aosp_x86_64;; |
| 702 | mips64) product=aosp_mips64;; |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 703 | esac |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 704 | if [ -z "$variant" ]; then |
| 705 | variant=eng |
| 706 | fi |
Ying Wang | c048c9b | 2010-06-24 15:08:33 -0700 | [diff] [blame] | 707 | if [ -z "$apps" ]; then |
| 708 | apps=all |
| 709 | fi |
Justin Morey | 29d225c | 2014-11-04 13:35:51 -0600 | [diff] [blame] | 710 | if [ -z "$density" ]; then |
| 711 | density=alldpi |
| 712 | fi |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 713 | |
Ying Wang | 67f0292 | 2012-08-22 10:25:20 -0700 | [diff] [blame] | 714 | export TARGET_PRODUCT=$product |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 715 | export TARGET_BUILD_VARIANT=$variant |
Jeff Hamilton | 5069bd6 | 2014-09-04 21:28:00 -0700 | [diff] [blame] | 716 | export TARGET_BUILD_DENSITY=$density |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 717 | export TARGET_BUILD_TYPE=release |
| 718 | export TARGET_BUILD_APPS=$apps |
| 719 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 720 | build_build_var_cache |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 721 | set_stuff_for_environment |
| 722 | printconfig |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 723 | destroy_build_var_cache |
Joe Onorato | da12daf | 2010-06-09 18:18:31 -0700 | [diff] [blame] | 724 | } |
| 725 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 726 | function gettop |
| 727 | { |
Colin Cross | 6cdc5d2 | 2017-10-20 11:37:33 -0700 | [diff] [blame] | 728 | local TOPFILE=build/make/core/envsetup.mk |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 729 | if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then |
Brian Carlstrom | a5c4f17 | 2014-09-12 00:33:25 -0700 | [diff] [blame] | 730 | # The following circumlocution ensures we remove symlinks from TOP. |
| 731 | (cd $TOP; PWD= /bin/pwd) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 732 | else |
| 733 | if [ -f $TOPFILE ] ; then |
Dan Bornstein | d0b274d | 2009-11-24 15:48:50 -0800 | [diff] [blame] | 734 | # The following circumlocution (repeated below as well) ensures |
| 735 | # that we record the true directory name and not one that is |
| 736 | # faked up with symlink names. |
| 737 | PWD= /bin/pwd |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 738 | else |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 739 | local HERE=$PWD |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 740 | local T= |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 741 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 742 | \cd .. |
synergy | b112a40 | 2013-07-05 19:47:47 -0700 | [diff] [blame] | 743 | T=`PWD= /bin/pwd -P` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 744 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 745 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 746 | if [ -f "$T/$TOPFILE" ]; then |
| 747 | echo $T |
| 748 | fi |
| 749 | fi |
| 750 | fi |
| 751 | } |
| 752 | |
| 753 | function m() |
| 754 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 755 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 756 | if [ "$T" ]; then |
Chih-Hung Hsieh | 7ed0db8 | 2018-02-15 11:20:04 -0800 | [diff] [blame] | 757 | _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 758 | else |
| 759 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 760 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 761 | fi |
| 762 | } |
| 763 | |
| 764 | function findmakefile() |
| 765 | { |
Colin Cross | 6cdc5d2 | 2017-10-20 11:37:33 -0700 | [diff] [blame] | 766 | local TOPFILE=build/make/core/envsetup.mk |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 767 | local HERE=$PWD |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 768 | local T= |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 769 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
Ying Wang | 11b15b1 | 2012-10-11 15:05:07 -0700 | [diff] [blame] | 770 | T=`PWD= /bin/pwd` |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 771 | if [ -f "$T/Android.mk" -o -f "$T/Android.bp" ]; then |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 772 | echo $T/Android.mk |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 773 | \cd $HERE |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 774 | return |
| 775 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 776 | \cd .. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 777 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 778 | \cd $HERE |
Steven Moreland | 3b99ecf | 2018-06-13 15:31:59 -0700 | [diff] [blame] | 779 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | function mm() |
| 783 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 784 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 785 | # If we're sitting in the root of the build tree, just do a |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 786 | # normal build. |
| 787 | if [ -f build/soong/soong_ui.bash ]; then |
Chih-Hung Hsieh | 7ed0db8 | 2018-02-15 11:20:04 -0800 | [diff] [blame] | 788 | _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 789 | else |
| 790 | # Find the closest Android.mk file. |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 791 | local M=$(findmakefile) |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 792 | local MODULES= |
| 793 | local GET_INSTALL_PATH= |
| 794 | local ARGS= |
Robert Greenwalt | 3c794d7 | 2009-07-15 15:07:44 -0700 | [diff] [blame] | 795 | # Remove the path to top as the makefilepath needs to be relative |
| 796 | local M=`echo $M|sed 's:'$T'/::'` |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 797 | if [ ! "$T" ]; then |
| 798 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 799 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 800 | elif [ ! "$M" ]; then |
| 801 | echo "Couldn't locate a makefile from the current directory." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 802 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 803 | else |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 804 | local ARG |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 805 | for ARG in $@; do |
| 806 | case $ARG in |
| 807 | GET-INSTALL-PATH) GET_INSTALL_PATH=$ARG;; |
| 808 | esac |
| 809 | done |
| 810 | if [ -n "$GET_INSTALL_PATH" ]; then |
| 811 | MODULES= |
Dan Willemsen | 53e3899 | 2016-08-11 17:20:33 -0700 | [diff] [blame] | 812 | ARGS=GET-INSTALL-PATH-IN-$(dirname ${M}) |
| 813 | ARGS=${ARGS//\//-} |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 814 | else |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 815 | MODULES=MODULES-IN-$(dirname ${M}) |
| 816 | # Convert "/" to "-". |
| 817 | MODULES=${MODULES//\//-} |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 818 | ARGS=$@ |
| 819 | fi |
Chih-Hung Hsieh | a9a55c7 | 2016-03-31 16:30:23 -0700 | [diff] [blame] | 820 | if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then |
| 821 | MODULES=tidy_only |
| 822 | fi |
Chih-Hung Hsieh | 7ed0db8 | 2018-02-15 11:20:04 -0800 | [diff] [blame] | 823 | ONE_SHOT_MAKEFILE=$M _wrap_build $T/build/soong/soong_ui.bash --make-mode $MODULES $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 824 | fi |
| 825 | fi |
| 826 | } |
| 827 | |
| 828 | function mmm() |
| 829 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 830 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 831 | if [ "$T" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 832 | local MAKEFILE= |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 833 | local MODULES= |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 834 | local MODULES_IN_PATHS= |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 835 | local ARGS= |
| 836 | local DIR TO_CHOP |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 837 | local DIR_MODULES |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 838 | local GET_INSTALL_PATH= |
Dan Willemsen | 53e3899 | 2016-08-11 17:20:33 -0700 | [diff] [blame] | 839 | local GET_INSTALL_PATHS= |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 840 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 841 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 842 | for DIR in $DIRS ; do |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 843 | DIR_MODULES=`echo $DIR | sed -n -e 's/.*:\(.*$\)/\1/p' | sed 's/,/ /'` |
Alon Albert | 68895a9 | 2011-11-30 12:40:19 -0800 | [diff] [blame] | 844 | DIR=`echo $DIR | sed -e 's/:.*//' -e 's:/$::'` |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 845 | # Remove the leading ./ and trailing / if any exists. |
| 846 | DIR=${DIR#./} |
| 847 | DIR=${DIR%/} |
| 848 | if [ -f $DIR/Android.mk -o -f $DIR/Android.bp ]; then |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 849 | local TO_CHOP=`(\cd -P -- $T && pwd -P) | wc -c | tr -d ' '` |
| 850 | local TO_CHOP=`expr $TO_CHOP + 1` |
| 851 | local START=`PWD= /bin/pwd` |
Colin Cross | 4bfae06 | 2016-08-31 17:22:36 -0700 | [diff] [blame] | 852 | local MDIR=`echo $START | cut -c${TO_CHOP}-` |
| 853 | if [ "$MDIR" = "" ] ; then |
| 854 | MDIR=$DIR |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 855 | else |
Colin Cross | 4bfae06 | 2016-08-31 17:22:36 -0700 | [diff] [blame] | 856 | MDIR=$MDIR/$DIR |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 857 | fi |
Colin Cross | 4bfae06 | 2016-08-31 17:22:36 -0700 | [diff] [blame] | 858 | MDIR=${MDIR%/.} |
| 859 | if [ "$DIR_MODULES" = "" ]; then |
| 860 | MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$MDIR" |
| 861 | GET_INSTALL_PATHS="$GET_INSTALL_PATHS GET-INSTALL-PATH-IN-$MDIR" |
| 862 | else |
| 863 | MODULES="$MODULES $DIR_MODULES" |
| 864 | fi |
| 865 | MAKEFILE="$MAKEFILE $MDIR/Android.mk" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 866 | else |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 867 | case $DIR in |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 868 | showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";; |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 869 | GET-INSTALL-PATH) GET_INSTALL_PATH=$DIR;; |
Abhinav1997 | a72a6e7 | 2015-10-18 20:25:48 +0200 | [diff] [blame] | 870 | *) if [ -d $DIR ]; then |
| 871 | echo "No Android.mk in $DIR."; |
| 872 | else |
| 873 | echo "Couldn't locate the directory $DIR"; |
| 874 | fi |
| 875 | return 1;; |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 876 | esac |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 877 | fi |
| 878 | done |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 879 | if [ -n "$GET_INSTALL_PATH" ]; then |
Dan Willemsen | 53e3899 | 2016-08-11 17:20:33 -0700 | [diff] [blame] | 880 | ARGS=${GET_INSTALL_PATHS//\//-} |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 881 | MODULES= |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 882 | MODULES_IN_PATHS= |
Ying Wang | a7deb08 | 2013-08-16 13:24:47 -0700 | [diff] [blame] | 883 | fi |
Chih-Hung Hsieh | a9a55c7 | 2016-03-31 16:30:23 -0700 | [diff] [blame] | 884 | if [ "1" = "${WITH_TIDY_ONLY}" -o "true" = "${WITH_TIDY_ONLY}" ]; then |
| 885 | MODULES=tidy_only |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 886 | MODULES_IN_PATHS= |
Chih-Hung Hsieh | a9a55c7 | 2016-03-31 16:30:23 -0700 | [diff] [blame] | 887 | fi |
Colin Cross | 8642525 | 2016-05-26 15:32:15 -0700 | [diff] [blame] | 888 | # Convert "/" to "-". |
| 889 | MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-} |
Chih-Hung Hsieh | 7ed0db8 | 2018-02-15 11:20:04 -0800 | [diff] [blame] | 890 | ONE_SHOT_MAKEFILE="$MAKEFILE" _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $MODULES $MODULES_IN_PATHS $ARGS |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 891 | else |
| 892 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 893 | return 1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 894 | fi |
| 895 | } |
| 896 | |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 897 | function mma() |
| 898 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 899 | local T=$(gettop) |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 900 | if [ -f build/soong/soong_ui.bash ]; then |
Chih-Hung Hsieh | 7ed0db8 | 2018-02-15 11:20:04 -0800 | [diff] [blame] | 901 | _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 902 | else |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 903 | if [ ! "$T" ]; then |
| 904 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 905 | return 1 |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 906 | fi |
Steven Moreland | 3b99ecf | 2018-06-13 15:31:59 -0700 | [diff] [blame] | 907 | local M=$(findmakefile || echo $(realpath $PWD)/Android.mk) |
Colin Cross | 127fcea | 2016-09-01 15:30:18 -0700 | [diff] [blame] | 908 | # Remove the path to top as the makefilepath needs to be relative |
| 909 | local M=`echo $M|sed 's:'$T'/::'` |
| 910 | local MODULES_IN_PATHS=MODULES-IN-$(dirname ${M}) |
Ying Wang | 61cd884 | 2015-09-24 16:19:19 -0700 | [diff] [blame] | 911 | # Convert "/" to "-". |
| 912 | MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-} |
Chih-Hung Hsieh | 7ed0db8 | 2018-02-15 11:20:04 -0800 | [diff] [blame] | 913 | _wrap_build $T/build/soong/soong_ui.bash --make-mode $@ $MODULES_IN_PATHS |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 914 | fi |
| 915 | } |
| 916 | |
| 917 | function mmma() |
| 918 | { |
Andrew Hsieh | 906cb78 | 2013-09-10 17:37:14 +0800 | [diff] [blame] | 919 | local T=$(gettop) |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 920 | if [ "$T" ]; then |
| 921 | local DASH_ARGS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^-.*$/') |
| 922 | local DIRS=$(echo "$@" | awk -v RS=" " -v ORS=" " '/^[^-].*$/') |
| 923 | local MY_PWD=`PWD= /bin/pwd` |
| 924 | if [ "$MY_PWD" = "$T" ]; then |
| 925 | MY_PWD= |
| 926 | else |
| 927 | MY_PWD=`echo $MY_PWD|sed 's:'$T'/::'` |
| 928 | fi |
| 929 | local DIR= |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 930 | local MODULES_IN_PATHS= |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 931 | local ARGS= |
| 932 | for DIR in $DIRS ; do |
| 933 | if [ -d $DIR ]; then |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 934 | # Remove the leading ./ and trailing / if any exists. |
| 935 | DIR=${DIR#./} |
| 936 | DIR=${DIR%/} |
| 937 | if [ "$MY_PWD" != "" ]; then |
| 938 | DIR=$MY_PWD/$DIR |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 939 | fi |
Ying Wang | 61cd884 | 2015-09-24 16:19:19 -0700 | [diff] [blame] | 940 | MODULES_IN_PATHS="$MODULES_IN_PATHS MODULES-IN-$DIR" |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 941 | else |
| 942 | case $DIR in |
Ying Wang | caeaa08 | 2015-09-23 16:08:55 -0700 | [diff] [blame] | 943 | showcommands | snod | dist | *=*) ARGS="$ARGS $DIR";; |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 944 | *) echo "Couldn't find directory $DIR"; return 1;; |
| 945 | esac |
| 946 | fi |
| 947 | done |
Ying Wang | 61cd884 | 2015-09-24 16:19:19 -0700 | [diff] [blame] | 948 | # Convert "/" to "-". |
| 949 | MODULES_IN_PATHS=${MODULES_IN_PATHS//\//-} |
Chih-Hung Hsieh | 7ed0db8 | 2018-02-15 11:20:04 -0800 | [diff] [blame] | 950 | _wrap_build $T/build/soong/soong_ui.bash --make-mode $DASH_ARGS $ARGS $MODULES_IN_PATHS |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 951 | else |
| 952 | echo "Couldn't locate the top of the tree. Try setting TOP." |
Ying Wang | 0c1374c | 2015-04-01 10:13:02 -0700 | [diff] [blame] | 953 | return 1 |
Ying Wang | b607f7b | 2013-02-08 18:01:04 -0800 | [diff] [blame] | 954 | fi |
| 955 | } |
| 956 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 957 | function croot() |
| 958 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 959 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 960 | if [ "$T" ]; then |
Marie Janssen | 32ec50a | 2016-04-21 16:53:39 -0700 | [diff] [blame] | 961 | if [ "$1" ]; then |
| 962 | \cd $(gettop)/$1 |
| 963 | else |
| 964 | \cd $(gettop) |
| 965 | fi |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 966 | else |
| 967 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 968 | fi |
| 969 | } |
| 970 | |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 971 | function cproj() |
| 972 | { |
Colin Cross | 6cdc5d2 | 2017-10-20 11:37:33 -0700 | [diff] [blame] | 973 | local TOPFILE=build/make/core/envsetup.mk |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 974 | local HERE=$PWD |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 975 | local T= |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 976 | while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do |
| 977 | T=$PWD |
| 978 | if [ -f "$T/Android.mk" ]; then |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 979 | \cd $T |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 980 | return |
| 981 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 982 | \cd .. |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 983 | done |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 984 | \cd $HERE |
Joe Onorato | 2a5d4d8 | 2009-07-30 10:23:21 -0700 | [diff] [blame] | 985 | echo "can't find Android.mk" |
| 986 | } |
| 987 | |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 988 | # simplified version of ps; output in the form |
| 989 | # <pid> <procname> |
| 990 | function qpid() { |
| 991 | local prepend='' |
| 992 | local append='' |
| 993 | if [ "$1" = "--exact" ]; then |
| 994 | prepend=' ' |
| 995 | append='$' |
| 996 | shift |
| 997 | elif [ "$1" = "--help" -o "$1" = "-h" ]; then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 998 | echo "usage: qpid [[--exact] <process name|pid>" |
| 999 | return 255 |
| 1000 | fi |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1001 | |
| 1002 | local EXE="$1" |
| 1003 | if [ "$EXE" ] ; then |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1004 | qpid | \grep "$prepend$EXE$append" |
| 1005 | else |
| 1006 | adb shell ps \ |
| 1007 | | tr -d '\r' \ |
| 1008 | | sed -e 1d -e 's/^[^ ]* *\([0-9]*\).* \([^ ]*\)$/\1 \2/' |
| 1009 | fi |
Daniel Sandler | 47e0a88 | 2013-07-30 13:23:52 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 1012 | # coredump_setup - enable core dumps globally for any process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1013 | # that has the core-file-size limit set correctly |
| 1014 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1015 | # NOTE: You must call also coredump_enable for a specific process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1016 | # if its core-file-size limit is not set already. |
| 1017 | # NOTE: Core dumps are written to ramdisk; they will not survive a reboot! |
| 1018 | |
Iliyan Malchev | e675cfb | 2014-11-03 17:04:47 -0800 | [diff] [blame] | 1019 | function coredump_setup() |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1020 | { |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1021 | echo "Getting root..."; |
| 1022 | adb root; |
| 1023 | adb wait-for-device; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1024 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1025 | echo "Remounting root partition read-write..."; |
| 1026 | adb shell mount -w -o remount -t rootfs rootfs; |
| 1027 | sleep 1; |
| 1028 | adb wait-for-device; |
| 1029 | adb shell mkdir -p /cores; |
| 1030 | adb shell mount -t tmpfs tmpfs /cores; |
| 1031 | adb shell chmod 0777 /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1032 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1033 | echo "Granting SELinux permission to dump in /cores..."; |
| 1034 | adb shell restorecon -R /cores; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1035 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1036 | echo "Set core pattern."; |
| 1037 | adb shell 'echo /cores/core.%p > /proc/sys/kernel/core_pattern'; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1038 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1039 | echo "Done." |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1042 | # coredump_enable - enable core dumps for the specified process |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1043 | # $1 = PID of process (e.g., $(pid mediaserver)) |
| 1044 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1045 | # NOTE: coredump_setup must have been called as well for a core |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1046 | # dump to actually be generated. |
| 1047 | |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1048 | function coredump_enable() |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1049 | { |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1050 | local PID=$1; |
| 1051 | if [ -z "$PID" ]; then |
| 1052 | printf "Expecting a PID!\n"; |
| 1053 | return; |
| 1054 | fi; |
| 1055 | echo "Setting core limit for $PID to infinite..."; |
Elliott Hughes | 910a355 | 2016-03-07 13:53:53 -0800 | [diff] [blame] | 1056 | adb shell /system/bin/ulimit -p $PID -c unlimited |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | # core - send SIGV and pull the core for process |
| 1060 | # $1 = PID of process (e.g., $(pid mediaserver)) |
| 1061 | # |
Iliyan Malchev | af5de97 | 2014-11-04 20:57:37 -0800 | [diff] [blame] | 1062 | # NOTE: coredump_setup must be called once per boot for core dumps to be |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1063 | # enabled globally. |
| 1064 | |
| 1065 | function core() |
| 1066 | { |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1067 | local PID=$1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1068 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1069 | if [ -z "$PID" ]; then |
| 1070 | printf "Expecting a PID!\n"; |
| 1071 | return; |
| 1072 | fi; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1073 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1074 | local CORENAME=core.$PID; |
| 1075 | local COREPATH=/cores/$CORENAME; |
| 1076 | local SIG=SEGV; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1077 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1078 | coredump_enable $1; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1079 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1080 | local done=0; |
| 1081 | while [ $(adb shell "[ -d /proc/$PID ] && echo -n yes") ]; do |
| 1082 | printf "\tSending SIG%s to %d...\n" $SIG $PID; |
| 1083 | adb shell kill -$SIG $PID; |
| 1084 | sleep 1; |
| 1085 | done; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1086 | |
Ying Wang | 08800fd | 2016-03-03 20:57:21 -0800 | [diff] [blame] | 1087 | adb shell "while [ ! -f $COREPATH ] ; do echo waiting for $COREPATH to be generated; sleep 1; done" |
| 1088 | echo "Done: core is under $COREPATH on device."; |
Iliyan Malchev | 248f4d5 | 2014-10-28 18:00:42 -0700 | [diff] [blame] | 1089 | } |
| 1090 | |
Christopher Tate | 744ee80 | 2009-11-12 15:33:08 -0800 | [diff] [blame] | 1091 | # systemstack - dump the current stack trace of all threads in the system process |
| 1092 | # to the usual ANR traces file |
| 1093 | function systemstack() |
| 1094 | { |
Jeff Sharkey | f582437 | 2013-02-19 17:00:46 -0800 | [diff] [blame] | 1095 | stacks system_server |
| 1096 | } |
| 1097 | |
Michael Wright | aeed721 | 2014-06-19 19:58:12 -0700 | [diff] [blame] | 1098 | # Read the ELF header from /proc/$PID/exe to determine if the process is |
| 1099 | # 64-bit. |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1100 | function is64bit() |
| 1101 | { |
| 1102 | local PID="$1" |
| 1103 | if [ "$PID" ] ; then |
Elliott Hughes | d3e4725 | 2018-11-15 16:32:14 -0800 | [diff] [blame] | 1104 | if [[ "$(adb shell cat /proc/$PID/exe | xxd -l 1 -s 4 -p)" -eq "02" ]] ; then |
Ben Cheng | fba67bf | 2014-02-25 10:27:07 -0800 | [diff] [blame] | 1105 | echo "64" |
| 1106 | else |
| 1107 | echo "" |
| 1108 | fi |
| 1109 | else |
| 1110 | echo "" |
| 1111 | fi |
| 1112 | } |
| 1113 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1114 | case `uname -s` in |
| 1115 | Darwin) |
| 1116 | function sgrep() |
| 1117 | { |
Aurelio Jargas | 67edd15 | 2018-11-06 17:25:11 +0100 | [diff] [blame] | 1118 | find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cc|cpp|hpp|S|java|xml|sh|mk|aidl|vts)' \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1119 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | ;; |
| 1123 | *) |
| 1124 | function sgrep() |
| 1125 | { |
Aurelio Jargas | 67edd15 | 2018-11-06 17:25:11 +0100 | [diff] [blame] | 1126 | find . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.\(c\|h\|cc\|cpp\|hpp\|S\|java\|xml\|sh\|mk\|aidl\|vts\)' \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1127 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1128 | } |
| 1129 | ;; |
| 1130 | esac |
| 1131 | |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1132 | function gettargetarch |
| 1133 | { |
| 1134 | get_build_var TARGET_ARCH |
| 1135 | } |
| 1136 | |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 1137 | function ggrep() |
| 1138 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1139 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.gradle" \ |
| 1140 | -exec grep --color -n "$@" {} + |
Jon Boekenoogen | cbca56f | 2014-04-07 10:57:38 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1143 | function jgrep() |
| 1144 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1145 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.java" \ |
| 1146 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | function cgrep() |
| 1150 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1151 | 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' \) \ |
| 1152 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | function resgrep() |
| 1156 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1157 | local dir |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1158 | for dir in `find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -name res -type d`; do |
| 1159 | find $dir -type f -name '*\.xml' -exec grep --color -n "$@" {} + |
| 1160 | done |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
Jeff Sharkey | 50b61e9 | 2013-03-08 10:20:47 -0800 | [diff] [blame] | 1163 | function mangrep() |
| 1164 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1165 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -type f -name 'AndroidManifest.xml' \ |
| 1166 | -exec grep --color -n "$@" {} + |
Jeff Sharkey | 50b61e9 | 2013-03-08 10:20:47 -0800 | [diff] [blame] | 1167 | } |
| 1168 | |
Alex Klyubin | ba5fc8e | 2013-05-06 14:11:48 -0700 | [diff] [blame] | 1169 | function sepgrep() |
| 1170 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1171 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o -name sepolicy -type d \ |
| 1172 | -exec grep --color -n -r --exclude-dir=\.git "$@" {} + |
Alex Klyubin | ba5fc8e | 2013-05-06 14:11:48 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Jeff Sharkey | ea0068a | 2015-02-26 14:13:46 -0800 | [diff] [blame] | 1175 | function rcgrep() |
| 1176 | { |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1177 | find . -name .repo -prune -o -name .git -prune -o -name out -prune -o -type f -name "*\.rc*" \ |
| 1178 | -exec grep --color -n "$@" {} + |
Jeff Sharkey | ea0068a | 2015-02-26 14:13:46 -0800 | [diff] [blame] | 1179 | } |
| 1180 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1181 | case `uname -s` in |
| 1182 | Darwin) |
| 1183 | function mgrep() |
| 1184 | { |
David Gross | d1d6fc5 | 2017-05-10 10:49:44 -0700 | [diff] [blame] | 1185 | find -E . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -iregex '.*/(Makefile|Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regex '(.*/)?soong/[^/]*.go' \) -type f \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1186 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | function treegrep() |
| 1190 | { |
Aurelio Jargas | 67edd15 | 2018-11-06 17:25:11 +0100 | [diff] [blame] | 1191 | find -E . -name .repo -prune -o -name .git -prune -o -type f -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1192 | -exec grep --color -n -i "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | ;; |
| 1196 | *) |
| 1197 | function mgrep() |
| 1198 | { |
David Gross | d1d6fc5 | 2017-05-10 10:49:44 -0700 | [diff] [blame] | 1199 | find . -name .repo -prune -o -name .git -prune -o -path ./out -prune -o \( -regextype posix-egrep -iregex '(.*\/Makefile|.*\/Makefile\..*|.*\.make|.*\.mak|.*\.mk|.*\.bp)' -o -regextype posix-extended -regex '(.*/)?soong/[^/]*.go' \) -type f \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1200 | -exec grep --color -n "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | function treegrep() |
| 1204 | { |
Aurelio Jargas | 67edd15 | 2018-11-06 17:25:11 +0100 | [diff] [blame] | 1205 | find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|hpp|S|java|xml)' -type f \ |
Mike Frysinger | 5e47973 | 2015-09-22 18:13:48 -0400 | [diff] [blame] | 1206 | -exec grep --color -n -i "$@" {} + |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | ;; |
| 1210 | esac |
| 1211 | |
| 1212 | function getprebuilt |
| 1213 | { |
| 1214 | get_abs_build_var ANDROID_PREBUILTS |
| 1215 | } |
| 1216 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1217 | function tracedmdump() |
| 1218 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1219 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1220 | if [ ! "$T" ]; then |
| 1221 | echo "Couldn't locate the top of the tree. Try setting TOP." |
| 1222 | return |
| 1223 | fi |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1224 | local prebuiltdir=$(getprebuilt) |
Raghu Gandham | 8da4310 | 2012-07-25 19:57:22 -0700 | [diff] [blame] | 1225 | local arch=$(gettargetarch) |
| 1226 | local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1227 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1228 | local TRACE=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1229 | if [ ! "$TRACE" ] ; then |
| 1230 | echo "usage: tracedmdump tracename" |
| 1231 | return |
| 1232 | fi |
| 1233 | |
Jack Veenstra | 60116fc | 2009-04-09 18:12:34 -0700 | [diff] [blame] | 1234 | if [ ! -r "$KERNEL" ] ; then |
| 1235 | echo "Error: cannot find kernel: '$KERNEL'" |
| 1236 | return |
| 1237 | fi |
| 1238 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1239 | local BASETRACE=$(basename $TRACE) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1240 | if [ "$BASETRACE" = "$TRACE" ] ; then |
| 1241 | TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE |
| 1242 | fi |
| 1243 | |
| 1244 | echo "post-processing traces..." |
| 1245 | rm -f $TRACE/qtrace.dexlist |
| 1246 | post_trace $TRACE |
| 1247 | if [ $? -ne 0 ]; then |
| 1248 | echo "***" |
| 1249 | echo "*** Error: malformed trace. Did you remember to exit the emulator?" |
| 1250 | echo "***" |
| 1251 | return |
| 1252 | fi |
| 1253 | echo "generating dexlist output..." |
| 1254 | /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 |
| 1255 | echo "generating dmtrace data..." |
| 1256 | q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return |
| 1257 | echo "generating html file..." |
| 1258 | dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return |
| 1259 | echo "done, see $TRACE/dmtrace.html for details" |
| 1260 | echo "or run:" |
| 1261 | echo " traceview $TRACE/dmtrace" |
| 1262 | } |
| 1263 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1264 | # communicate with a running device or emulator, set up necessary state, |
| 1265 | # and run the hat command. |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1266 | function runhat() |
| 1267 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1268 | # process standard adb options |
| 1269 | local adbTarget="" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1270 | if [ "$1" = "-d" -o "$1" = "-e" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1271 | adbTarget=$1 |
| 1272 | shift 1 |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1273 | elif [ "$1" = "-s" ]; then |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1274 | adbTarget="$1 $2" |
| 1275 | shift 2 |
| 1276 | fi |
| 1277 | local adbOptions=${adbTarget} |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1278 | #echo adbOptions = ${adbOptions} |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1279 | |
| 1280 | # runhat options |
| 1281 | local targetPid=$1 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1282 | |
| 1283 | if [ "$targetPid" = "" ]; then |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1284 | echo "Usage: runhat [ -d | -e | -s serial ] target-pid" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1285 | return |
| 1286 | fi |
| 1287 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1288 | # confirm hat is available |
| 1289 | if [ -z $(which hat) ]; then |
| 1290 | echo "hat is not available in this configuration." |
| 1291 | return |
| 1292 | fi |
| 1293 | |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1294 | # issue "am" command to cause the hprof dump |
Nick Kralevich | 9948b1e | 2014-07-18 15:45:38 -0700 | [diff] [blame] | 1295 | local devFile=/data/local/tmp/hprof-$targetPid |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1296 | echo "Poking $targetPid and waiting for data..." |
Dianne Hackborn | 6b9549f | 2012-09-26 15:00:59 -0700 | [diff] [blame] | 1297 | echo "Storing data at $devFile" |
Andy McFadden | b628985 | 2010-07-12 08:00:19 -0700 | [diff] [blame] | 1298 | adb ${adbOptions} shell am dumpheap $targetPid $devFile |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1299 | echo "Press enter when logcat shows \"hprof: heap dump completed\"" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1300 | echo -n "> " |
| 1301 | read |
| 1302 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1303 | local localFile=/tmp/$$-hprof |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1304 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1305 | echo "Retrieving file $devFile..." |
| 1306 | adb ${adbOptions} pull $devFile $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1307 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1308 | adb ${adbOptions} shell rm $devFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1309 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1310 | echo "Running hat on $localFile" |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1311 | echo "View the output by pointing your browser at http://localhost:7000/" |
| 1312 | echo "" |
Dianne Hackborn | 6e4e1bb | 2011-11-10 15:19:51 -0800 | [diff] [blame] | 1313 | hat -JXmx512m $localFile |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | function getbugreports() |
| 1317 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1318 | local reports=(`adb shell ls /sdcard/bugreports | tr -d '\r'`) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1319 | |
| 1320 | if [ ! "$reports" ]; then |
| 1321 | echo "Could not locate any bugreports." |
| 1322 | return |
| 1323 | fi |
| 1324 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1325 | local report |
| 1326 | for report in ${reports[@]} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1327 | do |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1328 | echo "/sdcard/bugreports/${report}" |
| 1329 | adb pull /sdcard/bugreports/${report} ${report} |
| 1330 | gunzip ${report} |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1331 | done |
| 1332 | } |
| 1333 | |
Victoria Lease | 1b296b4 | 2012-08-21 15:44:06 -0700 | [diff] [blame] | 1334 | function getsdcardpath() |
| 1335 | { |
| 1336 | adb ${adbOptions} shell echo -n \$\{EXTERNAL_STORAGE\} |
| 1337 | } |
| 1338 | |
| 1339 | function getscreenshotpath() |
| 1340 | { |
| 1341 | echo "$(getsdcardpath)/Pictures/Screenshots" |
| 1342 | } |
| 1343 | |
| 1344 | function getlastscreenshot() |
| 1345 | { |
| 1346 | local screenshot_path=$(getscreenshotpath) |
| 1347 | local screenshot=`adb ${adbOptions} ls ${screenshot_path} | grep Screenshot_[0-9-]*.*\.png | sort -rk 3 | cut -d " " -f 4 | head -n 1` |
| 1348 | if [ "$screenshot" = "" ]; then |
| 1349 | echo "No screenshots found." |
| 1350 | return |
| 1351 | fi |
| 1352 | echo "${screenshot}" |
| 1353 | adb ${adbOptions} pull ${screenshot_path}/${screenshot} |
| 1354 | } |
| 1355 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1356 | function startviewserver() |
| 1357 | { |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1358 | local port=4939 |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1359 | if [ $# -gt 0 ]; then |
| 1360 | port=$1 |
| 1361 | fi |
| 1362 | adb shell service call window 1 i32 $port |
| 1363 | } |
| 1364 | |
| 1365 | function stopviewserver() |
| 1366 | { |
| 1367 | adb shell service call window 2 |
| 1368 | } |
| 1369 | |
| 1370 | function isviewserverstarted() |
| 1371 | { |
| 1372 | adb shell service call window 3 |
| 1373 | } |
| 1374 | |
Romain Guy | b84049a | 2010-10-04 16:56:11 -0700 | [diff] [blame] | 1375 | function key_home() |
| 1376 | { |
| 1377 | adb shell input keyevent 3 |
| 1378 | } |
| 1379 | |
| 1380 | function key_back() |
| 1381 | { |
| 1382 | adb shell input keyevent 4 |
| 1383 | } |
| 1384 | |
| 1385 | function key_menu() |
| 1386 | { |
| 1387 | adb shell input keyevent 82 |
| 1388 | } |
| 1389 | |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1390 | function smoketest() |
| 1391 | { |
| 1392 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1393 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1394 | return |
| 1395 | fi |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1396 | local T=$(gettop) |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1397 | if [ ! "$T" ]; then |
| 1398 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1399 | return |
| 1400 | fi |
| 1401 | |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1402 | (\cd "$T" && mmm tests/SmokeTest) && |
The Android Open Source Project | b6c1cf6 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1403 | adb uninstall com.android.smoketest > /dev/null && |
| 1404 | adb uninstall com.android.smoketest.tests > /dev/null && |
| 1405 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTestApp.apk && |
| 1406 | adb install $ANDROID_PRODUCT_OUT/data/app/SmokeTest.apk && |
| 1407 | adb shell am instrument -w com.android.smoketest.tests/android.test.InstrumentationTestRunner |
| 1408 | } |
| 1409 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1410 | # simple shortcut to the runtest command |
| 1411 | function runtest() |
| 1412 | { |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1413 | local T=$(gettop) |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1414 | if [ ! "$T" ]; then |
| 1415 | echo "Couldn't locate the top of the tree. Try setting TOP." >&2 |
| 1416 | return |
| 1417 | fi |
Brett Chabot | 3fb149d | 2009-10-21 20:05:26 -0700 | [diff] [blame] | 1418 | ("$T"/development/testrunner/runtest.py $@) |
Brett Chabot | 762748c | 2009-03-27 10:25:11 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1421 | function godir () { |
| 1422 | if [[ -z "$1" ]]; then |
| 1423 | echo "Usage: godir <regex>" |
| 1424 | return |
| 1425 | fi |
Christopher Ferris | 55257d2 | 2017-03-23 11:08:58 -0700 | [diff] [blame] | 1426 | local T=$(gettop) |
| 1427 | local FILELIST |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1428 | if [ ! "$OUT_DIR" = "" ]; then |
| 1429 | mkdir -p $OUT_DIR |
| 1430 | FILELIST=$OUT_DIR/filelist |
| 1431 | else |
| 1432 | FILELIST=$T/filelist |
| 1433 | fi |
| 1434 | if [[ ! -f $FILELIST ]]; then |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1435 | echo -n "Creating index..." |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1436 | (\cd $T; find . -wholename ./out -prune -o -wholename ./.repo -prune -o -type f > $FILELIST) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1437 | echo " Done" |
| 1438 | echo "" |
| 1439 | fi |
| 1440 | local lines |
Brian Carlstrom | f225742 | 2015-09-30 20:28:54 -0700 | [diff] [blame] | 1441 | lines=($(\grep "$1" $FILELIST | sed -e 's/\/[^/]*$//' | sort | uniq)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1442 | if [[ ${#lines[@]} = 0 ]]; then |
| 1443 | echo "Not found" |
| 1444 | return |
| 1445 | fi |
| 1446 | local pathname |
| 1447 | local choice |
| 1448 | if [[ ${#lines[@]} > 1 ]]; then |
| 1449 | while [[ -z "$pathname" ]]; do |
| 1450 | local index=1 |
| 1451 | local line |
| 1452 | for line in ${lines[@]}; do |
| 1453 | printf "%6s %s\n" "[$index]" $line |
Doug Zongker | 2903498 | 2011-04-22 08:16:56 -0700 | [diff] [blame] | 1454 | index=$(($index + 1)) |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1455 | done |
| 1456 | echo |
| 1457 | echo -n "Select one: " |
| 1458 | unset choice |
| 1459 | read choice |
| 1460 | if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then |
| 1461 | echo "Invalid choice" |
| 1462 | continue |
| 1463 | fi |
Kan-Ru Chen | 0745376 | 2010-07-05 15:53:47 +0800 | [diff] [blame] | 1464 | pathname=${lines[$(($choice-1))]} |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1465 | done |
| 1466 | else |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1467 | pathname=${lines[0]} |
| 1468 | fi |
Ying Wang | 9cd1764 | 2012-12-13 10:52:07 -0800 | [diff] [blame] | 1469 | \cd $T/$pathname |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1472 | # Update module-info.json in out. |
| 1473 | function refreshmod() { |
| 1474 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1475 | echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 |
| 1476 | return 1 |
| 1477 | fi |
| 1478 | |
| 1479 | echo "Refreshing modules (building module-info.json). Log at $ANDROID_PRODUCT_OUT/module-info.json.build.log." >&2 |
| 1480 | |
| 1481 | # for the output of the next command |
| 1482 | mkdir -p $ANDROID_PRODUCT_OUT || return 1 |
| 1483 | |
| 1484 | # Note, can't use absolute path because of the way make works. |
| 1485 | m out/target/product/$(get_build_var TARGET_DEVICE)/module-info.json \ |
| 1486 | > $ANDROID_PRODUCT_OUT/module-info.json.build.log 2>&1 |
| 1487 | } |
| 1488 | |
| 1489 | # List all modules for the current device, as cached in module-info.json. If any build change is |
| 1490 | # made and it should be reflected in the output, you should run 'refreshmod' first. |
| 1491 | function allmod() { |
| 1492 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1493 | echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 |
| 1494 | return 1 |
| 1495 | fi |
| 1496 | |
| 1497 | if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then |
| 1498 | echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2 |
| 1499 | refreshmod || return 1 |
| 1500 | fi |
| 1501 | |
| 1502 | python -c "import json; print '\n'.join(sorted(json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')).keys()))" |
| 1503 | } |
| 1504 | |
| 1505 | # Go to a specific module in the android tree, as cached in module-info.json. If any build change |
| 1506 | # is made, and it should be reflected in the output, you should run 'refreshmod' first. |
| 1507 | function gomod() { |
| 1508 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1509 | echo "No ANDROID_PRODUCT_OUT. Try running 'lunch' first." >&2 |
| 1510 | return 1 |
| 1511 | fi |
| 1512 | |
| 1513 | if [[ $# -ne 1 ]]; then |
| 1514 | echo "usage: gomod <module>" >&2 |
| 1515 | return 1 |
| 1516 | fi |
| 1517 | |
| 1518 | if [ ! -f "$ANDROID_PRODUCT_OUT/module-info.json" ]; then |
| 1519 | echo "Could not find module-info.json. It will only be built once, and it can be updated with 'refreshmod'" >&2 |
| 1520 | refreshmod || return 1 |
| 1521 | fi |
| 1522 | |
| 1523 | local relpath=$(python -c "import json, os |
| 1524 | module = '$1' |
| 1525 | module_info = json.load(open('$ANDROID_PRODUCT_OUT/module-info.json')) |
| 1526 | if module not in module_info: |
| 1527 | exit(1) |
| 1528 | print module_info[module]['path'][0]" 2>/dev/null) |
| 1529 | |
| 1530 | if [ -z "$relpath" ]; then |
| 1531 | echo "Could not find module '$1' (try 'refreshmod' if there have been build changes?)." >&2 |
| 1532 | return 1 |
| 1533 | else |
| 1534 | cd $ANDROID_BUILD_TOP/$relpath |
| 1535 | fi |
| 1536 | } |
| 1537 | |
dimitry | 73b8481 | 2018-12-11 18:06:00 +0100 | [diff] [blame^] | 1538 | function _complete_android_module_names() { |
Steven Moreland | 62054a4 | 2018-12-06 10:11:40 -0800 | [diff] [blame] | 1539 | local word=${COMP_WORDS[COMP_CWORD]} |
| 1540 | COMPREPLY=( $(allmod | grep -E "^$word") ) |
| 1541 | } |
| 1542 | |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1543 | # Print colored exit condition |
| 1544 | function pez { |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1545 | "$@" |
| 1546 | local retval=$? |
| 1547 | if [ $retval -ne 0 ] |
| 1548 | then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1549 | echo $'\E'"[0;31mFAILURE\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1550 | else |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1551 | echo $'\E'"[0;32mSUCCESS\e[00m" |
Michael Wright | eb73384 | 2013-03-08 17:34:02 -0800 | [diff] [blame] | 1552 | fi |
| 1553 | return $retval |
Alex Ray | f0d08eb | 2013-03-08 15:15:06 -0800 | [diff] [blame] | 1554 | } |
| 1555 | |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1556 | function get_make_command() |
| 1557 | { |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1558 | # If we're in the top of an Android tree, use soong_ui.bash instead of make |
| 1559 | if [ -f build/soong/soong_ui.bash ]; then |
Dan Willemsen | e984224 | 2017-07-28 13:00:13 -0700 | [diff] [blame] | 1560 | # Always use the real make if -C is passed in |
| 1561 | for arg in "$@"; do |
| 1562 | if [[ $arg == -C* ]]; then |
| 1563 | echo command make |
| 1564 | return |
| 1565 | fi |
| 1566 | done |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1567 | echo build/soong/soong_ui.bash --make-mode |
| 1568 | else |
| 1569 | echo command make |
| 1570 | fi |
Ying Wang | ed21d4c | 2014-08-24 22:14:19 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1573 | function _wrap_build() |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1574 | { |
| 1575 | local start_time=$(date +"%s") |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1576 | "$@" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1577 | local ret=$? |
| 1578 | local end_time=$(date +"%s") |
| 1579 | local tdiff=$(($end_time-$start_time)) |
| 1580 | local hours=$(($tdiff / 3600 )) |
| 1581 | local mins=$((($tdiff % 3600) / 60)) |
| 1582 | local secs=$(($tdiff % 60)) |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1583 | local ncolors=$(tput colors 2>/dev/null) |
| 1584 | if [ -n "$ncolors" ] && [ $ncolors -ge 8 ]; then |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1585 | color_failed=$'\E'"[0;31m" |
| 1586 | color_success=$'\E'"[0;32m" |
| 1587 | color_reset=$'\E'"[00m" |
Greg Hackmann | d95c7f7 | 2014-06-23 14:05:06 -0700 | [diff] [blame] | 1588 | else |
| 1589 | color_failed="" |
| 1590 | color_success="" |
| 1591 | color_reset="" |
| 1592 | fi |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1593 | echo |
| 1594 | if [ $ret -eq 0 ] ; then |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1595 | echo -n "${color_success}#### build completed successfully " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1596 | else |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1597 | echo -n "${color_failed}#### failed to build some targets " |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1598 | fi |
| 1599 | if [ $hours -gt 0 ] ; then |
| 1600 | printf "(%02g:%02g:%02g (hh:mm:ss))" $hours $mins $secs |
| 1601 | elif [ $mins -gt 0 ] ; then |
| 1602 | printf "(%02g:%02g (mm:ss))" $mins $secs |
| 1603 | elif [ $secs -gt 0 ] ; then |
| 1604 | printf "(%s seconds)" $secs |
| 1605 | fi |
Jacky Cao | 89483b8 | 2015-05-15 22:12:53 +0800 | [diff] [blame] | 1606 | echo " ####${color_reset}" |
Ed Heyl | cc6be0a | 2014-06-18 14:55:58 -0700 | [diff] [blame] | 1607 | echo |
| 1608 | return $ret |
| 1609 | } |
| 1610 | |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1611 | function make() |
| 1612 | { |
Dan Willemsen | e984224 | 2017-07-28 13:00:13 -0700 | [diff] [blame] | 1613 | _wrap_build $(get_make_command "$@") "$@" |
Dan Willemsen | d41ec5a | 2017-07-12 16:14:50 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
David Zeuthen | 1b126ff | 2015-09-30 17:10:48 -0400 | [diff] [blame] | 1616 | function provision() |
| 1617 | { |
| 1618 | if [ ! "$ANDROID_PRODUCT_OUT" ]; then |
| 1619 | echo "Couldn't locate output files. Try running 'lunch' first." >&2 |
| 1620 | return 1 |
| 1621 | fi |
| 1622 | if [ ! -e "$ANDROID_PRODUCT_OUT/provision-device" ]; then |
| 1623 | echo "There is no provisioning script for the device." >&2 |
| 1624 | return 1 |
| 1625 | fi |
| 1626 | |
| 1627 | # Check if user really wants to do this. |
| 1628 | if [ "$1" = "--no-confirmation" ]; then |
| 1629 | shift 1 |
| 1630 | else |
| 1631 | echo "This action will reflash your device." |
| 1632 | echo "" |
| 1633 | echo "ALL DATA ON THE DEVICE WILL BE IRREVOCABLY ERASED." |
| 1634 | echo "" |
Marie Janssen | 4afc2c0 | 2015-11-10 10:41:15 -0800 | [diff] [blame] | 1635 | echo -n "Are you sure you want to do this (yes/no)? " |
| 1636 | read |
David Zeuthen | 1b126ff | 2015-09-30 17:10:48 -0400 | [diff] [blame] | 1637 | if [[ "${REPLY}" != "yes" ]] ; then |
| 1638 | echo "Not taking any action. Exiting." >&2 |
| 1639 | return 1 |
| 1640 | fi |
| 1641 | fi |
| 1642 | "$ANDROID_PRODUCT_OUT/provision-device" "$@" |
| 1643 | } |
| 1644 | |
Simran Basi | 424b876 | 2017-08-23 12:03:04 -0700 | [diff] [blame] | 1645 | function atest() |
| 1646 | { |
Jim Tang | f258e7e | 2018-11-01 18:00:05 +0800 | [diff] [blame] | 1647 | # Let's use the built version over the prebuilt, then source code. |
| 1648 | local os_arch=$(get_build_var HOST_PREBUILT_TAG) |
| 1649 | local built_atest=${ANDROID_HOST_OUT}/bin/atest |
| 1650 | local prebuilt_atest="$(gettop)"/prebuilts/asuite/atest/$os_arch/atest |
| 1651 | if [[ -x $built_atest ]]; then |
| 1652 | $built_atest "$@" |
| 1653 | elif [[ -x $prebuilt_atest ]]; then |
| 1654 | $prebuilt_atest "$@" |
| 1655 | else |
| 1656 | # TODO: once prebuilt atest released, remove the source code section |
| 1657 | # and change the location of atest_completion.sh in addcompletions(). |
| 1658 | "$(gettop)"/tools/tradefederation/core/atest/atest.py "$@" |
| 1659 | fi |
Simran Basi | 424b876 | 2017-08-23 12:03:04 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1662 | # Zsh needs bashcompinit called to support bash-style completion. |
Patrik Fimml | df248e6 | 2018-10-15 18:15:12 +0200 | [diff] [blame] | 1663 | function enable_zsh_completion() { |
| 1664 | # Don't override user's options if bash-style completion is already enabled. |
| 1665 | if ! declare -f complete >/dev/null; then |
| 1666 | autoload -U compinit && compinit |
| 1667 | autoload -U bashcompinit && bashcompinit |
| 1668 | fi |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | function validate_current_shell() { |
| 1672 | local current_sh="$(ps -o command -p $$)" |
| 1673 | case "$current_sh" in |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1674 | *bash*) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1675 | function check_type() { type -t "$1"; } |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1676 | ;; |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1677 | *zsh*) |
| 1678 | function check_type() { type "$1"; } |
Patrik Fimml | df248e6 | 2018-10-15 18:15:12 +0200 | [diff] [blame] | 1679 | enable_zsh_completion ;; |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1680 | *) |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1681 | echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results." |
Raphael Moll | 70a86b0 | 2011-06-20 16:03:14 -0700 | [diff] [blame] | 1682 | ;; |
| 1683 | esac |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1684 | } |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1685 | |
Kevin Cheng | bf89aff | 2018-05-22 14:07:50 -0700 | [diff] [blame] | 1686 | function acloud() |
| 1687 | { |
| 1688 | # Let's use the built version over the prebuilt. |
| 1689 | local built_acloud=${ANDROID_HOST_OUT}/bin/acloud |
| 1690 | if [ -f $built_acloud ]; then |
| 1691 | $built_acloud "$@" |
| 1692 | return $? |
| 1693 | fi |
| 1694 | |
| 1695 | local host_os_arch=$(get_build_var HOST_PREBUILT_TAG) |
| 1696 | case $host_os_arch in |
| 1697 | linux-x86) "$(gettop)"/prebuilts/asuite/acloud/linux-x86/acloud "$@" |
| 1698 | ;; |
| 1699 | *) |
| 1700 | echo "acloud is not supported on your host arch: $host_os_arch" |
| 1701 | ;; |
| 1702 | esac |
| 1703 | } |
| 1704 | |
patricktu | 345c9ae | 2018-11-29 15:25:40 +0800 | [diff] [blame] | 1705 | function aidegen() |
| 1706 | { |
| 1707 | # Always use the prebuilt version. |
| 1708 | local host_os_arch=$(get_build_var HOST_PREBUILT_TAG) |
| 1709 | case $host_os_arch in |
| 1710 | linux-x86) "$(gettop)"/prebuilts/asuite/aidegen/linux-x86/aidegen "$@" |
| 1711 | ;; |
| 1712 | *) |
| 1713 | echo "aidegen is not supported on your host arch: $host_os_arch" |
| 1714 | ;; |
| 1715 | esac |
| 1716 | } |
| 1717 | |
The Android Open Source Project | dcc08f0 | 2008-12-17 18:03:49 -0800 | [diff] [blame] | 1718 | # Execute the contents of any vendorsetup.sh files we can find. |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1719 | function source_vendorsetup() { |
| 1720 | for dir in device vendor product; do |
| 1721 | for f in $(test -d $dir && \ |
| 1722 | find -L $dir -maxdepth 4 -name 'vendorsetup.sh' 2>/dev/null | sort); do |
| 1723 | echo "including $f"; . $f |
| 1724 | done |
| 1725 | done |
| 1726 | } |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1727 | |
Jim Tang | a881a25 | 2018-06-19 16:34:41 +0800 | [diff] [blame] | 1728 | validate_current_shell |
| 1729 | source_vendorsetup |
Kenny Root | 52aa81c | 2011-07-15 11:07:06 -0700 | [diff] [blame] | 1730 | addcompletions |