Skip to content

Add stdarch-gen-common: shared check/bless harness for generators#2157

Open
xonx4l wants to merge 1 commit into
rust-lang:mainfrom
xonx4l:stdarch-gen-common
Open

Add stdarch-gen-common: shared check/bless harness for generators#2157
xonx4l wants to merge 1 commit into
rust-lang:mainfrom
xonx4l:stdarch-gen-common

Conversation

@xonx4l

@xonx4l xonx4l commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This PR adds a library crate stdarch-gen-common that gives every generator three modes -:

  1. Write - Generator writes files straight into the committed location.
  2. Check - Generator write into a temporary directory . The crate diffs it against committed and fails on any mismatch without touching the working copy .
  3. Bless - Generator writes into a temp directory the crate then mirrors temp over committed. Adding, overwriting, and deleting files as needed.

Mode is picked via the STDARCH_GEN_MODE env var. The harness only touches files the generator explicitly lists as its own so hand-written files in the same directory are safe.

This PR also hooks stdarch-gen-hexagon to use it as the first example.

r? @folkertdev

@Kobzol

Kobzol commented Jun 9, 2026

Copy link
Copy Markdown
Member

For a bit more context, this is done for the stdarch GSoC project, where we try to integrate stdarch's tests in rust-lang/rust's CI. We want to move the blessing logic out of the CI YAML files and into Rust, to make it easier to reuse, and also share code amongst the various generators.

I'll take a look, but also CC @folkertdev , in case you have in mind who owns this code amongst the stdarch maintainers and who could also chime in.

@rustbot rustbot assigned folkertdev and unassigned Kobzol Jun 9, 2026

@Kobzol Kobzol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating the crate! I left a few comments.

View changes since this review

use std::path::{Path, PathBuf};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does Write differ from Bless? I'd expect those two modes to be the same. Could you please add some doc comments on the mode to explain what the individual modes mean? Thanks!

}

impl Mode {
pub fn from_env() -> Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a doc comment here that explains how to use the function, i.e. which env var it expects to read and what are the possible values.


// owned is the list of relative paths the generator manages. Files in
// committed not listed here are left untouched by Bless and ignored by Check.
pub fn run<F, E>(committed: &Path, owned: &[&str], mode: Mode, generate: F) -> Result<()>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a doc comment that explains in more detail what the function is supposed to be doing? The signature is kinda complex.

I think that we can simplify the function by changing it to only work with a single subdirectory, it doesn't really need to handle slices and multiple paths at once.

write!(f, "{}: committed but no longer generated", path.display())
}
MismatchKind::ContentsDiffer => write!(f, "{}: contents differ", path.display()),
MismatchKind::MissingFromGenerated => write!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we bless, it can happen that the new blessed output has less files than before, right? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants