blob: f3028890b2c5eb4229c54e31aac7ef6a9449b01f [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 Gaston0e3d19a2019-10-02 12:17:39 -040039 # We don't set a default DIST_DIR in an else clause here because Studio doesn't use gradlew
40 # and doesn't set DIST_DIR and we want gradlew and Studio to match
41fi
42
Jeff Gastonc21ecb32020-11-05 17:16:35 -050043# unset ANDROID_BUILD_TOP so that Lint doesn't think we're building the platform itself
44unset ANDROID_BUILD_TOP
Aurimas Liutikas9979d072018-03-13 15:38:56 -070045# ----------------------------------------------------------------------------
46
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070047# 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 -070048
Jeff Gastonc6df4152021-11-03 10:24:02 -040049if [[ " ${@} " =~ " -PupdateLintBaseline " ]]; then
50 # remove when b/188666845 is complete
51 # Inform lint to not fail even when creating a baseline file
52 JAVA_OPTS="$JAVA_OPTS -Dlint.baselines.continue=true"
53fi
54
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070055APP_NAME="Gradle"
56APP_BASE_NAME=`basename "$0"`
57
58# Use the maximum available, or set MAX_FD != -1 to use that value.
59MAX_FD="maximum"
60
61warn ( ) {
62 echo "$*"
63}
64
65die ( ) {
66 echo
67 echo "$*"
68 echo
69 exit 1
70}
71
72# OS specific support (must be 'true' or 'false').
73cygwin=false
74msys=false
75darwin=false
76case "`uname`" in
77 CYGWIN* )
78 cygwin=true
79 ;;
80 Darwin* )
81 darwin=true
82 ;;
83 MINGW* )
84 msys=true
85 ;;
86esac
Rahul Ravikumar465ccfc2022-02-14 14:58:20 -080087platform_suffix="x86"
88case "$(arch)" in
89 arm64* )
90 platform_suffix="arm64"
91esac
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070092# Attempt to set APP_HOME
93# Resolve links: $0 may be a link
94PRG="$0"
95# Need this for relative symlinks.
96while [ -h "$PRG" ] ; do
97 ls=`ls -ld "$PRG"`
98 link=`expr "$ls" : '.*-> \(.*\)$'`
99 if expr "$link" : '/.*' > /dev/null; then
100 PRG="$link"
101 else
102 PRG=`dirname "$PRG"`"/$link"
103 fi
104done
105SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700106cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700107APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700108cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700109
110CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
111
Jeff Gaston79a43f22019-04-09 16:19:12 -0400112# --------- androidx specific code needed for lint and java. ------------------
113
Alan Viveretted38b36c2017-02-01 16:45:31 -0500114# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -0500115if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -0500116 plat="darwin"
117else
118 plat="linux"
119fi
Alan Viveretted38b36c2017-02-01 16:45:31 -0500120
Matthew Fraschilla6ab84fc32019-11-21 16:40:16 -0800121# Tests for lint checks default to using sdk defined by this variable. This removes a lot of
122# setup from each lint module.
123export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +0000124# override JAVA_HOME, because CI machines have it and it points to very old JDK
Aurimas Liutikas420b7f62022-08-02 13:53:39 -0700125export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk17/$plat-$platform_suffix"
Aurimas Liutikas4b897cb2019-10-14 13:25:08 -0700126export JAVA_TOOLS_JAR="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86/lib/tools.jar"
127export STUDIO_GRADLE_JDK=$JAVA_HOME
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -0500128
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700129# Warn developers if they try to build top level project without the full checkout
Alan Viverette6b2fb212022-10-17 17:11:29 +0000130[ ! -d "$JAVA_HOME" ] && echo "Failed to find: $JAVA_HOME
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700131
Alan Viverette6b2fb212022-10-17 17:11:29 +0000132Typically, this means either:
1331. You are using the standalone AndroidX checkout, e.g. GitHub, which only supports
134 building a subset of projects. See CONTRIBUTING.md for details.
1352. You are using the repo checkout, but the last repo sync failed. Use repo status
136 to check for projects which are partially-synced, e.g. showing ***NO BRANCH***." && exit -1
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700137
Jeff Gaston79a43f22019-04-09 16:19:12 -0400138# ----------------------------------------------------------------------------
139
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700140# Determine the Java command to use to start the JVM.
141if [ -n "$JAVA_HOME" ] ; then
142 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 # IBM's JDK on AIX uses strange locations for the executables
144 JAVACMD="$JAVA_HOME/jre/sh/java"
145 else
146 JAVACMD="$JAVA_HOME/bin/java"
147 fi
148 if [ ! -x "$JAVACMD" ] ; then
149 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
150
151Please set the JAVA_HOME variable in your environment to match the
152location of your Java installation."
153 fi
154else
155 JAVACMD="java"
156 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
157
158Please set the JAVA_HOME variable in your environment to match the
159location of your Java installation."
160fi
161
162# Increase the maximum file descriptors if we can.
163if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
164 MAX_FD_LIMIT=`ulimit -H -n`
165 if [ $? -eq 0 ] ; then
166 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
167 MAX_FD="$MAX_FD_LIMIT"
168 fi
169 ulimit -n $MAX_FD
170 if [ $? -ne 0 ] ; then
171 warn "Could not set maximum file descriptor limit: $MAX_FD"
172 fi
173 else
174 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
175 fi
176fi
177
178# For Darwin, add options to specify how the application appears in the dock
179if $darwin; then
180 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
181fi
182
183# For Cygwin, switch paths to Windows format before running java
184if $cygwin ; then
185 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
186 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700187 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700188
189 # We build the pattern for arguments to be converted via cygpath
190 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
191 SEP=""
192 for dir in $ROOTDIRSRAW ; do
193 ROOTDIRS="$ROOTDIRS$SEP$dir"
194 SEP="|"
195 done
196 OURCYGPATTERN="(^($ROOTDIRS))"
197 # Add a user-defined pattern to the cygpath arguments
198 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
199 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
200 fi
201 # Now convert the arguments - kludge to limit ourselves to /bin/sh
202 i=0
203 for arg in "$@" ; do
204 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
205 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
206
207 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
208 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
209 else
210 eval `echo args$i`="\"$arg\""
211 fi
212 i=$((i+1))
213 done
214 case $i in
215 (0) set -- ;;
216 (1) set -- "$args0" ;;
217 (2) set -- "$args0" "$args1" ;;
218 (3) set -- "$args0" "$args1" "$args2" ;;
219 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
220 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
221 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
222 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
223 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
224 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
225 esac
226fi
227
228# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
229function splitJvmOpts() {
230 JVM_OPTS=("$@")
231}
232eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
233JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
234
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500235#TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed
236HOME_SYSTEM_PROPERTY_ARGUMENT=""
237if [ "$GRADLE_USER_HOME" != "" ]; then
238 HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME"
239fi
Jeff Gaston38004a62019-12-11 15:43:10 -0500240if [ "$TMPDIR" != "" ]; then
241 TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR"
242fi
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500243
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400244if [[ " ${@} " =~ " --clean " ]]; then
245 cleanCaches=true
246else
247 cleanCaches=false
248fi
249
Jeff Gaston794b0b72021-09-28 12:47:47 -0400250if [[ " ${@} " =~ " --no-ci " ]]; then
251 disableCi=true
252else
253 disableCi=false
254fi
255
Jeff Gaston829fd822021-09-23 11:42:48 -0400256# workaround for https://github.com/gradle/gradle/issues/18386
257if [[ " ${@} " =~ " --profile " ]]; then
258 mkdir -p reports
259fi
260
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500261# Expand some arguments
Jeff Gaston794b0b72021-09-28 12:47:47 -0400262for compact in "--ci" "--strict" "--clean" "--no-ci"; do
263 expanded=""
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500264 if [ "$compact" == "--ci" ]; then
Jeff Gaston794b0b72021-09-28 12:47:47 -0400265 if [ "$disableCi" == "false" ]; then
266 expanded="--strict\
267 --stacktrace\
268 -Pandroidx.summarizeStderr\
269 -Pandroidx.enableAffectedModuleDetection\
270 --no-watch-fs"
271 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500272 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500273 if [ "$compact" == "--strict" ]; then
Aurimas Liutikas41c58e02022-06-09 08:54:18 -0700274 expanded="-Pandroidx.validateNoUnrecognizedMessages\
Jeff Gaston55624742021-04-22 14:05:49 -0400275 -Pandroidx.verifyUpToDate\
Aurimas Liutikasf06703b2022-07-08 16:28:11 +0000276 --no-watch-fs"
Jeff Gaston934d0b12022-04-26 17:47:25 -0400277 if [ "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "" ]; then
278 expanded="$expanded --offline"
279 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500280 fi
Jeff Gaston794b0b72021-09-28 12:47:47 -0400281 # if compact is something else then we parsed the argument above but
282 # still have to remove it (expanded == "") to avoid confusing Gradle
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500283
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400284 # check whether this particular compat argument was passed (and therefore needs expansion)
285 if [[ " ${@} " =~ " $compact " ]]; then
286 # Expand an individual argument
287 # Start by making a copy of our list of arguments and iterating through the copy
288 for arg in "$@"; do
289 # Remove this argument from our list of arguments.
290 # By the time we've completed this loop, we will have removed the original copy of
291 # each argument, and potentially re-added a new copy or an expansion of each.
292 shift
293 # Determine whether to expand this argument
294 if [ "$arg" == "$compact" ]; then
295 # Add the expansion to our arguments
296 set -- "$@" $expanded
297 if [ "$expanded" != "" ]; then
298 echo "gradlew expanded '$compact' into '$expanded'"
299 echo
300 fi
301 # We avoid re-adding this argument itself back into the list for two reasons:
302 # 1. This argument might not be directly understood by Gradle
303 # 2. We want to enforce that all behaviors enabled by this flag can be toggled independently,
304 # so we don't want it to be easy to inadvertently check for the presence of this flag
305 # specifically
306 else
307 # Add this argument back into our arguments
308 set -- "$@" "$arg"
309 fi
310 done
311 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500312done
313
Jeff Gastonb03b05a2022-04-11 11:41:59 -0400314# check whether the user has requested profiling via yourkit
315yourkitArgPrefix="androidx.profile.yourkitAgentPath"
316yourkitAgentPath=""
317if [[ " ${@}" =~ " -P$yourkitArgPrefix" ]]; then
318 for arg in "$@"; do
319 if echo "$arg" | grep "${yourkitArgPrefix}=" >/dev/null; then
320 yourkitAgentPath="$(echo "$arg" | sed "s/-P${yourkitArgPrefix}=//")"
321 fi
322 done
323 if [ "$yourkitAgentPath" == "" ]; then
324 echo "Error: $yourkitArgPrefix must be set to the path of the YourKit Java agent" >&2
325 exit 1
326 fi
327 if [ ! -e "$yourkitAgentPath" ]; then
328 echo "Error: $yourkitAgentPath does not exist" >&2
329 exit 1
330 fi
331 # add the agent to the path
332 export _JAVA_OPTIONS="$_JAVA_OPTIONS -agentpath:$yourkitAgentPath"
333 # add arguments
334 set -- "$@" --no-daemon --rerun-tasks
335
336 # lots of blank lines because these messages are important
337 echo
338 echo
339 echo
340 echo
341 echo
342 # suggest --clean
343 if [ "$cleanCaches" == "false" ]; then
344 echo "When setting $yourkitArgPrefix you may also want to pass --clean"
345 fi
346 COLOR_YELLOW="\u001B[33m"
347 COLOR_CLEAR="\u001B[0m"
348
349 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}"
350 echo
351 echo
352 echo
353 echo
354 echo
355fi
356
Jeff Gastond2806b32021-09-29 12:20:39 -0400357if [[ " ${@} " =~ " --scan " ]]; then
358 if [[ " ${@} " =~ " --offline " ]]; then
359 echo "--scan incompatible with --offline"
360 echo "you could try --no-ci"
361 exit 1
362 fi
363fi
364
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400365function removeCaches() {
366 rm -rf $SCRIPT_PATH/.gradle
367 rm -rf $SCRIPT_PATH/buildSrc/.gradle
368 rm -f $SCRIPT_PATH/local.properties
369 if [ "$GRADLE_USER_HOME" != "" ]; then
370 rm -rf "$GRADLE_USER_HOME"
371 else
372 rm -rf ~/.gradle
373 fi
Jeff Gaston829fd822021-09-23 11:42:48 -0400374 # https://github.com/gradle/gradle/issues/18386
375 rm -rf $SCRIPT_PATH/reports
Jeff Gaston96eb6012021-09-27 14:55:36 +0000376 rm -rf $SCRIPT_PATH/build
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400377 rm -rf $OUT_DIR
378}
379
Jeff Gaston224eb172020-01-09 12:31:47 -0500380function runGradle() {
Jeff Gaston41b90222020-08-18 11:09:55 -0400381 processOutput=false
Jeff Gastone4b4b872020-08-25 09:02:13 -0400382 if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then
Jeff Gaston41b90222020-08-18 11:09:55 -0400383 processOutput=true
384 fi
385 if [[ " ${@} " =~ " -Pandroidx.summarizeStderr " ]]; then
386 processOutput=true
387 fi
388 if [ "$processOutput" == "true" ]; then
389 wrapper="$SCRIPT_PATH/development/build_log_processor.sh"
390 else
391 wrapper=""
392 fi
Jeff Gaston3febf902021-03-16 11:23:15 -0400393
Jeff Gaston1e67a612021-11-24 13:31:10 -0500394 RETURN_VALUE=0
Jeff Gaston3febf902021-03-16 11:23:15 -0400395 PROJECT_CACHE_DIR_ARGUMENT="--project-cache-dir $OUT_DIR/gradle-project-cache"
396 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 -0500397 RETURN_VALUE=0
Jeff Gaston224eb172020-01-09 12:31:47 -0500398 else
399 # Print AndroidX-specific help message if build fails
400 # Have to do this build-failure detection in gradlew rather than in build.gradle
401 # so that this message still prints even if buildSrc itself fails
402 echo
Jeff Gaston61cef332020-12-22 11:23:09 -0500403 echo For help with unexpected failures, see development/diagnose-build-failure/README.md
404 echo
Jeff Gaston1e67a612021-11-24 13:31:10 -0500405 RETURN_VALUE=1
Jeff Gaston69713292020-06-04 12:53:39 -0400406 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500407
408 # If the caller specified where to save data, then also save the build scan data
409 if [ "$DIST_DIR" != "" ]; then
410 if [ "$GRADLE_USER_HOME" != "" ]; then
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400411 scanDir="$GRADLE_USER_HOME/build-scan-data"
412 if [ -e "$scanDir" ]; then
413 if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
414 zipPath="$DIST_DIR/scan-up-to-date.zip"
415 else
416 zipPath="$DIST_DIR/scan.zip"
417 fi
418 rm -f "$zipPath"
419 cd "$GRADLE_USER_HOME/build-scan-data"
420 zip -q -r "$zipPath" .
421 cd -
Jeff Gaston1e67a612021-11-24 13:31:10 -0500422 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500423 fi
424 fi
425 return $RETURN_VALUE
Jeff Gaston69713292020-06-04 12:53:39 -0400426}
427
Jeff Gaston87a4bbb2022-04-21 12:31:08 -0400428if [ "$cleanCaches" == true ]; then
429 echo "IF ./gradlew --clean FIXES YOUR BUILD; OPEN A BUG."
430 echo "In nearly all cases, it should not be necessary to run a clean build."
431 echo
432 # 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
433 # another case where it is convenient to have a clean build is for performance testing
434 # 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)
435
436 echo "Stopping Gradle daemons"
437 runGradle --stop || true
438 echo
439
440 backupDir=~/androidx-build-state-backup
441 ./development/diagnose-build-failure/impl/backup-state.sh "$backupDir" --move # prints that it is saving state into this dir"
442
443 echo "To restore this state later, run:"
444 echo
445 echo " ./development/diagnose-build-failure/impl/restore-state.sh $backupDir"
446 echo
447 echo "Running Gradle"
448 echo
449fi
450
Jeff Gaston7121d832022-06-08 13:36:50 -0400451if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
452 echo "Setting 'DISALLOW_TASK_EXECUTION' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?"
Jeff Gaston400ccb32020-06-08 16:44:58 -0400453 echo "See TaskUpToDateValidator.java for more information"
454 exit 1
455fi
456
Jeff Gaston55624742021-04-22 14:05:49 -0400457runGradle "$@"
458# Check whether we were given the "-Pandroidx.verifyUpToDate" argument
459if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then
Jeff Gastoncefdeae2020-03-09 13:12:35 -0400460 # Re-run Gradle, and find all tasks that are unexpectly out of date
Jeff Gaston7121d832022-06-08 13:36:50 -0400461 if ! DISALLOW_TASK_EXECUTION=true runGradle "$@" --continue; then
Jeff Gastone906e5c2020-11-05 12:33:10 -0500462 echo >&2
Jeff Gaston20f5e7a2022-01-27 13:39:25 -0500463 echo "TaskUpToDateValidator's second build failed. To reproduce, try running './gradlew -Pandroidx.verifyUpToDate <failing tasks>'" >&2
Jeff Gastone906e5c2020-11-05 12:33:10 -0500464 exit 1
465 fi
Jeff Gastonb89c82b2019-08-21 16:24:09 -0400466fi