From 685991c6edecbc02a53a2a24168ca83bba9ed6ab Mon Sep 17 00:00:00 2001 From: Marrub Date: Mon, 25 Mar 2019 20:07:58 -0400 Subject: [PATCH] rewrite build script to actually pick up on changes properly --- source/tycho/build.rs | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/source/tycho/build.rs b/source/tycho/build.rs index 43d44fe..58aab15 100644 --- a/source/tycho/build.rs +++ b/source/tycho/build.rs @@ -1,11 +1,36 @@ -use std::process::Command; +use std::{env, fs, io, path::Path, process::Command}; -fn main() -> std::io::Result<()> +fn io_err(st: &'static str) -> io::Error { - let out_file = std::env::var("OUT_DIR").unwrap(); + io::Error::new(io::ErrorKind::Other, st) +} + +fn traverse_dir(path: &Path) -> io::Result<()> +{ + for ent in fs::read_dir(path)? { + let path = ent?.path(); + + if path.is_dir() { + traverse_dir(&path)?; + } else { + if let Some(path) = path.to_str() { + println!("cargo:rerun-if-changed={}", path); + } else { + return Err(io_err("failed to convert path")); + } + } + } + + Ok(()) +} + +fn main() -> io::Result<()> +{ + let out_file = env::var("OUT_DIR").unwrap(); let out_file = format!("--target={}/resources", out_file); - println!("cargo:rerun-if-changed=data"); + // traverse each file in the data directory, because cargo won't do this + traverse_dir(Path::new("data"))?; let o = Command::new("glib-compile-resources").arg("data/resources.xml") .arg(out_file) @@ -14,7 +39,7 @@ fn main() -> std::io::Result<()> if !o.status.success() { dbg!(o); - Err(std::io::Error::new(std::io::ErrorKind::Other, "failed to compile resources")) + Err(io_err("failed to compile resources")) } else { Ok(()) }