crates/draupnir-build-thing/src/main.rs
//! `draupnir-build-thing` — the recipe's door.
//!
//! * `--list` — every declared variant and what builds it.
//! * `toml` — the emitted `.nornir/build-variants.toml` on stdout.
//! * `emit` — REGENERATE `<repo>/.nornir/build-variants.toml` from the code
//! (the repo root is found from this crate's manifest dir; `emit <root>`
//! names another).
//!
//! It owns no build knowledge (LAW 5): every answer comes from the recipe's own
//! `variants()`.
use std::path::PathBuf;
use std::process::ExitCode;
use draupnir_build_thing::{emit::repo_root, DraupnirBuildThing};
use nornir_build_thing::plugin::BuildThing;
fn main() -> ExitCode {
let args: Vec<String> = std::env::args().skip(1).collect();
match args.first().map(String::as_str) {
Some("--list") => {
let set = DraupnirBuildThing.variants();
for v in &set.variants {
let what = if v.kind.is_cargo() {
v.command_line()
} else {
format!(
"(typ {}: built by the {} builder, runs no cargo)",
v.kind.as_str(),
v.kind.as_str()
)
};
println!("{:<28} {what}", v.name);
}
ExitCode::SUCCESS
}
Some("toml") => match draupnir_build_thing::emitted_toml() {
Ok(t) => {
print!("{t}");
ExitCode::SUCCESS
}
Err(e) => {
eprintln!("draupnir-build-thing: {e:#}");
ExitCode::FAILURE
}
},
Some("emit") => {
let root = args.get(1).map(PathBuf::from).unwrap_or_else(repo_root);
match draupnir_build_thing::write_emitted(&root) {
Ok(p) => {
println!("emitted {}", p.display());
ExitCode::SUCCESS
}
Err(e) => {
eprintln!("draupnir-build-thing: {e:#}");
ExitCode::FAILURE
}
}
}
_ => {
eprintln!("usage: draupnir-build-thing --list | toml | emit [<repo-root>]");
ExitCode::FAILURE
}
}
}