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 3 commits 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!
There was a problem hiding this comment.
Added doc comments .The two modes hit different code paths in run write skips the owned-list filter entirely.
There was a problem hiding this comment.
These comments use a lot of terms and I'm not sure what do they mean 😆
What is target directory? How does "committed tree" differ from "owned list"?
There was a problem hiding this comment.
Haha I used those in order to differentiate better and more readable but I think rewording made them confusing . Here target directory and committed tree mean the same thing the folder the generator writes into to make it less confusing I will simplify it naming to just committed and owned list means the list of file names inside that folder that this generator is responsible for .
| } | ||
|
|
||
| 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.
There was a problem hiding this comment.
Added doc comment explaining the signature . I kept the slice instead of switching to one folder per generator because generated files are aligned next to hand-written ones in the same folder . if we owned the whole folder bless would delete those hand-written files. Thank you!
There was a problem hiding this comment.
I don't understand, you can still just take the for loop that is now executed inside run, and perform it outside the function, by just passing it a since owned string, right?
There was a problem hiding this comment.
Yes makes sense , the the loop can move out.
| 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? 🤔
There was a problem hiding this comment.
Yes there's a case for it already MissingFromGenerated. Added the comment that explains . Thank you!
There was a problem hiding this comment.
What I meant was that MissingFromGenerated shouldn't happen, if something is not present in the generated output, we should delete it from the committed tree.
There was a problem hiding this comment.
I think I'll have to examine how the generator behaves a bit deeper (I'll try to do that on Monday), because I'm still quite surprised from the behavior here 😅 I think that we might wanna do some targeted changes to the generator and the directory layout to make blessing simpler, if the complexity here is caused by the current directory layout.
| use std::path::{Path, PathBuf}; | ||
|
|
||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum Mode { |
There was a problem hiding this comment.
These comments use a lot of terms and I'm not sure what do they mean 😆
What is target directory? How does "committed tree" differ from "owned list"?
| 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.
What I meant was that MissingFromGenerated shouldn't happen, if something is not present in the generated output, we should delete it from the committed tree.
Yes targeted changes to the generator will likely make this crate much simpler. Btw we are in a fixing loop :) |
| match std::env::var("STDARCH_GEN_MODE").as_deref() { | ||
| Ok("check") => Mode::Check, | ||
| Ok("bless") => Mode::Bless, | ||
| _ => Mode::Write, |
There was a problem hiding this comment.
I'd rather panic on an unknown value? Unless this is standard practice somehow?
| /// - [`Mode::Bless`]: runs the generator into a temp dir and copies `owned` | ||
| /// into `committed`, or removes `committed`'s copy if the generator no | ||
| /// longer produces it. | ||
| pub fn run<F, E>(committed: &Path, owned: &str, mode: Mode, generate: F) -> Result<()> |
There was a problem hiding this comment.
| pub fn run<F, E>(committed: &Path, owned: &str, mode: Mode, generate: F) -> Result<()> | |
| pub fn run_generator<F, E>(committed: &Path, owned: &str, mode: Mode, generate: F) -> Result<()> |
maybe? run itself is quite vague at the use site.
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