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