Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-build-thing/src/main.rs

//! `facett-build-thing [--list | toml | emit]` — say what facett declares, and
//! write the description.
//!
//! Repository tooling, never shipped. It owns no build knowledge (LAW 5): it looks
//! the declaration up and prints it. BUILDING goes through the forge door,
//! `dwarves buildthing facett --variant facett-wheel` (or `facett-demo-wheel`), or through facett's own
//! `cargo ops publish-pip` — never through this binary.

use std::process::ExitCode;

use facett_build_thing::{repo_root, BuildThing, FacettBuildThing};

fn main() -> ExitCode {
    let args: Vec<String> = std::env::args().skip(1).collect();
    match args.first().map(String::as_str) {
        Some("--list") | None => {
            let set = FacettBuildThing.variants();
            for v in &set.variants {
                // A row is described by the CELL it delegates to when it has one.
                // `command_line()` answers `cargo build` for every kind, and for a
                // container row that answer is false in the one way this repo cares
                // about: cargo does not build an image, and a roster that says it
                // does is a description of a build nobody runs.
                let what = match (set.package(&v.name), set.container(&v.name)) {
                    (Some(p), _) => format!(
                        "{} ({}) → {} in {}",
                        p.format.tool(),
                        p.distribution,
                        p.required_members()
                            .iter()
                            .map(|m| m.as_str())
                            .collect::<Vec<_>>()
                            .join(" + "),
                        p.out_dir
                    ),
                    (None, Some(c)) => format!("podman build -f {} (image {})", c.containerfile, c.name),
                    (None, None) => v.command_line(),
                };
                println!("{:<21} {what}", v.name);
            }
            ExitCode::SUCCESS
        }
        // The EMISSION doors. `.nornir/build-variants.toml` is this crate's OUTPUT,
        // never its input.
        Some("toml") => match facett_build_thing::emitted_toml() {
            Ok(t) => {
                print!("{t}");
                ExitCode::SUCCESS
            }
            Err(e) => {
                eprintln!("facett-build-thing: {e:#}");
                ExitCode::FAILURE
            }
        },
        Some("emit") => match facett_build_thing::write_emitted(&repo_root())
            .and_then(|p| facett_build_thing::write_routing(&repo_root()).map(|r| (p, r)))
        {
            Ok((p, r)) => {
                println!("wrote {}\nwrote {}", p.display(), r.display());
                ExitCode::SUCCESS
            }
            Err(e) => {
                eprintln!("facett-build-thing: {e:#}");
                ExitCode::FAILURE
            }
        },
        Some(other) => {
            eprintln!("facett-build-thing: unknown argument {other:?}; try --list, toml, emit");
            ExitCode::FAILURE
        }
    }
}