use of xsbti.compile.ClassFileManagerType in project gradle by gradle.
the class ZincScalaCompiler method execute.
public WorkResult execute(final ScalaJavaJointCompileSpec spec) {
LOGGER.info("Compiling with Zinc Scala compiler.");
Timer timer = Time.startTimer();
IncrementalCompilerImpl incremental = new IncrementalCompilerImpl();
Compilers compilers = incremental.compilers(scalaInstance, ClasspathOptionsUtil.boot(), Option.apply(Jvm.current().getJavaHome()), scalaCompiler);
List<String> scalacOptions = new ZincScalaCompilerArgumentsGenerator().generate(spec);
List<String> javacOptions = new JavaCompilerArgumentsBuilder(spec).includeClasspath(false).noEmptySourcePath().build();
File[] classpath = Iterables.toArray(spec.getCompileClasspath(), File.class);
CompileOptions compileOptions = CompileOptions.create().withSources(Iterables.toArray(spec.getSourceFiles(), File.class)).withClasspath(classpath).withScalacOptions(scalacOptions.toArray(new String[0])).withClassesDirectory(spec.getDestinationDir()).withJavacOptions(javacOptions.toArray(new String[0]));
File analysisFile = spec.getAnalysisFile();
Optional<AnalysisStore> analysisStore;
Optional<ClassFileManagerType> classFileManagerType;
if (spec.getScalaCompileOptions().isForce()) {
analysisStore = Optional.empty();
classFileManagerType = IncOptions.defaultClassFileManagerType();
} else {
analysisStore = Optional.of(analysisStoreProvider.get(analysisFile));
classFileManagerType = Optional.of(TransactionalManagerType.of(spec.getClassfileBackupDir(), new SbtLoggerAdapter()));
}
PreviousResult previousResult = analysisStore.flatMap(store -> store.get().map(a -> PreviousResult.of(Optional.of(a.getAnalysis()), Optional.of(a.getMiniSetup())))).orElse(PreviousResult.of(Optional.empty(), Optional.empty()));
IncOptions incOptions = IncOptions.of().withExternalHooks(new LookupOnlyExternalHooks(new ExternalBinariesLookup())).withRecompileOnMacroDef(Optional.of(false)).withClassfileManagerType(classFileManagerType).withTransitiveStep(5);
Setup setup = incremental.setup(new EntryLookup(spec), false, analysisFile, CompilerCache.fresh(), incOptions, // MappedPosition is used to make sure toString returns proper error messages
new LoggedReporter(100, new SbtLoggerAdapter(), MappedPosition::new), Option.empty(), getExtra());
Inputs inputs = incremental.inputs(compileOptions, compilers, setup, previousResult);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(inputs.toString());
}
if (spec.getScalaCompileOptions().isForce()) {
// TODO This should use Deleter
GFileUtils.deleteDirectory(spec.getDestinationDir());
GFileUtils.deleteQuietly(spec.getAnalysisFile());
}
LOGGER.info("Prepared Zinc Scala inputs: {}", timer.getElapsed());
try {
CompileResult compile = incremental.compile(inputs, new SbtLoggerAdapter());
if (analysisStore.isPresent()) {
AnalysisContents contentNext = AnalysisContents.create(compile.analysis(), compile.setup());
analysisStore.get().set(contentNext);
}
} catch (xsbti.CompileFailed e) {
throw new CompilationFailedException(e);
}
LOGGER.info("Completed Scala compilation: {}", timer.getElapsed());
return WorkResults.didWork(true);
}
Aggregations