Add stdarch-gen-common: shared check/bless harness for generators#2157
Add stdarch-gen-common: shared check/bless harness for generators#2157xonx4l wants to merge 1 commit into
Conversation
|
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. |
| use std::path::{Path, PathBuf}; | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum Mode { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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<()> |
There was a problem hiding this comment.
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!( |
There was a problem hiding this comment.
When we bless, it can happen that the new blessed output has less files than before, right? 🤔
This PR adds a library crate
stdarch-gen-commonthat gives every generator three modes -:Mode is picked via the
STDARCH_GEN_MODEenv 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-hexagonto use it as the first example.r? @folkertdev