blob: b2ac4268f0e1c35bdfd2984409d9318c962f1246 [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"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +0000100# override JAVA_HOME, because CI machines have it and it points to very old JDK
101export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86"
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -0500102
Jeff Gaston79a43f22019-04-09 16:19:12 -0400103# ----------------------------------------------------------------------------
104
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700105# Determine the Java command to use to start the JVM.
106if [ -n "$JAVA_HOME" ] ; then
107 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
108 # IBM's JDK on AIX uses strange locations for the executables
109 JAVACMD="$JAVA_HOME/jre/sh/java"
110 else
111 JAVACMD="$JAVA_HOME/bin/java"
112 fi
113 if [ ! -x "$JAVACMD" ] ; then
114 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
115
116Please set the JAVA_HOME variable in your environment to match the
117location of your Java installation."
118 fi
119else
120 JAVACMD="java"
121 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
122
123Please set the JAVA_HOME variable in your environment to match the
124location of your Java installation."
125fi
126
127# Increase the maximum file descriptors if we can.
128if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
129 MAX_FD_LIMIT=`ulimit -H -n`
130 if [ $? -eq 0 ] ; then
131 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
132 MAX_FD="$MAX_FD_LIMIT"
133 fi
134 ulimit -n $MAX_FD
135 if [ $? -ne 0 ] ; then
136 warn "Could not set maximum file descriptor limit: $MAX_FD"
137 fi
138 else
139 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
140 fi
141fi
142
143# For Darwin, add options to specify how the application appears in the dock
144if $darwin; then
145 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
146fi
147
148# For Cygwin, switch paths to Windows format before running java
149if $cygwin ; then
150 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
151 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700152 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700153
154 # We build the pattern for arguments to be converted via cygpath
155 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
156 SEP=""
157 for dir in $ROOTDIRSRAW ; do
158 ROOTDIRS="$ROOTDIRS$SEP$dir"
159 SEP="|"
160 done
161 OURCYGPATTERN="(^($ROOTDIRS))"
162 # Add a user-defined pattern to the cygpath arguments
163 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
164 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
165 fi
166 # Now convert the arguments - kludge to limit ourselves to /bin/sh
167 i=0
168 for arg in "$@" ; do
169 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
170 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
171
172 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
173 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
174 else
175 eval `echo args$i`="\"$arg\""
176 fi
177 i=$((i+1))
178 done
179 case $i in
180 (0) set -- ;;
181 (1) set -- "$args0" ;;
182 (2) set -- "$args0" "$args1" ;;
183 (3) set -- "$args0" "$args1" "$args2" ;;
184 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
185 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
186 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
187 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
188 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
189 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
190 esac
191fi
192
193# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
194function splitJvmOpts() {
195 JVM_OPTS=("$@")
196}
197eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
198JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
199
Jeff Gaston826bdbe2019-11-20 14:56:24 -0500200#TODO: Remove HOME_SYSTEM_PROPERTY_ARGUMENT if https://github.com/gradle/gradle/issues/11433 gets fixed
201HOME_SYSTEM_PROPERTY_ARGUMENT=""
202if [ "$GRADLE_USER_HOME" != "" ]; then
203 HOME_SYSTEM_PROPERTY_ARGUMENT="-Duser.home=$GRADLE_USER_HOME"
204fi
205
206if "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain $HOME_SYSTEM_PROPERTY_ARGUMENT "$@"; then
Jeff Gastonb89c82b2019-08-21 16:24:09 -0400207 exit 0
208else
209 # Print AndroidX-specific help message if build fails
210 # Have to do this build-failure detection in gradlew rather than in build.gradle
211 # so that this message still prints even if buildSrc itself fails
212 echo
213 echo See also development/diagnose-build-failure for help with build failures in this project.
214 exit 1
215fi