Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Jeff Gaston | 6971329 | 2020-06-04 12:53:39 -0400 | [diff] [blame] | 2 | set -o pipefail |
| 3 | set -e |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 4 | |
| 5 | ############################################################################## |
| 6 | ## |
| 7 | ## Gradle start up script for UN*X |
| 8 | ## |
| 9 | ############################################################################## |
| 10 | |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 11 | # --------- androidx specific code needed for build server. ------------------ |
| 12 | |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 13 | SCRIPT_PATH="$(cd $(dirname $0) && pwd -P)" |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 14 | if [ -n "$OUT_DIR" ] ; then |
Jeff Gaston | 8fd9fc8 | 2019-07-26 14:26:10 -0400 | [diff] [blame] | 15 | mkdir -p "$OUT_DIR" |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 16 | OUT_DIR="$(cd $OUT_DIR && pwd -P)" |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 17 | export GRADLE_USER_HOME="$OUT_DIR/.gradle" |
Jeff Gaston | 38004a6 | 2019-12-11 15:43:10 -0500 | [diff] [blame] | 18 | export TMPDIR=$OUT_DIR |
Jeff Gaston | cc694ab | 2019-04-11 16:51:36 -0400 | [diff] [blame] | 19 | else |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 20 | CHECKOUT_ROOT="$(cd $SCRIPT_PATH/../.. && pwd -P)" |
Jeff Gaston | cc694ab | 2019-04-11 16:51:36 -0400 | [diff] [blame] | 21 | export OUT_DIR="$CHECKOUT_ROOT/out" |
Jeff Gaston | d571989 | 2022-04-21 12:06:24 -0400 | [diff] [blame] | 22 | export GRADLE_USER_HOME=~/.gradle |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 23 | fi |
| 24 | |
Jeff Gaston | 440e1ac | 2020-09-09 08:32:22 -0400 | [diff] [blame] | 25 | ORG_GRADLE_JVMARGS="$(cd $SCRIPT_PATH && grep org.gradle.jvmargs gradle.properties | sed 's/^/-D/')" |
Jeff Gaston | 0e3d19a | 2019-10-02 12:17:39 -0400 | [diff] [blame] | 26 | if [ -n "$DIST_DIR" ]; then |
| 27 | mkdir -p "$DIST_DIR" |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 28 | DIST_DIR="$(cd $DIST_DIR && pwd -P)" |
Jeff Gaston | 0e3d19a | 2019-10-02 12:17:39 -0400 | [diff] [blame] | 29 | |
Jeff Gaston | 440e1ac | 2020-09-09 08:32:22 -0400 | [diff] [blame] | 30 | # tell Gradle where to put a heap dump on failure |
| 31 | ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s|$| -XX:HeapDumpPath=$DIST_DIR|")" |
Jeff Gaston | e72d230 | 2019-12-19 18:32:31 -0500 | [diff] [blame] | 32 | |
Jeff Gaston | 0e3d19a | 2019-10-02 12:17:39 -0400 | [diff] [blame] | 33 | # We don't set a default DIST_DIR in an else clause here because Studio doesn't use gradlew |
| 34 | # and doesn't set DIST_DIR and we want gradlew and Studio to match |
| 35 | fi |
| 36 | |
Alan Viverette | 9d65136 | 2023-03-23 12:34:03 -0400 | [diff] [blame] | 37 | # Loading the AIDL lexer requires disabling Lint's bytecode verification |
| 38 | export ANDROID_LINT_SKIP_BYTECODE_VERIFIER=true |
| 39 | |
Jeff Gaston | c21ecb3 | 2020-11-05 17:16:35 -0500 | [diff] [blame] | 40 | # unset ANDROID_BUILD_TOP so that Lint doesn't think we're building the platform itself |
| 41 | unset ANDROID_BUILD_TOP |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 42 | # ---------------------------------------------------------------------------- |
| 43 | |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 44 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 45 | |
| 46 | APP_NAME="Gradle" |
| 47 | APP_BASE_NAME=`basename "$0"` |
| 48 | |
| 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. |
| 50 | MAX_FD="maximum" |
| 51 | |
| 52 | warn ( ) { |
| 53 | echo "$*" |
| 54 | } |
| 55 | |
| 56 | die ( ) { |
| 57 | echo |
| 58 | echo "$*" |
| 59 | echo |
| 60 | exit 1 |
| 61 | } |
| 62 | |
| 63 | # OS specific support (must be 'true' or 'false'). |
| 64 | cygwin=false |
| 65 | msys=false |
| 66 | darwin=false |
| 67 | case "`uname`" in |
| 68 | CYGWIN* ) |
| 69 | cygwin=true |
| 70 | ;; |
| 71 | Darwin* ) |
| 72 | darwin=true |
| 73 | ;; |
| 74 | MINGW* ) |
| 75 | msys=true |
| 76 | ;; |
| 77 | esac |
Rahul Ravikumar | 465ccfc | 2022-02-14 14:58:20 -0800 | [diff] [blame] | 78 | platform_suffix="x86" |
| 79 | case "$(arch)" in |
| 80 | arm64* ) |
| 81 | platform_suffix="arm64" |
| 82 | esac |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 83 | # Attempt to set APP_HOME |
| 84 | # Resolve links: $0 may be a link |
| 85 | PRG="$0" |
| 86 | # Need this for relative symlinks. |
| 87 | while [ -h "$PRG" ] ; do |
| 88 | ls=`ls -ld "$PRG"` |
| 89 | link=`expr "$ls" : '.*-> \(.*\)$'` |
| 90 | if expr "$link" : '/.*' > /dev/null; then |
| 91 | PRG="$link" |
| 92 | else |
| 93 | PRG=`dirname "$PRG"`"/$link" |
| 94 | fi |
| 95 | done |
| 96 | SAVED="`pwd`" |
Yigit Boyar | f77697d | 2016-08-16 10:55:36 -0700 | [diff] [blame] | 97 | cd "`dirname \"$PRG\"`/" >/dev/null |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 98 | APP_HOME="`pwd -P`" |
Yigit Boyar | f77697d | 2016-08-16 10:55:36 -0700 | [diff] [blame] | 99 | cd "$SAVED" >/dev/null |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 100 | |
| 101 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar |
| 102 | |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 103 | # --------- androidx specific code needed for lint and java. ------------------ |
| 104 | |
Alan Viverette | d38b36c | 2017-02-01 16:45:31 -0500 | [diff] [blame] | 105 | # Pick the correct fullsdk for this OS. |
Alan Viverette | 7df63ff | 2017-03-06 13:12:24 -0500 | [diff] [blame] | 106 | if [ $darwin == "true" ]; then |
Alan Viverette | d38b36c | 2017-02-01 16:45:31 -0500 | [diff] [blame] | 107 | plat="darwin" |
| 108 | else |
| 109 | plat="linux" |
| 110 | fi |
Alan Viverette | d38b36c | 2017-02-01 16:45:31 -0500 | [diff] [blame] | 111 | |
Matthew Fraschilla | 6ab84fc3 | 2019-11-21 16:40:16 -0800 | [diff] [blame] | 112 | # Tests for lint checks default to using sdk defined by this variable. This removes a lot of |
| 113 | # setup from each lint module. |
| 114 | export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat" |
Sergey Vasilinets | efab5eb | 2019-01-04 12:38:06 +0000 | [diff] [blame] | 115 | # override JAVA_HOME, because CI machines have it and it points to very old JDK |
Aurimas Liutikas | 420b7f6 | 2022-08-02 13:53:39 -0700 | [diff] [blame] | 116 | export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk17/$plat-$platform_suffix" |
Aurimas Liutikas | 4b897cb | 2019-10-14 13:25:08 -0700 | [diff] [blame] | 117 | export STUDIO_GRADLE_JDK=$JAVA_HOME |
Oussama Ben Abdelbaki | f825eb5 | 2018-12-04 16:17:00 -0500 | [diff] [blame] | 118 | |
Aurimas Liutikas | d6bc55a | 2022-05-24 13:19:07 -0700 | [diff] [blame] | 119 | # Warn developers if they try to build top level project without the full checkout |
Alan Viverette | 6b2fb21 | 2022-10-17 17:11:29 +0000 | [diff] [blame] | 120 | [ ! -d "$JAVA_HOME" ] && echo "Failed to find: $JAVA_HOME |
Aurimas Liutikas | d6bc55a | 2022-05-24 13:19:07 -0700 | [diff] [blame] | 121 | |
Alan Viverette | 6b2fb21 | 2022-10-17 17:11:29 +0000 | [diff] [blame] | 122 | Typically, this means either: |
| 123 | 1. You are using the standalone AndroidX checkout, e.g. GitHub, which only supports |
| 124 | building a subset of projects. See CONTRIBUTING.md for details. |
| 125 | 2. You are using the repo checkout, but the last repo sync failed. Use repo status |
| 126 | to check for projects which are partially-synced, e.g. showing ***NO BRANCH***." && exit -1 |
Aurimas Liutikas | d6bc55a | 2022-05-24 13:19:07 -0700 | [diff] [blame] | 127 | |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 128 | # ---------------------------------------------------------------------------- |
| 129 | |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 130 | # Determine the Java command to use to start the JVM. |
| 131 | if [ -n "$JAVA_HOME" ] ; then |
| 132 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then |
| 133 | # IBM's JDK on AIX uses strange locations for the executables |
| 134 | JAVACMD="$JAVA_HOME/jre/sh/java" |
| 135 | else |
| 136 | JAVACMD="$JAVA_HOME/bin/java" |
| 137 | fi |
| 138 | if [ ! -x "$JAVACMD" ] ; then |
| 139 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME |
| 140 | |
| 141 | Please set the JAVA_HOME variable in your environment to match the |
| 142 | location of your Java installation." |
| 143 | fi |
| 144 | else |
| 145 | JAVACMD="java" |
| 146 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
| 147 | |
| 148 | Please set the JAVA_HOME variable in your environment to match the |
| 149 | location of your Java installation." |
| 150 | fi |
| 151 | |
| 152 | # Increase the maximum file descriptors if we can. |
| 153 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then |
| 154 | MAX_FD_LIMIT=`ulimit -H -n` |
| 155 | if [ $? -eq 0 ] ; then |
| 156 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then |
| 157 | MAX_FD="$MAX_FD_LIMIT" |
| 158 | fi |
| 159 | ulimit -n $MAX_FD |
| 160 | if [ $? -ne 0 ] ; then |
| 161 | warn "Could not set maximum file descriptor limit: $MAX_FD" |
| 162 | fi |
| 163 | else |
| 164 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" |
| 165 | fi |
| 166 | fi |
| 167 | |
| 168 | # For Darwin, add options to specify how the application appears in the dock |
| 169 | if $darwin; then |
| 170 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" |
| 171 | fi |
| 172 | |
| 173 | # For Cygwin, switch paths to Windows format before running java |
| 174 | if $cygwin ; then |
| 175 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` |
| 176 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` |
Yigit Boyar | f77697d | 2016-08-16 10:55:36 -0700 | [diff] [blame] | 177 | JAVACMD=`cygpath --unix "$JAVACMD"` |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 178 | |
| 179 | # We build the pattern for arguments to be converted via cygpath |
| 180 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` |
| 181 | SEP="" |
| 182 | for dir in $ROOTDIRSRAW ; do |
| 183 | ROOTDIRS="$ROOTDIRS$SEP$dir" |
| 184 | SEP="|" |
| 185 | done |
| 186 | OURCYGPATTERN="(^($ROOTDIRS))" |
| 187 | # Add a user-defined pattern to the cygpath arguments |
| 188 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then |
| 189 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" |
| 190 | fi |
| 191 | # Now convert the arguments - kludge to limit ourselves to /bin/sh |
| 192 | i=0 |
| 193 | for arg in "$@" ; do |
| 194 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` |
| 195 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option |
| 196 | |
| 197 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition |
| 198 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` |
| 199 | else |
| 200 | eval `echo args$i`="\"$arg\"" |
| 201 | fi |
| 202 | i=$((i+1)) |
| 203 | done |
| 204 | case $i in |
| 205 | (0) set -- ;; |
| 206 | (1) set -- "$args0" ;; |
| 207 | (2) set -- "$args0" "$args1" ;; |
| 208 | (3) set -- "$args0" "$args1" "$args2" ;; |
| 209 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; |
| 210 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; |
| 211 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; |
| 212 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; |
| 213 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; |
| 214 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; |
| 215 | esac |
| 216 | fi |
| 217 | |
| 218 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules |
| 219 | function splitJvmOpts() { |
| 220 | JVM_OPTS=("$@") |
| 221 | } |
| 222 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS |
| 223 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" |
| 224 | |
Jeff Gaston | 826bdbe | 2019-11-20 14:56:24 -0500 | [diff] [blame] | 225 | #TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed |
| 226 | HOME_SYSTEM_PROPERTY_ARGUMENT="" |
| 227 | if [ "$GRADLE_USER_HOME" != "" ]; then |
| 228 | HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME" |
| 229 | fi |
Jeff Gaston | 38004a6 | 2019-12-11 15:43:10 -0500 | [diff] [blame] | 230 | if [ "$TMPDIR" != "" ]; then |
| 231 | TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR" |
| 232 | fi |
Jeff Gaston | 826bdbe | 2019-11-20 14:56:24 -0500 | [diff] [blame] | 233 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 234 | if [[ " ${@} " =~ " --clean " ]]; then |
| 235 | cleanCaches=true |
| 236 | else |
| 237 | cleanCaches=false |
| 238 | fi |
| 239 | |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 240 | if [[ " ${@} " =~ " --no-ci " ]]; then |
| 241 | disableCi=true |
| 242 | else |
| 243 | disableCi=false |
| 244 | fi |
| 245 | |
Jeff Gaston | 829fd82 | 2021-09-23 11:42:48 -0400 | [diff] [blame] | 246 | # workaround for https://github.com/gradle/gradle/issues/18386 |
| 247 | if [[ " ${@} " =~ " --profile " ]]; then |
| 248 | mkdir -p reports |
| 249 | fi |
| 250 | |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 251 | # Expand some arguments |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 252 | for compact in "--ci" "--strict" "--clean" "--no-ci"; do |
| 253 | expanded="" |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 254 | if [ "$compact" == "--ci" ]; then |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 255 | if [ "$disableCi" == "false" ]; then |
| 256 | expanded="--strict\ |
| 257 | --stacktrace\ |
| 258 | -Pandroidx.summarizeStderr\ |
| 259 | -Pandroidx.enableAffectedModuleDetection\ |
Jeff Gaston | 3fa62a8 | 2023-10-25 15:00:25 -0400 | [diff] [blame] | 260 | -Pandroidx.printTimestamps\ |
Jeff Gaston | eeb07d3 | 2023-10-05 12:14:08 -0400 | [diff] [blame] | 261 | --no-watch-fs\ |
| 262 | -Pandroidx.highMemory" |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 263 | fi |
Jeff Gaston | 4537e14 | 2021-01-27 13:08:50 -0500 | [diff] [blame] | 264 | fi |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 265 | if [ "$compact" == "--strict" ]; then |
Aurimas Liutikas | 41c58e0 | 2022-06-09 08:54:18 -0700 | [diff] [blame] | 266 | expanded="-Pandroidx.validateNoUnrecognizedMessages\ |
Jeff Gaston | 5562474 | 2021-04-22 14:05:49 -0400 | [diff] [blame] | 267 | -Pandroidx.verifyUpToDate\ |
Aurimas Liutikas | f06703b | 2022-07-08 16:28:11 +0000 | [diff] [blame] | 268 | --no-watch-fs" |
Jeff Gaston | 934d0b1 | 2022-04-26 17:47:25 -0400 | [diff] [blame] | 269 | if [ "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "" ]; then |
| 270 | expanded="$expanded --offline" |
| 271 | fi |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 272 | fi |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 273 | # if compact is something else then we parsed the argument above but |
| 274 | # still have to remove it (expanded == "") to avoid confusing Gradle |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 275 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 276 | # check whether this particular compat argument was passed (and therefore needs expansion) |
| 277 | if [[ " ${@} " =~ " $compact " ]]; then |
| 278 | # Expand an individual argument |
| 279 | # Start by making a copy of our list of arguments and iterating through the copy |
| 280 | for arg in "$@"; do |
| 281 | # Remove this argument from our list of arguments. |
| 282 | # By the time we've completed this loop, we will have removed the original copy of |
| 283 | # each argument, and potentially re-added a new copy or an expansion of each. |
| 284 | shift |
| 285 | # Determine whether to expand this argument |
| 286 | if [ "$arg" == "$compact" ]; then |
| 287 | # Add the expansion to our arguments |
| 288 | set -- "$@" $expanded |
| 289 | if [ "$expanded" != "" ]; then |
| 290 | echo "gradlew expanded '$compact' into '$expanded'" |
| 291 | echo |
| 292 | fi |
| 293 | # We avoid re-adding this argument itself back into the list for two reasons: |
| 294 | # 1. This argument might not be directly understood by Gradle |
| 295 | # 2. We want to enforce that all behaviors enabled by this flag can be toggled independently, |
| 296 | # so we don't want it to be easy to inadvertently check for the presence of this flag |
| 297 | # specifically |
| 298 | else |
| 299 | # Add this argument back into our arguments |
| 300 | set -- "$@" "$arg" |
| 301 | fi |
| 302 | done |
| 303 | fi |
Jeff Gaston | 4537e14 | 2021-01-27 13:08:50 -0500 | [diff] [blame] | 304 | done |
| 305 | |
Jeff Gaston | 2196fc6 | 2024-01-30 11:46:34 -0500 | [diff] [blame] | 306 | raiseMemory=false |
Jeff Gaston | eeb07d3 | 2023-10-05 12:14:08 -0400 | [diff] [blame] | 307 | if [[ " ${@} " =~ " -Pandroidx.highMemory " ]]; then |
Jeff Gaston | 2196fc6 | 2024-01-30 11:46:34 -0500 | [diff] [blame] | 308 | raiseMemory=true |
| 309 | fi |
| 310 | if [[ " ${@} " =~ " -Pandroidx.lowMemory " ]]; then |
| 311 | if [ "$raiseMemory" == "true" ]; then |
| 312 | echo "androidx.lowMemory overriding androidx.highMemory" |
| 313 | echo |
| 314 | fi |
| 315 | raiseMemory=false |
| 316 | fi |
Jeff Gaston | eeb07d3 | 2023-10-05 12:14:08 -0400 | [diff] [blame] | 317 | |
Jeff Gaston | 2196fc6 | 2024-01-30 11:46:34 -0500 | [diff] [blame] | 318 | if [ "$raiseMemory" == "true" ]; then |
| 319 | # Set the initial heap size to match the max heap size, |
| 320 | # by replacing a string like "-Xmx1g" with one like "-Xms1g -Xmx1g" |
| 321 | MAX_MEM=32g |
| 322 | ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s/-Xmx\([^ ]*\)/-Xms$MAX_MEM -Xmx$MAX_MEM/")" |
| 323 | |
| 324 | # Increase the compiler cache size: b/260643754 . Remove when updating to JDK 20 ( https://bugs.openjdk.org/browse/JDK-8295724 ) |
| 325 | ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s|$| -XX:ReservedCodeCacheSize=576M|")" |
Jeff Gaston | eeb07d3 | 2023-10-05 12:14:08 -0400 | [diff] [blame] | 326 | fi |
| 327 | |
Jeff Gaston | b03b05a | 2022-04-11 11:41:59 -0400 | [diff] [blame] | 328 | # check whether the user has requested profiling via yourkit |
| 329 | yourkitArgPrefix="androidx.profile.yourkitAgentPath" |
| 330 | yourkitAgentPath="" |
| 331 | if [[ " ${@}" =~ " -P$yourkitArgPrefix" ]]; then |
| 332 | for arg in "$@"; do |
| 333 | if echo "$arg" | grep "${yourkitArgPrefix}=" >/dev/null; then |
| 334 | yourkitAgentPath="$(echo "$arg" | sed "s/-P${yourkitArgPrefix}=//")" |
| 335 | fi |
| 336 | done |
| 337 | if [ "$yourkitAgentPath" == "" ]; then |
| 338 | echo "Error: $yourkitArgPrefix must be set to the path of the YourKit Java agent" >&2 |
| 339 | exit 1 |
| 340 | fi |
| 341 | if [ ! -e "$yourkitAgentPath" ]; then |
| 342 | echo "Error: $yourkitAgentPath does not exist" >&2 |
| 343 | exit 1 |
| 344 | fi |
| 345 | # add the agent to the path |
| 346 | export _JAVA_OPTIONS="$_JAVA_OPTIONS -agentpath:$yourkitAgentPath" |
| 347 | # add arguments |
| 348 | set -- "$@" --no-daemon --rerun-tasks |
| 349 | |
| 350 | # lots of blank lines because these messages are important |
| 351 | echo |
| 352 | echo |
| 353 | echo |
| 354 | echo |
| 355 | echo |
| 356 | # suggest --clean |
| 357 | if [ "$cleanCaches" == "false" ]; then |
| 358 | echo "When setting $yourkitArgPrefix you may also want to pass --clean" |
| 359 | fi |
| 360 | COLOR_YELLOW="\u001B[33m" |
| 361 | COLOR_CLEAR="\u001B[0m" |
| 362 | |
| 363 | echo -e "${COLOR_YELLOW}Also be sure to start the YourKit user interface and connect to the appropriate Java process (probably the Gradle Daemon)${COLOR_CLEAR}" |
| 364 | echo |
| 365 | echo |
| 366 | echo |
| 367 | echo |
| 368 | echo |
| 369 | fi |
| 370 | |
Jeff Gaston | d2806b3 | 2021-09-29 12:20:39 -0400 | [diff] [blame] | 371 | if [[ " ${@} " =~ " --scan " ]]; then |
| 372 | if [[ " ${@} " =~ " --offline " ]]; then |
| 373 | echo "--scan incompatible with --offline" |
| 374 | echo "you could try --no-ci" |
| 375 | exit 1 |
| 376 | fi |
| 377 | fi |
| 378 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 379 | function removeCaches() { |
| 380 | rm -rf $SCRIPT_PATH/.gradle |
| 381 | rm -rf $SCRIPT_PATH/buildSrc/.gradle |
| 382 | rm -f $SCRIPT_PATH/local.properties |
| 383 | if [ "$GRADLE_USER_HOME" != "" ]; then |
| 384 | rm -rf "$GRADLE_USER_HOME" |
| 385 | else |
| 386 | rm -rf ~/.gradle |
| 387 | fi |
Jeff Gaston | 829fd82 | 2021-09-23 11:42:48 -0400 | [diff] [blame] | 388 | # https://github.com/gradle/gradle/issues/18386 |
| 389 | rm -rf $SCRIPT_PATH/reports |
Jeff Gaston | 96eb601 | 2021-09-27 14:55:36 +0000 | [diff] [blame] | 390 | rm -rf $SCRIPT_PATH/build |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 391 | rm -rf $OUT_DIR |
| 392 | } |
| 393 | |
Jeff Gaston | 6cca77e5 | 2023-08-07 11:10:17 -0400 | [diff] [blame] | 394 | # Move any preexisting build scan to make room for a new one |
| 395 | # After moving a build scan several times it eventually gets deleted |
| 396 | function rotateBuildScans() { |
| 397 | filePrefix="$1" |
| 398 | iPlus1="10" |
| 399 | for i in $(seq 9 -1 1); do |
| 400 | mv "${filePrefix}.${i}.zip" "${filePrefix}.${iPlus1}.zip" 2>/dev/null || true |
| 401 | iPlus1=$i |
| 402 | done |
| 403 | mv ${filePrefix}.zip "${filePrefix}.1.zip" 2>/dev/null || true |
| 404 | } |
| 405 | |
Jeff Gaston | 224eb17 | 2020-01-09 12:31:47 -0500 | [diff] [blame] | 406 | function runGradle() { |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 407 | processOutput=false |
Jeff Gaston | e4b4b87 | 2020-08-25 09:02:13 -0400 | [diff] [blame] | 408 | if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 409 | processOutput=true |
| 410 | fi |
| 411 | if [[ " ${@} " =~ " -Pandroidx.summarizeStderr " ]]; then |
| 412 | processOutput=true |
| 413 | fi |
Jeff Gaston | 3fa62a8 | 2023-10-25 15:00:25 -0400 | [diff] [blame] | 414 | if [[ "${@} " =~ " -Pandroidx.printTimestamps " ]]; then |
| 415 | processOutput=true |
| 416 | fi |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 417 | if [ "$processOutput" == "true" ]; then |
| 418 | wrapper="$SCRIPT_PATH/development/build_log_processor.sh" |
| 419 | else |
| 420 | wrapper="" |
| 421 | fi |
Jeff Gaston | 3febf90 | 2021-03-16 11:23:15 -0400 | [diff] [blame] | 422 | |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 423 | RETURN_VALUE=0 |
Aurimas Liutikas | 07c47d3 | 2023-08-03 15:46:39 -0700 | [diff] [blame] | 424 | set -- "$@" -Dorg.gradle.projectcachedir="$OUT_DIR/gradle-project-cache" |
Jeff Gaston | dc9c8cb | 2023-02-08 16:24:38 -0500 | [diff] [blame] | 425 | # Disabled in Studio until these errors become shown (b/268380971) or computed more quickly (https://github.com/gradle/gradle/issues/23272) |
| 426 | if [[ " ${@} " =~ " --dependency-verification=" ]]; then |
| 427 | VERIFICATION_ARGUMENT="" # already specified by caller |
| 428 | else |
| 429 | VERIFICATION_ARGUMENT=--dependency-verification=strict |
| 430 | fi |
Aurimas Liutikas | 07c47d3 | 2023-08-03 15:46:39 -0700 | [diff] [blame] | 431 | if $wrapper "$JAVACMD" "${JVM_OPTS[@]}" $TMPDIR_ARG -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain $HOME_SYSTEM_PROPERTY_ARGUMENT $TMPDIR_ARG $VERIFICATION_ARGUMENT "$ORG_GRADLE_JVMARGS" "$@"; then |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 432 | RETURN_VALUE=0 |
Jeff Gaston | 224eb17 | 2020-01-09 12:31:47 -0500 | [diff] [blame] | 433 | else |
| 434 | # Print AndroidX-specific help message if build fails |
| 435 | # Have to do this build-failure detection in gradlew rather than in build.gradle |
| 436 | # so that this message still prints even if buildSrc itself fails |
| 437 | echo |
Jeff Gaston | 61cef33 | 2020-12-22 11:23:09 -0500 | [diff] [blame] | 438 | echo For help with unexpected failures, see development/diagnose-build-failure/README.md |
| 439 | echo |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 440 | RETURN_VALUE=1 |
Jeff Gaston | 6971329 | 2020-06-04 12:53:39 -0400 | [diff] [blame] | 441 | fi |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 442 | |
| 443 | # If the caller specified where to save data, then also save the build scan data |
| 444 | if [ "$DIST_DIR" != "" ]; then |
| 445 | if [ "$GRADLE_USER_HOME" != "" ]; then |
Jeff Gaston | 9d97d5c | 2022-07-06 10:55:47 -0400 | [diff] [blame] | 446 | scanDir="$GRADLE_USER_HOME/build-scan-data" |
| 447 | if [ -e "$scanDir" ]; then |
| 448 | if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then |
Jeff Gaston | 6cca77e5 | 2023-08-07 11:10:17 -0400 | [diff] [blame] | 449 | zipPrefix="$DIST_DIR/scan-up-to-date" |
Jeff Gaston | 9d97d5c | 2022-07-06 10:55:47 -0400 | [diff] [blame] | 450 | else |
Jeff Gaston | 6cca77e5 | 2023-08-07 11:10:17 -0400 | [diff] [blame] | 451 | zipPrefix="$DIST_DIR/scan" |
Jeff Gaston | 9d97d5c | 2022-07-06 10:55:47 -0400 | [diff] [blame] | 452 | fi |
Jeff Gaston | 6cca77e5 | 2023-08-07 11:10:17 -0400 | [diff] [blame] | 453 | rotateBuildScans "$zipPrefix" |
| 454 | zipPath="${zipPrefix}.zip" |
Jeff Gaston | 9d97d5c | 2022-07-06 10:55:47 -0400 | [diff] [blame] | 455 | cd "$GRADLE_USER_HOME/build-scan-data" |
| 456 | zip -q -r "$zipPath" . |
| 457 | cd - |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 458 | fi |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 459 | fi |
| 460 | fi |
| 461 | return $RETURN_VALUE |
Jeff Gaston | 6971329 | 2020-06-04 12:53:39 -0400 | [diff] [blame] | 462 | } |
| 463 | |
Jeff Gaston | 87a4bbb | 2022-04-21 12:31:08 -0400 | [diff] [blame] | 464 | if [ "$cleanCaches" == true ]; then |
| 465 | echo "IF ./gradlew --clean FIXES YOUR BUILD; OPEN A BUG." |
| 466 | echo "In nearly all cases, it should not be necessary to run a clean build." |
| 467 | echo |
| 468 | # one case where it is convenient to have a clean build is for double-checking that a build failure isn't due to an incremental build failure |
| 469 | # another case where it is convenient to have a clean build is for performance testing |
| 470 | # another case where it is convenient to have a clean build is when you're modifying the build and may have introduced some errors but haven't shared your changes yet (at which point you should have fixed the errors) |
| 471 | |
| 472 | echo "Stopping Gradle daemons" |
| 473 | runGradle --stop || true |
| 474 | echo |
| 475 | |
| 476 | backupDir=~/androidx-build-state-backup |
| 477 | ./development/diagnose-build-failure/impl/backup-state.sh "$backupDir" --move # prints that it is saving state into this dir" |
| 478 | |
| 479 | echo "To restore this state later, run:" |
| 480 | echo |
| 481 | echo " ./development/diagnose-build-failure/impl/restore-state.sh $backupDir" |
| 482 | echo |
| 483 | echo "Running Gradle" |
| 484 | echo |
| 485 | fi |
| 486 | |
Jeff Gaston | 7121d83 | 2022-06-08 13:36:50 -0400 | [diff] [blame] | 487 | if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then |
| 488 | echo "Setting 'DISALLOW_TASK_EXECUTION' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?" |
Jeff Gaston | 400ccb3 | 2020-06-08 16:44:58 -0400 | [diff] [blame] | 489 | echo "See TaskUpToDateValidator.java for more information" |
| 490 | exit 1 |
| 491 | fi |
| 492 | |
Jeff Gaston | 5562474 | 2021-04-22 14:05:49 -0400 | [diff] [blame] | 493 | runGradle "$@" |
| 494 | # Check whether we were given the "-Pandroidx.verifyUpToDate" argument |
| 495 | if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then |
Jeff Gaston | cefdeae | 2020-03-09 13:12:35 -0400 | [diff] [blame] | 496 | # Re-run Gradle, and find all tasks that are unexpectly out of date |
Jeff Gaston | 7121d83 | 2022-06-08 13:36:50 -0400 | [diff] [blame] | 497 | if ! DISALLOW_TASK_EXECUTION=true runGradle "$@" --continue; then |
Jeff Gaston | e906e5c | 2020-11-05 12:33:10 -0500 | [diff] [blame] | 498 | echo >&2 |
Jeff Gaston | 20f5e7a | 2022-01-27 13:39:25 -0500 | [diff] [blame] | 499 | echo "TaskUpToDateValidator's second build failed. To reproduce, try running './gradlew -Pandroidx.verifyUpToDate <failing tasks>'" >&2 |
Jeff Gaston | e906e5c | 2020-11-05 12:33:10 -0500 | [diff] [blame] | 500 | exit 1 |
| 501 | fi |
Jeff Gaston | b89c82b | 2019-08-21 16:24:09 -0400 | [diff] [blame] | 502 | fi |