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