From 28ddd7ed7f89e21e4736bce0cd69d64b9a4a1549 Mon Sep 17 00:00:00 2001 From: itowlson Date: Wed, 15 Nov 2023 10:03:37 +1300 Subject: [PATCH] Watch should not serve until there is a build Signed-off-by: itowlson --- src/commands/watch.rs | 1 + src/commands/watch/buildifier.rs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/commands/watch.rs b/src/commands/watch.rs index 10ba72e5bb..f5a3b5ea01 100644 --- a/src/commands/watch.rs +++ b/src/commands/watch.rs @@ -111,6 +111,7 @@ impl WatchCommand { spin_bin: spin_bin.clone(), manifest: manifest_file.clone(), clear_screen: self.clear, + has_ever_built: false, watched_changes: source_code_rx, uppificator_pauser: pause_tx, }; diff --git a/src/commands/watch/buildifier.rs b/src/commands/watch/buildifier.rs index 79ebda16bf..74bd433d07 100644 --- a/src/commands/watch/buildifier.rs +++ b/src/commands/watch/buildifier.rs @@ -8,11 +8,13 @@ pub(crate) struct Buildifier { pub spin_bin: PathBuf, pub manifest: PathBuf, pub clear_screen: bool, + pub has_ever_built: bool, pub watched_changes: tokio::sync::watch::Receiver, // TODO: refine which component(s) a change affects pub uppificator_pauser: tokio::sync::mpsc::Sender, } impl Buildifier { + #[allow(clippy::collapsible_if)] pub(crate) async fn run(&mut self) { // Other components may close channels as part of shutdown, so if any channels // fail, just exit the loop and fall out normally. @@ -26,10 +28,15 @@ impl Buildifier { break; } - _ = self.build_once().await; + let build_result = self.build_once().await; + if !self.has_ever_built { + self.has_ever_built = matches!(build_result, Ok(true)); + } - if self.uppificator_pauser.send(Pause::Unpause).await.is_err() { - break; + if self.has_ever_built { + if self.uppificator_pauser.send(Pause::Unpause).await.is_err() { + break; + } } if self.watched_changes.changed().await.is_err() {