Skip to content

Commit

Permalink
call close() on compiler in scalacWorker after each job (#1504)
Browse files Browse the repository at this point in the history
* call close() on compiler in scalacworker
  • Loading branch information
crt-31 authored Jul 17, 2023
1 parent 58b98f2 commit 0124872
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/java/io/bazel/rulesscala/scalac/ReportableMainClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,28 @@
import scala.tools.nsc.MainClass;
import scala.tools.nsc.Settings;
import scala.tools.nsc.reporters.Reporter;
import java.lang.AutoCloseable;

public class ReportableMainClass extends MainClass {
private Reporter reporter;
private final CompileOptions ops;
private Global compiler = null;

public ReportableMainClass(CompileOptions ops) {
this.ops = ops;
}

public void close() throws Exception{
if(compiler != null){

//nsc.Global didn't inherit from Closeable until 2.12.9.
if(compiler instanceof AutoCloseable){
((AutoCloseable)compiler).close();
}
compiler = null;
}
}

@Override
public Global newCompiler() {
createDiagnosticsFile();
Expand All @@ -31,7 +44,8 @@ public Global newCompiler() {

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

return new Global(settings, reporter);
compiler = new Global(settings, reporter);
return compiler;
}

private void createDiagnosticsFile() {
Expand Down
6 changes: 5 additions & 1 deletion src/java/io/bazel/rulesscala/scalac/ScalacWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private static boolean isMacroException(Throwable ex) {
}

private static void compileScalaSources(CompileOptions ops, String[] scalaSources, Path classes)
throws IOException {
throws IOException, Exception {

String[] pluginArgs = buildPluginArgs(ops.plugins);
String[] pluginParams = getPluginParamsFrom(ops);
Expand All @@ -285,7 +285,11 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource
} else {
throw ex;
}
}finally {
comp.close();
}


long stop = System.currentTimeMillis();
if (ops.printCompileTime) {
System.err.println("Compiler runtime: " + (stop - start) + "ms.");
Expand Down

0 comments on commit 0124872

Please sign in to comment.