diff --git a/src/build.rs b/src/build.rs index b8b6342..aece691 100644 --- a/src/build.rs +++ b/src/build.rs @@ -18,6 +18,7 @@ use console::style; use indicatif::{ProgressBar, ProgressStyle}; use serde::Serialize; use std::fmt; +use std::fs::File; use std::io::{stdout, Write}; use std::path::PathBuf; use std::time::{Duration, Instant}; @@ -414,6 +415,20 @@ impl fmt::Display for BuildError { } } +pub fn write_build_ninja(build_state: &BuildState) { + // write build.ninja files in the packages after a non-incremental build + // this is necessary to bust the editor tooling cache. The editor tooling + // is watching this file. + // we don't need to do this in an incremental build because there are no file + // changes (deletes / additions) + for package in build_state.packages.values() { + // write empty file: + let mut f = File::create(std::path::Path::new(&package.get_bs_build_path()).join("build.ninja")) + .expect("Unable to write file"); + f.write_all(b"").expect("unable to write to ninja file"); + } +} + pub fn build( filter: &Option, path: &str, @@ -440,10 +455,12 @@ pub fn build( default_timing.unwrap_or(timing_total_elapsed).as_secs_f64() ); clean::cleanup_after_build(&build_state); + write_build_ninja(&build_state); Ok(build_state) } Err(e) => { clean::cleanup_after_build(&build_state); + write_build_ninja(&build_state); Err(BuildError::IncrementalBuild(e)) } } diff --git a/src/watcher.rs b/src/watcher.rs index 166d44c..74251e5 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -212,6 +212,9 @@ async fn async_watch( if let Some(a) = after_build.clone() { cmd::run(a) } + + build::write_build_ninja(&build_state); + let timing_total_elapsed = timing_total.elapsed(); println!( "\n{}{}Finished compilation in {:.2}s\n",