blob: d4e9c09062f50a45df3ef55dcb55136be55eac91 [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 Gastone72d2302019-12-19 18:32:31 -050030 #Set the initial heap size to match the max heap size,
31 #by replacing a string like "-Xmx1g" with one like "-Xms1g -Xmx1g"
Jeff Gaston77bb2b12021-04-15 12:51:08 -040032 MAX_MEM=24g
Jeff Gastoncca984c2020-10-05 12:54:17 -040033 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s/-Xmx\([^ ]*\)/-Xms$MAX_MEM -Xmx$MAX_MEM/")"
Jeff Gaston440e1ac2020-09-09 08:32:22 -040034
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 Gastone72d2302019-12-19 18:32:31 -050037
Jeff Gaston8b7f1ee2022-12-08 14:26:54 -050038 # Increase the compiler cache size: b/260643754 . Remove when updating to JDK 20 ( https://bugs.openjdk.org/browse/JDK-8295724 )
39 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s|$| -XX:ReservedCodeCacheSize=576M|")"
40
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040041 # We don't set a default DIST_DIR in an else clause here because Studio doesn't use gradlew
42 # and doesn't set DIST_DIR and we want gradlew and Studio to match
43fi
44
Alan Viverette9d651362023-03-23 12:34:03 -040045# Loading the AIDL lexer requires disabling Lint's bytecode verification
46export ANDROID_LINT_SKIP_BYTECODE_VERIFIER=true
47
Jeff Gastonc21ecb32020-11-05 17:16:35 -050048# unset ANDROID_BUILD_TOP so that Lint doesn't think we're building the platform itself
49unset ANDROID_BUILD_TOP
Aurimas Liutikas9979d072018-03-13 15:38:56 -070050# ----------------------------------------------------------------------------
51
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070052# 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 -070053
Jeff Gastonc6df4152021-11-03 10:24:02 -040054if [[ " ${@} " =~ " -PupdateLintBaseline " ]]; then
55 # remove when b/188666845 is complete
56 # Inform lint to not fail even when creating a baseline file
57 JAVA_OPTS="$JAVA_OPTS -Dlint.baselines.continue=true"
58fi
59
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070060APP_NAME="Gradle"
61APP_BASE_NAME=`basename "$0"`
62
63# Use the maximum available, or set MAX_FD != -1 to use that value.
64MAX_FD="maximum"
65
66warn ( ) {
67 echo "$*"
68}
69
70die ( ) {
71 echo
72 echo "$*"
73 echo
74 exit 1
75}
76
77# OS specific support (must be 'true' or 'false').
78cygwin=false
79msys=false
80darwin=false
81case "`uname`" in
82 CYGWIN* )
83 cygwin=true
84 ;;
85 Darwin* )
86 darwin=true
87 ;;
88 MINGW* )
89 msys=true
90 ;;
91esac
Rahul Ravikumar465ccfc2022-02-14 14:58:20 -080092platform_suffix="x86"
93case "$(arch)" in
94 arm64* )
95 platform_suffix="arm64"
96esac
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070097# Attempt to set APP_HOME
98# Resolve links: $0 may be a link
99PRG="$0"
100# Need this for relative symlinks.
101while [ -h "$PRG" ] ; do
102 ls=`ls -ld "$PRG"`
103 link=`expr "$ls" : '.*-> \(.*\)$'`
104 if expr "$link" : '/.*' > /dev/null; then
105 PRG="$link"
106 else
107 PRG=`dirname "$PRG"`"/$link"
108 fi
109done
110SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700111cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700112APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700113cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700114
115CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
116
Jeff Gaston79a43f22019-04-09 16:19:12 -0400117# --------- androidx specific code needed for lint and java. ------------------
118
Alan Viveretted38b36c2017-02-01 16:45:31 -0500119# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -0500120if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -0500121 plat="darwin"
122else
123 plat="linux"
124fi
Alan Viveretted38b36c2017-02-01 16:45:31 -0500125
Matthew Fraschilla6ab84fc32019-11-21 16:40:16 -0800126# Tests for lint checks default to using sdk defined by this variable. This removes a lot of
127# setup from each lint module.
128export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +0000129# override JAVA_HOME, because CI machines have it and it points to very old JDK
Aurimas Liutikas420b7f62022-08-02 13:53:39 -0700130export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk17/$plat-$platform_suffix"
Aurimas Liutikas4b897cb2019-10-14 13:25:08 -0700131export JAVA_TOOLS_JAR="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86/lib/tools.jar"
132export STUDIO_GRADLE_JDK=$JAVA_HOME
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -0500133
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700134# Warn developers if they try to build top level project without the full checkout
Alan Viverette6b2fb212022-10-17 17:11:29 +0000135[ ! -d "$JAVA_HOME" ] && echo "Failed to find: $JAVA_HOME
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700136
Alan Viverette6b2fb212022-10-17 17:11:29 +0000137Typically, this means either:
1381. You are using the standalone AndroidX checkout, e.g. GitHub, which only supports
139 building a subset of projects. See CONTRIBUTING.md for details.
1402. You are using the repo checkout, but the last repo sync failed. Use repo status
141 to check for projects which are partially-synced, e.g. showing ***NO BRANCH***." && exit -1
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700142
Jeff Gaston79a43f22019-04-09 16:19:12 -0400143# ----------------------------------------------------------------------------
144
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700145# Determine the Java command to use to start the JVM.
146if [ -n "$JAVA_HOME" ] ; then
147 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
148 # IBM's JDK on AIX uses strange locations for the executables
149 JAVACMD="$JAVA_HOME/jre/sh/java"
150 else
151 JAVACMD="$JAVA_HOME/bin/java"
152 fi
153 if [ ! -x "$JAVACMD" ] ; then
154 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
155
156Please set the JAVA_HOME variable in your environment to match the
157location of your Java installation."
158 fi
159else
160 JAVACMD="java"
161 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
162
163Please set the JAVA_HOME variable in your environment to match the
164location of your Java installation."
165fi
166
167# Increase the maximum file descriptors if we can.
168if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
169 MAX_FD_LIMIT=`ulimit -H -n`
170 if [ $? -eq 0 ] ; then
171 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
172 MAX_FD="$MAX_FD_LIMIT"
173 fi
174 ulimit -n $MAX_FD
175 if [ $? -ne 0 ] ; then
176 warn "Could not set maximum file descriptor limit: $MAX_FD"
177 fi
178 else
179 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
180 fi
181fi
182
183# For Darwin, add options to specify how the application appears in the dock
184if $darwin; then
185 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
186fi
187
188# For Cygwin, switch paths to Windows format before running java
189if $cygwin ; then
190 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
191 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700192 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700193
194 # We build the pattern for arguments to be converted via cygpath
195 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
196 SEP=""
197 for dir in $ROOTDIRSRAW ; do
198 ROOTDIRS="$ROOTDIRS$SEP$dir"
199 SEP="|"
200 done
201 OURCYGPATTERN="(^($ROOTDIRS))"
202 # Add a user-defined pattern to the cygpath arguments
203 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
204 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
205 fi
206 # Now convert the arguments - kludge to limit ourselves to /bin/sh
207 i=0
208 for arg in "$@" ; do
209 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
210 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
211
212 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
213 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
214 else
215 eval `echo args$i`="\"$arg\""
216 fi
217 i=$((i+1))
218 done
219 case $i in
220 (0) set -- ;;
221 (1) set -- "$args0" ;;
222 (2) set -- "$args0" "$args1" ;;
223 (3) set -- "$args0" "$args1" "$args2" ;;
224 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
225 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
226 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
227 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
228 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
229 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
230 esac
231fi
232
233# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
234function splitJvmOpts() {
235 JVM_OPTS=("$@")
236}
237eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
238JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
239
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500240#TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed
241HOME_SYSTEM_PROPERTY_ARGUMENT=""
242if [ "$GRADLE_USER_HOME" != "" ]; then
243 HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME"
244fi
Jeff Gaston38004a62019-12-11 15:43:10 -0500245if [ "$TMPDIR" != "" ]; then
246 TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR"
247fi
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500248
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400249if [[ " ${@} " =~ " --clean " ]]; then
250 cleanCaches=true
251else
252 cleanCaches=false
253fi
254
Jeff Gaston794b0b72021-09-28 12:47:47 -0400255if [[ " ${@} " =~ " --no-ci " ]]; then
256 disableCi=true
257else
258 disableCi=false
259fi
260
Jeff Gaston829fd822021-09-23 11:42:48 -0400261# workaround for https://github.com/gradle/gradle/issues/18386
262if [[ " ${@} " =~ " --profile " ]]; then
263 mkdir -p reports
264fi
265
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500266# Expand some arguments
Jeff Gaston794b0b72021-09-28 12:47:47 -0400267for compact in "--ci" "--strict" "--clean" "--no-ci"; do
268 expanded=""
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500269 if [ "$compact" == "--ci" ]; then
Jeff Gaston794b0b72021-09-28 12:47:47 -0400270 if [ "$disableCi" == "false" ]; then
271 expanded="--strict\
272 --stacktrace\
273 -Pandroidx.summarizeStderr\
274 -Pandroidx.enableAffectedModuleDetection\
275 --no-watch-fs"
276 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500277 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500278 if [ "$compact" == "--strict" ]; then
Aurimas Liutikas41c58e02022-06-09 08:54:18 -0700279 expanded="-Pandroidx.validateNoUnrecognizedMessages\
Jeff Gaston55624742021-04-22 14:05:49 -0400280 -Pandroidx.verifyUpToDate\
Aurimas Liutikasf06703b2022-07-08 16:28:11 +0000281 --no-watch-fs"
Jeff Gaston934d0b12022-04-26 17:47:25 -0400282 if [ "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "" ]; then
283 expanded="$expanded --offline"
284 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500285 fi
Jeff Gaston794b0b72021-09-28 12:47:47 -0400286 # if compact is something else then we parsed the argument above but
287 # still have to remove it (expanded == "") to avoid confusing Gradle
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500288
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400289 # check whether this particular compat argument was passed (and therefore needs expansion)
290 if [[ " ${@} " =~ " $compact " ]]; then
291 # Expand an individual argument
292 # Start by making a copy of our list of arguments and iterating through the copy
293 for arg in "$@"; do
294 # Remove this argument from our list of arguments.
295 # By the time we've completed this loop, we will have removed the original copy of
296 # each argument, and potentially re-added a new copy or an expansion of each.
297 shift
298 # Determine whether to expand this argument
299 if [ "$arg" == "$compact" ]; then
300 # Add the expansion to our arguments
301 set -- "$@" $expanded
302 if [ "$expanded" != "" ]; then
303 echo "gradlew expanded '$compact' into '$expanded'"
304 echo
305 fi
306 # We avoid re-adding this argument itself back into the list for two reasons:
307 # 1. This argument might not be directly understood by Gradle
308 # 2. We want to enforce that all behaviors enabled by this flag can be toggled independently,
309 # so we don't want it to be easy to inadvertently check for the presence of this flag
310 # specifically
311 else
312 # Add this argument back into our arguments
313 set -- "$@" "$arg"
314 fi
315 done
316 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500317done
318
Jeff Gastonb03b05a2022-04-11 11:41:59 -0400319# check whether the user has requested profiling via yourkit
320yourkitArgPrefix="androidx.profile.yourkitAgentPath"
321yourkitAgentPath=""
322if [[ " ${@}" =~ " -P$yourkitArgPrefix" ]]; then
323 for arg in "$@"; do
324 if echo "$arg" | grep "${yourkitArgPrefix}=" >/dev/null; then
325 yourkitAgentPath="$(echo "$arg" | sed "s/-P${yourkitArgPrefix}=//")"
326 fi
327 done
328 if [ "$yourkitAgentPath" == "" ]; then
329 echo "Error: $yourkitArgPrefix must be set to the path of the YourKit Java agent" >&2
330 exit 1
331 fi
332 if [ ! -e "$yourkitAgentPath" ]; then
333 echo "Error: $yourkitAgentPath does not exist" >&2
334 exit 1
335 fi
336 # add the agent to the path
337 export _JAVA_OPTIONS="$_JAVA_OPTIONS -agentpath:$yourkitAgentPath"
338 # add arguments
339 set -- "$@" --no-daemon --rerun-tasks
340
341 # lots of blank lines because these messages are important
342 echo
343 echo
344 echo
345 echo
346 echo
347 # suggest --clean
348 if [ "$cleanCaches" == "false" ]; then
349 echo "When setting $yourkitArgPrefix you may also want to pass --clean"
350 fi
351 COLOR_YELLOW="\u001B[33m"
352 COLOR_CLEAR="\u001B[0m"
353
354 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}"
355 echo
356 echo
357 echo
358 echo
359 echo
360fi
361
Jeff Gastond2806b32021-09-29 12:20:39 -0400362if [[ " ${@} " =~ " --scan " ]]; then
363 if [[ " ${@} " =~ " --offline " ]]; then
364 echo "--scan incompatible with --offline"
365 echo "you could try --no-ci"
366 exit 1
367 fi
368fi
369
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400370function removeCaches() {
371 rm -rf $SCRIPT_PATH/.gradle
372 rm -rf $SCRIPT_PATH/buildSrc/.gradle
373 rm -f $SCRIPT_PATH/local.properties
374 if [ "$GRADLE_USER_HOME" != "" ]; then
375 rm -rf "$GRADLE_USER_HOME"
376 else
377 rm -rf ~/.gradle
378 fi
Jeff Gaston829fd822021-09-23 11:42:48 -0400379 # https://github.com/gradle/gradle/issues/18386
380 rm -rf $SCRIPT_PATH/reports
Jeff Gaston96eb6012021-09-27 14:55:36 +0000381 rm -rf $SCRIPT_PATH/build
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400382 rm -rf $OUT_DIR
383}
384
Jeff Gaston224eb172020-01-09 12:31:47 -0500385function runGradle() {
Jeff Gaston41b90222020-08-18 11:09:55 -0400386 processOutput=false
Jeff Gastone4b4b872020-08-25 09:02:13 -0400387 if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then
Jeff Gaston41b90222020-08-18 11:09:55 -0400388 processOutput=true
389 fi
390 if [[ " ${@} " =~ " -Pandroidx.summarizeStderr " ]]; then
391 processOutput=true
392 fi
393 if [ "$processOutput" == "true" ]; then
394 wrapper="$SCRIPT_PATH/development/build_log_processor.sh"
395 else
396 wrapper=""
397 fi
Jeff Gaston3febf902021-03-16 11:23:15 -0400398
Jeff Gaston1e67a612021-11-24 13:31:10 -0500399 RETURN_VALUE=0
Jeff Gaston3febf902021-03-16 11:23:15 -0400400 PROJECT_CACHE_DIR_ARGUMENT="--project-cache-dir $OUT_DIR/gradle-project-cache"
Jeff Gastondc9c8cb2023-02-08 16:24:38 -0500401 # Disabled in Studio until these errors become shown (b/268380971) or computed more quickly (https://github.com/gradle/gradle/issues/23272)
402 if [[ " ${@} " =~ " --dependency-verification=" ]]; then
403 VERIFICATION_ARGUMENT="" # already specified by caller
404 else
405 VERIFICATION_ARGUMENT=--dependency-verification=strict
406 fi
407 if $wrapper "$JAVACMD" "${JVM_OPTS[@]}" $TMPDIR_ARG -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain $HOME_SYSTEM_PROPERTY_ARGUMENT $TMPDIR_ARG $PROJECT_CACHE_DIR_ARGUMENT $VERIFICATION_ARGUMENT "$ORG_GRADLE_JVMARGS" "$@"; then
Jeff Gaston1e67a612021-11-24 13:31:10 -0500408 RETURN_VALUE=0
Jeff Gaston224eb172020-01-09 12:31:47 -0500409 else
410 # Print AndroidX-specific help message if build fails
411 # Have to do this build-failure detection in gradlew rather than in build.gradle
412 # so that this message still prints even if buildSrc itself fails
413 echo
Jeff Gaston61cef332020-12-22 11:23:09 -0500414 echo For help with unexpected failures, see development/diagnose-build-failure/README.md
415 echo
Jeff Gaston1e67a612021-11-24 13:31:10 -0500416 RETURN_VALUE=1
Jeff Gaston69713292020-06-04 12:53:39 -0400417 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500418
419 # If the caller specified where to save data, then also save the build scan data
420 if [ "$DIST_DIR" != "" ]; then
421 if [ "$GRADLE_USER_HOME" != "" ]; then
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400422 scanDir="$GRADLE_USER_HOME/build-scan-data"
423 if [ -e "$scanDir" ]; then
424 if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
425 zipPath="$DIST_DIR/scan-up-to-date.zip"
426 else
427 zipPath="$DIST_DIR/scan.zip"
428 fi
429 rm -f "$zipPath"
430 cd "$GRADLE_USER_HOME/build-scan-data"
431 zip -q -r "$zipPath" .
432 cd -
Jeff Gaston1e67a612021-11-24 13:31:10 -0500433 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500434 fi
435 fi
436 return $RETURN_VALUE
Jeff Gaston69713292020-06-04 12:53:39 -0400437}
438
Jeff Gaston87a4bbb2022-04-21 12:31:08 -0400439if [ "$cleanCaches" == true ]; then
440 echo "IF ./gradlew --clean FIXES YOUR BUILD; OPEN A BUG."
441 echo "In nearly all cases, it should not be necessary to run a clean build."
442 echo
443 # 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
444 # another case where it is convenient to have a clean build is for performance testing
445 # 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)
446
447 echo "Stopping Gradle daemons"
448 runGradle --stop || true
449 echo
450
451 backupDir=~/androidx-build-state-backup
452 ./development/diagnose-build-failure/impl/backup-state.sh "$backupDir" --move # prints that it is saving state into this dir"
453
454 echo "To restore this state later, run:"
455 echo
456 echo " ./development/diagnose-build-failure/impl/restore-state.sh $backupDir"
457 echo
458 echo "Running Gradle"
459 echo
460fi
461
Jeff Gaston7121d832022-06-08 13:36:50 -0400462if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
463 echo "Setting 'DISALLOW_TASK_EXECUTION' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?"
Jeff Gaston400ccb32020-06-08 16:44:58 -0400464 echo "See TaskUpToDateValidator.java for more information"
465 exit 1
466fi
467
Jeff Gaston55624742021-04-22 14:05:49 -0400468runGradle "$@"
469# Check whether we were given the "-Pandroidx.verifyUpToDate" argument
470if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then
Jeff Gastoncefdeae2020-03-09 13:12:35 -0400471 # Re-run Gradle, and find all tasks that are unexpectly out of date
Jeff Gaston7121d832022-06-08 13:36:50 -0400472 if ! DISALLOW_TASK_EXECUTION=true runGradle "$@" --continue; then
Jeff Gastone906e5c2020-11-05 12:33:10 -0500473 echo >&2
Jeff Gaston20f5e7a2022-01-27 13:39:25 -0500474 echo "TaskUpToDateValidator's second build failed. To reproduce, try running './gradlew -Pandroidx.verifyUpToDate <failing tasks>'" >&2
Jeff Gastone906e5c2020-11-05 12:33:10 -0500475 exit 1
476 fi
Jeff Gastonb89c82b2019-08-21 16:24:09 -0400477fi