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

nordisk/gunnar

xtask/src/lib.rs

//! gunnar's repository tasks.
//!
//! `xtask` is a workspace member that **nothing depends on**. Repository
//! tooling (docs generation, the dependency guard, the local CI runner) is
//! invoked as a tool, never as a dependency, so `cargo build -p gunnar-cli`
//! never resolves any of it.
//!
//! The library half exists so the guard can be exercised from tests
//! ([`guard`]'s red-first proofs in `xtask/tests/guard.rs`) with the same code
//! the binary runs, rather than a second copy of the rules that could drift out
//! of agreement with it — one implementation, not two.

pub mod appliance;
pub mod bench_readme;
pub mod benchguard;
pub mod benchland;
pub mod benchrun;
pub mod both_ways;
pub mod build;
pub mod ci_check;
pub mod ci_quick;
pub mod cli_stage;
pub mod cve;
pub mod cycle_svg;
pub mod datapath_svg;
pub mod deploy_check;
pub mod docsbook;
pub mod engine_seam;
pub mod fast;
pub mod fmt;
pub mod guard;
pub mod idp;
pub mod image_formats;
pub mod images;
pub mod installer_pin;
pub mod isoinstaller;
pub mod json;
pub mod key_census;
pub mod mashup;
pub mod medium;
pub mod one_clone;
pub mod pack_pipeline;
pub mod paid_guard;
pub mod payload;
pub mod products;
pub mod publish;
pub mod reinstall;
pub mod release_version;
pub mod roundtrip;
pub mod setup_svg;
pub mod siblings;
pub mod staging_guard;
pub mod trailer_guard;
pub mod twins;
pub mod variant_svg;
pub mod vendor_patch;
pub mod wireproxy;
pub mod worktree;

/// **`~` in a path literal, expanded against `$HOME`.**
///
/// Every scratch and target path in this repository is written as `~/…` rather
/// than as one developer's absolute home: a path with a username baked into it
/// is a path that is wrong for everybody else, and it does not belong in a
/// public tree. `~` is a SHELL convention, so nothing expands it inside a Rust
/// string — this function is the one place that does, and every literal that is
/// used as a real filesystem path goes through it.
///
/// A path that does not start with `~/` is returned unchanged, so a caller may
/// pass an absolute override straight through.
///
/// # ⚠ A KNOWN TWIN, kept on purpose — `nornir_xtask_support::expand_home`
///
/// This body is byte-identical to the canonical one in
/// `edda/crates/nornir-xtask-support` (md5 `8e5f9c67` on the extracted fn), and
/// to `installtest/src/lane_dir.rs`'s `home_expanded`. `bench/src/lib.rs` and
/// `deploy/upcloud/src/site.rs` carried the same body until 2026-09-10 and are
/// now `pub use`s of the edda leaf; `nornir mimir analyze duplicates` clustered
/// all four and named that leaf the keep.
///
/// This one does NOT move, and the reason is the rule in `Cargo.toml` two
/// directories up: **this crate has ZERO dependencies, deliberately.** A
/// workspace member takes part in resolver-2 feature unification for
/// `cargo build --workspace`, so a dependency added here could turn a feature on
/// in a crate the appliance links — and the guard's whole job is not to be the
/// thing it is guarding against. Nothing to unify is the strongest form of that
/// guarantee, and four lines of `strip_prefix` is a cheap price for it.
///
/// The behaviour is pinned in the leaf by
/// `expand_home_expands_only_a_leading_tilde_slash`. If that test's answers ever
/// change, this copy is wrong and nothing here will say so — which is exactly
/// why the twin is named rather than left to be rediscovered.
pub fn expand_home(p: &str) -> std::path::PathBuf {
    match p.strip_prefix("~/") {
        Some(rest) => {
            std::path::PathBuf::from(std::env::var("HOME").unwrap_or_else(|_| "/root".to_string()))
                .join(rest)
        }
        None => std::path::PathBuf::from(p),
    }
}