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