mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-29 17:55:45 +01:00
Merge pull request #1423 from dotCooCoo/feat/craft-xtask-names
craft-xtask: add the display-name scanner for words the app lists
This commit is contained in:
3 files changed
+3051
-1
No files matched your search
+108
-1
@@ -8,6 +8,7 @@ The crate is native only and is a dependency of an app's `xtask` package only.
|
||||
|---|---|---|
|
||||
| `runner` | always | `Step`, `run_steps` (steps in order, stop at the first failure, the `ok`, `FAIL` and `skip` summary), `root`, `cargo`, `run`, `run_cancelable`, `nextest_or_test`, `doctest`, `Cancel` |
|
||||
| `assets` | always | `Policy`, `RowMode`, `check`, `run`, `list_files`, `read_document`, `is_asset`, `ASSET_EXT`: the asset attribution check against the document, folders and extensions the app supplies |
|
||||
| `names` | always | `Policy`, `Input`, `scan`, `scan_source`, `literals`, `test_path`: the display-name scanner, which looks for the words an app lists in its string literals, `Cargo.toml` descriptions and text files |
|
||||
| `lock` | `lock` | `LockConfig`, `try_acquire`, `acquire`, `holders`: 1 to 64 slots held across processes through file locks in a directory the app chooses |
|
||||
| `report` | `report` | `write` and `to_json`: the per-step JSON report (schema 1), replaced atomically through `craft-atomic` |
|
||||
| `stats` | `stats` | `run`, `collect` and `write_table`: files, lines and tests of Rust per workspace crate (`cargo xtask stats`) |
|
||||
@@ -66,6 +67,102 @@ or file could not be opened or locked) or `Report` (the run passed but the repor
|
||||
written). A report that cannot be written after a failed run is printed to stderr, and the run keeps
|
||||
its `Step` error.
|
||||
|
||||
## Names
|
||||
|
||||
The app owns its word list, the paths it scans, the literals and exceptions that may keep a word,
|
||||
the marker, the command or test that runs the scan, and the message it prints. The library reads the
|
||||
files and returns the findings:
|
||||
|
||||
```rust,no_run
|
||||
use std::path::Path;
|
||||
use craft_xtask::names::{self, Input, Policy};
|
||||
|
||||
const BANNED: &[&str] = &["Amber Tool", "AzureKit"];
|
||||
const ALLOWED: &[&str] = &["AzureKit Design"];
|
||||
const POLICY: Policy<'static> = Policy { allowed: ALLOWED, ..Policy::new(BANNED) };
|
||||
|
||||
#[test]
|
||||
fn production_display_names_stay_neutral() {
|
||||
let base = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let inputs = [Input::rust(Path::new("src")), Input::rust(Path::new("../engine/src/cmd"))];
|
||||
let found = names::scan(base, &inputs, &POLICY).unwrap();
|
||||
let list: Vec<String> = found.iter().map(ToString::to_string).collect();
|
||||
assert!(list.is_empty(), "Banned display names:\n{}", list.join("\n"));
|
||||
}
|
||||
```
|
||||
|
||||
- `Input::rust` takes a Rust file or a folder, which is read recursively for `.rs` files that
|
||||
`Policy::skip` keeps, given their path below the folder (`test_path` by default: `tests.rs`,
|
||||
`*_tests.rs` and files under a `tests` folder). Links to folders are not followed, also when the
|
||||
link is an input. A file input is read whatever its name.
|
||||
- `Input::manifest` reads the values at the key paths `package.description` and
|
||||
`workspace.package.description` of a `Cargo.toml`: the table header (`[package]`,
|
||||
`[workspace.package]`) joined with the key, which may be bare, quoted or dotted. Headers and keys
|
||||
inside strings and arrays do not count, and a key inside an inline table is not read. Before the
|
||||
first header, the dotted keys `package.description` and `workspace.package.description` are read,
|
||||
and a bare `description` is not. A `description` under any other table is not read. A TOML string,
|
||||
single-line or multi-line, is decoded, and a comment after it is not read; any other value is
|
||||
read as the rest of its line. `Input::text` reads every line of a text file, and
|
||||
`Input::text_mark_above` also lets a `#` line with the marker exempt the line below it. Inputs
|
||||
must not include binary files.
|
||||
- In Rust, the scanner reads `"…"` and `r"…"` literals with any number of `#`, decodes every escape
|
||||
(`\n`, `\x7A`, `\u{…}`, a backslash before a line break) and reads CRLF as LF. `b"…"`, `br"…"`,
|
||||
`c"…"` and `cr"…"` are read when `Policy::literals` asks for them; their `\x` escapes are decoded
|
||||
together as UTF-8, and bytes that are not UTF-8 become U+FFFD. A shebang line, comments,
|
||||
character, byte and lifetime tokens, and the rest of a module after `#![cfg(test)]` are skipped.
|
||||
So is the code under `#[cfg(test)]`, comments in the attribute included: a `const`, `static` or
|
||||
`let` up to its `;`, another item up to the `}` that closes it or the `;` that ends it, and a
|
||||
field, argument, arm or statement up to its `,` or `;`. A `,` in an expression's generic
|
||||
arguments (`f::<A, B>`), in the type of a field, a parameter (after its name or pattern) or a
|
||||
cast (`mut p: Pair<A, B>`, `ptr as *const Pair<A, B>`), or in the parameters of a closure that
|
||||
starts the expression does not end it. An item keyword counts only when nothing
|
||||
but qualifiers (`pub`, `unsafe`, `extern "C"` and the like) comes before it, so the `fn` in
|
||||
`f::<fn()>(…)` or in a field's type does not start an item, and the braces of a macro in an
|
||||
item's header (`-> ty! { u8 }`) are not its body. A block expression (a block, a macro's braces, a labeled block, or
|
||||
`if`, `match`, `loop`, `while`, `for`, `unsafe`, `async` or `const`), as the whole statement or as
|
||||
an arm's expression after `=>`, ends at its `}`, or at the last `}` of an `if` with `else`
|
||||
branches. Braces in the condition of an `if`, `while`, `match` or `for` (a macro's, or a block
|
||||
operand such as `if { ready } { … }`) are not its block. When a method call, field or `?` follows
|
||||
that `}`, it runs up to its `,` or `;`
|
||||
instead. Other `cfg` expressions and macros are not evaluated. A source the lexer cannot read
|
||||
(an unterminated literal or comment, an unknown escape, unbalanced delimiters) is an error.
|
||||
- A word matches as a whole word: the characters next to it are not letters, digits or `_`, in any
|
||||
script. `MatchCase::Exact` compares characters exactly, and `MatchCase::AsciiInsensitive` ignores
|
||||
the case of ASCII letters. `allowed` and `exceptions` exempt a whole decoded literal or
|
||||
description or trimmed text line, never part of one.
|
||||
- In Rust, the marker counts only inside a comment on a line the literal spans. In a manifest it
|
||||
counts anywhere on a line the description spans, and in a text file anywhere on the line.
|
||||
- `scan` identifies a file by its input path joined to the base folder, and joins a relative base
|
||||
folder to the current folder before it lists any input (on Windows, a drive-relative base such as
|
||||
`C:src` to the current folder of its drive), so a relative and an absolute input for one file are
|
||||
read once; `..` and links are not resolved. A drive-relative input is joined to the current
|
||||
folder of its drive once, before it is listed, and its files are opened under that path.
|
||||
- `scan` reads each file once, in path order, and returns the findings in path order, then source
|
||||
order, then the order of `banned`. A `Finding` has the path, the first line of the literal or
|
||||
description, the word, the decoded text or text line and the kind; its `Display` text is
|
||||
`path:line: "word" in "text"`. `scan_source` scans one source already in memory, and
|
||||
`literals` returns a source's literals.
|
||||
- `names::Error` is `Policy` (no banned words, an empty word or an empty marker), `Io` (with the
|
||||
path), `InvalidUtf8`, `FileTooLarge`, `TotalTooLarge`, `TooDeep`, `Conflict` (a file given as two
|
||||
kinds of input) or `Syntax` (with the path and line). `DEFAULT_LIMITS` is 8 MiB per file, 512 MiB
|
||||
per scan and folders 64 deep; a file larger than the per-file limit, or than what is left of the
|
||||
scan's limit, is rejected before it is read.
|
||||
|
||||
The source copies differ in a few rules. An app that switches lists the results that change:
|
||||
|
||||
- The eight `display_names.rs` tests compare exactly (`MatchCase::Exact`), read byte and C strings
|
||||
like other strings, skip only `#[cfg(test)] mod` (GridCraft skips any `#[cfg(test)]` item up to
|
||||
its `}` or `;`), pass `\x` and `\u{…}` through undecoded, can take the quote in `'\"'` as the
|
||||
start of a string (LightCraft, FigCraft, PhotoCraft), follow folder links, skip a file root named
|
||||
like a test file, and stop with a panic on a file they cannot read (FigCraft returns the error).
|
||||
Each finds more or less here accordingly.
|
||||
- VectorCraft's `brands` check compares ASCII letters without case (`MatchCase::AsciiInsensitive`)
|
||||
and reads byte and C strings (`Literals`). It also takes a non-ASCII letter or `_` next to a word
|
||||
as a word boundary, takes its marker anywhere on a line, literals included, reads an escape as a
|
||||
space, reads manifest lines that start with `description` as they are (comments included, one
|
||||
line of a multi-line value), and skips a file it cannot read.
|
||||
- PhotoCraft's check of its locale catalogs stays in the app.
|
||||
|
||||
## Assets
|
||||
|
||||
The app owns its `cargo xtask assets` command, the printing and the gate step. The library lists the
|
||||
@@ -267,14 +364,22 @@ fn version(rest: &[&str]) -> Result<(), String> {
|
||||
| `runner`: the step loop and summary, `root`, `cargo`, `run`, the nextest probe and fallback, doctests | DesignCraft `xtask/src/main.rs:68-82`, `:160-201`, `:204-249` at [8b169f8](https://github.com/storytold/designcraft/blob/8b169f8ee7832e60ed1ac4c9f5dd34f954d3a992/xtask/src/main.rs) |
|
||||
| `lock` and its tests `one_slot_is_exclusive_until_dropped`, `more_slots_admit_more_runs` | LightCraft `xtask/src/ci_lock.rs` at [25ffe3e](https://github.com/storytold/lightcraft/blob/25ffe3e5d4ac754829b99dd7368d94185adbf8d5/xtask/src/ci_lock.rs) |
|
||||
| `report`: the per-step fields | LightCraft `xtask/src/ci.rs:347-414` at [25ffe3e](https://github.com/storytold/lightcraft/blob/25ffe3e5d4ac754829b99dd7368d94185adbf8d5/xtask/src/ci.rs#L347-L414) |
|
||||
| `names`: the literal lexer, whole-word matching, allowed literals, the tree walk and the tests `production_display_names_stay_neutral`, `guard_distinguishes_labels_from_identifiers_and_comments`, `guard_scans_production_after_test_only_items`, `guard_skips_escaped_character_literals`, `guard_decodes_whitespace_escapes` | CADCraft `crates/ui-egui/tests/display_names.rs` at [8e69890](https://github.com/storytold/cadcraft/blob/8e6989022398ff5f79adaab77d19fdd7137591f3/crates/ui-egui/tests/display_names.rs) and DeckCraft at [b0c77eb](https://github.com/storytold/deckcraft/blob/b0c77ebd6a6fe6c9037cfbe1c8a7f397304b2205/crates/ui-egui/tests/display_names.rs) |
|
||||
| `names`: the test `guard_scans_after_escaped_character_literals` | AniCraft `crates/engine/tests/display_names.rs` at [3435e98](https://github.com/storytold/anicraft/blob/3435e9868150312e54694c0a70082609b2fe8573/crates/engine/tests/display_names.rs) |
|
||||
| `names`: read errors returned, and the test `source_read_failures_are_reported` | FigCraft `crates/mcp/tests/display_names.rs` at [bad07e4](https://github.com/storytold/figcraft/blob/bad07e4433240cad046589129c084bd2fc36f097/crates/mcp/tests/display_names.rs) |
|
||||
| `names`: the tests `guard_scans_production_after_test_only_items_and_parses_raw_labels`, `guard_skips_escaped_character_literals_without_hiding_labels`, and `exceptions` for a group-label prefix | WordCraft `crates/ui-egui/tests/display_names.rs` at [323cf78](https://github.com/storytold/wordcraft/blob/323cf78232ff3c07f9dbb7989ed729d5851c9773/crates/ui-egui/tests/display_names.rs) |
|
||||
| `names`: `exceptions` for a message prefix | LightCraft `crates/ui-egui/tests/display_names.rs` at [6b2b7e6](https://github.com/storytold/lightcraft/blob/6b2b7e6d1117e683a1701568e56f979d061e4699/crates/ui-egui/tests/display_names.rs) |
|
||||
| `names`: a single file as a root | GridCraft `crates/ui-egui/tests/display_names.rs` at [f204433](https://github.com/storytold/gridcraft/blob/f2044337c7e195bdf6bec1b3914937a3dd386749/crates/ui-egui/tests/display_names.rs) |
|
||||
| `names`: allowed literals | PhotoCraft `crates/ui-egui/tests/display_names.rs` at [d6557b9](https://github.com/storytold/photocraft/blob/d6557b9a8b40f0542a99e7382ec2b5250548e27b/crates/ui-egui/tests/display_names.rs) |
|
||||
| `names`: `MatchCase::AsciiInsensitive`, manifest descriptions, text files, the marker and the line above it, the literal's first line, and the tests `rust_literals_skip_comments_identifiers_tests_and_marked_lines`, `whole_words_only`, `docs_packaging_and_manifests`, `scope`, `injected_strings_fail_the_gate`, `the_tree_is_clean` | VectorCraft `xtask/src/brands.rs` at [107078a](https://github.com/storytold/vectorcraft/blob/107078ad10870f8a8fdeade9bd5627a3eea34a67/xtask/src/brands.rs) |
|
||||
| `stats`: the folder walk that skips directory links, and the table | DesignCraft `xtask/src/stats.rs` at `dc9eea2695` |
|
||||
| `stats`: regular files only, and `a_walk_does_not_follow_directory_links` | WordCraft `xtask/src/stats.rs` at `6b163b33dc` |
|
||||
| `stats`: the entry budget that returns an error, and its two tests | CADCraft `xtask/src/stats.rs` at `ca87680fb0` |
|
||||
| `stats`: the per-file size limit, and its two tests | GridCraft `xtask/src/stats.rs` at `9e9f13114f` |
|
||||
| The root and slot-count errors, the `--exclude` of the xtask package, cancellation, the bounded owner read and the atomic report; in `names`, the full escape decoder, byte and C strings as an option, every `#[cfg(test)]` item form and `#![cfg(test)]`, the syntax errors, the marker only in comments, word boundaries in every script, the limits, the sorted findings and the skipped folder links; in `stats`, the metadata, total-size, depth and `--list` output limits, the metadata checks and the line naming failed listings | written here |
|
||||
| `version`: `read`, `validate` with the overflow and prerelease checks, the restore after a failed update, and the tests `reads_the_workspace_version`, `replaces_only_the_workspace_version`, `keeps_crlf_line_endings`, `validates_versions`, `rejects_what_cargo_rejects`, `a_failed_update_restores_the_manifest` | SoundCraft `xtask/src/version.rs` at [6c84416](https://github.com/storytold/soundcraft/blob/6c84416c3cffb72d8d350ddfefc4fc9ee954ca1a/xtask/src/version.rs) |
|
||||
| `version`: the path dependency pins and the test `moves_the_workspace_crates_pins_with_it` | PdfCraft `xtask/src/version.rs` at [3e30645](https://github.com/storytold/pdfcraft/blob/3e3064532f04fd6ec769c6bd7b2c97464757970e/xtask/src/version.rs) |
|
||||
| `version`: the `toml_edit` edit that keeps quotes and line endings, the `=OLD` pins, the `Cargo.lock` restore, the size limits, the unchanged-version case and the one-`set`-at-a-time lock | written here |
|
||||
| The root and slot-count errors, the `--exclude` of the xtask package, cancellation, the bounded owner read and the atomic report; in `stats`, the metadata, total-size, depth and `--list` output limits, the metadata checks and the line naming failed listings | written here |
|
||||
| `assets`: `is_asset`, the exact-row check, `run`, the three asset folders and the test `detects_unattributed_assets` | VectorCraft `xtask/src/assets.rs` at [bada8e1](https://github.com/storytold/vectorcraft/blob/bada8e17103db9917de44e40a1cead5a7fc71c3c/xtask/src/assets.rs) and DesignCraft `xtask/src/assets.rs` at [8b169f8](https://github.com/storytold/designcraft/blob/8b169f8ee7832e60ed1ac4c9f5dd34f954d3a992/xtask/src/assets.rs) |
|
||||
| `assets`: the CADCraft and WordCraft extension lists, the `-z` listing, the exit-status check and the tests in `assets::tests::wordcraft` | CADCraft `xtask/src/assets.rs` at [8e69890](https://github.com/storytold/cadcraft/blob/8e6989022398ff5f79adaab77d19fdd7137591f3/xtask/src/assets.rs), WordCraft `xtask/src/assets.rs` at [42a5df5](https://github.com/storytold/wordcraft/blob/42a5df5f94e03288037f731ffd86dee7c7cf1332/xtask/src/assets.rs) |
|
||||
| `assets`: the DeckCraft extension list, the pattern table and the tests in `assets::tests::deckcraft` | DeckCraft `xtask/src/assets.rs` at [b0c77eb](https://github.com/storytold/deckcraft/blob/b0c77ebd6a6fe6c9037cfbe1c8a7f397304b2205/xtask/src/assets.rs) |
|
||||
@@ -289,6 +394,8 @@ No app uses this crate yet.
|
||||
| App | Status |
|
||||
|---|---|
|
||||
| DesignCraft | Planned: `cmd_ci`, `root`, `cargo`, `run`, `cmd_test` and `cmd_doctest` move to `runner`, with `TestMode::PreferNextest`. The step list, `TEST_TARGETS` and the i18n report stay in the app. |
|
||||
| AniCraft, CADCraft, DeckCraft, FigCraft, GridCraft, LightCraft, PhotoCraft, WordCraft | Planned: the lexer and matcher of `display_names.rs` move to `names`, with `MatchCase::Exact`. `BANNED`, `ALLOWED`, `ROOTS`, the prefix exceptions (LightCraft, WordCraft), PhotoCraft's catalog test and the tests named after them stay in the app. |
|
||||
| VectorCraft | Planned: `cargo xtask brands` calls `names::scan` with `MatchCase::AsciiInsensitive`, byte and C strings, `brand-ok` and its desktop entry as `Input::text_mark_above`. The word list, the file selection from `git ls-files` and the message stay in the app. |
|
||||
| LightCraft | Planned: `ci_lock.rs` moves to `lock`, with `LIGHTCRAFT_CI_LOCK` and `LIGHTCRAFT_CI_SLOTS` read by the app. The machine, GPU, corpus and skip report stays in the app. |
|
||||
| CADCraft, DeckCraft, DesignCraft, GridCraft, LightCraft, PhotoCraft, VectorCraft, WordCraft | Planned: `xtask/src/stats.rs` moves to `stats`. Each app's switch lists its per-crate counts before and after in its pull request. |
|
||||
| SoundCraft, PdfCraft | Planned: `xtask/src/version.rs` moves to `version`, with the app's root and `CARGO` passed to `run`. `the_real_manifest_has_a_valid_version`, and PdfCraft's `workspace_rust_version_covers_the_ui_crate`, stay in the app. |
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
//! - [`assets`]: the asset attribution check. The app supplies its attribution document, folders
|
||||
//! and extra extensions as an [`assets::Policy`]; [`assets::run`] lists the files through Git and
|
||||
//! reports each asset without a row.
|
||||
//! - [`names`]: the display-name scanner. [`names::scan`] looks for the words an app lists in its
|
||||
//! Rust string literals, `Cargo.toml` descriptions and text files, and returns what it finds.
|
||||
//! - `lock` (feature `lock`): a fixed number of slots, held across processes through file locks, so
|
||||
//! that gate runs in several checkouts of one machine take turns.
|
||||
//! - `report` (feature `report`): the per-step JSON report, replaced atomically.
|
||||
@@ -45,6 +47,7 @@
|
||||
pub mod assets;
|
||||
#[cfg(feature = "lock")]
|
||||
pub mod lock;
|
||||
pub mod names;
|
||||
#[cfg(feature = "report")]
|
||||
pub mod report;
|
||||
pub mod runner;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user