Search in sources :

Example 1 with Setup

use of xsbti.compile.Setup 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);
}
Also used : Compiler(org.gradle.language.base.internal.compile.Compiler) FileHash(xsbti.compile.FileHash) WorkResult(org.gradle.api.tasks.WorkResult) IncOptions(xsbti.compile.IncOptions) Inputs(xsbti.compile.Inputs) TransactionalManagerType(xsbti.compile.TransactionalManagerType) Map(java.util.Map) ScalaCompiler(xsbti.compile.ScalaCompiler) PreviousResult(xsbti.compile.PreviousResult) JavaCompilerArgumentsBuilder(org.gradle.api.internal.tasks.compile.JavaCompilerArgumentsBuilder) Some(scala.Some) Jvm(org.gradle.internal.jvm.Jvm) ClassFileManager(xsbti.compile.ClassFileManager) ExternalLookup(sbt.internal.inc.ExternalLookup) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DefinesClass(xsbti.compile.DefinesClass) AnalysisContents(xsbti.compile.AnalysisContents) WorkResults(org.gradle.api.tasks.WorkResults) List(java.util.List) CompilerCache(xsbti.compile.CompilerCache) IncrementalCompilerImpl(sbt.internal.inc.IncrementalCompilerImpl) JavaConverters(scala.collection.JavaConverters) Optional(java.util.Optional) ExternalHooks(xsbti.compile.ExternalHooks) Timer(org.gradle.internal.time.Timer) CompileAnalysis(xsbti.compile.CompileAnalysis) Set(scala.collection.immutable.Set) Iterables(com.google.common.collect.Iterables) LoggedReporter(sbt.internal.inc.LoggedReporter) Stamper(sbt.internal.inc.Stamper) CompileOptions(xsbti.compile.CompileOptions) MapBackedCache(org.gradle.cache.internal.MapBackedCache) Setup(xsbti.compile.Setup) HashMap(java.util.HashMap) CompileResult(xsbti.compile.CompileResult) Logger(org.gradle.api.logging.Logger) ClassFileManagerType(xsbti.compile.ClassFileManagerType) PerClasspathEntryLookup(xsbti.compile.PerClasspathEntryLookup) Inject(javax.inject.Inject) Changes(xsbti.compile.Changes) T2(xsbti.T2) GFileUtils(org.gradle.util.internal.GFileUtils) Compilers(xsbti.compile.Compilers) ScalaInstance(sbt.internal.inc.ScalaInstance) Option(scala.Option) AnalysisStore(xsbti.compile.AnalysisStore) File(java.io.File) Analysis(sbt.internal.inc.Analysis) CompilationFailedException(org.gradle.api.internal.tasks.compile.CompilationFailedException) Locate(sbt.internal.inc.Locate) ClasspathOptionsUtil(xsbti.compile.ClasspathOptionsUtil) Logging(org.gradle.api.logging.Logging) Time(org.gradle.internal.time.Time) Stamp(xsbti.compile.analysis.Stamp) JavaCompilerArgumentsBuilder(org.gradle.api.internal.tasks.compile.JavaCompilerArgumentsBuilder) CompilationFailedException(org.gradle.api.internal.tasks.compile.CompilationFailedException) IncrementalCompilerImpl(sbt.internal.inc.IncrementalCompilerImpl) AnalysisContents(xsbti.compile.AnalysisContents) Setup(xsbti.compile.Setup) Inputs(xsbti.compile.Inputs) ClassFileManagerType(xsbti.compile.ClassFileManagerType) PerClasspathEntryLookup(xsbti.compile.PerClasspathEntryLookup) LoggedReporter(sbt.internal.inc.LoggedReporter) PreviousResult(xsbti.compile.PreviousResult) CompileOptions(xsbti.compile.CompileOptions) IncOptions(xsbti.compile.IncOptions) Timer(org.gradle.internal.time.Timer) AnalysisStore(xsbti.compile.AnalysisStore) CompileResult(xsbti.compile.CompileResult) File(java.io.File) Compilers(xsbti.compile.Compilers)

Aggregations

Iterables (com.google.common.collect.Iterables)1 File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Inject (javax.inject.Inject)1 CompilationFailedException (org.gradle.api.internal.tasks.compile.CompilationFailedException)1 JavaCompilerArgumentsBuilder (org.gradle.api.internal.tasks.compile.JavaCompilerArgumentsBuilder)1 Logger (org.gradle.api.logging.Logger)1 Logging (org.gradle.api.logging.Logging)1 WorkResult (org.gradle.api.tasks.WorkResult)1 WorkResults (org.gradle.api.tasks.WorkResults)1 MapBackedCache (org.gradle.cache.internal.MapBackedCache)1 Jvm (org.gradle.internal.jvm.Jvm)1 Time (org.gradle.internal.time.Time)1 Timer (org.gradle.internal.time.Timer)1 Compiler (org.gradle.language.base.internal.compile.Compiler)1 GFileUtils (org.gradle.util.internal.GFileUtils)1