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" |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 22 | fi |
| 23 | |
Jeff Gaston | 440e1ac | 2020-09-09 08:32:22 -0400 | [diff] [blame] | 24 | 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] | 25 | if [ -n "$DIST_DIR" ]; then |
| 26 | mkdir -p "$DIST_DIR" |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 27 | DIST_DIR="$(cd $DIST_DIR && pwd -P)" |
Jeff Gaston | 0e3d19a | 2019-10-02 12:17:39 -0400 | [diff] [blame] | 28 | export LINT_PRINT_STACKTRACE=true |
| 29 | |
Jeff Gaston | e72d230 | 2019-12-19 18:32:31 -0500 | [diff] [blame] | 30 | #Set the initial heap size to match the max heap size, |
| 31 | #by replacing a string like "-Xmx1g" with one like "-Xms1g -Xmx1g" |
Jeff Gaston | 77bb2b1 | 2021-04-15 12:51:08 -0400 | [diff] [blame] | 32 | MAX_MEM=24g |
Jeff Gaston | cca984c | 2020-10-05 12:54:17 -0400 | [diff] [blame] | 33 | ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s/-Xmx\([^ ]*\)/-Xms$MAX_MEM -Xmx$MAX_MEM/")" |
Jeff Gaston | 440e1ac | 2020-09-09 08:32:22 -0400 | [diff] [blame] | 34 | |
| 35 | # tell Gradle where to put a heap dump on failure |
| 36 | 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] | 37 | |
Jeff Gaston | 0e3d19a | 2019-10-02 12:17:39 -0400 | [diff] [blame] | 38 | # We don't set a default DIST_DIR in an else clause here because Studio doesn't use gradlew |
| 39 | # and doesn't set DIST_DIR and we want gradlew and Studio to match |
| 40 | fi |
| 41 | |
Jeff Gaston | c21ecb3 | 2020-11-05 17:16:35 -0500 | [diff] [blame] | 42 | # unset ANDROID_BUILD_TOP so that Lint doesn't think we're building the platform itself |
| 43 | unset ANDROID_BUILD_TOP |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 44 | # ---------------------------------------------------------------------------- |
| 45 | |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 46 | # 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] | 47 | |
Jeff Gaston | 54723ef | 2021-08-16 11:35:08 -0400 | [diff] [blame] | 48 | JAVA_OPTS="$JAVA_OPTS -Dkotlin.incremental.compilation=true" # b/188565660 |
| 49 | |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 50 | APP_NAME="Gradle" |
| 51 | APP_BASE_NAME=`basename "$0"` |
| 52 | |
| 53 | # Use the maximum available, or set MAX_FD != -1 to use that value. |
| 54 | MAX_FD="maximum" |
| 55 | |
| 56 | warn ( ) { |
| 57 | echo "$*" |
| 58 | } |
| 59 | |
| 60 | die ( ) { |
| 61 | echo |
| 62 | echo "$*" |
| 63 | echo |
| 64 | exit 1 |
| 65 | } |
| 66 | |
| 67 | # OS specific support (must be 'true' or 'false'). |
| 68 | cygwin=false |
| 69 | msys=false |
| 70 | darwin=false |
| 71 | case "`uname`" in |
| 72 | CYGWIN* ) |
| 73 | cygwin=true |
| 74 | ;; |
| 75 | Darwin* ) |
| 76 | darwin=true |
| 77 | ;; |
| 78 | MINGW* ) |
| 79 | msys=true |
| 80 | ;; |
| 81 | esac |
| 82 | |
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 |
| 111 | DEFAULT_JVM_OPTS="-DLINT_API_DATABASE=$APP_HOME/../../prebuilts/fullsdk-$plat/platform-tools/api/api-versions.xml" |
| 112 | |
Matthew Fraschilla | 6ab84fc3 | 2019-11-21 16:40:16 -0800 | [diff] [blame] | 113 | # Tests for lint checks default to using sdk defined by this variable. This removes a lot of |
| 114 | # setup from each lint module. |
| 115 | export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat" |
Sergey Vasilinets | efab5eb | 2019-01-04 12:38:06 +0000 | [diff] [blame] | 116 | # override JAVA_HOME, because CI machines have it and it points to very old JDK |
Aurimas Liutikas | 4b897cb | 2019-10-14 13:25:08 -0700 | [diff] [blame] | 117 | export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk11/$plat-x86" |
| 118 | export JAVA_TOOLS_JAR="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86/lib/tools.jar" |
| 119 | export STUDIO_GRADLE_JDK=$JAVA_HOME |
Oussama Ben Abdelbaki | f825eb5 | 2018-12-04 16:17:00 -0500 | [diff] [blame] | 120 | |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 121 | # ---------------------------------------------------------------------------- |
| 122 | |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 123 | # Determine the Java command to use to start the JVM. |
| 124 | if [ -n "$JAVA_HOME" ] ; then |
| 125 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then |
| 126 | # IBM's JDK on AIX uses strange locations for the executables |
| 127 | JAVACMD="$JAVA_HOME/jre/sh/java" |
| 128 | else |
| 129 | JAVACMD="$JAVA_HOME/bin/java" |
| 130 | fi |
| 131 | if [ ! -x "$JAVACMD" ] ; then |
| 132 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME |
| 133 | |
| 134 | Please set the JAVA_HOME variable in your environment to match the |
| 135 | location of your Java installation." |
| 136 | fi |
| 137 | else |
| 138 | JAVACMD="java" |
| 139 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. |
| 140 | |
| 141 | Please set the JAVA_HOME variable in your environment to match the |
| 142 | location of your Java installation." |
| 143 | fi |
| 144 | |
| 145 | # Increase the maximum file descriptors if we can. |
| 146 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then |
| 147 | MAX_FD_LIMIT=`ulimit -H -n` |
| 148 | if [ $? -eq 0 ] ; then |
| 149 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then |
| 150 | MAX_FD="$MAX_FD_LIMIT" |
| 151 | fi |
| 152 | ulimit -n $MAX_FD |
| 153 | if [ $? -ne 0 ] ; then |
| 154 | warn "Could not set maximum file descriptor limit: $MAX_FD" |
| 155 | fi |
| 156 | else |
| 157 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" |
| 158 | fi |
| 159 | fi |
| 160 | |
| 161 | # For Darwin, add options to specify how the application appears in the dock |
| 162 | if $darwin; then |
| 163 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" |
| 164 | fi |
| 165 | |
| 166 | # For Cygwin, switch paths to Windows format before running java |
| 167 | if $cygwin ; then |
| 168 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` |
| 169 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` |
Yigit Boyar | f77697d | 2016-08-16 10:55:36 -0700 | [diff] [blame] | 170 | JAVACMD=`cygpath --unix "$JAVACMD"` |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 171 | |
| 172 | # We build the pattern for arguments to be converted via cygpath |
| 173 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` |
| 174 | SEP="" |
| 175 | for dir in $ROOTDIRSRAW ; do |
| 176 | ROOTDIRS="$ROOTDIRS$SEP$dir" |
| 177 | SEP="|" |
| 178 | done |
| 179 | OURCYGPATTERN="(^($ROOTDIRS))" |
| 180 | # Add a user-defined pattern to the cygpath arguments |
| 181 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then |
| 182 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" |
| 183 | fi |
| 184 | # Now convert the arguments - kludge to limit ourselves to /bin/sh |
| 185 | i=0 |
| 186 | for arg in "$@" ; do |
| 187 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` |
| 188 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option |
| 189 | |
| 190 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition |
| 191 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` |
| 192 | else |
| 193 | eval `echo args$i`="\"$arg\"" |
| 194 | fi |
| 195 | i=$((i+1)) |
| 196 | done |
| 197 | case $i in |
| 198 | (0) set -- ;; |
| 199 | (1) set -- "$args0" ;; |
| 200 | (2) set -- "$args0" "$args1" ;; |
| 201 | (3) set -- "$args0" "$args1" "$args2" ;; |
| 202 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; |
| 203 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; |
| 204 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; |
| 205 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; |
| 206 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; |
| 207 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; |
| 208 | esac |
| 209 | fi |
| 210 | |
| 211 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules |
| 212 | function splitJvmOpts() { |
| 213 | JVM_OPTS=("$@") |
| 214 | } |
| 215 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS |
| 216 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" |
| 217 | |
Jeff Gaston | 826bdbe | 2019-11-20 14:56:24 -0500 | [diff] [blame] | 218 | #TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed |
| 219 | HOME_SYSTEM_PROPERTY_ARGUMENT="" |
| 220 | if [ "$GRADLE_USER_HOME" != "" ]; then |
| 221 | HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME" |
| 222 | fi |
Jeff Gaston | 38004a6 | 2019-12-11 15:43:10 -0500 | [diff] [blame] | 223 | if [ "$TMPDIR" != "" ]; then |
| 224 | TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR" |
| 225 | fi |
Jeff Gaston | 826bdbe | 2019-11-20 14:56:24 -0500 | [diff] [blame] | 226 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 227 | if [[ " ${@} " =~ " --clean " ]]; then |
| 228 | cleanCaches=true |
| 229 | else |
| 230 | cleanCaches=false |
| 231 | fi |
| 232 | |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 233 | if [[ " ${@} " =~ " --no-ci " ]]; then |
| 234 | disableCi=true |
| 235 | else |
| 236 | disableCi=false |
| 237 | fi |
| 238 | |
Jeff Gaston | 829fd82 | 2021-09-23 11:42:48 -0400 | [diff] [blame] | 239 | # workaround for https://github.com/gradle/gradle/issues/18386 |
| 240 | if [[ " ${@} " =~ " --profile " ]]; then |
| 241 | mkdir -p reports |
| 242 | fi |
| 243 | |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 244 | # Expand some arguments |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 245 | for compact in "--ci" "--strict" "--clean" "--no-ci"; do |
| 246 | expanded="" |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 247 | if [ "$compact" == "--ci" ]; then |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 248 | if [ "$disableCi" == "false" ]; then |
| 249 | expanded="--strict\ |
| 250 | --stacktrace\ |
| 251 | -Pandroidx.summarizeStderr\ |
| 252 | -Pandroidx.enableAffectedModuleDetection\ |
| 253 | --no-watch-fs" |
| 254 | fi |
Jeff Gaston | 4537e14 | 2021-01-27 13:08:50 -0500 | [diff] [blame] | 255 | fi |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 256 | if [ "$compact" == "--strict" ]; then |
| 257 | expanded="-Pandroidx.allWarningsAsErrors\ |
| 258 | -Pandroidx.validateNoUnrecognizedMessages\ |
Jeff Gaston | 5562474 | 2021-04-22 14:05:49 -0400 | [diff] [blame] | 259 | -Pandroidx.verifyUpToDate\ |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 260 | --no-watch-fs\ |
| 261 | --no-daemon\ |
| 262 | --offline" |
| 263 | fi |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 264 | # if compact is something else then we parsed the argument above but |
| 265 | # still have to remove it (expanded == "") to avoid confusing Gradle |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 266 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 267 | # check whether this particular compat argument was passed (and therefore needs expansion) |
| 268 | if [[ " ${@} " =~ " $compact " ]]; then |
| 269 | # Expand an individual argument |
| 270 | # Start by making a copy of our list of arguments and iterating through the copy |
| 271 | for arg in "$@"; do |
| 272 | # Remove this argument from our list of arguments. |
| 273 | # By the time we've completed this loop, we will have removed the original copy of |
| 274 | # each argument, and potentially re-added a new copy or an expansion of each. |
| 275 | shift |
| 276 | # Determine whether to expand this argument |
| 277 | if [ "$arg" == "$compact" ]; then |
| 278 | # Add the expansion to our arguments |
| 279 | set -- "$@" $expanded |
| 280 | if [ "$expanded" != "" ]; then |
| 281 | echo "gradlew expanded '$compact' into '$expanded'" |
| 282 | echo |
| 283 | fi |
| 284 | # We avoid re-adding this argument itself back into the list for two reasons: |
| 285 | # 1. This argument might not be directly understood by Gradle |
| 286 | # 2. We want to enforce that all behaviors enabled by this flag can be toggled independently, |
| 287 | # so we don't want it to be easy to inadvertently check for the presence of this flag |
| 288 | # specifically |
| 289 | else |
| 290 | # Add this argument back into our arguments |
| 291 | set -- "$@" "$arg" |
| 292 | fi |
| 293 | done |
| 294 | fi |
Jeff Gaston | 4537e14 | 2021-01-27 13:08:50 -0500 | [diff] [blame] | 295 | done |
| 296 | |
Jeff Gaston | d2806b3 | 2021-09-29 12:20:39 -0400 | [diff] [blame] | 297 | if [[ " ${@} " =~ " --scan " ]]; then |
| 298 | if [[ " ${@} " =~ " --offline " ]]; then |
| 299 | echo "--scan incompatible with --offline" |
| 300 | echo "you could try --no-ci" |
| 301 | exit 1 |
| 302 | fi |
| 303 | fi |
| 304 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 305 | function removeCaches() { |
| 306 | rm -rf $SCRIPT_PATH/.gradle |
| 307 | rm -rf $SCRIPT_PATH/buildSrc/.gradle |
| 308 | rm -f $SCRIPT_PATH/local.properties |
| 309 | if [ "$GRADLE_USER_HOME" != "" ]; then |
| 310 | rm -rf "$GRADLE_USER_HOME" |
| 311 | else |
| 312 | rm -rf ~/.gradle |
| 313 | fi |
Jeff Gaston | 829fd82 | 2021-09-23 11:42:48 -0400 | [diff] [blame] | 314 | # https://github.com/gradle/gradle/issues/18386 |
| 315 | rm -rf $SCRIPT_PATH/reports |
Jeff Gaston | 96eb601 | 2021-09-27 14:55:36 +0000 | [diff] [blame] | 316 | rm -rf $SCRIPT_PATH/build |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 317 | rm -rf $OUT_DIR |
| 318 | } |
| 319 | |
| 320 | if [ "$cleanCaches" == true ]; then |
| 321 | echo "IF ./gradlew --clean FIXES YOUR BUILD; OPEN A BUG." |
| 322 | echo "In nearly all cases, it should not be necessary to run a clean build." |
| 323 | echo |
| 324 | echo "You may be more interested in running:" |
| 325 | echo |
| 326 | echo " ./development/diagnose-build-failure/diagnose-build-failure.sh $*" |
| 327 | echo |
| 328 | echo "which attempts to diagnose more details about build failures." |
| 329 | echo |
| 330 | echo "Removing caches" |
| 331 | # 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 |
| 332 | # another case where it is convenient to have a clean build is for performance testing |
| 333 | # 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) |
| 334 | echo |
| 335 | |
| 336 | removeCaches |
| 337 | fi |
| 338 | |
Jeff Gaston | 224eb17 | 2020-01-09 12:31:47 -0500 | [diff] [blame] | 339 | function runGradle() { |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 340 | processOutput=false |
Jeff Gaston | e4b4b87 | 2020-08-25 09:02:13 -0400 | [diff] [blame] | 341 | if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 342 | processOutput=true |
| 343 | fi |
| 344 | if [[ " ${@} " =~ " -Pandroidx.summarizeStderr " ]]; then |
| 345 | processOutput=true |
| 346 | fi |
| 347 | if [ "$processOutput" == "true" ]; then |
| 348 | wrapper="$SCRIPT_PATH/development/build_log_processor.sh" |
| 349 | else |
| 350 | wrapper="" |
| 351 | fi |
Jeff Gaston | 3febf90 | 2021-03-16 11:23:15 -0400 | [diff] [blame] | 352 | |
| 353 | PROJECT_CACHE_DIR_ARGUMENT="--project-cache-dir $OUT_DIR/gradle-project-cache" |
| 354 | if $wrapper "$JAVACMD" "${JVM_OPTS[@]}" $TMPDIR_ARG -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain $HOME_SYSTEM_PROPERTY_ARGUMENT $TMPDIR_ARG $PROJECT_CACHE_DIR_ARGUMENT "$ORG_GRADLE_JVMARGS" "$@"; then |
Jeff Gaston | 224eb17 | 2020-01-09 12:31:47 -0500 | [diff] [blame] | 355 | return 0 |
| 356 | else |
| 357 | # Print AndroidX-specific help message if build fails |
| 358 | # Have to do this build-failure detection in gradlew rather than in build.gradle |
| 359 | # so that this message still prints even if buildSrc itself fails |
| 360 | echo |
Jeff Gaston | 61cef33 | 2020-12-22 11:23:09 -0500 | [diff] [blame] | 361 | echo For help with unexpected failures, see development/diagnose-build-failure/README.md |
| 362 | echo |
Jeff Gaston | 6971329 | 2020-06-04 12:53:39 -0400 | [diff] [blame] | 363 | return 1 |
| 364 | fi |
| 365 | } |
| 366 | |
Jeff Gaston | 400ccb3 | 2020-06-08 16:44:58 -0400 | [diff] [blame] | 367 | if [[ " ${@} " =~ " -PdisallowExecution " ]]; then |
Jeff Gaston | 5562474 | 2021-04-22 14:05:49 -0400 | [diff] [blame] | 368 | echo "Passing '-PdisallowExecution' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?" |
Jeff Gaston | 400ccb3 | 2020-06-08 16:44:58 -0400 | [diff] [blame] | 369 | echo "See TaskUpToDateValidator.java for more information" |
| 370 | exit 1 |
| 371 | fi |
| 372 | |
Jeff Gaston | 224eb17 | 2020-01-09 12:31:47 -0500 | [diff] [blame] | 373 | if [[ " ${@} " =~ " -PverifyUpToDate " ]]; then |
Jeff Gaston | 5562474 | 2021-04-22 14:05:49 -0400 | [diff] [blame] | 374 | echo "-PverifyUpToDate has been renamed to -Pandroidx.verifyUpToDate" |
| 375 | exit 1 |
| 376 | fi |
| 377 | |
| 378 | runGradle "$@" |
| 379 | # Check whether we were given the "-Pandroidx.verifyUpToDate" argument |
| 380 | if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then |
Jeff Gaston | cefdeae | 2020-03-09 13:12:35 -0400 | [diff] [blame] | 381 | # Re-run Gradle, and find all tasks that are unexpectly out of date |
Jeff Gaston | e906e5c | 2020-11-05 12:33:10 -0500 | [diff] [blame] | 382 | if ! runGradle "$@" -PdisallowExecution --continue; then |
| 383 | echo >&2 |
| 384 | echo "TaskUpToDateValidator's second build failed, -PdisallowExecution specified" >&2 |
| 385 | exit 1 |
| 386 | fi |
Jeff Gaston | b89c82b | 2019-08-21 16:24:09 -0400 | [diff] [blame] | 387 | fi |