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