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