Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Jeff Gaston | 6971329 | 2020-06-04 12:53:39 -0400 | [diff] [blame] | 2 | set -o pipefail |
| 3 | set -e |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 4 | |
| 5 | ############################################################################## |
| 6 | ## |
| 7 | ## Gradle start up script for UN*X |
| 8 | ## |
| 9 | ############################################################################## |
| 10 | |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 11 | # --------- androidx specific code needed for build server. ------------------ |
| 12 | |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 13 | SCRIPT_PATH="$(cd $(dirname $0) && pwd -P)" |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 14 | if [ -n "$OUT_DIR" ] ; then |
Jeff Gaston | 8fd9fc8 | 2019-07-26 14:26:10 -0400 | [diff] [blame] | 15 | mkdir -p "$OUT_DIR" |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 16 | OUT_DIR="$(cd $OUT_DIR && pwd -P)" |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 17 | export GRADLE_USER_HOME="$OUT_DIR/.gradle" |
Jeff Gaston | 38004a6 | 2019-12-11 15:43:10 -0500 | [diff] [blame] | 18 | export TMPDIR=$OUT_DIR |
Jeff Gaston | cc694ab | 2019-04-11 16:51:36 -0400 | [diff] [blame] | 19 | else |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 20 | CHECKOUT_ROOT="$(cd $SCRIPT_PATH/../.. && pwd -P)" |
Jeff Gaston | cc694ab | 2019-04-11 16:51:36 -0400 | [diff] [blame] | 21 | export OUT_DIR="$CHECKOUT_ROOT/out" |
Jeff Gaston | d571989 | 2022-04-21 12:06:24 -0400 | [diff] [blame] | 22 | export GRADLE_USER_HOME=~/.gradle |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 23 | fi |
| 24 | |
Jeff Gaston | 440e1ac | 2020-09-09 08:32:22 -0400 | [diff] [blame] | 25 | ORG_GRADLE_JVMARGS="$(cd $SCRIPT_PATH && grep org.gradle.jvmargs gradle.properties | sed 's/^/-D/')" |
Jeff Gaston | 0e3d19a | 2019-10-02 12:17:39 -0400 | [diff] [blame] | 26 | if [ -n "$DIST_DIR" ]; then |
| 27 | mkdir -p "$DIST_DIR" |
Jeff Gaston | dd8a6e9 | 2020-09-01 14:26:49 -0400 | [diff] [blame] | 28 | DIST_DIR="$(cd $DIST_DIR && pwd -P)" |
Jeff Gaston | 0e3d19a | 2019-10-02 12:17:39 -0400 | [diff] [blame] | 29 | |
Jeff Gaston | e72d230 | 2019-12-19 18:32:31 -0500 | [diff] [blame] | 30 | #Set the initial heap size to match the max heap size, |
| 31 | #by replacing a string like "-Xmx1g" with one like "-Xms1g -Xmx1g" |
Jeff Gaston | 77bb2b1 | 2021-04-15 12:51:08 -0400 | [diff] [blame] | 32 | MAX_MEM=24g |
Jeff Gaston | cca984c | 2020-10-05 12:54:17 -0400 | [diff] [blame] | 33 | ORG_GRADLE_JVMARGS="$(echo $ORG_GRADLE_JVMARGS | sed "s/-Xmx\([^ ]*\)/-Xms$MAX_MEM -Xmx$MAX_MEM/")" |
Jeff Gaston | 440e1ac | 2020-09-09 08:32:22 -0400 | [diff] [blame] | 34 | |
| 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 Gaston | e72d230 | 2019-12-19 18:32:31 -0500 | [diff] [blame] | 37 | |
Jeff Gaston | 8b7f1ee | 2022-12-08 14:26:54 -0500 | [diff] [blame] | 38 | # 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 Gaston | 0e3d19a | 2019-10-02 12:17:39 -0400 | [diff] [blame] | 41 | # 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 |
| 43 | fi |
| 44 | |
Alan Viverette | 9d65136 | 2023-03-23 12:34:03 -0400 | [diff] [blame] | 45 | # Loading the AIDL lexer requires disabling Lint's bytecode verification |
| 46 | export ANDROID_LINT_SKIP_BYTECODE_VERIFIER=true |
| 47 | |
Jeff Gaston | c21ecb3 | 2020-11-05 17:16:35 -0500 | [diff] [blame] | 48 | # unset ANDROID_BUILD_TOP so that Lint doesn't think we're building the platform itself |
| 49 | unset ANDROID_BUILD_TOP |
Aurimas Liutikas | 9979d07 | 2018-03-13 15:38:56 -0700 | [diff] [blame] | 50 | # ---------------------------------------------------------------------------- |
| 51 | |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 52 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 53 | |
Jeff Gaston | c6df415 | 2021-11-03 10:24:02 -0400 | [diff] [blame] | 54 | if [[ " ${@} " =~ " -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" |
| 58 | fi |
| 59 | |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 60 | APP_NAME="Gradle" |
| 61 | APP_BASE_NAME=`basename "$0"` |
| 62 | |
| 63 | # Use the maximum available, or set MAX_FD != -1 to use that value. |
| 64 | MAX_FD="maximum" |
| 65 | |
| 66 | warn ( ) { |
| 67 | echo "$*" |
| 68 | } |
| 69 | |
| 70 | die ( ) { |
| 71 | echo |
| 72 | echo "$*" |
| 73 | echo |
| 74 | exit 1 |
| 75 | } |
| 76 | |
| 77 | # OS specific support (must be 'true' or 'false'). |
| 78 | cygwin=false |
| 79 | msys=false |
| 80 | darwin=false |
| 81 | case "`uname`" in |
| 82 | CYGWIN* ) |
| 83 | cygwin=true |
| 84 | ;; |
| 85 | Darwin* ) |
| 86 | darwin=true |
| 87 | ;; |
| 88 | MINGW* ) |
| 89 | msys=true |
| 90 | ;; |
| 91 | esac |
Rahul Ravikumar | 465ccfc | 2022-02-14 14:58:20 -0800 | [diff] [blame] | 92 | platform_suffix="x86" |
| 93 | case "$(arch)" in |
| 94 | arm64* ) |
| 95 | platform_suffix="arm64" |
| 96 | esac |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 97 | # Attempt to set APP_HOME |
| 98 | # Resolve links: $0 may be a link |
| 99 | PRG="$0" |
| 100 | # Need this for relative symlinks. |
| 101 | while [ -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 |
| 109 | done |
| 110 | SAVED="`pwd`" |
Yigit Boyar | f77697d | 2016-08-16 10:55:36 -0700 | [diff] [blame] | 111 | cd "`dirname \"$PRG\"`/" >/dev/null |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 112 | APP_HOME="`pwd -P`" |
Yigit Boyar | f77697d | 2016-08-16 10:55:36 -0700 | [diff] [blame] | 113 | cd "$SAVED" >/dev/null |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 114 | |
| 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar |
| 116 | |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 117 | # --------- androidx specific code needed for lint and java. ------------------ |
| 118 | |
Alan Viverette | d38b36c | 2017-02-01 16:45:31 -0500 | [diff] [blame] | 119 | # Pick the correct fullsdk for this OS. |
Alan Viverette | 7df63ff | 2017-03-06 13:12:24 -0500 | [diff] [blame] | 120 | if [ $darwin == "true" ]; then |
Alan Viverette | d38b36c | 2017-02-01 16:45:31 -0500 | [diff] [blame] | 121 | plat="darwin" |
| 122 | else |
| 123 | plat="linux" |
| 124 | fi |
Alan Viverette | d38b36c | 2017-02-01 16:45:31 -0500 | [diff] [blame] | 125 | |
Matthew Fraschilla | 6ab84fc3 | 2019-11-21 16:40:16 -0800 | [diff] [blame] | 126 | # Tests for lint checks default to using sdk defined by this variable. This removes a lot of |
| 127 | # setup from each lint module. |
| 128 | export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat" |
Sergey Vasilinets | efab5eb | 2019-01-04 12:38:06 +0000 | [diff] [blame] | 129 | # override JAVA_HOME, because CI machines have it and it points to very old JDK |
Aurimas Liutikas | 420b7f6 | 2022-08-02 13:53:39 -0700 | [diff] [blame] | 130 | export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk17/$plat-$platform_suffix" |
Aurimas Liutikas | 4b897cb | 2019-10-14 13:25:08 -0700 | [diff] [blame] | 131 | export JAVA_TOOLS_JAR="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86/lib/tools.jar" |
| 132 | export STUDIO_GRADLE_JDK=$JAVA_HOME |
Oussama Ben Abdelbaki | f825eb5 | 2018-12-04 16:17:00 -0500 | [diff] [blame] | 133 | |
Aurimas Liutikas | d6bc55a | 2022-05-24 13:19:07 -0700 | [diff] [blame] | 134 | # Warn developers if they try to build top level project without the full checkout |
Alan Viverette | 6b2fb21 | 2022-10-17 17:11:29 +0000 | [diff] [blame] | 135 | [ ! -d "$JAVA_HOME" ] && echo "Failed to find: $JAVA_HOME |
Aurimas Liutikas | d6bc55a | 2022-05-24 13:19:07 -0700 | [diff] [blame] | 136 | |
Alan Viverette | 6b2fb21 | 2022-10-17 17:11:29 +0000 | [diff] [blame] | 137 | Typically, this means either: |
| 138 | 1. You are using the standalone AndroidX checkout, e.g. GitHub, which only supports |
| 139 | building a subset of projects. See CONTRIBUTING.md for details. |
| 140 | 2. 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 Liutikas | d6bc55a | 2022-05-24 13:19:07 -0700 | [diff] [blame] | 142 | |
Jeff Gaston | 79a43f2 | 2019-04-09 16:19:12 -0400 | [diff] [blame] | 143 | # ---------------------------------------------------------------------------- |
| 144 | |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 145 | # Determine the Java command to use to start the JVM. |
| 146 | if [ -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 | |
| 156 | Please set the JAVA_HOME variable in your environment to match the |
| 157 | location of your Java installation." |
| 158 | fi |
| 159 | else |
| 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 | |
| 163 | Please set the JAVA_HOME variable in your environment to match the |
| 164 | location of your Java installation." |
| 165 | fi |
| 166 | |
| 167 | # Increase the maximum file descriptors if we can. |
| 168 | if [ "$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 |
| 181 | fi |
| 182 | |
| 183 | # For Darwin, add options to specify how the application appears in the dock |
| 184 | if $darwin; then |
| 185 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" |
| 186 | fi |
| 187 | |
| 188 | # For Cygwin, switch paths to Windows format before running java |
| 189 | if $cygwin ; then |
| 190 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` |
| 191 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` |
Yigit Boyar | f77697d | 2016-08-16 10:55:36 -0700 | [diff] [blame] | 192 | JAVACMD=`cygpath --unix "$JAVACMD"` |
Xavier Ducrohet | 0f3d903 | 2014-03-18 17:25:21 -0700 | [diff] [blame] | 193 | |
| 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 |
| 231 | fi |
| 232 | |
| 233 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules |
| 234 | function splitJvmOpts() { |
| 235 | JVM_OPTS=("$@") |
| 236 | } |
| 237 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS |
| 238 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" |
| 239 | |
Jeff Gaston | 826bdbe | 2019-11-20 14:56:24 -0500 | [diff] [blame] | 240 | #TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed |
| 241 | HOME_SYSTEM_PROPERTY_ARGUMENT="" |
| 242 | if [ "$GRADLE_USER_HOME" != "" ]; then |
| 243 | HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME" |
| 244 | fi |
Jeff Gaston | 38004a6 | 2019-12-11 15:43:10 -0500 | [diff] [blame] | 245 | if [ "$TMPDIR" != "" ]; then |
| 246 | TMPDIR_ARG="-Djava.io.tmpdir=$TMPDIR" |
| 247 | fi |
Jeff Gaston | 826bdbe | 2019-11-20 14:56:24 -0500 | [diff] [blame] | 248 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 249 | if [[ " ${@} " =~ " --clean " ]]; then |
| 250 | cleanCaches=true |
| 251 | else |
| 252 | cleanCaches=false |
| 253 | fi |
| 254 | |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 255 | if [[ " ${@} " =~ " --no-ci " ]]; then |
| 256 | disableCi=true |
| 257 | else |
| 258 | disableCi=false |
| 259 | fi |
| 260 | |
Jeff Gaston | 829fd82 | 2021-09-23 11:42:48 -0400 | [diff] [blame] | 261 | # workaround for https://github.com/gradle/gradle/issues/18386 |
| 262 | if [[ " ${@} " =~ " --profile " ]]; then |
| 263 | mkdir -p reports |
| 264 | fi |
| 265 | |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 266 | # Expand some arguments |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 267 | for compact in "--ci" "--strict" "--clean" "--no-ci"; do |
| 268 | expanded="" |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 269 | if [ "$compact" == "--ci" ]; then |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 270 | if [ "$disableCi" == "false" ]; then |
| 271 | expanded="--strict\ |
| 272 | --stacktrace\ |
| 273 | -Pandroidx.summarizeStderr\ |
| 274 | -Pandroidx.enableAffectedModuleDetection\ |
| 275 | --no-watch-fs" |
| 276 | fi |
Jeff Gaston | 4537e14 | 2021-01-27 13:08:50 -0500 | [diff] [blame] | 277 | fi |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 278 | if [ "$compact" == "--strict" ]; then |
Aurimas Liutikas | 41c58e0 | 2022-06-09 08:54:18 -0700 | [diff] [blame] | 279 | expanded="-Pandroidx.validateNoUnrecognizedMessages\ |
Jeff Gaston | 5562474 | 2021-04-22 14:05:49 -0400 | [diff] [blame] | 280 | -Pandroidx.verifyUpToDate\ |
Aurimas Liutikas | f06703b | 2022-07-08 16:28:11 +0000 | [diff] [blame] | 281 | --no-watch-fs" |
Jeff Gaston | 934d0b1 | 2022-04-26 17:47:25 -0400 | [diff] [blame] | 282 | if [ "$USE_ANDROIDX_REMOTE_BUILD_CACHE" == "" ]; then |
| 283 | expanded="$expanded --offline" |
| 284 | fi |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 285 | fi |
Jeff Gaston | 794b0b7 | 2021-09-28 12:47:47 -0400 | [diff] [blame] | 286 | # if compact is something else then we parsed the argument above but |
| 287 | # still have to remove it (expanded == "") to avoid confusing Gradle |
Jeff Gaston | 7eafa5d | 2021-02-10 16:12:54 -0500 | [diff] [blame] | 288 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 289 | # 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 Gaston | 4537e14 | 2021-01-27 13:08:50 -0500 | [diff] [blame] | 317 | done |
| 318 | |
Jeff Gaston | b03b05a | 2022-04-11 11:41:59 -0400 | [diff] [blame] | 319 | # check whether the user has requested profiling via yourkit |
| 320 | yourkitArgPrefix="androidx.profile.yourkitAgentPath" |
| 321 | yourkitAgentPath="" |
| 322 | if [[ " ${@}" =~ " -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 |
| 360 | fi |
| 361 | |
Jeff Gaston | d2806b3 | 2021-09-29 12:20:39 -0400 | [diff] [blame] | 362 | if [[ " ${@} " =~ " --scan " ]]; then |
| 363 | if [[ " ${@} " =~ " --offline " ]]; then |
| 364 | echo "--scan incompatible with --offline" |
| 365 | echo "you could try --no-ci" |
| 366 | exit 1 |
| 367 | fi |
| 368 | fi |
| 369 | |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 370 | function 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 Gaston | 829fd82 | 2021-09-23 11:42:48 -0400 | [diff] [blame] | 379 | # https://github.com/gradle/gradle/issues/18386 |
| 380 | rm -rf $SCRIPT_PATH/reports |
Jeff Gaston | 96eb601 | 2021-09-27 14:55:36 +0000 | [diff] [blame] | 381 | rm -rf $SCRIPT_PATH/build |
Jeff Gaston | baa2b20 | 2021-04-23 15:44:59 -0400 | [diff] [blame] | 382 | rm -rf $OUT_DIR |
| 383 | } |
| 384 | |
Jeff Gaston | 224eb17 | 2020-01-09 12:31:47 -0500 | [diff] [blame] | 385 | function runGradle() { |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 386 | processOutput=false |
Jeff Gaston | e4b4b87 | 2020-08-25 09:02:13 -0400 | [diff] [blame] | 387 | if [[ " ${@} " =~ " -Pandroidx.validateNoUnrecognizedMessages " ]]; then |
Jeff Gaston | 41b9022 | 2020-08-18 11:09:55 -0400 | [diff] [blame] | 388 | 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 Gaston | 3febf90 | 2021-03-16 11:23:15 -0400 | [diff] [blame] | 398 | |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 399 | RETURN_VALUE=0 |
Jeff Gaston | 3febf90 | 2021-03-16 11:23:15 -0400 | [diff] [blame] | 400 | PROJECT_CACHE_DIR_ARGUMENT="--project-cache-dir $OUT_DIR/gradle-project-cache" |
Jeff Gaston | dc9c8cb | 2023-02-08 16:24:38 -0500 | [diff] [blame] | 401 | # 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 Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 408 | RETURN_VALUE=0 |
Jeff Gaston | 224eb17 | 2020-01-09 12:31:47 -0500 | [diff] [blame] | 409 | 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 Gaston | 61cef33 | 2020-12-22 11:23:09 -0500 | [diff] [blame] | 414 | echo For help with unexpected failures, see development/diagnose-build-failure/README.md |
| 415 | echo |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 416 | RETURN_VALUE=1 |
Jeff Gaston | 6971329 | 2020-06-04 12:53:39 -0400 | [diff] [blame] | 417 | fi |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 418 | |
| 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 Gaston | 9d97d5c | 2022-07-06 10:55:47 -0400 | [diff] [blame] | 422 | 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 Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 433 | fi |
Jeff Gaston | 1e67a61 | 2021-11-24 13:31:10 -0500 | [diff] [blame] | 434 | fi |
| 435 | fi |
| 436 | return $RETURN_VALUE |
Jeff Gaston | 6971329 | 2020-06-04 12:53:39 -0400 | [diff] [blame] | 437 | } |
| 438 | |
Jeff Gaston | 87a4bbb | 2022-04-21 12:31:08 -0400 | [diff] [blame] | 439 | if [ "$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 |
| 460 | fi |
| 461 | |
Jeff Gaston | 7121d83 | 2022-06-08 13:36:50 -0400 | [diff] [blame] | 462 | if [[ "$DISALLOW_TASK_EXECUTION" != "" ]]; then |
| 463 | echo "Setting 'DISALLOW_TASK_EXECUTION' directly is forbidden. Did you mean -Pandroidx.verifyUpToDate ?" |
Jeff Gaston | 400ccb3 | 2020-06-08 16:44:58 -0400 | [diff] [blame] | 464 | echo "See TaskUpToDateValidator.java for more information" |
| 465 | exit 1 |
| 466 | fi |
| 467 | |
Jeff Gaston | 5562474 | 2021-04-22 14:05:49 -0400 | [diff] [blame] | 468 | runGradle "$@" |
| 469 | # Check whether we were given the "-Pandroidx.verifyUpToDate" argument |
| 470 | if [[ " ${@} " =~ " -Pandroidx.verifyUpToDate " ]]; then |
Jeff Gaston | cefdeae | 2020-03-09 13:12:35 -0400 | [diff] [blame] | 471 | # Re-run Gradle, and find all tasks that are unexpectly out of date |
Jeff Gaston | 7121d83 | 2022-06-08 13:36:50 -0400 | [diff] [blame] | 472 | if ! DISALLOW_TASK_EXECUTION=true runGradle "$@" --continue; then |
Jeff Gaston | e906e5c | 2020-11-05 12:33:10 -0500 | [diff] [blame] | 473 | echo >&2 |
Jeff Gaston | 20f5e7a | 2022-01-27 13:39:25 -0500 | [diff] [blame] | 474 | echo "TaskUpToDateValidator's second build failed. To reproduce, try running './gradlew -Pandroidx.verifyUpToDate <failing tasks>'" >&2 |
Jeff Gaston | e906e5c | 2020-11-05 12:33:10 -0500 | [diff] [blame] | 475 | exit 1 |
| 476 | fi |
Jeff Gaston | b89c82b | 2019-08-21 16:24:09 -0400 | [diff] [blame] | 477 | fi |