blob: 5e8daf47b13a064fb412030fab7c5785017b6c94 [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"
Aurimas Liutikasc5f4f982018-05-17 14:03:04 -070015 export LINT_PRINT_STACKTRACE=true
Jeff Gastoncc694ab2019-04-11 16:51:36 -040016else
17 SCRIPT_PATH="$(cd $(dirname $0) && pwd)"
18 CHECKOUT_ROOT="$(cd $SCRIPT_PATH/../.. && pwd)"
19 export OUT_DIR="$CHECKOUT_ROOT/out"
Aurimas Liutikas9979d072018-03-13 15:38:56 -070020fi
21
22# ----------------------------------------------------------------------------
23
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070024# 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 -070025
26APP_NAME="Gradle"
27APP_BASE_NAME=`basename "$0"`
28
29# Use the maximum available, or set MAX_FD != -1 to use that value.
30MAX_FD="maximum"
31
32warn ( ) {
33 echo "$*"
34}
35
36die ( ) {
37 echo
38 echo "$*"
39 echo
40 exit 1
41}
42
43# OS specific support (must be 'true' or 'false').
44cygwin=false
45msys=false
46darwin=false
47case "`uname`" in
48 CYGWIN* )
49 cygwin=true
50 ;;
51 Darwin* )
52 darwin=true
53 ;;
54 MINGW* )
55 msys=true
56 ;;
57esac
58
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070059# Attempt to set APP_HOME
60# Resolve links: $0 may be a link
61PRG="$0"
62# Need this for relative symlinks.
63while [ -h "$PRG" ] ; do
64 ls=`ls -ld "$PRG"`
65 link=`expr "$ls" : '.*-> \(.*\)$'`
66 if expr "$link" : '/.*' > /dev/null; then
67 PRG="$link"
68 else
69 PRG=`dirname "$PRG"`"/$link"
70 fi
71done
72SAVED="`pwd`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070073cd "`dirname \"$PRG\"`/" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070074APP_HOME="`pwd -P`"
Yigit Boyarf77697d2016-08-16 10:55:36 -070075cd "$SAVED" >/dev/null
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070076
77CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
78
Jeff Gaston79a43f22019-04-09 16:19:12 -040079# --------- androidx specific code needed for lint and java. ------------------
80
Alan Viveretted38b36c2017-02-01 16:45:31 -050081# Pick the correct fullsdk for this OS.
Alan Viverette7df63ff2017-03-06 13:12:24 -050082if [ $darwin == "true" ]; then
Alan Viveretted38b36c2017-02-01 16:45:31 -050083 plat="darwin"
84else
85 plat="linux"
86fi
87DEFAULT_JVM_OPTS="-DLINT_API_DATABASE=$APP_HOME/../../prebuilts/fullsdk-$plat/platform-tools/api/api-versions.xml"
88
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050089# Temporary solution for custom, private lint rules https://issuetracker.google.com/issues/65248347
90# Gradle automatically invokes 'jar' task on 'buildSrc/' projects so this will always be available.
Jeff Gaston79a43f22019-04-09 16:19:12 -040091export ANDROID_LINT_JARS="$OUT_DIR/buildSrc/lint-checks/build/libs/lint-checks.jar"
Sergey Vasilinetsefab5eb2019-01-04 12:38:06 +000092# override JAVA_HOME, because CI machines have it and it points to very old JDK
93export JAVA_HOME="$APP_HOME/../../prebuilts/jdk/jdk8/$plat-x86"
Oussama Ben Abdelbakif825eb52018-12-04 16:17:00 -050094
Jeff Gaston79a43f22019-04-09 16:19:12 -040095# ----------------------------------------------------------------------------
96
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -070097# Determine the Java command to use to start the JVM.
98if [ -n "$JAVA_HOME" ] ; then
99 if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
100 # IBM's JDK on AIX uses strange locations for the executables
101 JAVACMD="$JAVA_HOME/jre/sh/java"
102 else
103 JAVACMD="$JAVA_HOME/bin/java"
104 fi
105 if [ ! -x "$JAVACMD" ] ; then
106 die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
107
108Please set the JAVA_HOME variable in your environment to match the
109location of your Java installation."
110 fi
111else
112 JAVACMD="java"
113 which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
114
115Please set the JAVA_HOME variable in your environment to match the
116location of your Java installation."
117fi
118
119# Increase the maximum file descriptors if we can.
120if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
121 MAX_FD_LIMIT=`ulimit -H -n`
122 if [ $? -eq 0 ] ; then
123 if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
124 MAX_FD="$MAX_FD_LIMIT"
125 fi
126 ulimit -n $MAX_FD
127 if [ $? -ne 0 ] ; then
128 warn "Could not set maximum file descriptor limit: $MAX_FD"
129 fi
130 else
131 warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
132 fi
133fi
134
135# For Darwin, add options to specify how the application appears in the dock
136if $darwin; then
137 GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
138fi
139
140# For Cygwin, switch paths to Windows format before running java
141if $cygwin ; then
142 APP_HOME=`cygpath --path --mixed "$APP_HOME"`
143 CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
Yigit Boyarf77697d2016-08-16 10:55:36 -0700144 JAVACMD=`cygpath --unix "$JAVACMD"`
Xavier Ducrohet0f3d9032014-03-18 17:25:21 -0700145
146 # We build the pattern for arguments to be converted via cygpath
147 ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
148 SEP=""
149 for dir in $ROOTDIRSRAW ; do
150 ROOTDIRS="$ROOTDIRS$SEP$dir"
151 SEP="|"
152 done
153 OURCYGPATTERN="(^($ROOTDIRS))"
154 # Add a user-defined pattern to the cygpath arguments
155 if [ "$GRADLE_CYGPATTERN" != "" ] ; then
156 OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
157 fi
158 # Now convert the arguments - kludge to limit ourselves to /bin/sh
159 i=0
160 for arg in "$@" ; do
161 CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
162 CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
163
164 if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
165 eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
166 else
167 eval `echo args$i`="\"$arg\""
168 fi
169 i=$((i+1))
170 done
171 case $i in
172 (0) set -- ;;
173 (1) set -- "$args0" ;;
174 (2) set -- "$args0" "$args1" ;;
175 (3) set -- "$args0" "$args1" "$args2" ;;
176 (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
177 (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
178 (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
179 (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
180 (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
181 (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
182 esac
183fi
184
185# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
186function splitJvmOpts() {
187 JVM_OPTS=("$@")
188}
189eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
190JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
191
Jeff Gaston9998eae2018-10-11 15:17:48 -0400192exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"