Skip to content

Commit 0124872

Browse files
authored
call close() on compiler in scalacWorker after each job (#1504)
* call close() on compiler in scalacworker
1 parent 58b98f2 commit 0124872

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/java/io/bazel/rulesscala/scalac/ReportableMainClass.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,28 @@
1111
import scala.tools.nsc.MainClass;
1212
import scala.tools.nsc.Settings;
1313
import scala.tools.nsc.reporters.Reporter;
14+
import java.lang.AutoCloseable;
1415

1516
public class ReportableMainClass extends MainClass {
1617
private Reporter reporter;
1718
private final CompileOptions ops;
19+
private Global compiler = null;
1820

1921
public ReportableMainClass(CompileOptions ops) {
2022
this.ops = ops;
2123
}
2224

25+
public void close() throws Exception{
26+
if(compiler != null){
27+
28+
//nsc.Global didn't inherit from Closeable until 2.12.9.
29+
if(compiler instanceof AutoCloseable){
30+
((AutoCloseable)compiler).close();
31+
}
32+
compiler = null;
33+
}
34+
}
35+
2336
@Override
2437
public Global newCompiler() {
2538
createDiagnosticsFile();
@@ -31,7 +44,8 @@ public Global newCompiler() {
3144

3245
reporter = new DepsTrackingReporter(settings, ops, reporter);
3346

34-
return new Global(settings, reporter);
47+
compiler = new Global(settings, reporter);
48+
return compiler;
3549
}
3650

3751
private void createDiagnosticsFile() {

src/java/io/bazel/rulesscala/scalac/ScalacWorker.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private static boolean isMacroException(Throwable ex) {
258258
}
259259

260260
private static void compileScalaSources(CompileOptions ops, String[] scalaSources, Path classes)
261-
throws IOException {
261+
throws IOException, Exception {
262262

263263
String[] pluginArgs = buildPluginArgs(ops.plugins);
264264
String[] pluginParams = getPluginParamsFrom(ops);
@@ -285,7 +285,11 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource
285285
} else {
286286
throw ex;
287287
}
288+
}finally {
289+
comp.close();
288290
}
291+
292+
289293
long stop = System.currentTimeMillis();
290294
if (ops.printCompileTime) {
291295
System.err.println("Compiler runtime: " + (stop - start) + "ms.");

0 commit comments

Comments
 (0)