mirror of
https://github.com/sbt/sbt.git
synced 2026-09-08 03:09:49 +02:00
Implement InternalActionResult
This commit is contained in:
@@ -33,7 +33,7 @@ object ActionCache:
|
||||
extraHash: Digest,
|
||||
tags: List[CacheLevelTag],
|
||||
)(
|
||||
action: I => (O, Seq[VirtualFile])
|
||||
action: I => InternalActionResult[O],
|
||||
)(
|
||||
config: BuildWideCacheConfiguration
|
||||
): O =
|
||||
@@ -44,8 +44,8 @@ object ActionCache:
|
||||
|
||||
def organicTask: O =
|
||||
// run action(...) and combine the newResult with outputs
|
||||
val (result, outputs) =
|
||||
try action(key)
|
||||
val InternalActionResult(result, outputs) =
|
||||
try action(key): @unchecked
|
||||
catch
|
||||
case e: Exception =>
|
||||
cacheEventLog.append(ActionCacheEvent.Error)
|
||||
@@ -90,6 +90,21 @@ object ActionCache:
|
||||
if paths.isEmpty then organicTask
|
||||
else valueFromStr(IO.read(paths.head.toFile()), result.origin)
|
||||
case Left(_) => organicTask
|
||||
|
||||
/**
|
||||
* Represents a value and output files, used internally by the macro.
|
||||
*/
|
||||
class InternalActionResult[A1] private (
|
||||
val value: A1,
|
||||
val outputs: Seq[VirtualFile],
|
||||
)
|
||||
end InternalActionResult
|
||||
object InternalActionResult:
|
||||
def apply[A1](value: A1, outputs: Seq[VirtualFile]): InternalActionResult[A1] =
|
||||
new InternalActionResult(value, outputs)
|
||||
private[sbt] def unapply[A1](r: InternalActionResult[A1]): Option[(A1, Seq[VirtualFile])] =
|
||||
Some(r.value, r.outputs)
|
||||
end InternalActionResult
|
||||
end ActionCache
|
||||
|
||||
class BuildWideCacheConfiguration(
|
||||
|
||||
@@ -11,6 +11,7 @@ import xsbti.VirtualFileRef
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.Files
|
||||
import ActionCache.InternalActionResult
|
||||
|
||||
object ActionCacheTest extends BasicTestSuite:
|
||||
val tags = CacheLevelTag.all.toList
|
||||
@@ -35,9 +36,9 @@ object ActionCacheTest extends BasicTestSuite:
|
||||
def testActionCacheBasic(cache: ActionCacheStore): Unit =
|
||||
import sjsonnew.BasicJsonProtocol.*
|
||||
var called = 0
|
||||
val action: ((Int, Int)) => (Int, Seq[VirtualFile]) = { case (a, b) =>
|
||||
val action: ((Int, Int)) => InternalActionResult[Int] = { case (a, b) =>
|
||||
called += 1
|
||||
(a + b, Nil)
|
||||
InternalActionResult(a + b, Nil)
|
||||
}
|
||||
IO.withTemporaryDirectory: (tempDir) =>
|
||||
val config = getCacheConfig(cache, tempDir)
|
||||
@@ -57,10 +58,10 @@ object ActionCacheTest extends BasicTestSuite:
|
||||
import sjsonnew.BasicJsonProtocol.*
|
||||
IO.withTemporaryDirectory: (tempDir) =>
|
||||
var called = 0
|
||||
val action: ((Int, Int)) => (Int, Seq[VirtualFile]) = { case (a, b) =>
|
||||
val action: ((Int, Int)) => InternalActionResult[Int] = { case (a, b) =>
|
||||
called += 1
|
||||
val out = StringVirtualFile1(s"$tempDir/a.txt", (a + b).toString)
|
||||
(a + b, Seq(out))
|
||||
InternalActionResult(a + b, Seq(out))
|
||||
}
|
||||
val config = getCacheConfig(cache, tempDir)
|
||||
val v1 =
|
||||
|
||||
Reference in New Issue
Block a user