Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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