Search in sources :

Example 1 with AnalyzingCompiler

use of sbt.internal.inc.AnalyzingCompiler in project gradle by gradle.

the class ZincScalaCompilerFactory method getCompiler.

static ZincScalaCompiler getCompiler(CacheRepository cacheRepository, HashedClasspath hashedScalaClasspath) {
    ScalaInstance scalaInstance;
    try {
        scalaInstance = getScalaInstance(hashedScalaClasspath);
    } catch (Exception e) {
        throw new RuntimeException("Failed create instance of the scala compiler", e);
    }
    String zincVersion = ZincCompilerUtil.class.getPackage().getImplementationVersion();
    String scalaVersion = scalaInstance.actualVersion();
    String javaVersion = Jvm.current().getJavaVersion().getMajorVersion();
    String zincCacheKey = String.format("zinc-%s_%s_%s", zincVersion, scalaVersion, javaVersion);
    String zincCacheName = String.format("%s compiler cache", zincCacheKey);
    final PersistentCache zincCache = cacheRepository.cache(zincCacheKey).withDisplayName(zincCacheName).withLockOptions(mode(FileLockManager.LockMode.OnDemand)).open();
    File compilerBridgeJar;
    if (isScala3(scalaVersion)) {
        compilerBridgeJar = findFile("scala3-sbt-bridge", hashedScalaClasspath.getClasspath());
    } else {
        File compilerBridgeSourceJar = findFile("compiler-bridge", hashedScalaClasspath.getClasspath());
        compilerBridgeJar = getBridgeJar(zincCache, scalaInstance, compilerBridgeSourceJar, sbt.util.Logger.xlog2Log(new SbtLoggerAdapter()));
    }
    ScalaCompiler scalaCompiler = new AnalyzingCompiler(scalaInstance, ZincUtil.constantBridgeProvider(scalaInstance, compilerBridgeJar), ClasspathOptionsUtil.manual(), k -> scala.runtime.BoxedUnit.UNIT, Option.apply(COMPILER_CLASSLOADER_CACHE));
    return new ZincScalaCompiler(scalaInstance, scalaCompiler, new AnalysisStoreProvider());
}
Also used : PersistentCache(org.gradle.cache.PersistentCache) AnalyzingCompiler(sbt.internal.inc.AnalyzingCompiler) ZincCompilerUtil(xsbti.compile.ZincCompilerUtil) ScalaCompiler(xsbti.compile.ScalaCompiler) ScalaInstance(sbt.internal.inc.ScalaInstance) File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 PersistentCache (org.gradle.cache.PersistentCache)1 AnalyzingCompiler (sbt.internal.inc.AnalyzingCompiler)1 ScalaInstance (sbt.internal.inc.ScalaInstance)1 ScalaCompiler (xsbti.compile.ScalaCompiler)1 ZincCompilerUtil (xsbti.compile.ZincCompilerUtil)1