Skip to content

Commit 0787390

Browse files
committed
Merge pull request #49 from DarkDimius/script
Bringing back dotc script that was accidentely deleted.
2 parents d827b01 + 1cccbbf commit 0787390

File tree

1 file changed

+232
-0
lines changed

1 file changed

+232
-0
lines changed

bin/dotc

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
#!/bin/bash
2+
# This script is used for running compiler standalone(outside of sbt)
3+
# it's based on miniboxing script and paulp's launcher script
4+
5+
6+
# Configuration
7+
SCALA_VERSION=2.11.0-M7
8+
DOTTY_VERSION=0.1
9+
bootcp=true
10+
default_java_opts="-Xmx768m -Xms768m"
11+
programName=$(basename "$0")
12+
# uncomment next line to enable debug output
13+
#debug=true
14+
15+
16+
17+
declare -a java_args scala_args residual_args
18+
unset verbose quiet cygwin toolcp colors saved_stty
19+
20+
21+
CompilerMain=dotty.tools.dotc.Main
22+
23+
24+
# Try to autodetect real location of the script
25+
DOTTY_ROOT="`readlink \"$0\"`" # relative, symbolic links resolved
26+
if [[ "$DOTTY_ROOT" == "" ]]; then
27+
DOTTY_ROOT="$0"
28+
fi
29+
DOTTY_ROOT="`dirname \"$DOTTY_ROOT\"`"
30+
DOTTY_ROOT="`( cd \"$DOTTY_ROOT\" && pwd )`/.." # absolute
31+
# autodetecting the compiler jar. this is location where sbt 'packages' it
32+
MAIN_JAR=$DOTTY_ROOT/target/scala-$SCALA_VERSION/dotty_$SCALA_VERSION-$DOTTY_VERSION-SNAPSHOT.jar
33+
34+
function checkjar {
35+
if [ ! -f "$1" ]
36+
then
37+
echo "The script is going to build the required jar file $1 by running \"sbt $2\""
38+
cd $DOTTY_ROOT
39+
sbt $2
40+
cd -
41+
if [ ! -f "$1" ]
42+
then
43+
echo "The required jar file has not been built by sbt. Please run \"sbt $2\""
44+
exit 1
45+
else
46+
echo "The required jar file was built successfully."
47+
fi
48+
fi
49+
}
50+
51+
checkjar $MAIN_JAR package
52+
53+
# Autodetecting the scala-library location, in case it wasn't provided by an environment variable
54+
if [ "$SCALA_LIBRARY_JAR" == "" ]
55+
then
56+
SCALA_LIBRARY_JAR=$HOME/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-$SCALA_VERSION.jar
57+
# this is location where sbt stores it in ivy cache
58+
fi
59+
# save as for scala-library now for scala-reflect
60+
if [ "$SCALA_REFLECT_JAR" == "" ]
61+
then
62+
SCALA_REFLECT_JAR=$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-$SCALA_VERSION.jar
63+
fi
64+
65+
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" ]
66+
then
67+
echo To use this script please set
68+
echo SCALA_LIBRARY_JAR to point to scala-library-$SCALA_VERSION.jar "(currently $SCALA_LIBRARY_JAR)"
69+
echo SCALA_REFLECT_JAR to point to scala-reflect-$SCALA_VERSION.jar "(currently $SCALA_REFLECT_JAR)"
70+
fi
71+
72+
ifdebug () {
73+
[[ -n $debug ]] && eval "$@"
74+
}
75+
echoErr () {
76+
echo >&2 "$@"
77+
}
78+
dlog () {
79+
[[ -n $debug ]] && echoErr "$@"
80+
}
81+
82+
die() {
83+
echo "Aborting: $@"
84+
exit 1
85+
}
86+
echoArgs () {
87+
echoErr ""
88+
for arg; do
89+
echoErr "$arg"
90+
done
91+
echoErr ""
92+
}
93+
execCommand () {
94+
ifdebug echoArgs "$@"
95+
ignore="$(cat "$HOME/.scala_ignore_crashes" 2>/dev/null)"
96+
if [[ $ignore == "true" ]]; then
97+
"$@" 2>&1 | scala-crash-filter
98+
else
99+
$@
100+
fi
101+
}
102+
103+
# restore stty settings (echo in particular)
104+
restoreSttySettings () {
105+
dlog "" && dlog "[restore stty] $saved_stty"
106+
stty $saved_stty && saved_stty=""
107+
}
108+
109+
onExit () {
110+
[[ -n $saved_stty ]] && restoreSttySettings
111+
exit $scala_exit_status
112+
}
113+
114+
# Get debug set early
115+
for arg in "$@"; do
116+
[[ $arg == "-d" ]] && debug=true
117+
done
118+
119+
# to reenable echo if we are interrupted before completing.
120+
trap onExit INT
121+
122+
# save terminal settings
123+
saved_stty="$(stty -g 2>/dev/null)"
124+
125+
# clear on error so we don't later try to restore them
126+
[[ $? ]] || saved_stty=""
127+
dlog "[save stty] $saved_stty"
128+
129+
if uname | grep -q ^CYGWIN; then
130+
cygwin="$(uname)"
131+
fi
132+
133+
addJava () {
134+
dlog "[addJava] arg = '$1'"
135+
java_args=( "${java_args[@]}" "$1" )
136+
}
137+
addScala () {
138+
dlog "[addScala] arg = '$1'"
139+
scala_args=( "${scala_args[@]}" "$1" )
140+
}
141+
addResidual () {
142+
dlog "[residual] arg = '$1'"
143+
residual_args=( "${residual_args[@]}" "$1" )
144+
}
145+
146+
onExit() {
147+
[[ -n $saved_stty ]] && restoreSttySettings
148+
exit $scala_exit_status
149+
}
150+
151+
# to reenable echo if we are interrupted before completing.
152+
trap onExit INT
153+
154+
# If using the boot classpath, also pass an empty classpath
155+
# to java to suppress "." from materializing.
156+
classpathArgs () {
157+
if [[ -n $bootcp ]]; then
158+
echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$MAIN_JAR -classpath $MAIN_JAR"
159+
else
160+
echo "-classpath $SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$MAIN_JAR"
161+
fi
162+
}
163+
164+
# e.g. path -java-home /path/to/java_home
165+
require_arg () {
166+
local type="$1"
167+
local opt="$2"
168+
local arg="$3"
169+
170+
if [[ -z "$arg" ]] || [[ "${arg:0:1}" == "-" ]]; then
171+
die "$opt requires <$type> argument"
172+
fi
173+
}
174+
175+
176+
177+
178+
179+
while [[ $# -gt 0 ]]; do
180+
case "$1" in
181+
--) shift; for arg; do addResidual "$arg"; done; set -- ;;
182+
-h|-help) usage; exit 1 ;;
183+
-v|-verbose) verbose=true && shift ;;
184+
-d|-debug) debug=true && shift ;;
185+
-q|-quiet) quiet=true && shift ;;
186+
187+
-repl) main_class=$ReplMain && shift ;;
188+
-compile) main_class=$CompilerMain && shift ;;
189+
-run) main_class=$ReplMain && shift ;;
190+
-fsc) main_class=$FscMain && shift ;;
191+
-bootcp) bootcp=true && shift ;;
192+
-no-bootcp) unset bootcp && shift ;;
193+
-colors) colors=true && shift ;;
194+
-no-colors) unset colors && shift ;;
195+
-jrebel) jrebel=true && shift ;;
196+
-no-jrebel) unset jrebel && shift ;;
197+
198+
-toolcp) require_arg classpath "$1" "$2" && toolcp="$2" && shift 2 ;;
199+
-java-home) require_arg path "$1" "$2" && java_cmd="$2/bin/java" && shift 2 ;;
200+
201+
# break out -D and -J options and add them to JAVA_OPTS as well
202+
# so they reach the JVM in time to do some good. The -D options
203+
# will be available as system properties.
204+
-D*) addJava "$1" && addScala "$1" && shift ;;
205+
-J*) addJava "${1:2}" && addScala "$1" && shift ;;
206+
*) addResidual "$1" && shift ;;
207+
esac
208+
done
209+
210+
211+
[[ -z $java_cmd ]] && prefix=${java_home:+$java_home/bin/} && java_cmd="${prefix}java"
212+
213+
# note that variables which may intentionally be empty must not
214+
# be quoted: otherwise an empty string will appear as a command line
215+
# argument, and java will think that is the program to run.
216+
execCommand \
217+
"$java_cmd" \
218+
${JAVA_OPTS:-$default_java_opts} \
219+
"${java_args[@]}" \
220+
"$(classpathArgs)" \
221+
-Dscala.usejavacp=true \
222+
"${CompilerMain}" \
223+
"${scala_args[@]}" \
224+
"${residual_args[@]}"
225+
226+
# record the exit status lest it be overwritten:
227+
# then reenable echo and propagate the code.
228+
scala_exit_status=$?
229+
onExit
230+
231+
232+
#echo java -cp $MAIN_JAR: -Dscala.usejavacp=true dotty.tools.dotc.Main $@

0 commit comments

Comments
 (0)