mirror of https://github.com/sbt/sbt.git
Revert "Use fileConverter in cacheStore"
This commit is contained in:
parent
1765fde1ba
commit
7c51ba2f64
|
|
@ -23,6 +23,7 @@ import sbt.util.Show
|
|||
import xsbti.{ HashedVirtualFileRef, VirtualFile }
|
||||
import sjsonnew.JsonFormat
|
||||
import scala.reflect.ClassTag
|
||||
import xsbti.FileConverter
|
||||
|
||||
/** A concrete settings system that uses `sbt.Scope` for the scope type. */
|
||||
object Def extends Init[Scope] with TaskMacroExtra with InitializeImplicits:
|
||||
|
|
@ -233,6 +234,7 @@ object Def extends Init[Scope] with TaskMacroExtra with InitializeImplicits:
|
|||
private[sbt] var _cacheStore: ActionCacheStore = InMemoryActionCacheStore()
|
||||
def cacheStore: ActionCacheStore = _cacheStore
|
||||
private[sbt] var _outputDirectory: Option[Path] = None
|
||||
private[sbt] var _fileConverter: Option[FileConverter] = None
|
||||
private[sbt] val cacheEventLog: CacheEventLog = CacheEventLog()
|
||||
def cacheConfiguration: BuildWideCacheConfiguration =
|
||||
BuildWideCacheConfiguration(
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import sbt.ProjectExtra.*
|
|||
import sbt.ScopeFilter.Make._
|
||||
import sbt.SlashSyntax0._
|
||||
import sbt.coursierint.LMCoursier
|
||||
import sbt.internal.inc.{ MappedFileConverter, HashUtil, JarUtils }
|
||||
import sbt.internal.inc.{ HashUtil, JarUtils }
|
||||
import sbt.internal.librarymanagement._
|
||||
import sbt.internal.remotecache._
|
||||
import sbt.io.IO
|
||||
|
|
@ -53,23 +53,12 @@ object RemoteCache {
|
|||
// TODO: figure out a good timing to initialize cache
|
||||
// currently this is called twice so metabuild can call compile with a minimal setting
|
||||
private[sbt] def initializeRemoteCache(s: State): Unit =
|
||||
val outDir =
|
||||
s.get(BasicKeys.rootOutputDirectory).getOrElse((s.baseDir / "target" / "out").toPath)
|
||||
Def._outputDirectory = Some(outDir)
|
||||
def defaultCache =
|
||||
val fileConverter = s
|
||||
.get(Keys.fileConverter.key)
|
||||
.getOrElse {
|
||||
MappedFileConverter(
|
||||
Defaults.getRootPaths(outDir, s.configuration),
|
||||
allowMachinePath = true
|
||||
)
|
||||
}
|
||||
DiskActionCacheStore((s.baseDir / "target" / "bootcache").toPath, fileConverter)
|
||||
Def._outputDirectory = s.get(BasicKeys.rootOutputDirectory)
|
||||
Def._cacheStore = s
|
||||
.get(BasicKeys.cacheStores)
|
||||
.collect { case xs if xs.nonEmpty => AggregateActionCacheStore(xs) }
|
||||
.getOrElse(defaultCache)
|
||||
.getOrElse(DiskActionCacheStore((s.baseDir / "target" / "bootcache").toPath))
|
||||
Def._fileConverter = s.get(Keys.fileConverter.key)
|
||||
|
||||
private[sbt] def artifactToStr(art: Artifact): String = {
|
||||
import LibraryManagementCodec._
|
||||
|
|
@ -110,7 +99,7 @@ object RemoteCache {
|
|||
},
|
||||
cacheStores := {
|
||||
List(
|
||||
DiskActionCacheStore(localCacheDirectory.value.toPath(), fileConverter.value)
|
||||
DiskActionCacheStore(localCacheDirectory.value.toPath())
|
||||
)
|
||||
},
|
||||
remoteCache := SysProp.remoteCache,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import sbt.io.IO
|
|||
import sbt.io.syntax.*
|
||||
import sbt.internal.util.StringVirtualFile1
|
||||
import sbt.internal.util.codec.ActionResultCodec.given
|
||||
import xsbti.{ FileConverter, HashedVirtualFileRef, PathBasedFile, VirtualFile }
|
||||
import xsbti.{ HashedVirtualFileRef, PathBasedFile, VirtualFile }
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
|
|
@ -166,8 +166,7 @@ class InMemoryActionCacheStore extends AbstractActionCacheStore:
|
|||
underlying.toString()
|
||||
end InMemoryActionCacheStore
|
||||
|
||||
class DiskActionCacheStore(base: Path, fileConverter: FileConverter)
|
||||
extends AbstractActionCacheStore:
|
||||
class DiskActionCacheStore(base: Path) extends AbstractActionCacheStore:
|
||||
lazy val casBase: Path = {
|
||||
val dir = base.resolve("cas")
|
||||
IO.createDirectory(dir.toFile)
|
||||
|
|
@ -242,10 +241,13 @@ class DiskActionCacheStore(base: Path, fileConverter: FileConverter)
|
|||
else None
|
||||
|
||||
override def syncBlobs(refs: Seq[HashedVirtualFileRef], outputDirectory: Path): Seq[Path] =
|
||||
refs.flatMap: ref =>
|
||||
val casFile = toCasFile(Digest(ref))
|
||||
refs.flatMap: r =>
|
||||
val casFile = toCasFile(Digest(r))
|
||||
if casFile.toFile().exists then
|
||||
val outPath = fileConverter.toPath(ref)
|
||||
val shortPath =
|
||||
if r.id.startsWith("${OUT}/") then r.id.drop(7)
|
||||
else r.id
|
||||
val outPath = outputDirectory.resolve(shortPath)
|
||||
Files.createDirectories(outPath.getParent())
|
||||
if outPath.toFile().exists() then IO.delete(outPath.toFile())
|
||||
Some(Files.createSymbolicLink(outPath, casFile))
|
||||
|
|
|
|||
|
|
@ -5,13 +5,7 @@ import sbt.internal.util.StringVirtualFile1
|
|||
import sbt.io.IO
|
||||
import sbt.io.syntax.*
|
||||
import verify.BasicTestSuite
|
||||
import xsbti.FileConverter
|
||||
import xsbti.VirtualFile
|
||||
import xsbti.VirtualFileRef
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
object ActionCacheTest extends BasicTestSuite:
|
||||
val tags = CacheLevelTag.all.toList
|
||||
|
|
@ -20,10 +14,10 @@ object ActionCacheTest extends BasicTestSuite:
|
|||
withDiskCache(testHoldBlob)
|
||||
|
||||
def testHoldBlob(cache: ActionCacheStore): Unit =
|
||||
val in = StringVirtualFile1("a.txt", "foo")
|
||||
val hashRefs = cache.putBlobs(in :: Nil)
|
||||
assert(hashRefs.size == 1)
|
||||
IO.withTemporaryDirectory: tempDir =>
|
||||
val in = StringVirtualFile1(s"$tempDir/a.txt", "foo")
|
||||
val hashRefs = cache.putBlobs(in :: Nil)
|
||||
assert(hashRefs.size == 1)
|
||||
val actual = cache.syncBlobs(hashRefs, tempDir.toPath()).head
|
||||
assert(actual.getFileName().toString() == "a.txt")
|
||||
|
||||
|
|
@ -55,14 +49,14 @@ object ActionCacheTest extends BasicTestSuite:
|
|||
withDiskCache(testActionCacheWithBlob)
|
||||
|
||||
def testActionCacheWithBlob(cache: ActionCacheStore): Unit =
|
||||
import sjsonnew.BasicJsonProtocol.*
|
||||
var called = 0
|
||||
val action: ((Int, Int)) => (Int, Seq[VirtualFile]) = { case (a, b) =>
|
||||
called += 1
|
||||
val out = StringVirtualFile1("a.txt", (a + b).toString)
|
||||
(a + b, Seq(out))
|
||||
}
|
||||
IO.withTemporaryDirectory: (tempDir) =>
|
||||
import sjsonnew.BasicJsonProtocol.*
|
||||
var called = 0
|
||||
val action: ((Int, Int)) => (Int, Seq[VirtualFile]) = { case (a, b) =>
|
||||
called += 1
|
||||
val out = StringVirtualFile1(s"$tempDir/a.txt", (a + b).toString)
|
||||
(a + b, Seq(out))
|
||||
}
|
||||
val config = BuildWideCacheConfiguration(cache, tempDir.toPath(), CacheEventLog())
|
||||
val v1 =
|
||||
ActionCache.cache[(Int, Int), Int]((1, 1), Digest.zero, Digest.zero, tags)(action)(config)
|
||||
|
|
@ -88,15 +82,9 @@ object ActionCacheTest extends BasicTestSuite:
|
|||
IO.withTemporaryDirectory(
|
||||
{ tempDir0 =>
|
||||
val tempDir = tempDir0.toPath
|
||||
val cache = DiskActionCacheStore(tempDir, fileConverter)
|
||||
val cache = DiskActionCacheStore(tempDir)
|
||||
f(cache)
|
||||
},
|
||||
keepDirectory = false
|
||||
)
|
||||
|
||||
def fileConverter = new FileConverter:
|
||||
override def toPath(ref: VirtualFileRef): Path = Paths.get(ref.id)
|
||||
override def toVirtualFile(path: Path): VirtualFile =
|
||||
val content = if Files.isRegularFile(path) then new String(Files.readAllBytes(path)) else ""
|
||||
StringVirtualFile1(path.toString, content)
|
||||
end ActionCacheTest
|
||||
|
|
|
|||
Loading…
Reference in New Issue