rewrite build script to actually pick up on changes properly

gui-branch
an 2019-03-25 20:07:58 -04:00
parent cbf87ff156
commit 685991c6ed
1 changed files with 30 additions and 5 deletions

View File

@ -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(())
}