Use project watchStartMessage for multi commands

It didn't make sense to aggregate the watch start command if it was
defined in multiple sources so we previously just fell back to the
default message if multiple commands were being run. This, however,
meant that if you ran, say, ~compile in an aggregate project, it wasn't
possible to customize the start message. There was a message in the
sbt gitter channel where someone found the new message too verbose and
wanted to print something shorter and I realized that this was an
unfortunate restriction. Instead of giving up, we can just use the
project's watchStartMessage as a default. If the watchStartMessage
setting is unset for some reason, we can fall back to the default.

I validated this change manually in the swoval project, which has an
aggregate root project, by running
set ThisBuild / watchStartMessage := { (_, _, _) => None }
and indeed nothing was printed after each task evaluation in '~compile'.
This commit is contained in:
Ethan Atkins 2019-06-11 16:20:46 -07:00
parent bf03d24f6d
commit 875a25c929
1 changed files with 9 additions and 4 deletions

View File

@ -469,7 +469,8 @@ private[sbt] object Continuous extends DeprecatedContinuous {
val project = extracted.currentRef
val logger = setLevel(rawLogger, configs.map(_.watchSettings.logLevel).min, state)
val beforeCommand = () => configs.foreach(_.watchSettings.beforeCommand())
val onStart: () => Watch.Action = getOnStart(project, commands, configs, rawLogger, count)
val onStart: () => Watch.Action =
getOnStart(project, commands, configs, rawLogger, count, extracted)
val nextInputEvent: () => Watch.Action = parseInputEvents(configs, state, inputStream, logger)
val (nextFileEvent, cleanupFileMonitor): (() => Option[(Watch.Event, Watch.Action)], () => Unit) =
getFileEvents(configs, rawLogger, state, count, commands, fileStampCache)
@ -501,7 +502,8 @@ private[sbt] object Continuous extends DeprecatedContinuous {
commands: Seq[String],
configs: Seq[Config],
logger: Logger,
count: AtomicInteger
count: AtomicInteger,
extracted: Extracted,
): () => Watch.Action = {
val f: () => Seq[Watch.Action] = () => {
configs.map { params =>
@ -522,8 +524,11 @@ private[sbt] object Continuous extends DeprecatedContinuous {
() => {
val res = f().min
// Print the default watch message if there are multiple tasks
if (configs.size > 1)
Watch.defaultStartWatch(count.get(), project, commands).foreach(logger.info(_))
if (configs.size > 1) {
val onStartWatch =
extracted.getOpt(watchStartMessage in project).getOrElse(Watch.defaultStartWatch)
onStartWatch(count.get(), project, commands).foreach(logger.info(_))
}
res
}
}