Merge pull request #4537 from eatkins/allow-watch-loops

Allow watch loops
This commit is contained in:
eugene yokota 2019-02-04 10:25:11 -05:00 committed by GitHub
commit e73d1fb7c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 3 additions and 48 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
@ -635,13 +619,10 @@ object Defaults extends BuildCommon {
watchOnTermination := Watched.onTermination,
watchConfig := {
val sources = watchTransitiveSources.value ++ watchProjectTransitiveSources.value
val extracted = Project.extract(state.value)
val wm = extracted
.getOpt(watchingMessage)
val wm = watchingMessage.?.value
.map(w => (count: Int) => Some(w(WatchState.empty(sources).withCount(count))))
.getOrElse(watchStartMessage.value)
val tm = extracted
.getOpt(triggeredMessage)
val tm = triggeredMessage.?.value
.map(
tm => (_: TypedPath, count: Int) => Some(tm(WatchState.empty(sources).withCount(count)))
)

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