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