blob: e8d45ff1fe9641273ce2c434c49474f0a18d3bc8 [file] [log] [blame]
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -07001#!/usr/bin/env bash
Jeff Gaston69713292020-06-04 12:53:39 -04002set -o pipefail
3set -e
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -07004
5##############################################################################
6##
7## Gradle start up script for UN*X
8##
9##############################################################################
10
Aurimas Liutikas9979d072018-03-13 15:38:56 -070011# --------- androidx specific code needed for build server. ------------------
12
Jeff Gastondd8a6e92020-09-01 14:26:49 -040013SCRIPT_PATH="$(cd $(dirname $0) && pwd -P)"
Aurimas Liutikas9979d072018-03-13 15:38:56 -070014if [ -n "$OUT_DIR" ] ; then
Jeff Gaston8fd9fc82019-07-26 14:26:10 -040015 mkdir -p "$OUT_DIR"
Jeff Gastondd8a6e92020-09-01 14:26:49 -040016 OUT_DIR="$(cd $OUT_DIR && pwd -P)"
Aurimas Liutikas9979d072018-03-13 15:38:56 -070017 export GRADLE_USER_HOME="$OUT_DIR/.gradle"
Jeff Gaston38004a62019-12-11 15:43:10 -050018 export TMPDIR=$OUT_DIR
Jeff Gastoncc694ab2019-04-11 16:51:36 -040019else
Jeff Gastondd8a6e92020-09-01 14:26:49 -040020 CHECKOUT_ROOT="$(cd $SCRIPT_PATH/../.. && pwd -P)"
Jeff Gastoncc694ab2019-04-11 16:51:36 -040021 export OUT_DIR="$CHECKOUT_ROOT/out"
Jeff Gastond5719892022-04-21 12:06:24 -040022 export GRADLE_USER_HOME=~/.gradle
Aurimas Liutikas9979d072018-03-13 15:38:56 -070023fi
24
Jeff Gaston440e1ac2020-09-09 08:32:22 -040025ORG_GRADLE_JVMARGS="$(cd $SCRIPT_PATH && grep org.gradle.jvmargs gradle.properties | sed 's/^/-D/')"
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040026if [ -n "$DIST_DIR" ]; then
27 mkdir -p "$DIST_DIR"
Jeff Gastondd8a6e92020-09-01 14:26:49 -040028 DIST_DIR="$(cd $DIST_DIR && pwd -P)"
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040029
Jeff Gaston440e1ac2020-09-09 08:32:22 -040030 # 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 Gastone72d2302019-12-19 18:32:31 -050032
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040033 # 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
35fi
36
Alan Viverette9d651362023-03-23 12:34:03 -040037# Loading the AIDL lexer requires disabling Lint's bytecode verification
38export ANDROID_LINT_SKIP_BYTECODE_VERIFIER=true
39
Jeff Gastonc21ecb32020-11-05 17:16:35 -050040# unset ANDROID_BUILD_TOP so that Lint doesn't think we're building the platform itself
41unset ANDROID_BUILD_TOP
Aurimas Liutikas9979d072018-03-13 15:38:56 -070042# ----------------------------------------------------------------------------
43
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070044# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070045
Jeff Gastonc6df4152021-11-03 10:24:02 -040046if [[ " ${@} " =~ " -PupdateLintBaseline " ]]; then
47 # remove when b/188666845 is complete
48 # Inform lint to not fail even when creating a baseline file
49 JAVA_OPTS="$JAVA_OPTS -Dlint.baselines.continue=true"
50fi
51
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070052APP_NAME="Gradle"
53APP_BASE_NAME=`basename "$0"`
54
55# Use the maximum available, or set MAX_FD != -1 to use that value.
56MAX_FD="maximum"
57
58warn ( ) {
59 echo "$*"
60}
61
62die ( ) {
63 echo
64 echo "$*"
65 echo
66 exit 1
67}
68
69# OS specific support (must be 'true' or 'false').
70cygwin=false
71msys=false
72darwin=false
73case "`uname`" in
74 CYGWIN* )
75 cygwin=true
76 ;;
77 Darwin* )
78 darwin=true
79 ;;
80 MINGW* )
81 msys=true
82 ;;
83esac
Rahul Ravikumar465ccfc2022-02-14 14:58:20 -080084platform_suffix="x86"
85case "$(arch)" in
86 arm64* )
87 platform_suffix="arm64"
88esac
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070089# Attempt to set APP_HOME
90# Resolve links: $0 may be a link
91PRG="$0"
92# Need this for relative symlinks.
93while [ -h "$PRG" ] ; do
94 ls=`ls -ld "$PRG"`
95 link=`expr "$ls" : '.*-> \(.*\)$'`
96 if expr "$link" : '/.*' > /dev/null; then
97 PRG="$link"
98 else
99 PRG=`dirname "$PRG"`"/$link"
100 fi
101done
102SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700103cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700104APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700105cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700106
107CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
108
Jeff Gaston79a43f22019-04-09 16:19:12 -0400109# --------- androidx specific code needed for lint and java. ------------------
110
Alan Viveretted38b36c2017-02-01 16:45:31 -0500111# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -0500112if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -0500113 plat="darwin"
114else
115 plat="linux"
116fi
Alan Viveretted38b36c2017-02-01 16:45:31 -0500117
Matthew Fraschilla6ab84fc32019-11-21 16:40:16 -0800118# Tests for lint checks default to using sdk defined by this variable. This removes a lot of
119# setup from each lint module.
120export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +0000121# override JAVA_HOME, because CI machines have it and it points to very old JDK
Aurimas Liutikas420b7f62022-08-02 13:53:39 -0700122export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk17/$plat-$platform_suffix"
Aurimas Liutikas4b897cb2019-10-14 13:25:08 -0700123export JAVA_TOOLS_JAR="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86/lib/tools.jar"
124export STUDIO_GRADLE_JDK=$JAVA_HOME
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -0500125
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700126# Warn developers if they try to build top level project without the full checkout
Alan Viverette6b2fb212022-10-17 17:11:29 +0000127[ ! -d "$JAVA_HOME" ] && echo "Failed to find: $JAVA_HOME
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700128
Alan Viverette6b2fb212022-10-17 17:11:29 +0000129Typically, this means either:
1301. You are using the standalone AndroidX checkout, e.g. GitHub, which only supports
131 building a subset of projects. See CONTRIBUTING.md for details.
1322. You are using the repo checkout, but the last repo sync failed. Use repo status
133 to check for projects which are partially-synced, e.g. showing ***NO BRANCH***." && exit -1
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700134
Jeff Gaston79a43f22019-04-09 16:19:12 -0400135# ----------------------------------------------------------------------------
136
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700137# Determine the Java command to use to start the JVM.
138if [ -n "$JAVA_HOME" ] ; then
139 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
140 # IBM's JDK on AIX uses strange locations for the executables
141 JAVACMD="$JAVA_HOME/jre/sh/java"
142 else
143 JAVACMD="$JAVA_HOME/bin/java"
144 fi
145 if [ ! -x "$JAVACMD" ] ; then
146 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
147
148Please set the JAVA_HOME variable in your environment to match the
149location of your Java installation."
150 fi
151else
152 JAVACMD="java"
153 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
154
155Please set the JAVA_HOME variable in your environment to match the
156location of your Java installation."
157fi
158
159# Increase the maximum file descriptors if we can.
160if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
161 MAX_FD_LIMIT=`ulimit -H -n`
162 if [ $? -eq 0 ] ; then
163 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
164 MAX_FD="$MAX_FD_LIMIT"
165 fi
166 ulimit -n $MAX_FD
167 if [ $? -ne 0 ] ; then
168 warn "Could not set maximum file descriptor limit: $MAX_FD"
169 fi
170 else
171 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
172 fi
173fi
174
175# For Darwin, add options to specify how the application appears in the dock
176if $darwin; then
177 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
178fi
179
180# For Cygwin, switch paths to Windows format before running java
181if $cygwin ; then
182 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
183 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700184 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700185
186 # We build the pattern for arguments to be converted via cygpath
187 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
188 SEP=""
189 for dir in $ROOTDIRSRAW ; do
190 ROOTDIRS="$ROOTDIRS$SEP$dir"
191 SEP="|"
192 done
193 OURCYGPATTERN="(^($ROOTDIRS))"
194 # Add a user-defined pattern to the cygpath arguments
195 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
196 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
197 fi
198 # Now convert the arguments - kludge to limit ourselves to /bin/sh
199 i=0
200 for arg in "$@" ; do
201 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
202 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
203
204 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
205 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
206 else
207 eval `echo args$i`="\"$arg\""
208 fi
209 i=$((i+1))
210 done
211 case $i in
212 (0) set -- ;;
213 (1) set -- "$args0" ;;
214 (2) set -- "$args0" "$args1" ;;
215 (3) set -- "$args0" "$args1" "$args2" ;;
216 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
217 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
218 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
219 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
220 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
221 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
222 esac
223fi
224
225# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
226function splitJvmOpts() {
227 JVM_OPTS=("$@")
228}
229eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
230JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
231
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500232#TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed
233HOME_SYSTEM_PROPERTY_ARGUMENT=""
234if [ "$GRADLE_USER_HOME" != "" ]; then
235 HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME"
236fi
Jeff Gaston38004a62019-12-11 15:43:10 -0500237if [ "$TMPDIR" != "" ]; then
238 TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR"
239fi
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500240
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400241if [[ " ${@} " =~ " --clean " ]]; then
242 cleanCaches=true
243else
244 cleanCaches=false
245fi
246
Jeff Gaston794b0b72021-09-28 12:47:47 -0400247if [[ " ${@} " =~ " --no-ci " ]]; then
248 disableCi=true
249else
250 disableCi=false
251fi
252
Jeff Gaston829fd822021-09-23 11:42:48 -0400253# workaround for https://github.com/gradle/gradle/issues/18386
254if [[ " ${@} " =~ " --profile " ]]; then
255 mkdir -p reports
256fi
257
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500258# Expand some arguments
Jeff Gaston794b0b72021-09-28 12:47:47 -0400259for compact in "--ci" "--strict" "--clean" "--no-ci"; do
260 expanded=""
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500261 if [ "$compact" == "--ci" ]; then
Jeff Gaston794b0b72021-09-28 12:47:47 -0400262 if [ "$disableCi" == "false" ]; then
263 expanded="--strict\
264 --stacktrace\
265 -Pandroidx.summarizeStderr\
266 -Pandroidx.enableAffectedModuleDetection\
Jeff Gastoneeb07d32023-10-05 12:14:08 -0400267 --no-watch-fs\
268 -Pandroidx.highMemory"
Jeff Gaston794b0b72021-09-28 12:47:47 -0400269 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500270 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500271 if [ "$compact" == "--strict" ]; then
Aurimas Liutikas41c58e02022-06-09 08:54:18 -0700272 expanded="-Pandroidx.validateNoUnrecognizedMessages\
Jeff Gaston55624742021-04-22 14:05:49 -0400273 -Pandroidx.verifyUpToDate\
Aurimas Liutikasf06703b2022-07-08 16:28:11 +0000274 --no-watch-fs"
Jeff Gaston934d0b12022-04-26 17:47:25 -0400275 if [ "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "" ]; then
276 expanded="$expanded --offline"
277 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500278 fi
Jeff Gaston794b0b72021-09-28 12:47:47 -0400279 # if compact is something else then we parsed the argument above but
280 # still have to remove it (expanded == "") to avoid confusing Gradle
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500281
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400282 # check whether this particular compat argument was passed (and therefore needs expansion)
283 if [[ " ${@} " =~ " $compact " ]]; then
284 # Expand an individual argument
285 # Start by making a copy of our list of arguments and iterating through the copy
286 for arg in "$@"; do
287 # Remove this argument from our list of arguments.
288 # By the time we've completed this loop, we will have removed the original copy of
289 # each argument, and potentially re-added a new copy or an expansion of each.
290 shift
291 # Determine whether to expand this argument
292 if [ "$arg" == "$compact" ]; then
293 # Add the expansion to our arguments
294 set -- "$@" $expanded
295 if [ "$expanded" != "" ]; then
296 echo "gradlew expanded '$compact' into '$expanded'"
297 echo
298 fi
299 # We avoid re-adding this argument itself back into the list for two reasons:
300 # 1. This argument might not be directly understood by Gradle
301 # 2. We want to enforce that all behaviors enabled by this flag can be toggled independently,
302 # so we don't want it to be easy to inadvertently check for the presence of this flag
303 # specifically
304 else
305 # Add this argument back into our arguments
306 set -- "$@" "$arg"
307 fi
308 done
309 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500310done
311
Jeff Gastoneeb07d32023-10-05 12:14:08 -0400312if [[ " ${@} " =~ " -Pandroidx.highMemory " ]]; then
313 #Set the initial heap size to match the max heap size,
314 #by replacing a string like "-Xmx1g" with one like "-Xms1g -Xmx1g"
315 MAX_MEM=32g
316 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s/-Xmx\([^ ]*\)/-Xms$MAX_MEM -Xmx$MAX_MEM/")"
317
318 # Increase the compiler cache size: b/260643754 . Remove when updating to JDK 20 ( https://bugs.openjdk.org/browse/JDK-8295724 )
319 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s|$| -XX:ReservedCodeCacheSize=576M|")"
320fi
321
Jeff Gastonb03b05a2022-04-11 11:41:59 -0400322# check whether the user has requested profiling via yourkit
323yourkitArgPrefix="androidx.profile.yourkitAgentPath"
324yourkitAgentPath=""
325if [[ " ${@}" =~ " -P$yourkitArgPrefix" ]]; then
326 for arg in "$@"; do
327 if echo "$arg" | grep "${yourkitArgPrefix}=" >/dev/null; then
328 yourkitAgentPath="$(echo "$arg" | sed "s/-P${yourkitArgPrefix}=//")"
329 fi
330 done
331 if [ "$yourkitAgentPath" == "" ]; then
332 echo "Error: $yourkitArgPrefix must be set to the path of the YourKit Java agent" >&2
333 exit 1
334 fi
335 if [ ! -e "$yourkitAgentPath" ]; then
336 echo "Error: $yourkitAgentPath does not exist" >&2
337 exit 1
338 fi
339 # add the agent to the path
340 export _JAVA_OPTIONS="$_JAVA_OPTIONS -agentpath:$yourkitAgentPath"
341 # add arguments
342 set -- "$@" --no-daemon --rerun-tasks
343
344 # lots of blank lines because these messages are important
345 echo
346 echo
347 echo
348 echo
349 echo
350 # suggest --clean
351 if [ "$cleanCaches" == "false" ]; then
352 echo "When setting $yourkitArgPrefix you may also want to pass --clean"
353 fi
354 COLOR_YELLOW="\u001B[33m"
355 COLOR_CLEAR="\u001B[0m"
356
357 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}"
358 echo
359 echo
360 echo
361 echo
362 echo
363fi
364
Jeff Gastond2806b32021-09-29 12:20:39 -0400365if [[ " ${@} " =~ " --scan " ]]; then
366 if [[ " ${@} " =~ " --offline " ]]; then
367 echo "--scan incompatible with --offline"
368 echo "you could try --no-ci"
369 exit 1
370 fi
371fi
372
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400373function removeCaches() {
374 rm -rf $SCRIPT_PATH/.gradle
375 rm -rf $SCRIPT_PATH/buildSrc/.gradle
376 rm -f $SCRIPT_PATH/local.properties
377 if [ "$GRADLE_USER_HOME" != "" ]; then
378 rm -rf "$GRADLE_USER_HOME"
379 else
380 rm -rf ~/.gradle
381 fi
Jeff Gaston829fd822021-09-23 11:42:48 -0400382 # https://github.com/gradle/gradle/issues/18386
383 rm -rf $SCRIPT_PATH/reports
Jeff Gaston96eb6012021-09-27 14:55:36 +0000384 rm -rf $SCRIPT_PATH/build
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400385 rm -rf $OUT_DIR
386}
387
Jeff Gaston6cca77e52023-08-07 11:10:17 -0400388# Move any preexisting build scan to make room for a new one
389# After moving a build scan several times it eventually gets deleted
390function rotateBuildScans() {
391 filePrefix="$1"
392 iPlus1="10"
393 for i in $(seq 9 -1 1); do
394 mv "${filePrefix}.${i}.zip" "${filePrefix}.${iPlus1}.zip" 2>/dev/null || true
395 iPlus1=$i
396 done
397 mv ${filePrefix}.zip "${filePrefix}.1.zip" 2>/dev/null || true
398}
399
Jeff Gaston224eb172020-01-09 12:31:47 -0500400function runGradle() {
Jeff Gaston41b90222020-08-18 11:09:55 -0400401 processOutput=false
Jeff Gastone4b4b872020-08-25 09:02:13 -0400402 if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then
Jeff Gaston41b90222020-08-18 11:09:55 -0400403 processOutput=true
404 fi
405 if [[ " ${@} " =~ " -Pandroidx.summarizeStderr " ]]; then
406 processOutput=true
407 fi
408 if [ "$processOutput" == "true" ]; then
409 wrapper="$SCRIPT_PATH/development/build_log_processor.sh"
410 else
411 wrapper=""
412 fi
Jeff Gaston3febf902021-03-16 11:23:15 -0400413
Jeff Gaston1e67a612021-11-24 13:31:10 -0500414 RETURN_VALUE=0
Aurimas Liutikas07c47d32023-08-03 15:46:39 -0700415 set -- "$@" -Dorg.gradle.projectcachedir="$OUT_DIR/gradle-project-cache"
Jeff Gastondc9c8cb2023-02-08 16:24:38 -0500416 # Disabled in Studio until these errors become shown (b/268380971) or computed more quickly (https://github.com/gradle/gradle/issues/23272)
417 if [[ " ${@} " =~ " --dependency-verification=" ]]; then
418 VERIFICATION_ARGUMENT="" # already specified by caller
419 else
420 VERIFICATION_ARGUMENT=--dependency-verification=strict
421 fi
Aurimas Liutikas07c47d32023-08-03 15:46:39 -0700422 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 Gaston1e67a612021-11-24 13:31:10 -0500423 RETURN_VALUE=0
Jeff Gaston224eb172020-01-09 12:31:47 -0500424 else
425 # Print AndroidX-specific help message if build fails
426 # Have to do this build-failure detection in gradlew rather than in build.gradle
427 # so that this message still prints even if buildSrc itself fails
428 echo
Jeff Gaston61cef332020-12-22 11:23:09 -0500429 echo For help with unexpected failures, see development/diagnose-build-failure/README.md
430 echo
Jeff Gaston1e67a612021-11-24 13:31:10 -0500431 RETURN_VALUE=1
Jeff Gaston69713292020-06-04 12:53:39 -0400432 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500433
434 # If the caller specified where to save data, then also save the build scan data
435 if [ "$DIST_DIR" != "" ]; then
436 if [ "$GRADLE_USER_HOME" != "" ]; then
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400437 scanDir="$GRADLE_USER_HOME/build-scan-data"
438 if [ -e "$scanDir" ]; then
439 if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
Jeff Gaston6cca77e52023-08-07 11:10:17 -0400440 zipPrefix="$DIST_DIR/scan-up-to-date"
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400441 else
Jeff Gaston6cca77e52023-08-07 11:10:17 -0400442 zipPrefix="$DIST_DIR/scan"
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400443 fi
Jeff Gaston6cca77e52023-08-07 11:10:17 -0400444 rotateBuildScans "$zipPrefix"
445 zipPath="${zipPrefix}.zip"
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400446 cd "$GRADLE_USER_HOME/build-scan-data"
447 zip -q -r "$zipPath" .
448 cd -
Jeff Gaston1e67a612021-11-24 13:31:10 -0500449 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500450 fi
451 fi
452 return $RETURN_VALUE
Jeff Gaston69713292020-06-04 12:53:39 -0400453}
454
Jeff Gaston87a4bbb2022-04-21 12:31:08 -0400455if [ "$cleanCaches" == true ]; then
456 echo "IF ./gradlew --clean FIXES YOUR BUILD; OPEN A BUG."
457 echo "In nearly all cases, it should not be necessary to run a clean build."
458 echo
459 # 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
460 # another case where it is convenient to have a clean build is for performance testing
461 # 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)
462
463 echo "Stopping Gradle daemons"
464 runGradle --stop || true
465 echo
466
467 backupDir=~/androidx-build-state-backup
468 ./development/diagnose-build-failure/impl/backup-state.sh "$backupDir" --move # prints that it is saving state into this dir"
469
470 echo "To restore this state later, run:"
471 echo
472 echo " ./development/diagnose-build-failure/impl/restore-state.sh $backupDir"
473 echo
474 echo "Running Gradle"
475 echo
476fi
477
Jeff Gaston7121d832022-06-08 13:36:50 -0400478if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
479 echo "Setting 'DISALLOW_TASK_EXECUTION' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?"
Jeff Gaston400ccb32020-06-08 16:44:58 -0400480 echo "See TaskUpToDateValidator.java for more information"
481 exit 1
482fi
483
Jeff Gaston55624742021-04-22 14:05:49 -0400484runGradle "$@"
485# Check whether we were given the "-Pandroidx.verifyUpToDate" argument
486if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then
Jeff Gastoncefdeae2020-03-09 13:12:35 -0400487 # Re-run Gradle, and find all tasks that are unexpectly out of date
Jeff Gaston7121d832022-06-08 13:36:50 -0400488 if ! DISALLOW_TASK_EXECUTION=true runGradle "$@" --continue; then
Jeff Gastone906e5c2020-11-05 12:33:10 -0500489 echo >&2
Jeff Gaston20f5e7a2022-01-27 13:39:25 -0500490 echo "TaskUpToDateValidator's second build failed. To reproduce, try running './gradlew -Pandroidx.verifyUpToDate <failing tasks>'" >&2
Jeff Gastone906e5c2020-11-05 12:33:10 -0500491 exit 1
492 fi
Jeff Gastonb89c82b2019-08-21 16:24:09 -0400493fi