From fd2ec7adc372bb89dbc40dcebcd69e0370d50adb Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sat, 10 Nov 2018 17:21:59 -0800 Subject: [PATCH] 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. --- .travis.yml | 2 +- main/src/main/scala/sbt/Defaults.scala | 21 ++++++++++++------- .../sbt-test/watch/watch-sources/build.sbt | 3 +++ .../watch/watch-sources/changes/Foo.scala | 1 + .../child/src/main/scala/Bar.scala | 1 + .../parent/src/main/scala/Foo.scala | 1 + .../watch/watch-sources/project/plugin.sbt | 1 + sbt/src/sbt-test/watch/watch-sources/test | 9 ++++++++ 8 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 sbt/src/sbt-test/watch/watch-sources/build.sbt create mode 100644 sbt/src/sbt-test/watch/watch-sources/changes/Foo.scala create mode 100644 sbt/src/sbt-test/watch/watch-sources/child/src/main/scala/Bar.scala create mode 100644 sbt/src/sbt-test/watch/watch-sources/parent/src/main/scala/Foo.scala create mode 100644 sbt/src/sbt-test/watch/watch-sources/project/plugin.sbt create mode 100644 sbt/src/sbt-test/watch/watch-sources/test diff --git a/.travis.yml b/.travis.yml index d17c5e546..1db7df73b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ env: - SBT_CMD="scripted source-dependencies/*1of3" - SBT_CMD="scripted source-dependencies/*2of3" - SBT_CMD="scripted source-dependencies/*3of3" - - SBT_CMD="scripted tests/*" + - SBT_CMD="scripted tests/* watch/*" - SBT_CMD="repoOverrideTest:scripted dependency-management/*" notifications: diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 0b4b26b86..f4663c5ab 100755 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -361,14 +361,19 @@ object Defaults extends BuildCommon { val include = (includeFilter in unmanagedSources).value val exclude = (excludeFilter in unmanagedSources).value match { case e => - (managedSources in ThisScope).value 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 + 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 baseSources = diff --git a/sbt/src/sbt-test/watch/watch-sources/build.sbt b/sbt/src/sbt-test/watch/watch-sources/build.sbt new file mode 100644 index 000000000..16a193e6f --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-sources/build.sbt @@ -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) diff --git a/sbt/src/sbt-test/watch/watch-sources/changes/Foo.scala b/sbt/src/sbt-test/watch/watch-sources/changes/Foo.scala new file mode 100644 index 000000000..c389887ee --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-sources/changes/Foo.scala @@ -0,0 +1 @@ +class Foo diff --git a/sbt/src/sbt-test/watch/watch-sources/child/src/main/scala/Bar.scala b/sbt/src/sbt-test/watch/watch-sources/child/src/main/scala/Bar.scala new file mode 100644 index 000000000..f6673f853 --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-sources/child/src/main/scala/Bar.scala @@ -0,0 +1 @@ +class Bar diff --git a/sbt/src/sbt-test/watch/watch-sources/parent/src/main/scala/Foo.scala b/sbt/src/sbt-test/watch/watch-sources/parent/src/main/scala/Foo.scala new file mode 100644 index 000000000..970bfef8a --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-sources/parent/src/main/scala/Foo.scala @@ -0,0 +1 @@ +class Foo { diff --git a/sbt/src/sbt-test/watch/watch-sources/project/plugin.sbt b/sbt/src/sbt-test/watch/watch-sources/project/plugin.sbt new file mode 100644 index 000000000..a12e17f90 --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-sources/project/plugin.sbt @@ -0,0 +1 @@ +addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.4") diff --git a/sbt/src/sbt-test/watch/watch-sources/test b/sbt/src/sbt-test/watch/watch-sources/test new file mode 100644 index 000000000..50a9e2b19 --- /dev/null +++ b/sbt/src/sbt-test/watch/watch-sources/test @@ -0,0 +1,9 @@ +> watchTransitiveSources + +-> compile + +$ copy-file changes/Foo.scala parent/src/main/scala/Foo.scala + +> watchTransitiveSources + +> compile