use std::{ env, path::{Path, PathBuf}, }; use eyre::{ContextCompat, eyre}; mod build; mod mkimg; fn main() -> Result<(), eyre::Error> { let mut args = env::args_os().skip(1); let task = args.next().context("no task provided")?; let task = task .to_str() .with_context(|| format!("invalid utf-8 \"{}\"", task.to_string_lossy()))?; let manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").context("CARGO_MANIFEST_DIR not set")?); let workspace_dir = manifest_dir .parent() .context("invalid CARGO_MANIFEST_DIR")?; let cargo_path = PathBuf::from(env::var_os("CARGO").context("CARGO not set")?); let ctx = Context { workspace: workspace_dir, cargo: &cargo_path, }; match task { "build" => build::build(&ctx), "mkimg" => mkimg::mkimg_bios_gpt(&ctx), _ => Err(eyre!("unknown task \"{}\"", task)), } } struct Context<'a> { workspace: &'a Path, cargo: &'a Path, }