Fix '~' for dependent projects with a broken parent

In #4446, @japgolly reported that in some projects, if a parent project
was broken, then '~' would immediately exit upon startup. I tracked it
down to this managed sources filter. The idea of this filter is to avoid
getting stuck in a build loop if managedSources writes into an unmanaged
source directory. If the (managedSources in ThisScope).value line
failed, however, it would cause the watchSources, and by delegation,
watchTransitiveSources task to fail. The fix is to only create this
filter if the managedSources task succeeds.

I'm not 100% sure if we shouldn't just get rid of this filter entirely
and just document that '~' will probably loop if a build writes the
result of managedSources into an unmanaged source directory.
This commit is contained in:
Ethan Atkins 2018-11-10 17:21:59 -08:00
parent 015d85836b
commit fd2ec7adc3
8 changed files with 30 additions and 9 deletions

View File

@ -41,7 +41,7 @@ env:
- SBT_CMD="scripted source-dependencies/*1of3" - SBT_CMD="scripted source-dependencies/*1of3"
- SBT_CMD="scripted source-dependencies/*2of3" - SBT_CMD="scripted source-dependencies/*2of3"
- SBT_CMD="scripted source-dependencies/*3of3" - SBT_CMD="scripted source-dependencies/*3of3"
- SBT_CMD="scripted tests/*" - SBT_CMD="scripted tests/* watch/*"
- SBT_CMD="repoOverrideTest:scripted dependency-management/*" - SBT_CMD="repoOverrideTest:scripted dependency-management/*"
notifications: notifications:

View File

@ -361,8 +361,10 @@ object Defaults extends BuildCommon {
val include = (includeFilter in unmanagedSources).value val include = (includeFilter in unmanagedSources).value
val exclude = (excludeFilter in unmanagedSources).value match { val exclude = (excludeFilter in unmanagedSources).value match {
case e => case e =>
(managedSources in ThisScope).value match { val s = state.value
case l if l.nonEmpty => try {
Project.extract(s).runTask(managedSources in Compile in ThisScope, s) match {
case (_, l) if l.nonEmpty =>
e || new FileFilter { e || new FileFilter {
private val files = l.toSet private val files = l.toSet
override def accept(pathname: File): Boolean = files.contains(pathname) override def accept(pathname: File): Boolean = files.contains(pathname)
@ -370,6 +372,9 @@ object Defaults extends BuildCommon {
} }
case _ => e case _ => e
} }
} catch {
case NonFatal(_) => e
}
} }
val baseSources = val baseSources =
if (sourcesInBase.value) Seq(new Source(baseDir, include, exclude, recursive = false)) if (sourcesInBase.value) Seq(new Source(baseDir, include, exclude, recursive = false))

View File

@ -0,0 +1,3 @@
lazy val root = (project in file(".")).aggregate(parent, child)
lazy val parent = project
lazy val child = project.enablePlugins(JmhPlugin).dependsOn(parent)

View File

@ -0,0 +1 @@
class Foo

View File

@ -0,0 +1 @@
class Bar

View File

@ -0,0 +1 @@
class Foo {

View File

@ -0,0 +1 @@
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.4")

View File

@ -0,0 +1,9 @@
> watchTransitiveSources
-> compile
$ copy-file changes/Foo.scala parent/src/main/scala/Foo.scala
> watchTransitiveSources
> compile