Don't attempt to prevent certain watch loops

If the managedSources task writes into an unmanaged source directory,
that would cause an infinite loop. I don't think it's worth doing out of
band task execution to try and prevent this.
This commit is contained in:
Ethan Atkins 2018-12-15 17:37:35 -08:00
parent f14bc7a503
commit 2ef97768a0
6 changed files with 1 additions and 43 deletions

View File

@ -379,23 +379,7 @@ object Defaults extends BuildCommon {
val baseDir = baseDirectory.value
val bases = unmanagedSourceDirectories.value
val include = (includeFilter in unmanagedSources).value
val exclude = (excludeFilter in unmanagedSources).value match {
case e =>
val s = state.value
try {
Project.extract(s).runTask(managedSources in Compile in ThisScope, s) match {
case (_, l) if l.nonEmpty =>
e || new FileFilter {
private val files = l.toSet
override def accept(pathname: File): Boolean = files.contains(pathname)
override def toString = s"ManagedSourcesFilter($files)"
}
case _ => e
}
} catch {
case NonFatal(_) => e
}
}
val exclude = (excludeFilter in unmanagedSources).value
val baseSources =
if (sourcesInBase.value) Seq(new Source(baseDir, include, exclude, recursive = false))
else Nil

View File

@ -1,17 +0,0 @@
import java.nio.file.Files
lazy val watchLoopTest = taskKey[Unit]("Check that managed sources are filtered")
sourceGenerators in Compile += Def.task {
val path = baseDirectory.value.toPath.resolve("src/main/scala/Foo.scala")
Files.write(path, "object Foo".getBytes).toFile :: Nil
}
watchLoopTest := {
val watched = watchSources.value
val managedSource = (managedSources in Compile).value.head
assert(!SourceWrapper.accept(watched, managedSource))
assert((sources in Compile).value.foldLeft((true, Set.empty[File])) {
case ((res, set), f) => (res && !set.contains(f), set + f)
}._1)
}

View File

@ -1,6 +0,0 @@
package sbt
object SourceWrapper {
def accept(sources: Seq[sbt.internal.io.Source], file: File): Boolean =
sources.exists(_.accept(file.toPath))
}

View File

@ -1 +0,0 @@
object Bar

View File

@ -1 +0,0 @@
object Foo

View File

@ -1 +0,0 @@
> watchLoopTest