Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
with:
# The test build carries the golden feature; bump this when the
# features it builds with change, or the old cache is restored whole
# and never saved again.
key: workspace-goldens-clippy
- name: Mesa lavapipe for the golden images
run: sudo apt-get update && sudo apt-get install -y mesa-vulkan-drivers
- run: cargo xtask ci
Expand Down
53 changes: 43 additions & 10 deletions xtask/src/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ pub struct Plan {
pub filter: Option<String>,
}

/// The golden check with no filter, as a `cargo xtask ci` step.
pub fn check_goldens() -> Result<()> {
run(&Plan {
mode: Mode::Check,
filter: None,
})
/// The workspace's whole test run with the goldens in it, as `cargo xtask ci`
/// runs it. `-p eggshell-ui --features snapshots` resolves the shared
/// dependencies' features differently from `--workspace` and rebuilds sixty-odd
/// crates, so the goldens ride in the one workspace build instead.
pub fn test_with_goldens() -> Result<()> {
guarded(&golden_dir(), workspace_step)
}

fn golden_dir() -> PathBuf {
process::workspace_root().join(GOLDEN_DIR)
}

pub fn run(plan: &Plan) -> Result<()> {
let golden_dir = process::workspace_root().join(GOLDEN_DIR);
let golden_dir = golden_dir();
match plan.mode {
Mode::Clean => {
let removed = clean(&golden_dir)?;
Expand All @@ -52,10 +56,15 @@ pub fn run(plan: &Plan) -> Result<()> {
}

fn check(plan: &Plan, golden_dir: &Path) -> Result<()> {
guarded(golden_dir, |icd| renderer_step(plan, icd))
}

/// Runs the step `renderer` makes and fails on any stray image it leaves.
fn guarded(golden_dir: &Path, renderer: impl FnOnce(&Path) -> Step) -> Result<()> {
let icd = lavapipe_icd()?;
// Strays from an earlier failed run would otherwise read as mismatches now.
clean(golden_dir)?;
let result = renderer_step(plan, &icd).run();
let result = renderer(&icd).run();
let strays = strays(golden_dir)?;
for stray in &strays {
println!("mismatch: {}", stray.display());
Expand Down Expand Up @@ -106,15 +115,30 @@ fn renderer_step(plan: &Plan, icd: &Path) -> Step {
"--nocapture",
],
)
.with_env("VK_ICD_FILENAMES", icd.display().to_string())
.with_env("VK_DRIVER_FILES", icd.display().to_string());
.on_lavapipe(icd);
if plan.mode == Mode::Update {
step = step.with_env("UPDATE_SNAPSHOTS", "1");
}
step.args.push(snapshot_filter(plan.filter.as_deref()));
step
}

/// Every test of the workspace, the goldens among them, with the software
/// renderer selected for the child only.
fn workspace_step(icd: &Path) -> Step {
Step::cargo(
"test",
&[
"test",
"--workspace",
"--all-targets",
"--features",
"eggshell-ui/snapshots",
],
)
.on_lavapipe(icd)
}

/// The libtest filter selecting the `snapshots` module of the `it` binary,
/// narrowed to the golden whose name starts with `name`.
fn snapshot_filter(name: Option<&str>) -> String {
Expand Down Expand Up @@ -261,6 +285,15 @@ mod tests {
);
}

#[test]
fn the_workspace_run_carries_the_goldens_and_selects_lavapipe() {
assert_eq!(
workspace_step(Path::new("/icd/lvp.json")).to_string(),
"VK_ICD_FILENAMES=\"/icd/lvp.json\" VK_DRIVER_FILES=\"/icd/lvp.json\" \
cargo test --workspace --all-targets --features eggshell-ui/snapshots"
);
}

#[test]
fn update_sets_the_variable_for_the_child_and_filter_follows_the_separator() {
let step = renderer_step(
Expand Down
23 changes: 15 additions & 8 deletions xtask/src/steps.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use anyhow::{Context, Result, bail};

Expand Down Expand Up @@ -53,6 +53,13 @@ impl Step {
}
}

/// Points Vulkan at the lavapipe driver whose manifest is `icd`.
pub fn on_lavapipe(self, icd: &Path) -> Self {
let icd = icd.display().to_string();
self.with_env("VK_ICD_FILENAMES", icd.clone())
.with_env("VK_DRIVER_FILES", icd)
}

pub fn with_env(mut self, key: &'static str, value: impl Into<String>) -> Self {
self.env.push((key, value.into()));
self
Expand Down Expand Up @@ -137,8 +144,8 @@ pub fn wasm() -> Step {

pub const WASM_TARGET: &str = "wasm32-unknown-unknown";

/// What CI runs, in order. The golden check needs Mesa lavapipe, locally and
/// on the runner alike.
/// What CI runs, in order. The test step carries the golden check, which needs
/// Mesa lavapipe, locally and on the runner alike.
pub fn ci_steps() -> Vec<Step> {
vec![
fmt(FmtMode::Check),
Expand All @@ -149,17 +156,18 @@ pub fn ci_steps() -> Vec<Step> {
"clippy",
"--workspace",
"--all-targets",
"--features",
"eggshell-ui/snapshots",
"--",
"-D",
"warnings",
],
),
Step::cargo("test", &["test", "--workspace", "--all-targets"]),
Step::internal("test", snapshots::test_with_goldens),
Step::cargo("doctest", &["test", "--workspace", "--doc"]),
Step::cargo("rustdoc", &["doc", "--workspace", "--no-deps"])
.with_env("RUSTDOCFLAGS", "-D warnings"),
wasm(),
Step::internal("snapshots", snapshots::check_goldens),
]
}

Expand Down Expand Up @@ -219,12 +227,11 @@ mod tests {
[
"cargo fmt --all --check",
"built-in clock check",
"cargo clippy --workspace --all-targets -- -D warnings",
"cargo test --workspace --all-targets",
"cargo clippy --workspace --all-targets --features eggshell-ui/snapshots -- -D warnings",
"built-in test check",
"cargo test --workspace --doc",
"RUSTDOCFLAGS=\"-D warnings\" cargo doc --workspace --no-deps",
"cargo check --target wasm32-unknown-unknown --workspace --exclude xtask --lib --examples",
"built-in snapshots check",
]
);
}
Expand Down
Loading