use glob::glob;
use std::{fs, path::Path};
fn gen_tests() -> Result<(), subplot_build::SubplotError> {
let subplots = glob("*.subplot").expect("failed to find subplots in subplotlib");
let tests = Path::new("tests");
let subplots = subplots.chain(Some(Ok("../subplot.subplot".into())));
let subplots = subplots
.chain(glob("../tests/subplots/common/*.subplot").expect("failed to find common subplots"));
for entry in subplots {
let entry = entry.expect("failed to get subplot dir entry in subplotlib");
let mut inc = tests.join(entry.file_name().unwrap());
inc.set_extension("rs");
if !inc.exists() {
panic!("missing include file: {}", inc.display());
}
println!("cargo:rerun-if-changed={}", inc.display());
println!("cargo:rerun-if-changed={}", entry.display());
subplot_build::codegen(Path::new(&entry)).expect("failed to generate code with Subplot");
}
Ok(())
}
fn main() {
if fs::metadata("../subplot.subplot").is_ok() {
if let Err(e) = gen_tests() {
eprintln!("Failed to generate code from subplot: {e}");
std::process::exit(1);
}
}
}