use std::collections::BTreeMap;
use std::fs;
use std::path::{Path, PathBuf};
use crate::Saja;
use crate::exports::Export;
impl Saja {
pub fn make_headers(&self, exports: Vec<Export>, out: &Path) -> anyhow::Result<()> {
let mut modules: BTreeMap<PathBuf, Vec<Export>> = BTreeMap::new();
for export in exports {
modules
.entry(export.module.clone())
.or_default()
.push(export);
}
for (module, exports) in modules {
let mut path = out.join(module);
path.set_extension("h");
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
let mut contents = String::new();
contents.push_str("#pragma once\n");
for export in exports {
contents.push_str(&export.forward());
contents.push('\n');
}
fs::write(path, contents)?;
}
Ok(())
}
}