Skip to content

Commit

Permalink
Check applet.wasm modification to avoid rebuild (google#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 authored Apr 24, 2023
1 parent cb1c221 commit a40871d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,10 @@ impl AppletOptions {
cargo.env("RUSTFLAGS", rustflags.join(" "));
cargo.current_dir(dir);
execute_command(&mut cargo)?;
std::fs::copy(wasm, "target/applet.wasm")?;
self.execute_wasm(main)
if copy_if_newer(&wasm, "target/applet.wasm")? {
self.execute_wasm(main)?;
}
Ok(())
}

fn execute_assemblyscript(&self, main: &MainOptions) -> Result<()> {
Expand Down Expand Up @@ -564,6 +566,17 @@ fn ensure_command(cmd: &[&str]) -> Result<()> {
execute_command(&mut ensure_bloat)
}

/// Copies a file if newer than the destination.
///
/// Returns whether the copy took place.
fn copy_if_newer(src: &str, dst: &str) -> Result<bool> {
let newer = std::fs::metadata(dst)?.modified()? < std::fs::metadata(src)?.modified()?;
if newer {
std::fs::copy(src, dst)?;
}
Ok(newer)
}

fn main() -> Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("warn"));
Flags::parse().execute()?;
Expand Down

0 comments on commit a40871d

Please sign in to comment.