mirror of
https://github.com/Zenithsiz/zbuild.git
synced 2026-02-04 06:28:57 +00:00
Added timeout argument for watcher.
This commit is contained in:
parent
96cd53ecbe
commit
7fa2def774
@ -12,7 +12,7 @@ use std::path::PathBuf;
|
||||
///
|
||||
/// Then you may request `zbuild` to create a certain file and it will parse
|
||||
/// all rules in order to find a way to build the output
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
#[derive(Debug)]
|
||||
#[derive(clap::Parser)]
|
||||
#[clap(author, version, about)]
|
||||
pub struct Args {
|
||||
@ -47,6 +47,10 @@ pub struct Args {
|
||||
#[clap(long = "watch", short = 'w')]
|
||||
pub watch: bool,
|
||||
|
||||
/// Watcher file event debouncer timeout
|
||||
#[clap(long = "watcher-debouncer-timeout-ms")]
|
||||
pub watch_debouncer_timeout_ms: Option<f64>,
|
||||
|
||||
/// Logs output to a file.
|
||||
///
|
||||
/// You can use `RUST_LOG_FILE` to set filtering options
|
||||
|
||||
@ -174,7 +174,12 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||
// Then create the watcher, if we're watching
|
||||
let watcher = args
|
||||
.watch
|
||||
.then(|| Watcher::new(builder.subscribe_events()))
|
||||
.then(|| {
|
||||
Watcher::new(
|
||||
builder.subscribe_events(),
|
||||
args.watch_debouncer_timeout_ms.unwrap_or(100.0),
|
||||
)
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
// Finally build all targets and start watching
|
||||
|
||||
@ -46,11 +46,16 @@ pub struct Watcher<'s> {
|
||||
|
||||
impl<'s> Watcher<'s> {
|
||||
/// Creates a new watcher
|
||||
pub fn new(builder_event_rx: async_broadcast::Receiver<build::Event<'s>>) -> Result<Self, AppError> {
|
||||
pub fn new(
|
||||
builder_event_rx: async_broadcast::Receiver<build::Event<'s>>,
|
||||
watch_debouncer_timeout_ms: f64,
|
||||
) -> Result<Self, AppError> {
|
||||
// Create the watcher
|
||||
let (fs_event_tx, fs_event_rx) = tokio::sync::mpsc::channel(16);
|
||||
let watcher =
|
||||
notify_debouncer_mini::new_debouncer(Duration::from_secs(1), None, move |fs_events| match fs_events {
|
||||
let watcher = notify_debouncer_mini::new_debouncer(
|
||||
Duration::from_secs_f64(watch_debouncer_timeout_ms / 1000.0),
|
||||
None,
|
||||
move |fs_events| match fs_events {
|
||||
Ok(fs_events) =>
|
||||
for fs_event in fs_events {
|
||||
tracing::trace!(?fs_event, "Watcher fs event");
|
||||
@ -61,9 +66,10 @@ impl<'s> Watcher<'s> {
|
||||
for err in errs {
|
||||
tracing::warn!("Error while watching: {:?}", anyhow::Error::from(err));
|
||||
},
|
||||
})
|
||||
.context("Unable to create file watcher")
|
||||
.map_err(AppError::Other)?;
|
||||
},
|
||||
)
|
||||
.context("Unable to create file watcher")
|
||||
.map_err(AppError::Other)?;
|
||||
|
||||
Ok(Self {
|
||||
watcher,
|
||||
@ -144,7 +150,7 @@ impl<'s> Watcher<'s> {
|
||||
Some(rev_dep) => rev_dep.clone(),
|
||||
None => return,
|
||||
};
|
||||
tracing::info!("Changed: {:?}", rev_dep.target);
|
||||
tracing::debug!("Changed: {:?}", rev_dep.target);
|
||||
tracing::trace!(?rev_dep, "Reverse dependencies");
|
||||
|
||||
// Note: We clone the parents so we don't hold onto the rev dep lock for too long
|
||||
@ -182,10 +188,7 @@ impl<'s> Watcher<'s> {
|
||||
// get rebuilt.
|
||||
dep_parents
|
||||
.iter()
|
||||
.map(|target| {
|
||||
tracing::info!("Rechecking: {target:?}");
|
||||
crate::build_target(builder, target, rules, ignore_missing)
|
||||
})
|
||||
.map(|target| crate::build_target(builder, target, rules, ignore_missing))
|
||||
.collect::<FuturesUnordered<_>>()
|
||||
.collect::<()>()
|
||||
.await;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user