mirror of https://github.com/sbt/sbt.git
Merge pull request #7676 from eed3si9n/wip/invalidate-on-resource
[2.x] fix: Invalidate testQuick on resource file changes
This commit is contained in:
commit
cb9a455915
|
|
@ -652,7 +652,14 @@ object Defaults extends BuildCommon {
|
||||||
PluginDiscovery.writeDescriptors(discoveredSbtPlugins.value, resourceManaged.value)
|
PluginDiscovery.writeDescriptors(discoveredSbtPlugins.value, resourceManaged.value)
|
||||||
}).taskValue,
|
}).taskValue,
|
||||||
managedResources := generate(resourceGenerators).value,
|
managedResources := generate(resourceGenerators).value,
|
||||||
resources := Classpaths.concat(managedResources, unmanagedResources).value
|
resources := Classpaths.concat(managedResources, unmanagedResources).value,
|
||||||
|
resourceDigests := {
|
||||||
|
val uifs = (unmanagedResources / inputFileStamps).value
|
||||||
|
val mifs = (managedResources / inputFileStamps).value
|
||||||
|
(uifs ++ mifs).sortBy(_._1.toString()).map { case (p, fileStamp) =>
|
||||||
|
FileStamp.toDigest(p, fileStamp)
|
||||||
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
// This exists for binary compatibility and probably never should have been public.
|
// This exists for binary compatibility and probably never should have been public.
|
||||||
def addBaseSources: Seq[Def.Setting[Task[Seq[File]]]] = Nil
|
def addBaseSources: Seq[Def.Setting[Task[Seq[File]]]] = Nil
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,7 @@ object Keys {
|
||||||
val managedResources = taskKey[Seq[File]]("Resources generated by the build.").withRank(BTask)
|
val managedResources = taskKey[Seq[File]]("Resources generated by the build.").withRank(BTask)
|
||||||
val resourceDirectories = settingKey[Seq[File]]("List of all resource directories, both managed and unmanaged.").withRank(BPlusSetting)
|
val resourceDirectories = settingKey[Seq[File]]("List of all resource directories, both managed and unmanaged.").withRank(BPlusSetting)
|
||||||
val resources = taskKey[Seq[File]]("All resource files, both managed and unmanaged.").withRank(BTask)
|
val resources = taskKey[Seq[File]]("All resource files, both managed and unmanaged.").withRank(BTask)
|
||||||
|
private[sbt] val resourceDigests = taskKey[Seq[Digest]]("All resource files, both managed and unmanaged.").withRank(BTask)
|
||||||
|
|
||||||
// Output paths
|
// Output paths
|
||||||
@cacheLevel(include = Array.empty)
|
@cacheLevel(include = Array.empty)
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,12 @@ object IncrementalTest:
|
||||||
val cp = (Keys.test / fullClasspath).value
|
val cp = (Keys.test / fullClasspath).value
|
||||||
val testNames = Keys.definedTests.value.map(_.name).toVector.distinct
|
val testNames = Keys.definedTests.value.map(_.name).toVector.distinct
|
||||||
val converter = fileConverter.value
|
val converter = fileConverter.value
|
||||||
|
val rds = Keys.resourceDigests.value
|
||||||
val extra = Keys.extraTestDigests.value
|
val extra = Keys.extraTestDigests.value
|
||||||
val stamper = ClassStamper(cp, converter)
|
val stamper = ClassStamper(cp, converter)
|
||||||
// TODO: Potentially do something about JUnit 5 and others which might not use class name
|
// TODO: Potentially do something about JUnit 5 and others which might not use class name
|
||||||
Map((testNames.flatMap: name =>
|
Map((testNames.flatMap: name =>
|
||||||
stamper.transitiveStamp(name, extra) match
|
stamper.transitiveStamp(name, extra ++ rds) match
|
||||||
case Some(ts) => Seq(name -> ts)
|
case Some(ts) => Seq(name -> ts)
|
||||||
case None => Nil
|
case None => Nil
|
||||||
): _*)
|
): _*)
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@ import java.nio.file.{ Path, Paths }
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
import sbt.internal.inc.{ EmptyStamp, Stamper, Hash => IncHash, LastModified => IncLastModified }
|
import sbt.internal.inc.{ EmptyStamp, Stamper, Hash => IncHash, LastModified => IncLastModified }
|
||||||
|
import sbt.internal.inc.JavaInterfaceUtil.given
|
||||||
import sbt.io.IO
|
import sbt.io.IO
|
||||||
import sbt.nio.file.FileAttributes
|
import sbt.nio.file.FileAttributes
|
||||||
|
import sbt.util.Digest
|
||||||
import sjsonnew.{ Builder, JsonFormat, Unbuilder, deserializationError }
|
import sjsonnew.{ Builder, JsonFormat, Unbuilder, deserializationError }
|
||||||
import xsbti.compile.analysis.{ Stamp => XStamp }
|
import xsbti.compile.analysis.{ Stamp => XStamp }
|
||||||
import xsbti.VirtualFileRef
|
import xsbti.VirtualFileRef
|
||||||
|
|
@ -103,6 +105,15 @@ object FileStamp {
|
||||||
private[sbt] final case class LastModified private[sbt] (time: Long) extends FileStamp
|
private[sbt] final case class LastModified private[sbt] (time: Long) extends FileStamp
|
||||||
private[sbt] final case class Error(exception: IOException) extends FileStamp
|
private[sbt] final case class Error(exception: IOException) extends FileStamp
|
||||||
|
|
||||||
|
def toDigest(path: Path, stamp: FileStamp): Digest = stamp match
|
||||||
|
case f: FileHashImpl =>
|
||||||
|
f.xstamp.getHash().toOption match
|
||||||
|
case Some(hash) => Digest.sha256Hash(hash.getBytes("UTF-8"))
|
||||||
|
case None => Digest.sha256Hash(path)
|
||||||
|
case FileStamp.Hash(hex) => Digest.sha256Hash(hex.getBytes("UTF-8"))
|
||||||
|
case FileStamp.Error(_) => Digest.zero
|
||||||
|
case FileStamp.LastModified(_) => Digest.sha256Hash(path)
|
||||||
|
|
||||||
object Formats {
|
object Formats {
|
||||||
implicit val seqPathJsonFormatter: JsonFormat[Seq[Path]] =
|
implicit val seqPathJsonFormatter: JsonFormat[Seq[Path]] =
|
||||||
asStringArray(_.toString, Paths.get(_))
|
asStringArray(_.toString, Paths.get(_))
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,12 @@ $ copy-file changes/updated-main.txt src/main/resources/foo.txt
|
||||||
|
|
||||||
> run foo.txt updated-main
|
> run foo.txt updated-main
|
||||||
|
|
||||||
> test
|
> testQuick
|
||||||
|
|
||||||
$ copy-file changes/updated-test.txt src/test/resources/bar.txt
|
$ copy-file changes/updated-test.txt src/test/resources/bar.txt
|
||||||
|
|
||||||
-> test
|
-> testQuick
|
||||||
|
|
||||||
$ copy-file changes/UpdatedResourceTest.scala src/test/scala/scripted/ResourceTest.scala
|
$ copy-file changes/UpdatedResourceTest.scala src/test/scala/scripted/ResourceTest.scala
|
||||||
|
|
||||||
> test
|
> testQuick
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue