Prefix snapshot outputs with input language (#7414)

This commit is contained in:
Connor Fitzgerald 2025-04-03 11:08:23 -04:00 committed by GitHub
parent c344bec508
commit f7bcc6294f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
543 changed files with 28 additions and 20 deletions

View File

@ -2,6 +2,8 @@
// the corresponding warnings aren't helpful. // the corresponding warnings aren't helpful.
#![allow(dead_code, unused_imports)] #![allow(dead_code, unused_imports)]
use core::fmt::Write;
use std::{ use std::{
fs, fs,
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -167,7 +169,7 @@ struct Input {
/// ///
/// If the subdirectory is omitted, we assume that the output goes /// If the subdirectory is omitted, we assume that the output goes
/// to "wgsl". /// to "wgsl".
subdirectory: Option<PathBuf>, subdirectory: PathBuf,
/// The input filename name, without a directory. /// The input filename name, without a directory.
file_name: PathBuf, file_name: PathBuf,
@ -190,9 +192,9 @@ impl Input {
/// The `input` path is interpreted relative to the `BASE_DIR_IN` /// The `input` path is interpreted relative to the `BASE_DIR_IN`
/// subdirectory of the directory given by the `CARGO_MANIFEST_DIR` /// subdirectory of the directory given by the `CARGO_MANIFEST_DIR`
/// environment variable. /// environment variable.
fn new(subdirectory: Option<&str>, name: &str, extension: &str) -> Input { fn new(subdirectory: &str, name: &str, extension: &str) -> Input {
Input { Input {
subdirectory: subdirectory.map(PathBuf::from), subdirectory: PathBuf::from(subdirectory),
// Don't wipe out any extensions on `name`, as // Don't wipe out any extensions on `name`, as
// `with_extension` would do. // `with_extension` would do.
file_name: PathBuf::from(format!("{name}.{extension}")), file_name: PathBuf::from(format!("{name}.{extension}")),
@ -202,13 +204,11 @@ impl Input {
/// Return an iterator that produces an `Input` for each entry in `subdirectory`. /// Return an iterator that produces an `Input` for each entry in `subdirectory`.
fn files_in_dir( fn files_in_dir(
subdirectory: Option<&'static str>, subdirectory: &'static str,
file_extensions: &'static [&'static str], file_extensions: &'static [&'static str],
) -> impl Iterator<Item = Input> + 'static { ) -> impl Iterator<Item = Input> + 'static {
let mut input_directory = Path::new(env!("CARGO_MANIFEST_DIR")).join(BASE_DIR_IN); let input_directory = Path::new(CRATE_ROOT).join(BASE_DIR_IN).join(subdirectory);
if let Some(ref subdirectory) = subdirectory {
input_directory.push(subdirectory);
}
let entries = match std::fs::read_dir(&input_directory) { let entries = match std::fs::read_dir(&input_directory) {
Ok(entries) => entries, Ok(entries) => entries,
Err(err) => panic!( Err(err) => panic!(
@ -245,14 +245,12 @@ impl Input {
/// Return the path to the input directory. /// Return the path to the input directory.
fn input_directory(&self) -> PathBuf { fn input_directory(&self) -> PathBuf {
let mut dir = Path::new(CRATE_ROOT).join(BASE_DIR_IN); let mut dir = Path::new(CRATE_ROOT).join(BASE_DIR_IN);
if let Some(ref subdirectory) = self.subdirectory { dir.push(&self.subdirectory);
dir.push(subdirectory);
}
dir dir
} }
/// Return the path to the output directory. /// Return the path to the output directory.
fn output_directory(&self, subdirectory: &str) -> PathBuf { fn output_directory(subdirectory: &str) -> PathBuf {
let mut dir = Path::new(CRATE_ROOT).join(BASE_DIR_OUT); let mut dir = Path::new(CRATE_ROOT).join(BASE_DIR_OUT);
dir.push(subdirectory); dir.push(subdirectory);
dir dir
@ -266,14 +264,24 @@ impl Input {
} }
fn output_path(&self, subdirectory: &str, extension: &str) -> PathBuf { fn output_path(&self, subdirectory: &str, extension: &str) -> PathBuf {
let mut output = self.output_directory(subdirectory); let mut output = Self::output_directory(subdirectory);
if self.keep_input_extension { if self.keep_input_extension {
let mut file_name = self.file_name.as_os_str().to_owned(); let file_name = format!(
file_name.push("."); "{}-{}.{}",
file_name.push(extension); self.subdirectory.display(),
self.file_name.display(),
extension
);
output.push(&file_name); output.push(&file_name);
} else { } else {
output.push(&self.file_name); let file_name = format!(
"{}-{}",
self.subdirectory.display(),
self.file_name.display()
);
output.push(&file_name);
output.set_extension(extension); output.set_extension(extension);
} }
output output
@ -792,7 +800,7 @@ fn write_output_wgsl(
fn convert_snapshots_wgsl() { fn convert_snapshots_wgsl() {
let _ = env_logger::try_init(); let _ = env_logger::try_init();
for input in Input::files_in_dir(Some("wgsl"), &["wgsl"]) { for input in Input::files_in_dir("wgsl", &["wgsl"]) {
let source = input.read_source(); let source = input.read_source();
// crlf will make the large split output different on different platform // crlf will make the large split output different on different platform
let source = source.replace('\r', ""); let source = source.replace('\r', "");
@ -813,7 +821,7 @@ fn convert_snapshots_spv() {
let _ = env_logger::try_init(); let _ = env_logger::try_init();
for input in Input::files_in_dir(Some("spv"), &["spvasm"]) { for input in Input::files_in_dir("spv", &["spvasm"]) {
println!("Assembling '{}'", input.file_name.display()); println!("Assembling '{}'", input.file_name.display());
let command = Command::new("spirv-as") let command = Command::new("spirv-as")
@ -861,7 +869,7 @@ fn convert_snapshots_spv() {
fn convert_snapshots_glsl() { fn convert_snapshots_glsl() {
let _ = env_logger::try_init(); let _ = env_logger::try_init();
for input in Input::files_in_dir(Some("glsl"), &["vert", "frag", "comp"]) { for input in Input::files_in_dir("glsl", &["vert", "frag", "comp"]) {
let input = Input { let input = Input {
keep_input_extension: true, keep_input_extension: true,
..input ..input

Some files were not shown because too many files have changed in this diff Show More