use std::env;
use std::path::Path;
fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR");
if let Ok(custom_path) = env::var("OXICODE_CATALOG_SNAPSHOT") {
let custom = Path::new(&custom_path);
assert!(
custom.exists(),
"OXICODE_CATALOG_SNAPSHOT not found: {}",
custom.display()
);
let committed = Path::new(&manifest_dir).join("data/catalog/_snapshot.json.gz");
if custom.canonicalize().ok() != committed.canonicalize().ok() {
std::fs::copy(custom, &committed)
.unwrap_or_else(|e| panic!("failed to copy snapshot: {e}"));
println!(
"cargo:warning=OXICODE_CATALOG_SNAPSHOT applied: {}",
custom.display()
);
}
println!("cargo:rerun-if-env-changed=OXICODE_CATALOG_SNAPSHOT");
}
let committed = Path::new(&manifest_dir).join("data/catalog/_snapshot.json.gz");
assert!(
committed.exists(),
"Committed snapshot not found at {}. Run `gzip -c < api.json > data/catalog/_snapshot.json.gz`.",
committed.display()
);
println!("cargo:rerun-if-changed=data/catalog/_snapshot.json.gz");
println!("cargo:rerun-if-changed=build.rs");
}