mirror of https://github.com/sbt/sbt.git
Fix cached update task
Fixes sbt/sbt#3226 One of the checks that the cached update task performs is called `depsUpdated`, which checks if the subproject dependencies have been thawed out of cache of now. For this to function correctly, when we thaw the `UpdateReport` from JSON, we need to mark the report as cached. This was done subtley in sbt 0.13 for sbinary (https://github.com/sbt/sbt-zero-thirteen/blob/v0.13.15/main/actions/src/main/scala/sbt/CacheIvy.scala#L66-L67).
This commit is contained in:
parent
13ec092be3
commit
3690ff193c
|
|
@ -71,17 +71,22 @@ object LibraryManagement {
|
||||||
def skipResolve(cache: CacheStore): UpdateInputs => UpdateReport = {
|
def skipResolve(cache: CacheStore): UpdateInputs => UpdateReport = {
|
||||||
import sbt.librarymanagement.LibraryManagementCodec._
|
import sbt.librarymanagement.LibraryManagementCodec._
|
||||||
Tracked.lastOutput[UpdateInputs, UpdateReport](cache) {
|
Tracked.lastOutput[UpdateInputs, UpdateReport](cache) {
|
||||||
case (_, Some(out)) => out
|
case (_, Some(out)) => markAsCached(out)
|
||||||
case _ =>
|
case _ =>
|
||||||
sys.error("Skipping update requested, but update has not previously run successfully.")
|
sys.error("Skipping update requested, but update has not previously run successfully.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark UpdateReport#stats as "cached." This is used by the dependers later
|
||||||
|
// to determine whether they now need to run update in the above `upToDate`.
|
||||||
|
def markAsCached(ur: UpdateReport): UpdateReport =
|
||||||
|
ur.withStats(ur.stats.withCached(true))
|
||||||
|
|
||||||
def doResolve(cache: CacheStore): UpdateInputs => UpdateReport = {
|
def doResolve(cache: CacheStore): UpdateInputs => UpdateReport = {
|
||||||
val doCachedResolve = { (inChanged: Boolean, updateInputs: UpdateInputs) =>
|
val doCachedResolve = { (inChanged: Boolean, updateInputs: UpdateInputs) =>
|
||||||
import sbt.librarymanagement.LibraryManagementCodec._
|
import sbt.librarymanagement.LibraryManagementCodec._
|
||||||
val cachedResolve = Tracked.lastOutput[UpdateInputs, UpdateReport](cache) {
|
val cachedResolve = Tracked.lastOutput[UpdateInputs, UpdateReport](cache) {
|
||||||
case (_, Some(out)) if upToDate(inChanged, out) => out
|
case (_, Some(out)) if upToDate(inChanged, out) => markAsCached(out)
|
||||||
case _ => resolve(updateInputs)
|
case _ => resolve(updateInputs)
|
||||||
}
|
}
|
||||||
import scala.util.control.Exception.catching
|
import scala.util.control.Exception.catching
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,54 @@
|
||||||
// #1620
|
scalaVersion in ThisBuild := "2.10.4"
|
||||||
|
|
||||||
ivyPaths := IvyPaths(
|
|
||||||
(baseDirectory in ThisBuild).value,
|
|
||||||
Some((baseDirectory in LocalRootProject).value / "ivy-cache")
|
|
||||||
)
|
|
||||||
|
|
||||||
scalaVersion := "2.10.4"
|
|
||||||
|
|
||||||
dependencyOverrides in ThisBuild += "com.github.nscala-time" %% "nscala-time" % "1.0.0"
|
dependencyOverrides in ThisBuild += "com.github.nscala-time" %% "nscala-time" % "1.0.0"
|
||||||
libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "1.0.0"
|
|
||||||
|
|
||||||
TaskKey[Unit]("check") := {
|
lazy val root = (project in file("."))
|
||||||
val s = (streams in update).value
|
.dependsOn(p1 % Compile)
|
||||||
val cacheStoreFactory = s.cacheStoreFactory sub updateCacheName.value
|
.settings(
|
||||||
val module = ivyModule.value
|
ivyPaths := IvyPaths(
|
||||||
val config = updateConfiguration.value
|
(baseDirectory in ThisBuild).value,
|
||||||
|
Some((baseDirectory in LocalRootProject).value / "ivy-cache")
|
||||||
|
),
|
||||||
|
libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "1.0.0",
|
||||||
|
|
||||||
import sbt.internal.librarymanagement.IvyConfiguration
|
// https://github.com/sbt/sbt/pull/1620
|
||||||
import sbt.librarymanagement.{ ModuleSettings, UpdateConfiguration }
|
// sbt resolves dependencies every compile when using %% with dependencyOverrides
|
||||||
|
TaskKey[Unit]("check") := {
|
||||||
|
val s = (streams in update).value
|
||||||
|
val cacheStoreFactory = s.cacheStoreFactory sub updateCacheName.value
|
||||||
|
val module = ivyModule.value
|
||||||
|
val config = updateConfiguration.value
|
||||||
|
|
||||||
type In = IvyConfiguration :+: ModuleSettings :+: UpdateConfiguration :+: HNil
|
import sbt.internal.librarymanagement.IvyConfiguration
|
||||||
|
import sbt.librarymanagement.{ ModuleSettings, UpdateConfiguration }
|
||||||
|
|
||||||
import sbt.util.CacheImplicits._
|
type In = IvyConfiguration :+: ModuleSettings :+: UpdateConfiguration :+: HNil
|
||||||
import sbt.internal.AltLibraryManagementCodec._
|
|
||||||
|
|
||||||
val f: In => Unit =
|
import sbt.util.CacheImplicits._
|
||||||
Tracked.inputChanged(cacheStoreFactory make "inputs") { (inChanged: Boolean, in: In) =>
|
import sbt.internal.AltLibraryManagementCodec._
|
||||||
if (inChanged)
|
|
||||||
sys.error(s"Update cache is invalidated: ${module.owner.configuration}, ${module.moduleSettings}, $config")
|
val f: In => Unit =
|
||||||
|
Tracked.inputChanged(cacheStoreFactory make "inputs") { (inChanged: Boolean, in: In) =>
|
||||||
|
if (inChanged)
|
||||||
|
sys.error(s"Update cache is invalidated: ${module.owner.configuration}, ${module.moduleSettings}, $config")
|
||||||
|
}
|
||||||
|
f(module.owner.configuration :+: module.moduleSettings :+: config :+: HNil)
|
||||||
|
},
|
||||||
|
|
||||||
|
// https://github.com/sbt/sbt/issues/3226
|
||||||
|
// update caching is not working on sbt 1.0.x
|
||||||
|
TaskKey[Unit]("check2") := {
|
||||||
|
val ur = update.value
|
||||||
|
if (!ur.stats.cached) {
|
||||||
|
sys.error(s"update.value is not cached! $ur")
|
||||||
|
}
|
||||||
|
val tu = transitiveUpdate.value
|
||||||
|
if (tu.exists(!_.stats.cached)) {
|
||||||
|
sys.error(s"uncached transitiveUpdate exists! $tu")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
f(module.owner.configuration :+: module.moduleSettings :+: config :+: HNil)
|
)
|
||||||
}
|
|
||||||
|
lazy val p1 = project
|
||||||
|
.settings(
|
||||||
|
libraryDependencies += "com.novocode" % "junit-interface" % "0.11"
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
> compile
|
> compile
|
||||||
> check
|
> check
|
||||||
|
> check2
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue