blob: fc93b4779a0494ac1041d2c0a74977975dff20c1 [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
Alan Viverette9d651362023-03-23 12:34:03 -040046# Loading the AIDL lexer requires disabling Lint's bytecode verification
47export ANDROID_LINT_SKIP_BYTECODE_VERIFIER=true
48
Jeff Gastonc21ecb32020-11-05 17:16:35 -050049# unset ANDROID_BUILD_TOP so that Lint doesn't think we're building the platform itself
50unset ANDROID_BUILD_TOP
Aurimas Liutikas9979d072018-03-13 15:38:56 -070051# ----------------------------------------------------------------------------
52
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070053# 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 -070054
Jeff Gastonc6df4152021-11-03 10:24:02 -040055if [[ " ${@} " =~ " -PupdateLintBaseline " ]]; then
56 # remove when b/188666845 is complete
57 # Inform lint to not fail even when creating a baseline file
58 JAVA_OPTS="$JAVA_OPTS -Dlint.baselines.continue=true"
59fi
60
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070061APP_NAME="Gradle"
62APP_BASE_NAME=`basename "$0"`
63
64# Use the maximum available, or set MAX_FD != -1 to use that value.
65MAX_FD="maximum"
66
67warn ( ) {
68 echo "$*"
69}
70
71die ( ) {
72 echo
73 echo "$*"
74 echo
75 exit 1
76}
77
78# OS specific support (must be 'true' or 'false').
79cygwin=false
80msys=false
81darwin=false
82case "`uname`" in
83 CYGWIN* )
84 cygwin=true
85 ;;
86 Darwin* )
87 darwin=true
88 ;;
89 MINGW* )
90 msys=true
91 ;;
92esac
Rahul Ravikumar465ccfc2022-02-14 14:58:20 -080093platform_suffix="x86"
94case "$(arch)" in
95 arm64* )
96 platform_suffix="arm64"
97esac
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070098# Attempt to set APP_HOME
99# Resolve links: $0 may be a link
100PRG="$0"
101# Need this for relative symlinks.
102while [ -h "$PRG" ] ; do
103 ls=`ls -ld "$PRG"`
104 link=`expr "$ls" : '.*-> \(.*\)$'`
105 if expr "$link" : '/.*' > /dev/null; then
106 PRG="$link"
107 else
108 PRG=`dirname "$PRG"`"/$link"
109 fi
110done
111SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700112cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700113APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700114cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700115
116CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
117
Jeff Gaston79a43f22019-04-09 16:19:12 -0400118# --------- androidx specific code needed for lint and java. ------------------
119
Alan Viveretted38b36c2017-02-01 16:45:31 -0500120# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -0500121if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -0500122 plat="darwin"
123else
124 plat="linux"
125fi
Alan Viveretted38b36c2017-02-01 16:45:31 -0500126
Matthew Fraschilla6ab84fc32019-11-21 16:40:16 -0800127# Tests for lint checks default to using sdk defined by this variable. This removes a lot of
128# setup from each lint module.
129export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +0000130# override JAVA_HOME, because CI machines have it and it points to very old JDK
Aurimas Liutikas420b7f62022-08-02 13:53:39 -0700131export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk17/$plat-$platform_suffix"
Aurimas Liutikas4b897cb2019-10-14 13:25:08 -0700132export JAVA_TOOLS_JAR="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86/lib/tools.jar"
133export STUDIO_GRADLE_JDK=$JAVA_HOME
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -0500134
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700135# Warn developers if they try to build top level project without the full checkout
Alan Viverette6b2fb212022-10-17 17:11:29 +0000136[ ! -d "$JAVA_HOME" ] && echo "Failed to find: $JAVA_HOME
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700137
Alan Viverette6b2fb212022-10-17 17:11:29 +0000138Typically, this means either:
1391. You are using the standalone AndroidX checkout, e.g. GitHub, which only supports
140 building a subset of projects. See CONTRIBUTING.md for details.
1412. You are using the repo checkout, but the last repo sync failed. Use repo status
142 to check for projects which are partially-synced, e.g. showing ***NO BRANCH***." && exit -1
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700143
Jeff Gaston79a43f22019-04-09 16:19:12 -0400144# ----------------------------------------------------------------------------
145
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700146# Determine the Java command to use to start the JVM.
147if [ -n "$JAVA_HOME" ] ; then
148 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
149 # IBM's JDK on AIX uses strange locations for the executables
150 JAVACMD="$JAVA_HOME/jre/sh/java"
151 else
152 JAVACMD="$JAVA_HOME/bin/java"
153 fi
154 if [ ! -x "$JAVACMD" ] ; then
155 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
156
157Please set the JAVA_HOME variable in your environment to match the
158location of your Java installation."
159 fi
160else
161 JAVACMD="java"
162 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
163
164Please set the JAVA_HOME variable in your environment to match the
165location of your Java installation."
166fi
167
168# Increase the maximum file descriptors if we can.
169if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
170 MAX_FD_LIMIT=`ulimit -H -n`
171 if [ $? -eq 0 ] ; then
172 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
173 MAX_FD="$MAX_FD_LIMIT"
174 fi
175 ulimit -n $MAX_FD
176 if [ $? -ne 0 ] ; then
177 warn "Could not set maximum file descriptor limit: $MAX_FD"
178 fi
179 else
180 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
181 fi
182fi
183
184# For Darwin, add options to specify how the application appears in the dock
185if $darwin; then
186 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
187fi
188
189# For Cygwin, switch paths to Windows format before running java
190if $cygwin ; then
191 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
192 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700193 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700194
195 # We build the pattern for arguments to be converted via cygpath
196 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
197 SEP=""
198 for dir in $ROOTDIRSRAW ; do
199 ROOTDIRS="$ROOTDIRS$SEP$dir"
200 SEP="|"
201 done
202 OURCYGPATTERN="(^($ROOTDIRS))"
203 # Add a user-defined pattern to the cygpath arguments
204 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
205 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
206 fi
207 # Now convert the arguments - kludge to limit ourselves to /bin/sh
208 i=0
209 for arg in "$@" ; do
210 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
211 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
212
213 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
214 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
215 else
216 eval `echo args$i`="\"$arg\""
217 fi
218 i=$((i+1))
219 done
220 case $i in
221 (0) set -- ;;
222 (1) set -- "$args0" ;;
223 (2) set -- "$args0" "$args1" ;;
224 (3) set -- "$args0" "$args1" "$args2" ;;
225 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
226 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
227 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
228 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
229 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
230 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
231 esac
232fi
233
234# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
235function splitJvmOpts() {
236 JVM_OPTS=("$@")
237}
238eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
239JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
240
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500241#TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed
242HOME_SYSTEM_PROPERTY_ARGUMENT=""
243if [ "$GRADLE_USER_HOME" != "" ]; then
244 HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME"
245fi
Jeff Gaston38004a62019-12-11 15:43:10 -0500246if [ "$TMPDIR" != "" ]; then
247 TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR"
248fi
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500249
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400250if [[ " ${@} " =~ " --clean " ]]; then
251 cleanCaches=true
252else
253 cleanCaches=false
254fi
255
Jeff Gaston794b0b72021-09-28 12:47:47 -0400256if [[ " ${@} " =~ " --no-ci " ]]; then
257 disableCi=true
258else
259 disableCi=false
260fi
261
Jeff Gaston829fd822021-09-23 11:42:48 -0400262# workaround for https://github.com/gradle/gradle/issues/18386
263if [[ " ${@} " =~ " --profile " ]]; then
264 mkdir -p reports
265fi
266
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500267# Expand some arguments
Jeff Gaston794b0b72021-09-28 12:47:47 -0400268for compact in "--ci" "--strict" "--clean" "--no-ci"; do
269 expanded=""
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500270 if [ "$compact" == "--ci" ]; then
Jeff Gaston794b0b72021-09-28 12:47:47 -0400271 if [ "$disableCi" == "false" ]; then
272 expanded="--strict\
273 --stacktrace\
274 -Pandroidx.summarizeStderr\
275 -Pandroidx.enableAffectedModuleDetection\
276 --no-watch-fs"
277 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500278 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500279 if [ "$compact" == "--strict" ]; then
Aurimas Liutikas41c58e02022-06-09 08:54:18 -0700280 expanded="-Pandroidx.validateNoUnrecognizedMessages\
Jeff Gaston55624742021-04-22 14:05:49 -0400281 -Pandroidx.verifyUpToDate\
Aurimas Liutikasf06703b2022-07-08 16:28:11 +0000282 --no-watch-fs"
Jeff Gaston934d0b12022-04-26 17:47:25 -0400283 if [ "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "" ]; then
284 expanded="$expanded --offline"
285 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500286 fi
Jeff Gaston794b0b72021-09-28 12:47:47 -0400287 # if compact is something else then we parsed the argument above but
288 # still have to remove it (expanded == "") to avoid confusing Gradle
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500289
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400290 # check whether this particular compat argument was passed (and therefore needs expansion)
291 if [[ " ${@} " =~ " $compact " ]]; then
292 # Expand an individual argument
293 # Start by making a copy of our list of arguments and iterating through the copy
294 for arg in "$@"; do
295 # Remove this argument from our list of arguments.
296 # By the time we've completed this loop, we will have removed the original copy of
297 # each argument, and potentially re-added a new copy or an expansion of each.
298 shift
299 # Determine whether to expand this argument
300 if [ "$arg" == "$compact" ]; then
301 # Add the expansion to our arguments
302 set -- "$@" $expanded
303 if [ "$expanded" != "" ]; then
304 echo "gradlew expanded '$compact' into '$expanded'"
305 echo
306 fi
307 # We avoid re-adding this argument itself back into the list for two reasons:
308 # 1. This argument might not be directly understood by Gradle
309 # 2. We want to enforce that all behaviors enabled by this flag can be toggled independently,
310 # so we don't want it to be easy to inadvertently check for the presence of this flag
311 # specifically
312 else
313 # Add this argument back into our arguments
314 set -- "$@" "$arg"
315 fi
316 done
317 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500318done
319
Jeff Gastonb03b05a2022-04-11 11:41:59 -0400320# check whether the user has requested profiling via yourkit
321yourkitArgPrefix="androidx.profile.yourkitAgentPath"
322yourkitAgentPath=""
323if [[ " ${@}" =~ " -P$yourkitArgPrefix" ]]; then
324 for arg in "$@"; do
325 if echo "$arg" | grep "${yourkitArgPrefix}=" >/dev/null; then
326 yourkitAgentPath="$(echo "$arg" | sed "s/-P${yourkitArgPrefix}=//")"
327 fi
328 done
329 if [ "$yourkitAgentPath" == "" ]; then
330 echo "Error: $yourkitArgPrefix must be set to the path of the YourKit Java agent" >&2
331 exit 1
332 fi
333 if [ ! -e "$yourkitAgentPath" ]; then
334 echo "Error: $yourkitAgentPath does not exist" >&2
335 exit 1
336 fi
337 # add the agent to the path
338 export _JAVA_OPTIONS="$_JAVA_OPTIONS -agentpath:$yourkitAgentPath"
339 # add arguments
340 set -- "$@" --no-daemon --rerun-tasks
341
342 # lots of blank lines because these messages are important
343 echo
344 echo
345 echo
346 echo
347 echo
348 # suggest --clean
349 if [ "$cleanCaches" == "false" ]; then
350 echo "When setting $yourkitArgPrefix you may also want to pass --clean"
351 fi
352 COLOR_YELLOW="\u001B[33m"
353 COLOR_CLEAR="\u001B[0m"
354
355 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}"
356 echo
357 echo
358 echo
359 echo
360 echo
361fi
362
Jeff Gastond2806b32021-09-29 12:20:39 -0400363if [[ " ${@} " =~ " --scan " ]]; then
364 if [[ " ${@} " =~ " --offline " ]]; then
365 echo "--scan incompatible with --offline"
366 echo "you could try --no-ci"
367 exit 1
368 fi
369fi
370
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400371function removeCaches() {
372 rm -rf $SCRIPT_PATH/.gradle
373 rm -rf $SCRIPT_PATH/buildSrc/.gradle
374 rm -f $SCRIPT_PATH/local.properties
375 if [ "$GRADLE_USER_HOME" != "" ]; then
376 rm -rf "$GRADLE_USER_HOME"
377 else
378 rm -rf ~/.gradle
379 fi
Jeff Gaston829fd822021-09-23 11:42:48 -0400380 # https://github.com/gradle/gradle/issues/18386
381 rm -rf $SCRIPT_PATH/reports
Jeff Gaston96eb6012021-09-27 14:55:36 +0000382 rm -rf $SCRIPT_PATH/build
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400383 rm -rf $OUT_DIR
384}
385
Jeff Gaston224eb172020-01-09 12:31:47 -0500386function runGradle() {
Jeff Gaston41b90222020-08-18 11:09:55 -0400387 processOutput=false
Jeff Gastone4b4b872020-08-25 09:02:13 -0400388 if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then
Jeff Gaston41b90222020-08-18 11:09:55 -0400389 processOutput=true
390 fi
391 if [[ " ${@} " =~ " -Pandroidx.summarizeStderr " ]]; then
392 processOutput=true
393 fi
394 if [ "$processOutput" == "true" ]; then
395 wrapper="$SCRIPT_PATH/development/build_log_processor.sh"
396 else
397 wrapper=""
398 fi
Jeff Gaston3febf902021-03-16 11:23:15 -0400399
Jeff Gaston1e67a612021-11-24 13:31:10 -0500400 RETURN_VALUE=0
Jeff Gaston3febf902021-03-16 11:23:15 -0400401 PROJECT_CACHE_DIR_ARGUMENT="--project-cache-dir $OUT_DIR/gradle-project-cache"
Jeff Gastondc9c8cb2023-02-08 16:24:38 -0500402 # Disabled in Studio until these errors become shown (b/268380971) or computed more quickly (https://github.com/gradle/gradle/issues/23272)
403 if [[ " ${@} " =~ " --dependency-verification=" ]]; then
404 VERIFICATION_ARGUMENT="" # already specified by caller
405 else
406 VERIFICATION_ARGUMENT=--dependency-verification=strict
407 fi
408 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 -0500409 RETURN_VALUE=0
Jeff Gaston224eb172020-01-09 12:31:47 -0500410 else
411 # Print AndroidX-specific help message if build fails
412 # Have to do this build-failure detection in gradlew rather than in build.gradle
413 # so that this message still prints even if buildSrc itself fails
414 echo
Jeff Gaston61cef332020-12-22 11:23:09 -0500415 echo For help with unexpected failures, see development/diagnose-build-failure/README.md
416 echo
Jeff Gaston1e67a612021-11-24 13:31:10 -0500417 RETURN_VALUE=1
Jeff Gaston69713292020-06-04 12:53:39 -0400418 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500419
420 # If the caller specified where to save data, then also save the build scan data
421 if [ "$DIST_DIR" != "" ]; then
422 if [ "$GRADLE_USER_HOME" != "" ]; then
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400423 scanDir="$GRADLE_USER_HOME/build-scan-data"
424 if [ -e "$scanDir" ]; then
425 if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
426 zipPath="$DIST_DIR/scan-up-to-date.zip"
427 else
428 zipPath="$DIST_DIR/scan.zip"
429 fi
430 rm -f "$zipPath"
431 cd "$GRADLE_USER_HOME/build-scan-data"
432 zip -q -r "$zipPath" .
433 cd -
Jeff Gaston1e67a612021-11-24 13:31:10 -0500434 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500435 fi
436 fi
437 return $RETURN_VALUE
Jeff Gaston69713292020-06-04 12:53:39 -0400438}
439
Jeff Gaston87a4bbb2022-04-21 12:31:08 -0400440if [ "$cleanCaches" == true ]; then
441 echo "IF ./gradlew --clean FIXES YOUR BUILD; OPEN A BUG."
442 echo "In nearly all cases, it should not be necessary to run a clean build."
443 echo
444 # 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
445 # another case where it is convenient to have a clean build is for performance testing
446 # 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)
447
448 echo "Stopping Gradle daemons"
449 runGradle --stop || true
450 echo
451
452 backupDir=~/androidx-build-state-backup
453 ./development/diagnose-build-failure/impl/backup-state.sh "$backupDir" --move # prints that it is saving state into this dir"
454
455 echo "To restore this state later, run:"
456 echo
457 echo " ./development/diagnose-build-failure/impl/restore-state.sh $backupDir"
458 echo
459 echo "Running Gradle"
460 echo
461fi
462
Jeff Gaston7121d832022-06-08 13:36:50 -0400463if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
464 echo "Setting 'DISALLOW_TASK_EXECUTION' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?"
Jeff Gaston400ccb32020-06-08 16:44:58 -0400465 echo "See TaskUpToDateValidator.java for more information"
466 exit 1
467fi
468
Jeff Gaston55624742021-04-22 14:05:49 -0400469runGradle "$@"
470# Check whether we were given the "-Pandroidx.verifyUpToDate" argument
471if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then
Jeff Gastoncefdeae2020-03-09 13:12:35 -0400472 # Re-run Gradle, and find all tasks that are unexpectly out of date
Jeff Gaston7121d832022-06-08 13:36:50 -0400473 if ! DISALLOW_TASK_EXECUTION=true runGradle "$@" --continue; then
Jeff Gastone906e5c2020-11-05 12:33:10 -0500474 echo >&2
Jeff Gaston20f5e7a2022-01-27 13:39:25 -0500475 echo "TaskUpToDateValidator's second build failed. To reproduce, try running './gradlew -Pandroidx.verifyUpToDate <failing tasks>'" >&2
Jeff Gastone906e5c2020-11-05 12:33:10 -0500476 exit 1
477 fi
Jeff Gastonb89c82b2019-08-21 16:24:09 -0400478fi