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