in src/java/io/bazel/rulesscala/scalac/ScalacWorker.java [240:292]
private static void compileScalaSources(CompileOptions ops, String[] scalaSources, Path classes)
throws IllegalAccessException, IOException {
String[] pluginArgs = buildPluginArgs(ops.plugins);
String[] pluginParams = getPluginParamsFrom(ops);
String[] constParams = {
"-classpath", String.join(pathSeparator, ops.classpath), "-d", classes.toString()
};
String[] compilerArgs =
merge(ops.scalaOpts, pluginArgs, constParams, pluginParams, scalaSources);
ReportableMainClass comp = new ReportableMainClass(ops);
long start = System.currentTimeMillis();
try {
comp.process(compilerArgs);
} catch (Throwable ex) {
if (ex.toString().contains("scala.reflect.internal.Types$TypeError")) {
throw new RuntimeException("Build failure with type error", ex);
} else {
throw ex;
}
}
long stop = System.currentTimeMillis();
if (ops.printCompileTime) {
System.err.println("Compiler runtime: " + (stop - start) + "ms.");
}
try {
String buildTime = "";
// If enable stats file we write the volatile string component
// otherwise empty string for better remote cache performance.
if (ops.enableStatsFile) {
buildTime = Long.toString(stop - start);
}
Files.write(Paths.get(ops.statsfile), Arrays.asList("build_time=" + buildTime));
} catch (IOException ex) {
throw new RuntimeException("Unable to write statsfile to " + ops.statsfile, ex);
}
ConsoleReporter reporter = (ConsoleReporter) comp.getReporter();
if (reporter instanceof ProtoReporter) {
ProtoReporter protoReporter = (ProtoReporter) reporter;
protoReporter.writeTo(Paths.get(ops.diagnosticsFile));
}
if (reporter.hasErrors()) {
reporter.flush();
throw new RuntimeException("Build failed");
}
}