mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 19:36:42 +00:00
Part of #1210. - `cargo xtask corpus --scripts` fetches 397 scripts and 1 included file from 19 MIT and Apache-2.0 repositories at pinned commits into corpus/scripts, each repository's license file beside its scripts. xtask/script-corpus.txt lists every file with its size and SHA-256; a download replaces the previous copy only when both match. One more candidate is listed as excluded because it is over the 1 MiB limit for one script. The fetch caps 64 MiB of scripts and 128 MiB of transfer, refuses `..`, absolute paths, reserved names, case-fold collisions and links, and holds a lock file while it runs. - `cargo xtask corpus` takes at most one of --download, --affinity and --scripts, and refuses other arguments with the usage text. - `cargo xtask scripts --pass-rate [--report <path>]` runs each script in a process of its own (the ignored `row` test in crates/engine/tests/script_corpus.rs): a new document, 5,000,000 instructions, no dialog answers, file reads only in the script's repository folder and a new folder of its own, file writes only in that folder, stopped after 10 seconds. It writes a JSON report with the pass rate overall, per repository and for scripts without dialogs or windows, how many parse, and each script's outcome, with local folders removed from messages. Script failures never fail the command, and without the corpus it prints a skip line and exits 0.
535 lines
25 KiB
Rust
535 lines
25 KiB
Rust
//! Workspace tooling: `cargo xtask <command>`.
|
||
//!
|
||
//! Pure Rust (std + serde_json). External tools (`cargo`, `curl`, `tar`) are
|
||
//! invoked through `std::process::Command`.
|
||
|
||
mod affinity_corpus;
|
||
mod assets;
|
||
mod brands;
|
||
mod bundle;
|
||
mod cursors;
|
||
mod ico;
|
||
mod layers;
|
||
mod pdf_deps;
|
||
mod pngsuite;
|
||
mod script_corpus;
|
||
mod sha256;
|
||
mod shards;
|
||
mod stats;
|
||
mod test262;
|
||
mod ui_commands;
|
||
mod version;
|
||
mod web_fonts;
|
||
|
||
use std::path::{Path, PathBuf};
|
||
use std::process::{Command, ExitCode};
|
||
|
||
const USAGE: &str = "\
|
||
usage: cargo xtask <command>
|
||
|
||
commands:
|
||
assets check that every icon/image/font/asset is attributed in ASSETS.md
|
||
brands check that user-visible text (labels, params docs, MCP, docs, packaging) names no other vendor's products
|
||
cursors warn about Cursor values with no entry in crates/tools/src/cursors.toml (never fails)
|
||
i18n-report list the strings each language's catalog lacks, shown in English (fails only on a
|
||
broken scan; ci runs it too)
|
||
ui-commands regenerate crates/mcp/src/ui_catalog.rs from desktop UI_COMMANDS; --check fails on drift
|
||
pdf-deps verify immutable shared PDF writer and patched Krilla sources
|
||
layers enforce the crate dependency layering (plan/architecture.md §3)
|
||
wasm cargo check --target wasm32-unknown-unknown for the wasm-safe crates and the web app
|
||
test the workspace tests (cargo nextest when installed, else cargo test), then the doctests
|
||
ci fmt --check, clippy -D warnings, test, doctests, no-bundled-fonts, pdf-deps, assets, brands, cursors (warnings only), ui-commands --check, layers, wasm (stops at first failure)
|
||
ci shard shard $GATE_SHARD of $GATE_SHARDS of ci (xtask/src/shards.rs): a test shard runs
|
||
the tests and doctests of its crates, the last shard the other steps
|
||
ci warm build what every shard builds, without running it (fills the gate's cache)
|
||
shards list the crates each shard tests; fails when a member is in no shard or in two,
|
||
or builds with other features in its shard than in the whole workspace
|
||
corpus [--download | --affinity | --scripts]
|
||
show where test corpora live; --download fetches PngSuite into corpus/pngsuite,
|
||
--affinity the pinned public Affinity documents into corpus/affinity, --scripts
|
||
the pinned public scripts of xtask/script-corpus.txt into corpus/scripts
|
||
bundle build dist/VectorCraft.app (macOS) with assets/app-icon/vectorcraft.icns
|
||
ico <out.ico> <png>...
|
||
pack PNGs into a Windows .ico (used by packaging/icons.sh)
|
||
scripts --pass-rate [--report <path>]
|
||
run each script in corpus/scripts headless in a process of its own and report how
|
||
many pass, as JSON (default target/script-corpus/report-<time>-<pid>.json, a new
|
||
file); script failures never fail it, and without the corpus it skips
|
||
stats [--exact] count tests and lines per crate (--exact: ask the test harness via `-- --list`)
|
||
test262 fetch the pinned ECMAScript conformance suite into corpus/test262 (sha256
|
||
verified), parse its ES5 subset with vectorcraft-js and run the ES5 language
|
||
and built-in tests its interpreter supports and the String, Number, RegExp
|
||
and Date built-ins tests, printing the counts; then fetch json2.js into
|
||
corpus/json2 (sha256 verified) and run it
|
||
web-fonts copy the craft-fonts faces in crates/text/web-fonts.txt into the web site (the Trunk
|
||
post_build hook; a no-op without CRAFT_FONTS_DIR)
|
||
";
|
||
|
||
fn main() -> ExitCode {
|
||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||
let rest: Vec<&str> = args.iter().skip(1).map(String::as_str).collect();
|
||
let result = match args.first().map(String::as_str) {
|
||
Some("assets") => assets::run(&root()),
|
||
Some("brands") => brands::run(&root()),
|
||
Some("cursors") => cursors::run(&root()),
|
||
Some("i18n-report") => cmd_i18n_report(),
|
||
Some("ui-commands") => ui_commands::run(&root(), rest.contains(&"--check")),
|
||
Some("layers") => cmd_layers(),
|
||
Some("pdf-deps") => pdf_deps::run(&root()),
|
||
Some("wasm") => cmd_wasm(),
|
||
Some("test") => cmd_test().and_then(|()| cmd_doctests()),
|
||
Some("ci") if rest.first() == Some(&"shard") => cmd_ci_shard(),
|
||
Some("ci") if rest.first() == Some(&"warm") => cmd_ci_warm(),
|
||
Some("ci") => cmd_ci(),
|
||
Some("shards") => shards::run().map(drop),
|
||
Some("corpus") => cmd_corpus_args(&rest),
|
||
Some("scripts") => script_corpus::scripts(&rest),
|
||
Some("bundle") => bundle::run(&root()),
|
||
Some("ico") => ico::run(&rest),
|
||
Some("version") => version::run(&root(), &rest),
|
||
Some("stats") => stats::run(&root(), rest.contains(&"--exact")),
|
||
Some("test262") => test262::run_suite(),
|
||
Some("web-fonts") => web_fonts::run(&root()),
|
||
Some("-h" | "--help" | "help") | None => {
|
||
print!("{USAGE}");
|
||
Ok(())
|
||
}
|
||
Some(other) => Err(format!("unknown command `{other}`\n\n{USAGE}")),
|
||
};
|
||
match result {
|
||
Ok(()) => ExitCode::SUCCESS,
|
||
Err(e) => {
|
||
eprintln!("error: {e}");
|
||
ExitCode::FAILURE
|
||
}
|
||
}
|
||
}
|
||
|
||
/// Workspace root (parent of the xtask crate).
|
||
pub fn root() -> PathBuf {
|
||
// The repository root, as a clean path (`join("..")` would print as `…/xtask/..`).
|
||
let manifest = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||
manifest.parent().unwrap_or(manifest).to_path_buf()
|
||
}
|
||
|
||
/// Tracked and untracked (not ignored) files that exist, relative to `root`.
|
||
pub fn repo_files(root: &Path) -> Result<Vec<String>, String> {
|
||
let out = Command::new("git")
|
||
.current_dir(root)
|
||
.args(["ls-files", "--cached", "--others", "--exclude-standard"])
|
||
.output()
|
||
.map_err(|e| format!("git ls-files: {e}"))?;
|
||
if !out.status.success() {
|
||
return Err(format!("git ls-files failed: {}", String::from_utf8_lossy(&out.stderr).trim()));
|
||
}
|
||
Ok(String::from_utf8_lossy(&out.stdout).lines().filter(|l| root.join(l).exists()).map(str::to_owned).collect())
|
||
}
|
||
|
||
/// A `cargo` command (the one running xtask, else `cargo` on the PATH) run in the workspace root.
|
||
pub fn cargo() -> Command {
|
||
let mut c = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()));
|
||
c.current_dir(root());
|
||
c
|
||
}
|
||
|
||
/// Prints `what` and runs `cmd`, which must exit successfully.
|
||
fn run(mut cmd: Command, what: &str) -> Result<(), String> {
|
||
eprintln!("$ {what}");
|
||
let status = cmd.status().map_err(|e| format!("{what}: failed to spawn: {e}"))?;
|
||
if status.success() { Ok(()) } else { Err(format!("{what}: exited with {status}")) }
|
||
}
|
||
|
||
/// `vectorcraft-ui-egui` and `vectorcraft-mcp` without their default features leave
|
||
/// vectorcraft-text's bundled fonts out: no crate they depend on turns them on (docs/development.md
|
||
/// › Leaving out the bundled fonts). The same tree with the default features must show them, so a
|
||
/// change in cargo tree's output can't make the check pass by finding nothing.
|
||
fn libraries_without_bundled_fonts() -> Result<(), String> {
|
||
["vectorcraft-ui-egui", "vectorcraft-mcp"].into_iter().try_for_each(without_bundled_fonts)
|
||
}
|
||
|
||
/// `package` shows vectorcraft-text's `bundled-fonts` in its feature tree with its default features
|
||
/// and nowhere without them, for any target.
|
||
fn without_bundled_fonts(package: &str) -> Result<(), String> {
|
||
const FEATURE: &str = "vectorcraft-text feature \"bundled-fonts\"";
|
||
let tree = |defaults: bool| -> Result<String, String> {
|
||
let mut args = vec!["tree", "-p", package, "--target", "all", "-e", "features,normal", "-i", "vectorcraft-text"];
|
||
if !defaults {
|
||
args.insert(3, "--no-default-features");
|
||
}
|
||
let what = format!("cargo {}", args.join(" "));
|
||
eprintln!("$ {what}");
|
||
let out = cargo().args(&args).output().map_err(|e| format!("{what}: failed to spawn: {e}"))?;
|
||
if !out.status.success() {
|
||
return Err(format!("{what}: exited with {}:\n{}", out.status, String::from_utf8_lossy(&out.stderr)));
|
||
}
|
||
Ok(String::from_utf8_lossy(&out.stdout).into_owned())
|
||
};
|
||
let with = tree(true)?;
|
||
if !with.contains(FEATURE) {
|
||
return Err(format!("{package} with its default features shows no {FEATURE} (has cargo tree's output changed?):\n{with}"));
|
||
}
|
||
let without = tree(false)?;
|
||
if without.contains(FEATURE) {
|
||
return Err(format!("{package} without default features still bundles the fonts:\n{without}"));
|
||
}
|
||
Ok(())
|
||
}
|
||
|
||
/// `cargo metadata --no-deps` for the workspace, as JSON.
|
||
pub fn metadata() -> Result<serde_json::Value, String> {
|
||
let out = cargo().args(["metadata", "--format-version", "1", "--no-deps"]).output().map_err(|e| format!("cargo metadata: {e}"))?;
|
||
if !out.status.success() {
|
||
return Err(format!("cargo metadata failed:\n{}", String::from_utf8_lossy(&out.stderr)));
|
||
}
|
||
serde_json::from_slice(&out.stdout).map_err(|e| format!("cargo metadata: bad JSON: {e}"))
|
||
}
|
||
|
||
fn cmd_layers() -> Result<(), String> {
|
||
let crates = layers::from_metadata(&metadata()?)?;
|
||
println!("Dependency layering (plan/architecture.md §3)\n");
|
||
println!("{:<28} {:<14} workspace deps", "crate", "layer");
|
||
for c in &crates {
|
||
let ws: Vec<String> = c
|
||
.deps
|
||
.iter()
|
||
.filter(|d| d.workspace)
|
||
.map(|d| {
|
||
let k = match d.kind {
|
||
layers::DepKind::Normal => "",
|
||
layers::DepKind::Dev => " (dev)",
|
||
layers::DepKind::Build => " (build)",
|
||
};
|
||
format!("{}{k}", layers::short_name(&d.name))
|
||
})
|
||
.collect();
|
||
println!("{:<28} {:<14} {}", c.name, layers::describe(layers::classify(&c.name)), ws.join(", "));
|
||
}
|
||
let violations = layers::check(&crates);
|
||
println!();
|
||
if violations.is_empty() {
|
||
println!("OK: {} crates, no layering violations.", crates.len());
|
||
Ok(())
|
||
} else {
|
||
println!("{} violation(s):", violations.len());
|
||
for v in &violations {
|
||
println!(" - {v}");
|
||
}
|
||
Err(format!("{} layering violation(s)", violations.len()))
|
||
}
|
||
}
|
||
|
||
/// Workspace packages that must build for wasm32: all L0–L5 crates, the egui
|
||
/// shell, and the web app (its wasm-only code is compiled by nothing else). Each comes with its
|
||
/// package id, which `-p` takes where the name would be ambiguous: craft-libs builds against this
|
||
/// repo's geom and pathops by git, so the graph can hold a second, older copy of a workspace crate.
|
||
fn wasm_set() -> Result<Vec<(String, String)>, String> {
|
||
let meta = metadata()?;
|
||
let ids: std::collections::HashMap<&str, &str> =
|
||
meta["packages"].as_array().into_iter().flatten().filter_map(|p| Some((p["name"].as_str()?, p["id"].as_str()?))).collect();
|
||
layers::from_metadata(&meta)?
|
||
.into_iter()
|
||
.filter(|c| match layers::classify(&c.name) {
|
||
Some(layers::Class::Layer(l)) => l <= 5 || layers::short_name(&c.name) == "ui-egui",
|
||
Some(layers::Class::Standalone) => true,
|
||
_ => layers::short_name(&c.name) == "web",
|
||
})
|
||
.map(|c| {
|
||
let id = ids.get(c.name.as_str()).ok_or_else(|| format!("cargo metadata: no package id for {}", c.name))?.to_string();
|
||
Ok((c.name, id))
|
||
})
|
||
.collect()
|
||
}
|
||
|
||
/// One `cargo check` over the whole wasm set: the crates share one build, and `--keep-going`
|
||
/// reports every crate that fails rather than only the first.
|
||
fn cmd_wasm() -> Result<(), String> {
|
||
let set = wasm_set()?;
|
||
let mut c = cargo();
|
||
c.args(["check", "--target", "wasm32-unknown-unknown", "--keep-going"]);
|
||
for (_, id) in &set {
|
||
c.args(["-p", id]);
|
||
}
|
||
let names: Vec<&str> = set.iter().map(|(name, _)| name.as_str()).collect();
|
||
run(c, &format!("cargo check --target wasm32-unknown-unknown --keep-going ({} crates: {})", set.len(), names.join(", ")))
|
||
}
|
||
|
||
/// Whether `cargo nextest` is installed.
|
||
fn has_nextest() -> bool {
|
||
cargo().args(["nextest", "--version"]).output().is_ok_and(|o| o.status.success())
|
||
}
|
||
|
||
/// The workspace's unit and integration tests, without examples (clippy still checks those).
|
||
/// nextest runs each test in its own process, in parallel across all test binaries.
|
||
fn cmd_test() -> Result<(), String> {
|
||
test_packages(&["--workspace".to_owned()], "--workspace")
|
||
}
|
||
|
||
/// [`cmd_test`] for the packages `select` picks (`--workspace` or `-p` ids), shown as `shown`.
|
||
fn test_packages(select: &[String], shown: &str) -> Result<(), String> {
|
||
const TARGETS: [&str; 3] = ["--lib", "--bins", "--tests"];
|
||
let mut c = cargo();
|
||
if has_nextest() {
|
||
c.args(["nextest", "run"]).args(select).args(TARGETS);
|
||
run(c, &format!("cargo nextest run {shown} --lib --bins --tests"))
|
||
} else {
|
||
eprintln!("note: cargo-nextest is not installed; running cargo test (cargo install cargo-nextest for faster runs)");
|
||
c.arg("test").args(select).args(TARGETS);
|
||
run(c, &format!("cargo test {shown} --lib --bins --tests"))
|
||
}
|
||
}
|
||
|
||
/// The doctests, which nextest doesn't run.
|
||
fn cmd_doctests() -> Result<(), String> {
|
||
doctest_packages(&["--workspace".to_owned()], "--workspace")
|
||
}
|
||
|
||
/// [`cmd_doctests`] for the packages `select` picks, shown as `shown`.
|
||
fn doctest_packages(select: &[String], shown: &str) -> Result<(), String> {
|
||
let mut c = cargo();
|
||
c.arg("test").args(select).arg("--doc");
|
||
run(c, &format!("cargo test {shown} --doc"))
|
||
}
|
||
|
||
/// One `cargo xtask ci` step: its name and what it runs.
|
||
type Step = (&'static str, Box<dyn Fn() -> Result<(), String>>);
|
||
|
||
/// The `ci` steps that build and run tests of the whole workspace; `ci shard` runs them per shard.
|
||
const TEST_STEPS: [&str; 3] = ["test", "doctests", "i18n-report"];
|
||
|
||
/// `cargo xtask ci`: each step in turn, stopping at the first that fails; the summary names the
|
||
/// steps that passed and, after a failure, the one that failed and those skipped.
|
||
fn cmd_ci() -> Result<(), String> {
|
||
run_steps(&ci_steps())
|
||
}
|
||
|
||
/// `cargo xtask ci shard`: shard `GATE_SHARD` of `GATE_SHARDS` (1-based, as the shared gate
|
||
/// workflow sets them). A test shard runs the shard checks, then the tests and doctests of its
|
||
/// crates, and the i18n report where it tests vectorcraft-ui-egui. The checks shard runs every
|
||
/// other `ci` step and the shard checks.
|
||
fn cmd_ci_shard() -> Result<(), String> {
|
||
let number = |key: &str| -> Result<usize, String> {
|
||
let value = std::env::var(key).map_err(|_| format!("ci shard: {key} is not set (the gate workflow sets it)"))?;
|
||
value.trim().parse().map_err(|_| format!("ci shard: {key} is `{value}`, not a number"))
|
||
};
|
||
let (shard, count) = (number("GATE_SHARD")?, number("GATE_SHARDS")?);
|
||
if count != shards::GROUPS.len() {
|
||
return Err(format!(
|
||
"ci shard: GATE_SHARDS is {count}, and xtask/src/shards.rs has {} shards (test-shards in .github/workflows/ci.yml)",
|
||
shards::GROUPS.len()
|
||
));
|
||
}
|
||
if !(1..=count).contains(&shard) {
|
||
return Err(format!("ci shard: GATE_SHARD is {shard}, not 1 to {count}"));
|
||
}
|
||
let checked = shards::run()?;
|
||
let mut steps: Vec<Step> = Vec::new();
|
||
match &checked[shard - 1] {
|
||
shards::Shard::Tests(crates) => {
|
||
let names = shards::names(crates);
|
||
eprintln!("ci shard {shard}/{count}: the tests of {names}");
|
||
let select = shards::select(crates);
|
||
let shown = crates.iter().map(|m| format!("-p {}", m.name)).collect::<Vec<_>>().join(" ");
|
||
let (s, w) = (select.clone(), shown.clone());
|
||
steps.push(("test", Box::new(move || test_packages(&s, &w))));
|
||
let (s, w) = (select.clone(), shown.clone());
|
||
steps.push(("doctests", Box::new(move || doctest_packages(&s, &w))));
|
||
if crates.iter().any(|m| m.name == "vectorcraft-ui-egui") {
|
||
steps.push(("i18n-report", Box::new(move || i18n_report_packages(&select, &shown))));
|
||
}
|
||
}
|
||
shards::Shard::Checks => {
|
||
eprintln!("ci shard {shard}/{count}: the ci steps other than the tests");
|
||
steps.extend(ci_steps().into_iter().filter(|(name, _)| !TEST_STEPS.contains(name)));
|
||
}
|
||
}
|
||
run_steps(&steps)
|
||
}
|
||
|
||
/// `cargo xtask ci warm`: for each test shard, builds its crates' library and binary tests without
|
||
/// running them, then builds what the checks shard builds, so one dependency-cache entry holds the
|
||
/// dependencies of every shard with the features that shard builds them with (cargo resolves
|
||
/// features over the packages each command selects). The integration tests are left out: they
|
||
/// build no dependency that the library tests do not, since both take the crate's dev-dependencies.
|
||
fn cmd_ci_warm() -> Result<(), String> {
|
||
let checked = shards::run()?;
|
||
let mut steps: Vec<Step> = Vec::new();
|
||
for shard in checked {
|
||
if let shards::Shard::Tests(crates) = shard {
|
||
steps.push((
|
||
"build tests",
|
||
Box::new(move || {
|
||
let mut c = cargo();
|
||
c.arg("test").args(shards::select(&crates)).args(["--lib", "--bins", "--no-run"]);
|
||
run(c, &format!("cargo test --lib --bins --no-run ({})", shards::names(&crates)))
|
||
}),
|
||
));
|
||
}
|
||
}
|
||
steps.push((
|
||
"clippy",
|
||
Box::new(|| {
|
||
let mut c = cargo();
|
||
c.args(["clippy", "--workspace", "--all-targets", "--keep-going"]);
|
||
run(c, "cargo clippy --workspace --all-targets --keep-going")
|
||
}),
|
||
));
|
||
steps.push((
|
||
"no-bundled-fonts",
|
||
Box::new(|| {
|
||
let mut c = cargo();
|
||
c.args(["test", "-p", "vectorcraft-text", "--no-default-features", "--test", "without_bundled_fonts", "--no-run"]);
|
||
run(c, "cargo test -p vectorcraft-text --no-default-features --test without_bundled_fonts --no-run")?;
|
||
let mut c = cargo();
|
||
c.args(["clippy", "-p", "vectorcraft-ui-egui", "--no-default-features", "--all-targets"]);
|
||
run(c, "cargo clippy -p vectorcraft-ui-egui --no-default-features --all-targets")?;
|
||
let mut c = cargo();
|
||
c.args(["test", "-p", "vectorcraft-ui-egui", "--no-default-features", "--test", "install_fonts", "--no-run"]);
|
||
run(c, "cargo test -p vectorcraft-ui-egui --no-default-features --test install_fonts --no-run")
|
||
}),
|
||
));
|
||
steps.push(("wasm", Box::new(cmd_wasm)));
|
||
run_steps(&steps)
|
||
}
|
||
|
||
/// Runs `steps` in turn, stopping at the first that fails; the summary names the steps that passed
|
||
/// and, after a failure, the one that failed and those skipped.
|
||
fn run_steps(steps: &[Step]) -> Result<(), String> {
|
||
let mut done = Vec::new();
|
||
for (name, f) in steps {
|
||
eprintln!("\n=== ci: {name} ===");
|
||
if let Err(e) = f() {
|
||
println!("\nCI summary:");
|
||
for d in &done {
|
||
println!(" ok {d}");
|
||
}
|
||
println!(" FAIL {name}: {e}");
|
||
for (n, _) in steps.iter().skip(done.len() + 1) {
|
||
println!(" skip {n}");
|
||
}
|
||
return Err(format!("ci failed at `{name}`"));
|
||
}
|
||
done.push(*name);
|
||
}
|
||
println!("\nCI summary: all {} steps passed ({})", done.len(), done.join(", "));
|
||
Ok(())
|
||
}
|
||
|
||
/// Every `cargo xtask ci` step, in order.
|
||
fn ci_steps() -> Vec<Step> {
|
||
vec![
|
||
(
|
||
"fmt",
|
||
Box::new(|| {
|
||
let mut c = cargo();
|
||
c.args(["fmt", "--all", "--", "--check"]);
|
||
run(c, "cargo fmt --all -- --check")
|
||
}),
|
||
),
|
||
(
|
||
"clippy",
|
||
Box::new(|| {
|
||
let mut c = cargo();
|
||
c.args(["clippy", "--workspace", "--all-targets", "--keep-going", "--", "-D", "warnings"]);
|
||
run(c, "cargo clippy --workspace --all-targets --keep-going -- -D warnings")
|
||
}),
|
||
),
|
||
("test", Box::new(cmd_test)),
|
||
("doctests", Box::new(cmd_doctests)),
|
||
(
|
||
"no-bundled-fonts",
|
||
Box::new(|| {
|
||
// vectorcraft-text as embedders that bring their own fonts build it.
|
||
let mut c = cargo();
|
||
c.args(["test", "-p", "vectorcraft-text", "--no-default-features", "--test", "without_bundled_fonts"]);
|
||
run(c, "cargo test -p vectorcraft-text --no-default-features --test without_bundled_fonts")?;
|
||
// The egui panels and the MCP server as such an embedder builds them: nothing turns
|
||
// the fonts back on.
|
||
libraries_without_bundled_fonts()?;
|
||
// The panels without their interface faces lint clean and still bind every family
|
||
// they draw in.
|
||
let mut c = cargo();
|
||
c.args(["clippy", "-p", "vectorcraft-ui-egui", "--no-default-features", "--all-targets", "--", "-D", "warnings"]);
|
||
run(c, "cargo clippy -p vectorcraft-ui-egui --no-default-features --all-targets -- -D warnings")?;
|
||
let mut c = cargo();
|
||
c.args(["test", "-p", "vectorcraft-ui-egui", "--no-default-features", "--test", "install_fonts"]);
|
||
run(c, "cargo test -p vectorcraft-ui-egui --no-default-features --test install_fonts")
|
||
}),
|
||
),
|
||
("pdf-deps", Box::new(|| pdf_deps::run(&root()))),
|
||
("assets", Box::new(|| assets::run(&root()))),
|
||
("brands", Box::new(|| brands::run(&root()))),
|
||
("cursors", Box::new(|| cursors::run(&root()))),
|
||
("i18n-report", Box::new(cmd_ci_i18n_report)),
|
||
("ui-commands", Box::new(|| ui_commands::run(&root(), true))),
|
||
("layers", Box::new(cmd_layers)),
|
||
("wasm", Box::new(cmd_wasm)),
|
||
]
|
||
}
|
||
|
||
/// `cargo xtask corpus` with at most one of its flags.
|
||
fn cmd_corpus_args(rest: &[&str]) -> Result<(), String> {
|
||
match rest {
|
||
[] => cmd_corpus(false),
|
||
["--download"] => cmd_corpus(true),
|
||
["--affinity"] => affinity_corpus::fetch(),
|
||
["--scripts"] => script_corpus::fetch(),
|
||
_ => Err(format!("`corpus` takes at most one of --download, --affinity and --scripts, got `{}`\n\n{USAGE}", rest.join(" "))),
|
||
}
|
||
}
|
||
|
||
fn cmd_corpus(download: bool) -> Result<(), String> {
|
||
let corpus = root().join("corpus");
|
||
println!(
|
||
"Test corpora live under {} (git-ignored, never committed).
|
||
Tests that use a corpus skip cleanly when it is absent.
|
||
|
||
corpus/pngsuite/ Original PngSuite PNGs (redistribution permitted), pinned and SHA-256
|
||
verified. Fetch: cargo xtask corpus --download
|
||
corpus/psd/ PSD samples from MIT/BSD projects (ag-psd, psd-tools test data).
|
||
Copy files in manually; licences must be MIT/BSD/CC0.
|
||
corpus/tiff/ libtiff pics (optional)
|
||
corpus/exr/ OpenEXR sample images (optional)
|
||
corpus/raw/ raw.pixls.us samples, CC0 (optional)
|
||
corpus/affinity/ public Affinity documents (CC0/MIT/Apache-2.0) at pinned commits, sha256
|
||
verified: oracles for the Affinity reader. Fetch: cargo xtask corpus --affinity
|
||
corpus/test262/ the ECMAScript conformance suite (BSD-3-Clause) at a pinned commit, sha256
|
||
verified: the JavaScript parser's and interpreter's ES5 subsets. Fetch and run:
|
||
cargo xtask test262
|
||
corpus/json2/ json2.js, the public-domain JSON polyfill, at a pinned commit, sha256 verified:
|
||
compared with vectorcraft-js's JSON. Fetch and run: cargo xtask test262
|
||
corpus/scripts/ public scripts from MIT and Apache-2.0 repositories at pinned commits, each
|
||
with its repository's license file, sha256 verified (xtask/script-corpus.txt):
|
||
the script host's headless pass rate. Fetch: cargo xtask corpus --scripts;
|
||
run: cargo xtask scripts --pass-rate
|
||
",
|
||
corpus.display()
|
||
);
|
||
if !download {
|
||
return Ok(());
|
||
}
|
||
pngsuite::fetch()
|
||
}
|
||
|
||
/// Prints the strings each language's catalog has no row for (`i18n::tests::untranslated_report`).
|
||
/// The interface shows them in English, so a gap never fails it; only a scan that finds nothing does.
|
||
fn cmd_i18n_report() -> Result<(), String> {
|
||
let mut c = cargo();
|
||
c.args(["test", "-p", "vectorcraft-ui-egui", "--lib", "--", "i18n::tests::untranslated_report", "--exact", "--nocapture"]);
|
||
run(c, "cargo test -p vectorcraft-ui-egui --lib -- i18n::tests::untranslated_report --exact --nocapture")
|
||
}
|
||
|
||
/// [`cmd_i18n_report`] in `ci`, selecting the packages and targets the test stage did so it
|
||
/// reuses that build: with `-p vectorcraft-ui-egui --lib` alone cargo resolves features
|
||
/// differently and recompiled for about 3.5 minutes. Every other test binary runs with no test
|
||
/// matching the filter.
|
||
fn cmd_ci_i18n_report() -> Result<(), String> {
|
||
i18n_report_packages(&["--workspace".to_owned()], "--workspace")
|
||
}
|
||
|
||
/// [`cmd_ci_i18n_report`] for the packages `select` picks (a `ci shard`'s), shown as `shown`.
|
||
fn i18n_report_packages(select: &[String], shown: &str) -> Result<(), String> {
|
||
let mut c = cargo();
|
||
c.arg("test").args(select).args(["--lib", "--bins", "--tests", "--", "i18n::tests::untranslated_report", "--exact", "--nocapture"]);
|
||
run(c, &format!("cargo test {shown} --lib --bins --tests -- i18n::tests::untranslated_report --exact --nocapture"))
|
||
}
|