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