blob: 99460ea565c2e46b20e09f8a12be9f6def50b055 [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"
Aurimas Liutikas54598672024-03-25 23:38:45 +000018 export TMPDIR="$OUT_DIR/tmp"
Aurimas Liutikascdacae42024-08-14 11:12:09 -070019elif [[ $SCRIPT_PATH == /google/cog/* ]] ; then
20 export OUT_DIR="$HOME/androidxout"
21 export GRADLE_USER_HOME=~/.gradle
Jeff Gastoncc694ab2019-04-11 16:51:36 -040022else
Jeff Gastondd8a6e92020-09-01 14:26:49 -040023 CHECKOUT_ROOT="$(cd $SCRIPT_PATH/../.. && pwd -P)"
Jeff Gastoncc694ab2019-04-11 16:51:36 -040024 export OUT_DIR="$CHECKOUT_ROOT/out"
Jeff Gastond5719892022-04-21 12:06:24 -040025 export GRADLE_USER_HOME=~/.gradle
Aurimas Liutikas9979d072018-03-13 15:38:56 -070026fi
27
Jeff Gaston440e1ac2020-09-09 08:32:22 -040028ORG_GRADLE_JVMARGS="$(cd $SCRIPT_PATH && grep org.gradle.jvmargs gradle.properties | sed 's/^/-D/')"
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040029if [ -n "$DIST_DIR" ]; then
30 mkdir -p "$DIST_DIR"
Jeff Gastondd8a6e92020-09-01 14:26:49 -040031 DIST_DIR="$(cd $DIST_DIR && pwd -P)"
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040032
Jeff Gaston440e1ac2020-09-09 08:32:22 -040033 # tell Gradle where to put a heap dump on failure
34 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s|$| -XX:HeapDumpPath=$DIST_DIR|")"
Jeff Gastone72d2302019-12-19 18:32:31 -050035
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040036 # We don't set a default DIST_DIR in an else clause here because Studio doesn't use gradlew
37 # and doesn't set DIST_DIR and we want gradlew and Studio to match
38fi
39
Alan Viverette9d651362023-03-23 12:34:03 -040040# Loading the AIDL lexer requires disabling Lint's bytecode verification
41export ANDROID_LINT_SKIP_BYTECODE_VERIFIER=true
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
49APP_NAME="Gradle"
50APP_BASE_NAME=`basename "$0"`
51
52# Use the maximum available, or set MAX_FD != -1 to use that value.
53MAX_FD="maximum"
54
55warn ( ) {
56 echo "$*"
57}
58
59die ( ) {
60 echo
61 echo "$*"
62 echo
63 exit 1
64}
65
66# OS specific support (must be 'true' or 'false').
67cygwin=false
68msys=false
69darwin=false
70case "`uname`" in
71 CYGWIN* )
72 cygwin=true
73 ;;
74 Darwin* )
75 darwin=true
76 ;;
77 MINGW* )
78 msys=true
79 ;;
80esac
Rahul Ravikumar465ccfc2022-02-14 14:58:20 -080081platform_suffix="x86"
82case "$(arch)" in
83 arm64* )
84 platform_suffix="arm64"
85esac
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070086# Attempt to set APP_HOME
87# Resolve links: $0 may be a link
88PRG="$0"
89# Need this for relative symlinks.
90while [ -h "$PRG" ] ; do
91 ls=`ls -ld "$PRG"`
92 link=`expr "$ls" : '.*-> \(.*\)$'`
93 if expr "$link" : '/.*' > /dev/null; then
94 PRG="$link"
95 else
96 PRG=`dirname "$PRG"`"/$link"
97 fi
98done
99SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700100cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700101APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -0700102cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700103
104CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
105
Jeff Gaston79a43f22019-04-09 16:19:12 -0400106# --------- androidx specific code needed for lint and java. ------------------
107
Alan Viveretted38b36c2017-02-01 16:45:31 -0500108# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -0500109if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -0500110 plat="darwin"
111else
112 plat="linux"
113fi
Alan Viveretted38b36c2017-02-01 16:45:31 -0500114
Matthew Fraschilla6ab84fc32019-11-21 16:40:16 -0800115# Tests for lint checks default to using sdk defined by this variable. This removes a lot of
116# setup from each lint module.
117export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +0000118# override JAVA_HOME, because CI machines have it and it points to very old JDK
Aurimas Liutikas4e41da22023-12-13 15:38:28 -0800119export ANDROIDX_JDK17="$APP_HOME/../../prebuilts/jdk/jdk17/$plat-$platform_suffix"
120export ANDROIDX_JDK21="$APP_HOME/../../prebuilts/jdk/jdk21/$plat-$platform_suffix"
121export JAVA_HOME=$ANDROIDX_JDK21
Aurimas Liutikas4b897cb2019-10-14 13:25:08 -0700122export STUDIO_GRADLE_JDK=$JAVA_HOME
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -0500123
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700124# Warn developers if they try to build top level project without the full checkout
Alan Viverette6b2fb212022-10-17 17:11:29 +0000125[ ! -d "$JAVA_HOME" ] && echo "Failed to find: $JAVA_HOME
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700126
Alan Viverette6b2fb212022-10-17 17:11:29 +0000127Typically, this means either:
1281. You are using the standalone AndroidX checkout, e.g. GitHub, which only supports
129 building a subset of projects. See CONTRIBUTING.md for details.
1302. You are using the repo checkout, but the last repo sync failed. Use repo status
131 to check for projects which are partially-synced, e.g. showing ***NO BRANCH***." && exit -1
Aurimas Liutikasd6bc55a2022-05-24 13:19:07 -0700132
Jeff Gaston79a43f22019-04-09 16:19:12 -0400133# ----------------------------------------------------------------------------
134
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700135# Determine the Java command to use to start the JVM.
136if [ -n "$JAVA_HOME" ] ; then
137 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
138 # IBM's JDK on AIX uses strange locations for the executables
139 JAVACMD="$JAVA_HOME/jre/sh/java"
140 else
141 JAVACMD="$JAVA_HOME/bin/java"
142 fi
143 if [ ! -x "$JAVACMD" ] ; then
144 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
145
146Please set the JAVA_HOME variable in your environment to match the
147location of your Java installation."
148 fi
149else
150 JAVACMD="java"
151 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
152
153Please set the JAVA_HOME variable in your environment to match the
154location of your Java installation."
155fi
156
157# Increase the maximum file descriptors if we can.
158if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
159 MAX_FD_LIMIT=`ulimit -H -n`
160 if [ $? -eq 0 ] ; then
161 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
162 MAX_FD="$MAX_FD_LIMIT"
163 fi
164 ulimit -n $MAX_FD
165 if [ $? -ne 0 ] ; then
166 warn "Could not set maximum file descriptor limit: $MAX_FD"
167 fi
168 else
169 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
170 fi
171fi
172
173# For Darwin, add options to specify how the application appears in the dock
174if $darwin; then
175 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
176fi
177
178# For Cygwin, switch paths to Windows format before running java
179if $cygwin ; then
180 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
181 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700182 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700183
184 # We build the pattern for arguments to be converted via cygpath
185 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
186 SEP=""
187 for dir in $ROOTDIRSRAW ; do
188 ROOTDIRS="$ROOTDIRS$SEP$dir"
189 SEP="|"
190 done
191 OURCYGPATTERN="(^($ROOTDIRS))"
192 # Add a user-defined pattern to the cygpath arguments
193 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
194 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
195 fi
196 # Now convert the arguments - kludge to limit ourselves to /bin/sh
197 i=0
198 for arg in "$@" ; do
199 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
200 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
201
202 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
203 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
204 else
205 eval `echo args$i`="\"$arg\""
206 fi
207 i=$((i+1))
208 done
209 case $i in
210 (0) set -- ;;
211 (1) set -- "$args0" ;;
212 (2) set -- "$args0" "$args1" ;;
213 (3) set -- "$args0" "$args1" "$args2" ;;
214 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
215 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
216 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
217 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
218 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
219 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
220 esac
221fi
222
223# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
224function splitJvmOpts() {
225 JVM_OPTS=("$@")
226}
227eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
228JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
229
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500230#TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed
231HOME_SYSTEM_PROPERTY_ARGUMENT=""
232if [ "$GRADLE_USER_HOME" != "" ]; then
233 HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME"
234fi
235
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400236if [[ " ${@} " =~ " --clean " ]]; then
237 cleanCaches=true
238else
239 cleanCaches=false
240fi
241
Jeff Gaston794b0b72021-09-28 12:47:47 -0400242if [[ " ${@} " =~ " --no-ci " ]]; then
243 disableCi=true
244else
245 disableCi=false
246fi
247
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500248# Expand some arguments
Jeff Gaston794b0b72021-09-28 12:47:47 -0400249for compact in "--ci" "--strict" "--clean" "--no-ci"; do
250 expanded=""
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500251 if [ "$compact" == "--ci" ]; then
Jeff Gaston794b0b72021-09-28 12:47:47 -0400252 if [ "$disableCi" == "false" ]; then
253 expanded="--strict\
254 --stacktrace\
255 -Pandroidx.summarizeStderr\
256 -Pandroidx.enableAffectedModuleDetection\
Jeff Gaston3fa62a82023-10-25 15:00:25 -0400257 -Pandroidx.printTimestamps\
Jeff Gastoneeb07d32023-10-05 12:14:08 -0400258 --no-watch-fs\
Jeff Gaston678a9872024-03-20 16:32:16 -0400259 -Pandroidx.highMemory\
260 --profile"
Jeff Gaston794b0b72021-09-28 12:47:47 -0400261 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500262 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500263 if [ "$compact" == "--strict" ]; then
Aurimas Liutikas41c58e02022-06-09 08:54:18 -0700264 expanded="-Pandroidx.validateNoUnrecognizedMessages\
Jeff Gastone79ed0e2024-02-09 11:54:02 -0500265 -Pandroidx.verifyUpToDate"
Jeff Gaston20419352024-04-08 16:23:17 -0400266 if [ "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "" -o "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "false" ]; then
Jeff Gaston934d0b12022-04-26 17:47:25 -0400267 expanded="$expanded --offline"
268 fi
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500269 fi
Jeff Gaston794b0b72021-09-28 12:47:47 -0400270 # if compact is something else then we parsed the argument above but
271 # still have to remove it (expanded == "") to avoid confusing Gradle
Jeff Gaston7eafa5d2021-02-10 16:12:54 -0500272
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400273 # check whether this particular compat argument was passed (and therefore needs expansion)
274 if [[ " ${@} " =~ " $compact " ]]; then
275 # Expand an individual argument
276 # Start by making a copy of our list of arguments and iterating through the copy
277 for arg in "$@"; do
278 # Remove this argument from our list of arguments.
279 # By the time we've completed this loop, we will have removed the original copy of
280 # each argument, and potentially re-added a new copy or an expansion of each.
281 shift
282 # Determine whether to expand this argument
283 if [ "$arg" == "$compact" ]; then
284 # Add the expansion to our arguments
285 set -- "$@" $expanded
286 if [ "$expanded" != "" ]; then
287 echo "gradlew expanded '$compact' into '$expanded'"
288 echo
289 fi
290 # We avoid re-adding this argument itself back into the list for two reasons:
291 # 1. This argument might not be directly understood by Gradle
292 # 2. We want to enforce that all behaviors enabled by this flag can be toggled independently,
293 # so we don't want it to be easy to inadvertently check for the presence of this flag
294 # specifically
295 else
296 # Add this argument back into our arguments
297 set -- "$@" "$arg"
298 fi
299 done
300 fi
Jeff Gaston4537e142021-01-27 13:08:50 -0500301done
302
Jeff Gaston678a9872024-03-20 16:32:16 -0400303# workaround for https://github.com/gradle/gradle/issues/18386
304if [[ " ${@} " =~ " --profile " ]]; then
305 mkdir -p reports
306fi
307
Jeff Gaston2196fc62024-01-30 11:46:34 -0500308raiseMemory=false
Jeff Gastoneeb07d32023-10-05 12:14:08 -0400309if [[ " ${@} " =~ " -Pandroidx.highMemory " ]]; then
Jeff Gaston2196fc62024-01-30 11:46:34 -0500310 raiseMemory=true
311fi
312if [[ " ${@} " =~ " -Pandroidx.lowMemory " ]]; then
313 if [ "$raiseMemory" == "true" ]; then
314 echo "androidx.lowMemory overriding androidx.highMemory"
315 echo
316 fi
317 raiseMemory=false
318fi
Jeff Gastoneeb07d32023-10-05 12:14:08 -0400319
Jeff Gaston2196fc62024-01-30 11:46:34 -0500320if [ "$raiseMemory" == "true" ]; then
321 # Set the initial heap size to match the max heap size,
322 # by replacing a string like "-Xmx1g" with one like "-Xms1g -Xmx1g"
323 MAX_MEM=32g
324 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s/-Xmx\([^ ]*\)/-Xms$MAX_MEM -Xmx$MAX_MEM/")"
325
326 # Increase the compiler cache size: b/260643754 . Remove when updating to JDK 20 ( https://bugs.openjdk.org/browse/JDK-8295724 )
327 ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s|$| -XX:ReservedCodeCacheSize=576M|")"
Jeff Gastoneeb07d32023-10-05 12:14:08 -0400328fi
329
Jeff Gastonb03b05a2022-04-11 11:41:59 -0400330# check whether the user has requested profiling via yourkit
331yourkitArgPrefix="androidx.profile.yourkitAgentPath"
332yourkitAgentPath=""
333if [[ " ${@}" =~ " -P$yourkitArgPrefix" ]]; then
334 for arg in "$@"; do
335 if echo "$arg" | grep "${yourkitArgPrefix}=" >/dev/null; then
336 yourkitAgentPath="$(echo "$arg" | sed "s/-P${yourkitArgPrefix}=//")"
337 fi
338 done
339 if [ "$yourkitAgentPath" == "" ]; then
340 echo "Error: $yourkitArgPrefix must be set to the path of the YourKit Java agent" >&2
341 exit 1
342 fi
343 if [ ! -e "$yourkitAgentPath" ]; then
344 echo "Error: $yourkitAgentPath does not exist" >&2
345 exit 1
346 fi
347 # add the agent to the path
348 export _JAVA_OPTIONS="$_JAVA_OPTIONS -agentpath:$yourkitAgentPath"
349 # add arguments
350 set -- "$@" --no-daemon --rerun-tasks
351
352 # lots of blank lines because these messages are important
353 echo
354 echo
355 echo
356 echo
357 echo
358 # suggest --clean
359 if [ "$cleanCaches" == "false" ]; then
360 echo "When setting $yourkitArgPrefix you may also want to pass --clean"
361 fi
362 COLOR_YELLOW="\u001B[33m"
363 COLOR_CLEAR="\u001B[0m"
364
365 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}"
366 echo
367 echo
368 echo
369 echo
370 echo
371fi
372
Jeff Gastond2806b32021-09-29 12:20:39 -0400373if [[ " ${@} " =~ " --scan " ]]; then
374 if [[ " ${@} " =~ " --offline " ]]; then
375 echo "--scan incompatible with --offline"
376 echo "you could try --no-ci"
377 exit 1
378 fi
379fi
380
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400381function removeCaches() {
382 rm -rf $SCRIPT_PATH/.gradle
383 rm -rf $SCRIPT_PATH/buildSrc/.gradle
384 rm -f $SCRIPT_PATH/local.properties
385 if [ "$GRADLE_USER_HOME" != "" ]; then
386 rm -rf "$GRADLE_USER_HOME"
387 else
388 rm -rf ~/.gradle
389 fi
Jeff Gaston829fd822021-09-23 11:42:48 -0400390 # https://github.com/gradle/gradle/issues/18386
391 rm -rf $SCRIPT_PATH/reports
Jeff Gaston96eb6012021-09-27 14:55:36 +0000392 rm -rf $SCRIPT_PATH/build
Jeff Gastonbaa2b202021-04-23 15:44:59 -0400393 rm -rf $OUT_DIR
394}
395
Jeff Gaston6cca77e52023-08-07 11:10:17 -0400396# Move any preexisting build scan to make room for a new one
397# After moving a build scan several times it eventually gets deleted
398function rotateBuildScans() {
399 filePrefix="$1"
400 iPlus1="10"
401 for i in $(seq 9 -1 1); do
402 mv "${filePrefix}.${i}.zip" "${filePrefix}.${iPlus1}.zip" 2>/dev/null || true
403 iPlus1=$i
404 done
405 mv ${filePrefix}.zip "${filePrefix}.1.zip" 2>/dev/null || true
406}
407
Jeff Gaston224eb172020-01-09 12:31:47 -0500408function runGradle() {
Jeff Gaston80dbac12024-04-22 16:03:15 -0400409 if [ "$TMPDIR" != "" ]; then
410 mkdir -p "$TMPDIR"
411 TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR"
412 fi
413
Jeff Gaston41b90222020-08-18 11:09:55 -0400414 processOutput=false
Jeff Gastone4b4b872020-08-25 09:02:13 -0400415 if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then
Jeff Gaston41b90222020-08-18 11:09:55 -0400416 processOutput=true
417 fi
418 if [[ " ${@} " =~ " -Pandroidx.summarizeStderr " ]]; then
419 processOutput=true
420 fi
Jeff Gaston3fa62a82023-10-25 15:00:25 -0400421 if [[ "${@} " =~ " -Pandroidx.printTimestamps " ]]; then
422 processOutput=true
423 fi
Jeff Gaston41b90222020-08-18 11:09:55 -0400424 if [ "$processOutput" == "true" ]; then
425 wrapper="$SCRIPT_PATH/development/build_log_processor.sh"
426 else
427 wrapper=""
428 fi
Jeff Gaston3febf902021-03-16 11:23:15 -0400429
Jeff Gaston1e67a612021-11-24 13:31:10 -0500430 RETURN_VALUE=0
Aurimas Liutikas07c47d32023-08-03 15:46:39 -0700431 set -- "$@" -Dorg.gradle.projectcachedir="$OUT_DIR/gradle-project-cache"
Jeff Gastondc9c8cb2023-02-08 16:24:38 -0500432 # Disabled in Studio until these errors become shown (b/268380971) or computed more quickly (https://github.com/gradle/gradle/issues/23272)
433 if [[ " ${@} " =~ " --dependency-verification=" ]]; then
434 VERIFICATION_ARGUMENT="" # already specified by caller
435 else
436 VERIFICATION_ARGUMENT=--dependency-verification=strict
437 fi
Aurimas Liutikas07c47d32023-08-03 15:46:39 -0700438 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 -0500439 RETURN_VALUE=0
Jeff Gaston224eb172020-01-09 12:31:47 -0500440 else
441 # Print AndroidX-specific help message if build fails
442 # Have to do this build-failure detection in gradlew rather than in build.gradle
443 # so that this message still prints even if buildSrc itself fails
444 echo
Jeff Gaston61cef332020-12-22 11:23:09 -0500445 echo For help with unexpected failures, see development/diagnose-build-failure/README.md
446 echo
Jeff Gaston1e67a612021-11-24 13:31:10 -0500447 RETURN_VALUE=1
Jeff Gaston69713292020-06-04 12:53:39 -0400448 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500449
450 # If the caller specified where to save data, then also save the build scan data
451 if [ "$DIST_DIR" != "" ]; then
452 if [ "$GRADLE_USER_HOME" != "" ]; then
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400453 scanDir="$GRADLE_USER_HOME/build-scan-data"
454 if [ -e "$scanDir" ]; then
455 if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
Jeff Gaston6cca77e52023-08-07 11:10:17 -0400456 zipPrefix="$DIST_DIR/scan-up-to-date"
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400457 else
Jeff Gaston6cca77e52023-08-07 11:10:17 -0400458 zipPrefix="$DIST_DIR/scan"
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400459 fi
Jeff Gaston6cca77e52023-08-07 11:10:17 -0400460 rotateBuildScans "$zipPrefix"
461 zipPath="${zipPrefix}.zip"
Jeff Gaston9d97d5c2022-07-06 10:55:47 -0400462 cd "$GRADLE_USER_HOME/build-scan-data"
463 zip -q -r "$zipPath" .
464 cd -
Jeff Gaston1e67a612021-11-24 13:31:10 -0500465 fi
Jeff Gaston1e67a612021-11-24 13:31:10 -0500466 fi
467 fi
468 return $RETURN_VALUE
Jeff Gaston69713292020-06-04 12:53:39 -0400469}
470
Jeff Gaston87a4bbb2022-04-21 12:31:08 -0400471if [ "$cleanCaches" == true ]; then
472 echo "IF ./gradlew --clean FIXES YOUR BUILD; OPEN A BUG."
473 echo "In nearly all cases, it should not be necessary to run a clean build."
474 echo
475 # 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
476 # another case where it is convenient to have a clean build is for performance testing
477 # 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)
478
479 echo "Stopping Gradle daemons"
480 runGradle --stop || true
481 echo
482
483 backupDir=~/androidx-build-state-backup
484 ./development/diagnose-build-failure/impl/backup-state.sh "$backupDir" --move # prints that it is saving state into this dir"
485
486 echo "To restore this state later, run:"
487 echo
488 echo " ./development/diagnose-build-failure/impl/restore-state.sh $backupDir"
489 echo
490 echo "Running Gradle"
491 echo
492fi
493
Jeff Gaston7121d832022-06-08 13:36:50 -0400494if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then
495 echo "Setting 'DISALLOW_TASK_EXECUTION' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?"
Jeff Gaston400ccb32020-06-08 16:44:58 -0400496 echo "See TaskUpToDateValidator.java for more information"
497 exit 1
498fi
499
Jeff Gaston55624742021-04-22 14:05:49 -0400500runGradle "$@"
501# Check whether we were given the "-Pandroidx.verifyUpToDate" argument
502if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then
Jeff Gastoncefdeae2020-03-09 13:12:35 -0400503 # Re-run Gradle, and find all tasks that are unexpectly out of date
Jeff Gaston7121d832022-06-08 13:36:50 -0400504 if ! DISALLOW_TASK_EXECUTION=true runGradle "$@" --continue; then
Jeff Gastone906e5c2020-11-05 12:33:10 -0500505 echo >&2
Jeff Gaston20f5e7a2022-01-27 13:39:25 -0500506 echo "TaskUpToDateValidator's second build failed. To reproduce, try running './gradlew -Pandroidx.verifyUpToDate <failing tasks>'" >&2
Jeff Gastone906e5c2020-11-05 12:33:10 -0500507 exit 1
508 fi
Jeff Gastonb89c82b2019-08-21 16:24:09 -0400509fi