From 4be431da616684965786f014fc9e9d11e7036637 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Wed, 10 Apr 2024 01:54:36 -0400 Subject: [PATCH] Provide helper function for new Analysis format --- build.sbt | 2 +- .../internal/inc/MixedAnalyzingCompiler.scala | 56 +++++++++++++++---- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/build.sbt b/build.sbt index 3491ae9bc..84cd62063 100644 --- a/build.sbt +++ b/build.sbt @@ -43,7 +43,7 @@ ThisBuild / version := { nightlyVersion match { case Some(v) => v case _ => - if ((ThisBuild / isSnapshot).value) "1.9.0-SNAPSHOT" + if ((ThisBuild / isSnapshot).value) "1.10.0-SNAPSHOT" else old } } diff --git a/zinc/src/main/scala/sbt/internal/inc/MixedAnalyzingCompiler.scala b/zinc/src/main/scala/sbt/internal/inc/MixedAnalyzingCompiler.scala index c511b23b0..93596b227 100644 --- a/zinc/src/main/scala/sbt/internal/inc/MixedAnalyzingCompiler.scala +++ b/zinc/src/main/scala/sbt/internal/inc/MixedAnalyzingCompiler.scala @@ -25,18 +25,19 @@ import xsbti.{ VirtualFile, VirtualFileRef } -import xsbti.compile._ import xsbti.compile.CompileOrder._ -import xsbti.compile.{ ClassFileManager => XClassFileManager } -import xsbti.compile.analysis.ReadStamps +import xsbti.compile.{ ClassFileManager => XClassFileManager, FileAnalysisStore => _, _ } +import xsbti.compile.analysis.{ ReadStamps, ReadWriteMappers } import sbt.io.{ IO, DirectoryFilter } import sbt.util.{ InterfaceUtil, Logger } +import sbt.internal.inc.consistent.ConsistentFileAnalysisStore import sbt.internal.inc.JavaInterfaceUtil.EnrichOption import sbt.internal.inc.JavaInterfaceUtil.EnrichOptional import sbt.internal.inc.VirtualFileUtil.toAbsolute import sbt.internal.inc.caching.ClasspathCache import sbt.internal.inc.javac.AnalyzingJavaCompiler import sbt.internal.util.ConsoleAppender +import scala.concurrent.ExecutionContext /** An instance of an analyzing compiler that can run both javac + scalac. */ final class MixedAnalyzingCompiler( @@ -496,14 +497,49 @@ object MixedAnalyzingCompiler { /** * Create a an analysis store cache at the desired location. - * - * Note: This method will be deprecated after Zinc 1.1. */ - def staticCachedStore(analysisFile: Path, useTextAnalysis: Boolean): AnalysisStore = { - import xsbti.compile.AnalysisStore - val fileStore = - if (useTextAnalysis) sbt.internal.inc.FileAnalysisStore.text(analysisFile.toFile) - else sbt.internal.inc.FileAnalysisStore.binary(analysisFile.toFile) + def staticCachedStore(analysisFile: Path, useTextAnalysis: Boolean): AnalysisStore = + staticCachedStore( + analysisFile = analysisFile, + useTextAnalysis = useTextAnalysis, + useConsistent = false, + mappers = ReadWriteMappers.getEmptyMappers(), + sort = true, + ec = ExecutionContext.global, + parallelism = Runtime.getRuntime.availableProcessors(), + ) + + def staticCachedStore( + analysisFile: Path, + useTextAnalysis: Boolean, + useConsistent: Boolean, + mappers: ReadWriteMappers, + sort: Boolean, + ec: ExecutionContext, + parallelism: Int, + ): AnalysisStore = { + val fileStore = (useTextAnalysis, useConsistent) match { + case (false, false) => + FileAnalysisStore.binary(analysisFile.toFile, mappers) + case (false, true) => + ConsistentFileAnalysisStore.binary( + file = analysisFile.toFile, + mappers = mappers, + sort = sort, + ec = ec, + parallelism = parallelism, + ) + case (true, false) => + FileAnalysisStore.text(analysisFile.toFile, mappers) + case (true, true) => + ConsistentFileAnalysisStore.text( + file = analysisFile.toFile, + mappers = mappers, + sort = sort, + ec = ec, + parallelism = parallelism, + ) + } val cachedStore = AnalysisStore.getCachedStore(fileStore) staticCache(analysisFile, AnalysisStore.getThreadSafeStore(cachedStore)) }