blob: 395fc826e60278be54f9ea2368d8a0546649a0e6 [file] [log] [blame]
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -07001#!/usr/bin/env bash
2
3##############################################################################
4##
5## Gradle start up script for UN*X
6##
7##############################################################################
8
Aurimas Liutikas9979d072018-03-13 15:38:56 -07009# --------- androidx specific code needed for build server. ------------------
10
11if [ -n "$OUT_DIR" ] ; then
Jeff Gaston8fd9fc82019-07-26 14:26:10 -040012 mkdir -p "$OUT_DIR"
13 OUT_DIR="$(cd $OUT_DIR && pwd)"
Aurimas Liutikas9979d072018-03-13 15:38:56 -070014 export GRADLE_USER_HOME="$OUT_DIR/.gradle"
Jeff Gastoncc694ab2019-04-11 16:51:36 -040015else
16 SCRIPT_PATH="$(cd $(dirname $0) && pwd)"
17 CHECKOUT_ROOT="$(cd $SCRIPT_PATH/../.. && pwd)"
18 export OUT_DIR="$CHECKOUT_ROOT/out"
Aurimas Liutikas9979d072018-03-13 15:38:56 -070019fi
20
Jeff Gaston0e3d19a2019-10-02 12:17:39 -040021if [ -n "$DIST_DIR" ]; then
22 mkdir -p "$DIST_DIR"
23 DIST_DIR="$(cd $DIST_DIR && pwd)"
24 export LINT_PRINT_STACKTRACE=true
25
26 # We don't set a default DIST_DIR in an else clause here because Studio doesn't use gradlew
27 # and doesn't set DIST_DIR and we want gradlew and Studio to match
28fi
29
Aurimas Liutikas9979d072018-03-13 15:38:56 -070030# ----------------------------------------------------------------------------
31
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070032# 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 -070033
34APP_NAME="Gradle"
35APP_BASE_NAME=`basename "$0"`
36
37# Use the maximum available, or set MAX_FD != -1 to use that value.
38MAX_FD="maximum"
39
40warn ( ) {
41 echo "$*"
42}
43
44die ( ) {
45 echo
46 echo "$*"
47 echo
48 exit 1
49}
50
51# OS specific support (must be 'true' or 'false').
52cygwin=false
53msys=false
54darwin=false
55case "`uname`" in
56 CYGWIN* )
57 cygwin=true
58 ;;
59 Darwin* )
60 darwin=true
61 ;;
62 MINGW* )
63 msys=true
64 ;;
65esac
66
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070067# Attempt to set APP_HOME
68# Resolve links: $0 may be a link
69PRG="$0"
70# Need this for relative symlinks.
71while [ -h "$PRG" ] ; do
72 ls=`ls -ld "$PRG"`
73 link=`expr "$ls" : '.*-> \(.*\)$'`
74 if expr "$link" : '/.*' > /dev/null; then
75 PRG="$link"
76 else
77 PRG=`dirname "$PRG"`"/$link"
78 fi
79done
80SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070081cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070082APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070083cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070084
85CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
86
Jeff Gaston79a43f22019-04-09 16:19:12 -040087# --------- androidx specific code needed for lint and java. ------------------
88
Alan Viveretted38b36c2017-02-01 16:45:31 -050089# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -050090if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -050091 plat="darwin"
92else
93 plat="linux"
94fi
95DEFAULT_JVM_OPTS="-DLINT_API_DATABASE=$APP_HOME/../../prebuilts/fullsdk-$plat/platform-tools/api/api-versions.xml"
96
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050097# Temporary solution for custom, private lint rules https://issuetracker.google.com/issues/65248347
98# Gradle automatically invokes 'jar' task on 'buildSrc/' projects so this will always be available.
Jeff Gaston79a43f22019-04-09 16:19:12 -040099export ANDROID_LINT_JARS="$OUT_DIR/buildSrc/lint-checks/build/libs/lint-checks.jar"
Matthew Fraschilla6ab84fc32019-11-21 16:40:16 -0800100# Tests for lint checks default to using sdk defined by this variable. This removes a lot of
101# setup from each lint module.
102export ANDROID_HOME="$APP_HOME/../../prebuilts/fullsdk-$plat"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +0000103# override JAVA_HOME, because CI machines have it and it points to very old JDK
104export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86"
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -0500105
Jeff Gaston79a43f22019-04-09 16:19:12 -0400106# ----------------------------------------------------------------------------
107
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700108# Determine the Java command to use to start the JVM.
109if [ -n "$JAVA_HOME" ] ; then
110 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
111 # IBM's JDK on AIX uses strange locations for the executables
112 JAVACMD="$JAVA_HOME/jre/sh/java"
113 else
114 JAVACMD="$JAVA_HOME/bin/java"
115 fi
116 if [ ! -x "$JAVACMD" ] ; then
117 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
118
119Please set the JAVA_HOME variable in your environment to match the
120location of your Java installation."
121 fi
122else
123 JAVACMD="java"
124 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
125
126Please set the JAVA_HOME variable in your environment to match the
127location of your Java installation."
128fi
129
130# Increase the maximum file descriptors if we can.
131if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
132 MAX_FD_LIMIT=`ulimit -H -n`
133 if [ $? -eq 0 ] ; then
134 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
135 MAX_FD="$MAX_FD_LIMIT"
136 fi
137 ulimit -n $MAX_FD
138 if [ $? -ne 0 ] ; then
139 warn "Could not set maximum file descriptor limit: $MAX_FD"
140 fi
141 else
142 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
143 fi
144fi
145
146# For Darwin, add options to specify how the application appears in the dock
147if $darwin; then
148 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
149fi
150
151# For Cygwin, switch paths to Windows format before running java
152if $cygwin ; then
153 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
154 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700155 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700156
157 # We build the pattern for arguments to be converted via cygpath
158 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
159 SEP=""
160 for dir in $ROOTDIRSRAW ; do
161 ROOTDIRS="$ROOTDIRS$SEP$dir"
162 SEP="|"
163 done
164 OURCYGPATTERN="(^($ROOTDIRS))"
165 # Add a user-defined pattern to the cygpath arguments
166 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
167 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
168 fi
169 # Now convert the arguments - kludge to limit ourselves to /bin/sh
170 i=0
171 for arg in "$@" ; do
172 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
173 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
174
175 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
176 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
177 else
178 eval `echo args$i`="\"$arg\""
179 fi
180 i=$((i+1))
181 done
182 case $i in
183 (0) set -- ;;
184 (1) set -- "$args0" ;;
185 (2) set -- "$args0" "$args1" ;;
186 (3) set -- "$args0" "$args1" "$args2" ;;
187 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
188 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
189 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
190 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
191 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
192 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
193 esac
194fi
195
196# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
197function splitJvmOpts() {
198 JVM_OPTS=("$@")
199}
200eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
201JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
202
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500203#TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed
204HOME_SYSTEM_PROPERTY_ARGUMENT=""
205if [ "$GRADLE_USER_HOME" != "" ]; then
206 HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME"
207fi
208
209if "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain $HOME_SYSTEM_PROPERTY_ARGUMENT "$@"; then
Jeff Gastonb89c82b2019-08-21 16:24:09 -0400210 exit 0
211else
212 # Print AndroidX-specific help message if build fails
213 # Have to do this build-failure detection in gradlew rather than in build.gradle
214 # so that this message still prints even if buildSrc itself fails
215 echo
216 echo See also development/diagnose-build-failure for help with build failures in this project.
217 exit 1
218fi