blob: 7acb3632d29ef2beacead6d0e6f3d16b3bbab3e2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
#!/usr/bin/env bash
#
##############################################################################
# Copyright 2002-2013 LAMP/EPFL
#
# This is free software; see the distribution for copying conditions.
# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
##############################################################################
findScalaHome () {
# see SI-2092 and SI-5792
local source="${BASH_SOURCE[0]}"
while [ -h "$source" ] ; do
local linked="$(readlink "$source")"
local dir="$( cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd )"
source="$dir/$(basename "$linked")"
done
( cd -P "$(dirname "$source")/.." && pwd )
}
execCommand () {
[[ -n $SCALA_RUNNER_DEBUG ]] && echo "" && for arg in "$@@"; do echo "$arg"; done && echo "";
"$@@"
}
# Not sure what the right default is here: trying nonzero.
scala_exit_status=127
saved_stty=""
# restore stty settings (echo in particular)
function restoreSttySettings() {
if [[ -n $SCALA_RUNNER_DEBUG ]]; then
echo "restoring stty:"
echo "$saved_stty"
fi
stty $saved_stty
saved_stty=""
}
function onExit() {
[[ "$saved_stty" != "" ]] && restoreSttySettings
exit $scala_exit_status
}
# to reenable echo if we are interrupted before completing.
trap onExit INT
# save terminal settings
saved_stty=$(stty -g 2>/dev/null)
# clear on error so we don't later try to restore them
if [[ ! $? ]]; then
saved_stty=""
fi
if [[ -n $SCALA_RUNNER_DEBUG ]]; then
echo "saved stty:"
echo "$saved_stty"
fi
unset cygwin
if uname | grep -q ^CYGWIN; then
cygwin="$(uname)"
fi
unset mingw
if uname | grep -q ^MINGW; then
mingw="$(uname)"
fi
# Finding the root folder for this Scala distribution
SCALA_HOME="$(findScalaHome)"
SEP=":"
# Possible additional command line options
WINDOWS_OPT=""
EMACS_OPT="-Denv.emacs=$EMACS"
# Remove spaces from SCALA_HOME on windows
if [[ -n "$cygwin" ]]; then
SCALA_HOME="$(shome="$(cygpath --windows --short-name "$SCALA_HOME")" ; cygpath --unix "$shome")"
# elif uname |grep -q ^MINGW; then
# SEP=";"
fi
# Constructing the extension classpath
TOOL_CLASSPATH="@classpath@"
if [[ -z "$TOOL_CLASSPATH" ]]; then
for ext in "$SCALA_HOME"/lib/* ; do
file_extension="${ext##*.}"
# SI-8967 Only consider directories and files named '*.jar'
if [[ -d "$ext" || $file_extension == "jar" ]]; then
if [[ -z "$TOOL_CLASSPATH" ]]; then
TOOL_CLASSPATH="$ext"
else
TOOL_CLASSPATH="${TOOL_CLASSPATH}${SEP}${ext}"
fi
fi
done
fi
if [[ -n "$cygwin" ]]; then
if [[ "$OS" = "Windows_NT" ]] && cygpath -m .>/dev/null 2>/dev/null ; then
format=mixed
else
format=windows
fi
SCALA_HOME="$(cygpath --$format "$SCALA_HOME")"
if [[ -n "$JAVA_HOME" ]]; then
JAVA_HOME="$(cygpath --$format "$JAVA_HOME")"
fi
TOOL_CLASSPATH="$(cygpath --path --$format "$TOOL_CLASSPATH")"
elif [[ -n "$mingw" ]]; then
SCALA_HOME="$(cmd //c echo "$SCALA_HOME")"
TOOL_CLASSPATH="$(cmd //c echo "$TOOL_CLASSPATH")"
fi
if [[ -n "$cygwin$mingw" ]]; then
case "$TERM" in
rxvt* | xterm*)
stty -icanon min 1 -echo
WINDOWS_OPT="-Djline.terminal=unix"
;;
esac
fi
[[ -n "$JAVA_OPTS" ]] || JAVA_OPTS="@javaflags@"
# break out -D and -J options and add them to JAVA_OPTS as well
# so they reach the underlying JVM in time to do some good. The
# -D options will be available as system properties.
declare -a java_args
declare -a scala_args
# default to the boot classpath for speed, except on cygwin/mingw because
# JLine on Windows requires a custom DLL to be loaded.
unset usebootcp
if [[ -z "$cygwin$mingw" ]]; then
usebootcp="true"
fi
# If using the boot classpath, also pass an empty classpath
# to java to suppress "." from materializing.
classpathArgs () {
if [[ -n $usebootcp ]]; then
echo "-Xbootclasspath/a:$TOOL_CLASSPATH -classpath \"\""
else
echo "-classpath $TOOL_CLASSPATH"
fi
}
# SI-8358, SI-8368 -- the default should really be false,
# but I don't want to flip the default during 2.11's RC cycle
OVERRIDE_USEJAVACP="-Dscala.usejavacp=true"
while [[ $# -gt 0 ]]; do
case "$1" in
-D*)
# pass to scala as well: otherwise we lose it sometimes when we
# need it, e.g. communicating with a server compiler.
java_args=("${java_args[@@]}" "$1")
scala_args=("${scala_args[@@]}" "$1")
# respect user-supplied -Dscala.usejavacp
case "$1" in -Dscala.usejavacp*) OVERRIDE_USEJAVACP="";; esac
shift
;;
-J*)
# as with -D, pass to scala even though it will almost
# never be used.
java_args=("${java_args[@@]}" "${1:2}")
scala_args=("${scala_args[@@]}" "$1")
shift
;;
-toolcp)
TOOL_CLASSPATH="${TOOL_CLASSPATH}${SEP}${2}"
shift 2
;;
-nobootcp)
unset usebootcp
shift
;;
-usebootcp)
usebootcp="true"
shift
;;
-debug)
SCALA_RUNNER_DEBUG=1
shift
;;
*)
scala_args=("${scala_args[@@]}" "$1")
shift
;;
esac
done
# reset "$@@" to the remaining args
set -- "${scala_args[@@]}"
if [[ -z "$JAVACMD" && -n "$JAVA_HOME" && -x "$JAVA_HOME/bin/java" ]]; then
JAVACMD="$JAVA_HOME/bin/java"
fi
# note that variables which may intentionally be empty must not
# be quoted: otherwise an empty string will appear as a command line
# argument, and java will think that is the program to run.
execCommand \
"${JAVACMD:=java}" \
$JAVA_OPTS \
"${java_args[@@]}" \
$(classpathArgs) \
-Dscala.home="$SCALA_HOME" \
$OVERRIDE_USEJAVACP \
"$EMACS_OPT" \
$WINDOWS_OPT \
@properties@ @class@ @toolflags@ "$@@"
# record the exit status lest it be overwritten:
# then reenable echo and propagate the code.
scala_exit_status=$?
onExit
|