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