blob: 9b54b573a78cd9d37dfb49756367a9453caecb7a [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 export LINT_PRINT_STACKTRACE=true
30
Jeff Gastone72d2302019-12-19 18:32:31 -050031 #Set the initial heap size to match the max heap size,
32 #by replacing a string like "-Xmx1g" with one like "-Xms1g -Xmx1g"
Jeff Gaston77bb2b12021-04-15 12:51:08 -040033 MAX_MEM=24g
Jeff Gastoncca984c2020-10-05 12:54:17 -040034 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s/-Xmx\([^ ]*\)/-Xms$MAX_MEM -Xmx$MAX_MEM/")"
Jeff Gaston440e1ac2020-09-09 08:32:22 -040035
36 # tell Gradle where to put a heap dump on failure
37 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s|$| -XX:HeapDumpPath=$DIST_DIR|")"
Jeff Gastone72d2302019-12-19 18:32:31 -050038
Jeff Gaston8b7f1ee2022-12-08 14:26:54 -050039 # Increase the compiler cache size: b/260643754 . Remove when updating to JDK 20 ( https://bugs.openjdk.org/browse/JDK-8295724 )
40 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s|$| -XX:ReservedCodeCacheSize=576M|")"
41
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040042 # We don't set a default DIST_DIR in an else clause here because Studio doesn't use gradlew
43 # and doesn't set DIST_DIR and we want gradlew and Studio to match
44fi
45
Jeff Gastonc21ecb32020-11-05 17:16:35 -050046# unset ANDROID_BUILD_TOP so that Lint doesn't think we're building the platform itself
47unset ANDROID_BUILD_TOP
Aurimas Liutikas9979d072018-03-13 15:38:56 -070048# ----------------------------------------------------------------------------
49
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070050# 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 -070051
Jeff Gastonc6df4152021-11-03 10:24:02 -040052if [[ " ${@} " =~ " -PupdateLintBaseline " ]]; then
53 # remove when b/188666845 is complete
54 # Inform lint to not fail even when creating a baseline file
55 JAVA_OPTS="$JAVA_OPTS -Dlint.baselines.continue=true"
56fi
57
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070058APP_NAME="Gradle"
59APP_BASE_NAME=`basename "$0"`
60
61# Use the maximum available, or set MAX_FD != -1 to use that value.
62MAX_FD="maximum"
63
64warn ( ) {
65 echo "$*"
66}
67
68die ( ) {
69 echo
70 echo "$*"
71 echo
72 exit 1
73}
74
75# OS specific support (must be 'true' or 'false').
76cygwin=false
77msys=false
78darwin=false
79case "`uname`" in
80 CYGWIN* )
81 cygwin=true
82 ;;
83 Darwin* )
84 darwin=true
85 ;;
86 MINGW* )
87 msys=true
88 ;;
89esac
Rahul Ravikumar465ccfc2022-02-14 14:58:20 -080090platform_suffix="x86"
91case "$(arch)" in
92 arm64* )
93 platform_suffix="arm64"
94esac
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070095# Attempt to set APP_HOME
96# Resolve links: $0 may be a link
97PRG="$0"
98# Need this for relative symlinks.
99while [ -h "$PRG" ] ; do
100 ls=`ls -ld "$PRG"`
101 link=`expr "$ls" : '.*-> \(.*\)$'`
102 if expr "$link" : '/.*' > /dev/null; then
103 PRG="$link"
104 else
105 PRG=`dirname "$PRG"`"/$link"
106 fi
107done
108SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700109cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700110APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700111cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700112
113CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
114
Jeff Gaston79a43f22019-04-09 16:19:12 -0400115# --------- androidx specific code needed for lint and java. ------------------
116
Alan Viveretted38b36c2017-02-01 16:45:31 -0500117# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -0500118if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -0500119 plat="darwin"
120else
121 plat="linux"
122fi
Alan Viveretted38b36c2017-02-01 16:45:31 -0500123
Matthew Fraschilla6ab84fc32019-11-21 16:40:16 -0800124# Tests for lint checks default to using sdk defined by this variable. This removes a lot of
125# setup from each lint module.
126export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +0000127# override JAVA_HOME, because CI machines have it and it points to very old JDK
Aurimas Liutikas420b7f62022-08-02 13:53:39 -0700128export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk17/$plat-$platform_suffix"
Aurimas Liutikas4b897cb2019-10-14 13:25:08 -0700129export JAVA_TOOLS_JAR="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86/lib/tools.jar"
130export STUDIO_GRADLE_JDK=$JAVA_HOME
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -0500131
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700132# Warn developers if they try to build top level project without the full checkout
Alan Viverette6b2fb212022-10-17 17:11:29 +0000133[ ! -d "$JAVA_HOME" ] && echo "Failed to find: $JAVA_HOME
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700134
Alan Viverette6b2fb212022-10-17 17:11:29 +0000135Typically, this means either:
1361. You are using the standalone AndroidX checkout, e.g. GitHub, which only supports
137 building a subset of projects. See CONTRIBUTING.md for details.
1382. You are using the repo checkout, but the last repo sync failed. Use repo status
139 to check for projects which are partially-synced, e.g. showing ***NO BRANCH***." && exit -1
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700140
Jeff Gaston79a43f22019-04-09 16:19:12 -0400141# ----------------------------------------------------------------------------
142
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700143# Determine the Java command to use to start the JVM.
144if [ -n "$JAVA_HOME" ] ; then
145 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
146 # IBM's JDK on AIX uses strange locations for the executables
147 JAVACMD="$JAVA_HOME/jre/sh/java"
148 else
149 JAVACMD="$JAVA_HOME/bin/java"
150 fi
151 if [ ! -x "$JAVACMD" ] ; then
152 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
153
154Please set the JAVA_HOME variable in your environment to match the
155location of your Java installation."
156 fi
157else
158 JAVACMD="java"
159 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
160
161Please set the JAVA_HOME variable in your environment to match the
162location of your Java installation."
163fi
164
165# Increase the maximum file descriptors if we can.
166if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
167 MAX_FD_LIMIT=`ulimit -H -n`
168 if [ $? -eq 0 ] ; then
169 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
170 MAX_FD="$MAX_FD_LIMIT"
171 fi
172 ulimit -n $MAX_FD
173 if [ $? -ne 0 ] ; then
174 warn "Could not set maximum file descriptor limit: $MAX_FD"
175 fi
176 else
177 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
178 fi
179fi
180
181# For Darwin, add options to specify how the application appears in the dock
182if $darwin; then
183 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
184fi
185
186# For Cygwin, switch paths to Windows format before running java
187if $cygwin ; then
188 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
189 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700190 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700191
192 # We build the pattern for arguments to be converted via cygpath
193 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
194 SEP=""
195 for dir in $ROOTDIRSRAW ; do
196 ROOTDIRS="$ROOTDIRS$SEP$dir"
197 SEP="|"
198 done
199 OURCYGPATTERN="(^($ROOTDIRS))"
200 # Add a user-defined pattern to the cygpath arguments
201 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
202 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
203 fi
204 # Now convert the arguments - kludge to limit ourselves to /bin/sh
205 i=0
206 for arg in "$@" ; do
207 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
208 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
209
210 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
211 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
212 else
213 eval `echo args$i`="\"$arg\""
214 fi
215 i=$((i+1))
216 done
217 case $i in
218 (0) set -- ;;
219 (1) set -- "$args0" ;;
220 (2) set -- "$args0" "$args1" ;;
221 (3) set -- "$args0" "$args1" "$args2" ;;
222 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
223 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
224 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
225 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
226 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
227 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
228 esac
229fi
230
231# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
232function splitJvmOpts() {
233 JVM_OPTS=("$@")
234}
235eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
236JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
237
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500238#TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed
239HOME_SYSTEM_PROPERTY_ARGUMENT=""
240if [ "$GRADLE_USER_HOME" != "" ]; then
241 HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME"
242fi
Jeff Gaston38004a62019-12-11 15:43:10 -0500243if [ "$TMPDIR" != "" ]; then
244 TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR"
245fi
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500246
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400247if [[ " ${@} " =~ " --clean " ]]; then
248 cleanCaches=true
249else
250 cleanCaches=false
251fi
252
Jeff Gaston794b0b72021-09-28 12:47:47 -0400253if [[ " ${@} " =~ " --no-ci " ]]; then
254 disableCi=true
255else
256 disableCi=false
257fi
258
Jeff Gaston829fd822021-09-23 11:42:48 -0400259# workaround for https://github.com/gradle/gradle/issues/18386
260if [[ " ${@} " =~ " --profile " ]]; then
261 mkdir -p reports
262fi
263
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500264# Expand some arguments
Jeff Gaston794b0b72021-09-28 12:47:47 -0400265for compact in "--ci" "--strict" "--clean" "--no-ci"; do
266 expanded=""
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500267 if [ "$compact" == "--ci" ]; then
Jeff Gaston794b0b72021-09-28 12:47:47 -0400268 if [ "$disableCi" == "false" ]; then
269 expanded="--strict\
270 --stacktrace\
271 -Pandroidx.summarizeStderr\
272 -Pandroidx.enableAffectedModuleDetection\
273 --no-watch-fs"
274 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500275 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500276 if [ "$compact" == "--strict" ]; then
Aurimas Liutikas41c58e02022-06-09 08:54:18 -0700277 expanded="-Pandroidx.validateNoUnrecognizedMessages\
Jeff Gaston55624742021-04-22 14:05:49 -0400278 -Pandroidx.verifyUpToDate\
Aurimas Liutikasf06703b2022-07-08 16:28:11 +0000279 --no-watch-fs"
Jeff Gaston934d0b12022-04-26 17:47:25 -0400280 if [ "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "" ]; then
281 expanded="$expanded --offline"
282 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500283 fi
Jeff Gaston794b0b72021-09-28 12:47:47 -0400284 # if compact is something else then we parsed the argument above but
285 # still have to remove it (expanded == "") to avoid confusing Gradle
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500286
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400287 # check whether this particular compat argument was passed (and therefore needs expansion)
288 if [[ " ${@} " =~ " $compact " ]]; then
289 # Expand an individual argument
290 # Start by making a copy of our list of arguments and iterating through the copy
291 for arg in "$@"; do
292 # Remove this argument from our list of arguments.
293 # By the time we've completed this loop, we will have removed the original copy of
294 # each argument, and potentially re-added a new copy or an expansion of each.
295 shift
296 # Determine whether to expand this argument
297 if [ "$arg" == "$compact" ]; then
298 # Add the expansion to our arguments
299 set -- "$@" $expanded
300 if [ "$expanded" != "" ]; then
301 echo "gradlew expanded '$compact' into '$expanded'"
302 echo
303 fi
304 # We avoid re-adding this argument itself back into the list for two reasons:
305 # 1. This argument might not be directly understood by Gradle
306 # 2. We want to enforce that all behaviors enabled by this flag can be toggled independently,
307 # so we don't want it to be easy to inadvertently check for the presence of this flag
308 # specifically
309 else
310 # Add this argument back into our arguments
311 set -- "$@" "$arg"
312 fi
313 done
314 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500315done
316
Jeff Gastonb03b05a2022-04-11 11:41:59 -0400317# check whether the user has requested profiling via yourkit
318yourkitArgPrefix="androidx.profile.yourkitAgentPath"
319yourkitAgentPath=""
320if [[ " ${@}" =~ " -P$yourkitArgPrefix" ]]; then
321 for arg in "$@"; do
322 if echo "$arg" | grep "${yourkitArgPrefix}=" >/dev/null; then
323 yourkitAgentPath="$(echo "$arg" | sed "s/-P${yourkitArgPrefix}=//")"
324 fi
325 done
326 if [ "$yourkitAgentPath" == "" ]; then
327 echo "Error: $yourkitArgPrefix must be set to the path of the YourKit Java agent" >&2
328 exit 1
329 fi
330 if [ ! -e "$yourkitAgentPath" ]; then
331 echo "Error: $yourkitAgentPath does not exist" >&2
332 exit 1
333 fi
334 # add the agent to the path
335 export _JAVA_OPTIONS="$_JAVA_OPTIONS -agentpath:$yourkitAgentPath"
336 # add arguments
337 set -- "$@" --no-daemon --rerun-tasks
338
339 # lots of blank lines because these messages are important
340 echo
341 echo
342 echo
343 echo
344 echo
345 # suggest --clean
346 if [ "$cleanCaches" == "false" ]; then
347 echo "When setting $yourkitArgPrefix you may also want to pass --clean"
348 fi
349 COLOR_YELLOW="\u001B[33m"
350 COLOR_CLEAR="\u001B[0m"
351
352 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}"
353 echo
354 echo
355 echo
356 echo
357 echo
358fi
359
Jeff Gastond2806b32021-09-29 12:20:39 -0400360if [[ " ${@} " =~ " --scan " ]]; then
361 if [[ " ${@} " =~ " --offline " ]]; then
362 echo "--scan incompatible with --offline"
363 echo "you could try --no-ci"
364 exit 1
365 fi
366fi
367
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400368function removeCaches() {
369 rm -rf $SCRIPT_PATH/.gradle
370 rm -rf $SCRIPT_PATH/buildSrc/.gradle
371 rm -f $SCRIPT_PATH/local.properties
372 if [ "$GRADLE_USER_HOME" != "" ]; then
373 rm -rf "$GRADLE_USER_HOME"
374 else
375 rm -rf ~/.gradle
376 fi
Jeff Gaston829fd822021-09-23 11:42:48 -0400377 # https://github.com/gradle/gradle/issues/18386
378 rm -rf $SCRIPT_PATH/reports
Jeff Gaston96eb6012021-09-27 14:55:36 +0000379 rm -rf $SCRIPT_PATH/build
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400380 rm -rf $OUT_DIR
381}
382
Jeff Gaston224eb172020-01-09 12:31:47 -0500383function runGradle() {
Jeff Gaston41b90222020-08-18 11:09:55 -0400384 processOutput=false
Jeff Gastone4b4b872020-08-25 09:02:13 -0400385 if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then
Jeff Gaston41b90222020-08-18 11:09:55 -0400386 processOutput=true
387 fi
388 if [[ " ${@} " =~ " -Pandroidx.summarizeStderr " ]]; then
389 processOutput=true
390 fi
391 if [ "$processOutput" == "true" ]; then
392 wrapper="$SCRIPT_PATH/development/build_log_processor.sh"
393 else
394 wrapper=""
395 fi
Jeff Gaston3febf902021-03-16 11:23:15 -0400396
Jeff Gaston1e67a612021-11-24 13:31:10 -0500397 RETURN_VALUE=0
Jeff Gaston3febf902021-03-16 11:23:15 -0400398 PROJECT_CACHE_DIR_ARGUMENT="--project-cache-dir $OUT_DIR/gradle-project-cache"
399 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 Gaston1e67a612021-11-24 13:31:10 -0500400 RETURN_VALUE=0
Jeff Gaston224eb172020-01-09 12:31:47 -0500401 else
402 # Print AndroidX-specific help message if build fails
403 # Have to do this build-failure detection in gradlew rather than in build.gradle
404 # so that this message still prints even if buildSrc itself fails
405 echo
Jeff Gaston61cef332020-12-22 11:23:09 -0500406 echo For help with unexpected failures, see development/diagnose-build-failure/README.md
407 echo
Jeff Gaston1e67a612021-11-24 13:31:10 -0500408 RETURN_VALUE=1
Jeff Gaston69713292020-06-04 12:53:39 -0400409 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500410
411 # If the caller specified where to save data, then also save the build scan data
412 if [ "$DIST_DIR" != "" ]; then
413 if [ "$GRADLE_USER_HOME" != "" ]; then
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400414 scanDir="$GRADLE_USER_HOME/build-scan-data"
415 if [ -e "$scanDir" ]; then
416 if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
417 zipPath="$DIST_DIR/scan-up-to-date.zip"
418 else
419 zipPath="$DIST_DIR/scan.zip"
420 fi
421 rm -f "$zipPath"
422 cd "$GRADLE_USER_HOME/build-scan-data"
423 zip -q -r "$zipPath" .
424 cd -
Jeff Gaston1e67a612021-11-24 13:31:10 -0500425 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500426 fi
427 fi
428 return $RETURN_VALUE
Jeff Gaston69713292020-06-04 12:53:39 -0400429}
430
Jeff Gaston87a4bbb2022-04-21 12:31:08 -0400431if [ "$cleanCaches" == true ]; then
432 echo "IF ./gradlew --clean FIXES YOUR BUILD; OPEN A BUG."
433 echo "In nearly all cases, it should not be necessary to run a clean build."
434 echo
435 # 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
436 # another case where it is convenient to have a clean build is for performance testing
437 # 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)
438
439 echo "Stopping Gradle daemons"
440 runGradle --stop || true
441 echo
442
443 backupDir=~/androidx-build-state-backup
444 ./development/diagnose-build-failure/impl/backup-state.sh "$backupDir" --move # prints that it is saving state into this dir"
445
446 echo "To restore this state later, run:"
447 echo
448 echo " ./development/diagnose-build-failure/impl/restore-state.sh $backupDir"
449 echo
450 echo "Running Gradle"
451 echo
452fi
453
Jeff Gaston7121d832022-06-08 13:36:50 -0400454if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
455 echo "Setting 'DISALLOW_TASK_EXECUTION' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?"
Jeff Gaston400ccb32020-06-08 16:44:58 -0400456 echo "See TaskUpToDateValidator.java for more information"
457 exit 1
458fi
459
Jeff Gaston55624742021-04-22 14:05:49 -0400460runGradle "$@"
461# Check whether we were given the "-Pandroidx.verifyUpToDate" argument
462if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then
Jeff Gastoncefdeae2020-03-09 13:12:35 -0400463 # Re-run Gradle, and find all tasks that are unexpectly out of date
Jeff Gaston7121d832022-06-08 13:36:50 -0400464 if ! DISALLOW_TASK_EXECUTION=true runGradle "$@" --continue; then
Jeff Gastone906e5c2020-11-05 12:33:10 -0500465 echo >&2
Jeff Gaston20f5e7a2022-01-27 13:39:25 -0500466 echo "TaskUpToDateValidator's second build failed. To reproduce, try running './gradlew -Pandroidx.verifyUpToDate <failing tasks>'" >&2
Jeff Gastone906e5c2020-11-05 12:33:10 -0500467 exit 1
468 fi
Jeff Gastonb89c82b2019-08-21 16:24:09 -0400469fi