[go: nahoru, domu]

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