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 5 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. |
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.
Yes targeted changes to the generator will likely make this crate much simpler. Btw we are in a fixing loop :) |
|
I looked at the code more and now I understand the issue with blessing; as you said, the I would suggest the following changes and simplifications: When an output directory is passed to the generator, it will load all files from that directory, and keep a map of files that are automatically generated. These files will be detected by reading their first line and checking if it begins with Keep only two modes:
This assumes that two generators won't ever write into the same directory, but I think that assumption should be fine. In fact I think that it would be easiest to simply move all the generators into a single crate, at which point we could generate everything at once, but let's not complicate it further for now. Does that make sense to you? |
|
@Kobzol Yes , this makes sense to me. I will refactor as per the idea you suggested as I think is quite good than per file version( especially the header one is a great way to diff) . The arm and loongarch generated files already carry the header And yeah alright two modes look's fine will drop Thanks for taking the time to dig into this, it's a huge help. |
|
@Kobzol made all the changes that were suggested and discussed . Thank you! |
There was a problem hiding this comment.
Thank you, looks great! Left a few minor comments.
On CI, you should modify the check-stdarch-gen job to add the environment variable STDARCH_GEN_MODE=check.
The output could be improved a bit, e.g. the "Output: " path could be normalized and the filename of the mismatched file could be made absolute, to make it easier to find where should the file be located:
Step 3: Generating v64.rs and v128.rs (mode: Check)...
Output: /projects/personal/rust/stdarch/crates/stdarch-gen-hexagon/../core_arch/src/hexagon/v64.rs
Output: /projects/personal/rust/stdarch/crates/stdarch-gen-hexagon/../core_arch/src/hexagon/v128.rs
Error: "v128.rs: contents differ"
but those are minor things and I don't think we need to deal with that in this PR.
|
Damn so fast was just going to ping :) , Yeah we need those Folkert opinions and feedbacks. |
| let Ok(contents) = fs::read_to_string(entry.path()) else { | ||
| continue; | ||
| }; |
There was a problem hiding this comment.
This is perhaps a bit wasteful? you can just read the first GENERATED_MARKER.len() bytes and just check those?
| if entry.file_type()?.is_file() { | ||
| if let Some(name) = entry.file_name().to_str() { |
There was a problem hiding this comment.
| if entry.file_type()?.is_file() { | |
| if let Some(name) = entry.file_name().to_str() { | |
| if entry.file_type()?.is_file() | |
| && let Some(name) = entry.file_name().to_str() { |
you can use let in that position these days.
| }), | ||
| (false, false) => Ok(()), | ||
| (true, true) => { | ||
| if fs::read(&gen_path)? != fs::read(&comm_path)? { |
There was a problem hiding this comment.
this is probably fine for now, but a more robust and efficient approach is to check the file sizes first, and if they are the same, read the files in chunks and compare those.
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(all(test, not(target_os = "ios")))] |
There was a problem hiding this comment.
please add a comment on why ios does not work?
| println!(" Output: {}", v128_path.display()); | ||
| let hexagon_dir = crate_dir.join("../core_arch/src/hexagon"); | ||
|
|
||
| let mode = Mode::from_env(); |
There was a problem hiding this comment.
maybe add a comment here on what the mode means, e.g.
| let mode = Mode::from_env(); | |
| // Either "check" to check the output versus the committed output, or "bless" to update the output. | |
| let mode = Mode::from_env(); |
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