From 6ec9edb7333eb682ded0140046d3ad30ff38971e Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Tue, 27 Aug 2019 10:37:24 -0700 Subject: [PATCH] Abort early in watch multi commands During refactoring of Continuous, I inadvertently changed the semantics of `~` so that all multi commands were run regardless of whether or not an earlier command had failed. I fixed the issue and added a regression test. --- main/src/main/scala/sbt/internal/Continuous.scala | 4 ++-- sbt/src/sbt-test/watch/multi-error/build.sbt | 8 ++++++++ sbt/src/sbt-test/watch/multi-error/changes/Foo.txt | 1 + .../sbt-test/watch/multi-error/src/main/scala/Foo.scala | 1 + sbt/src/sbt-test/watch/multi-error/test | 3 +++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 sbt/src/sbt-test/watch/multi-error/build.sbt create mode 100644 sbt/src/sbt-test/watch/multi-error/changes/Foo.txt create mode 100644 sbt/src/sbt-test/watch/multi-error/src/main/scala/Foo.scala create mode 100644 sbt/src/sbt-test/watch/multi-error/test diff --git a/main/src/main/scala/sbt/internal/Continuous.scala b/main/src/main/scala/sbt/internal/Continuous.scala index 89e5fe00e..e2d2143da 100644 --- a/main/src/main/scala/sbt/internal/Continuous.scala +++ b/main/src/main/scala/sbt/internal/Continuous.scala @@ -243,7 +243,7 @@ private[sbt] object Continuous extends DeprecatedContinuous { case exec :: rest => val updatedState = MainLoop.processCommand(exec, s.copy(remainingCommands = rest)) val remaining = - updatedState.remainingCommands.takeWhile(_.commandLine != FailureWall) + updatedState.remainingCommands.takeWhile(_.commandLine != failureCommandName) remaining match { case Nil => updatedState.remainingCommands.forall(_.commandLine != failureCommandName) @@ -351,7 +351,7 @@ private[sbt] object Continuous extends DeprecatedContinuous { currentCount.getAndIncrement() callbacks.beforeCommand() // abort as soon as one of the tasks fails - valid.takeWhile(_._3.apply()) + valid.takeWhile { case (_, _, task) => task() } updateLegacyWatchState(s, configs.flatMap(_.inputs().map(_.glob)), currentCount.get()) () } diff --git a/sbt/src/sbt-test/watch/multi-error/build.sbt b/sbt/src/sbt-test/watch/multi-error/build.sbt new file mode 100644 index 000000000..2e9cd6c3d --- /dev/null +++ b/sbt/src/sbt-test/watch/multi-error/build.sbt @@ -0,0 +1,8 @@ +import java.nio.file._ +watchOnIteration := { (_, _, _) => Watch.CancelWatch } + +val copyFile = taskKey[Unit]("copy a file") +copyFile := { + val base = baseDirectory.value.toPath + Files.copy(base / "changes" / "Foo.txt", base / "Foo.txt") +} \ No newline at end of file diff --git a/sbt/src/sbt-test/watch/multi-error/changes/Foo.txt b/sbt/src/sbt-test/watch/multi-error/changes/Foo.txt new file mode 100644 index 000000000..191028156 --- /dev/null +++ b/sbt/src/sbt-test/watch/multi-error/changes/Foo.txt @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/sbt/src/sbt-test/watch/multi-error/src/main/scala/Foo.scala b/sbt/src/sbt-test/watch/multi-error/src/main/scala/Foo.scala new file mode 100644 index 000000000..c4de1ce06 --- /dev/null +++ b/sbt/src/sbt-test/watch/multi-error/src/main/scala/Foo.scala @@ -0,0 +1 @@ +object Foo { \ No newline at end of file diff --git a/sbt/src/sbt-test/watch/multi-error/test b/sbt/src/sbt-test/watch/multi-error/test new file mode 100644 index 000000000..7088568c9 --- /dev/null +++ b/sbt/src/sbt-test/watch/multi-error/test @@ -0,0 +1,3 @@ +> ~compile; copyFile + +$ absent Foo.txt \ No newline at end of file