Skip to content

Commit

Permalink
Provide helper function for new Analysis format
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Apr 10, 2024
1 parent a700e3b commit 4be431d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
56 changes: 46 additions & 10 deletions zinc/src/main/scala/sbt/internal/inc/MixedAnalyzingCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 4be431d

Please sign in to comment.