From 9f8f2556c33aa06e24c2f0da60dfe3dbd2587a7d Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 25 Oct 2023 11:07:23 -0400 Subject: [PATCH] WIP: refactor(cli): consolidate new `read_and_parse_all_metadata` helper --- moz-webgpu-cts/src/main.rs | 159 ++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 91 deletions(-) diff --git a/moz-webgpu-cts/src/main.rs b/moz-webgpu-cts/src/main.rs index 5a07d9e..f032203 100644 --- a/moz-webgpu-cts/src/main.rs +++ b/moz-webgpu-cts/src/main.rs @@ -95,23 +95,51 @@ fn run(cli: Cli) -> ExitCode { ) }; + read_gecko_files_at(&gecko_checkout, &webgpu_cts_meta_parent_dir, "**/*.ini") + }; + + let read_and_parse_all_metadata = || -> Result<_, AlreadyReportedToCommandline> { + let mut started_parsing = false; let mut found_err = false; - let collected = - read_gecko_files_at(&gecko_checkout, &webgpu_cts_meta_parent_dir, "**/*.ini")? - .filter_map(|res| match res { - Ok(ok) => Some(ok), - Err(AlreadyReportedToCommandline) => { + let files_by_path = read_metadata()? + .filter_map(|res| match res { + Ok(ok) => { + found_err = true; + Some(ok) + } + Err(AlreadyReportedToCommandline) => None, + }) + .filter_map(|(path, file_contents)| { + if !started_parsing { + log::info!("parsing metadata…"); + started_parsing = true; + } + + log::debug!("parsing metadata at {}", path.display()); + match chumsky::Parser::parse(&metadata::File::parser(), &*file_contents) + .into_result() + { + Err(errors) => { found_err = true; + render_metadata_parse_errors( + &Arc::new(path), + &Arc::new(file_contents), + errors, + ); None } - }) - .map(|(p, fc)| (Arc::new(p), Arc::new(fc))) - .collect::>(); + Ok(file) => Some((path, file)), + } + }) + .collect::>(); if found_err { - Err(AlreadyReportedToCommandline) - } else { - Ok(collected) + log::error!(concat!( + "found one or more failures while reading and parsing metadata, ", + "see above for more details" + )); + return Err(AlreadyReportedToCommandline); } + Ok(files_by_path) }; fn render_metadata_parse_errors<'a>( @@ -232,40 +260,9 @@ fn run(cli: Cli) -> ExitCode { // TODO: If we don't need to consult metadata (because we plan on ignoring everything // there, and deleting anything not in reports), then don't even load these. - let meta_files_by_path = { - let raw_meta_files_by_path = match read_metadata() { - Ok(paths) => paths, - Err(AlreadyReportedToCommandline) => return ExitCode::FAILURE, - }; - - log::info!("parsing metadata…"); - let mut found_parse_err = false; - - let files = raw_meta_files_by_path - .into_iter() - .filter_map(|(path, file_contents)| { - match chumsky::Parser::parse(&metadata::File::parser(), &*file_contents) - .into_result() - { - Err(errors) => { - found_parse_err = true; - render_metadata_parse_errors(&path, &file_contents, errors); - None - } - Ok(file) => Some((path, file)), - } - }) - .collect::>(); - - if found_parse_err { - log::error!(concat!( - "found one or more failures while parsing metadata, ", - "see above for more details" - )); - return ExitCode::FAILURE; - } - - files + let meta_files_by_path = match read_and_parse_all_metadata() { + Ok(paths) => paths, + Err(AlreadyReportedToCommandline) => return ExitCode::FAILURE, }; let mut outcomes_by_test = IndexMap::::default(); @@ -543,7 +540,17 @@ fn run(cli: Cli) -> ExitCode { }; log::info!("formatting metadata in-place…"); let mut fmt_err_found = false; - for (path, file_contents) in raw_test_files_by_path { + for res in raw_test_files_by_path { + let (path, file_contents) = match res { + Ok(ok) => ok, + Err(AlreadyReportedToCommandline) => { + fmt_err_found = true; + continue; + } + }; + let path = Arc::new(path); + let file_contents = Arc::new(file_contents); + match chumsky::Parser::parse(&metadata::File::parser(), &*file_contents) .into_result() { @@ -596,47 +603,22 @@ fn run(cli: Cli) -> ExitCode { orig_path: Arc, inner: metadata::Test, } - let tests_by_name = { - let mut found_parse_err = false; - let raw_test_files_by_path = match read_metadata() { - Ok(paths) => paths, - Err(AlreadyReportedToCommandline) => return ExitCode::FAILURE, - }; - let extracted = raw_test_files_by_path - .iter() - .filter_map(|(path, file_contents)| { - match chumsky::Parser::parse(&metadata::File::parser(), file_contents) - .into_result() - { - Ok(metadata::File { tests }) => Some(tests.into_iter().map(|inner| { - let SectionHeader(name) = &inner.name; - ( - SectionHeader( - name.strip_prefix("cts.https.html?q=").unwrap().to_owned(), - ), - TaggedTest { - inner, - orig_path: path.clone(), - }, - ) - })), - Err(errors) => { - found_parse_err = true; - render_metadata_parse_errors(path, file_contents, errors); - None - } - } + let tests_by_name = match read_and_parse_all_metadata().map(|tests| { + tests + .into_iter() + .flat_map(|(_path, metadata::File { tests })| tests) + .map(|test| { + let SectionHeader(name) = &test.name; + ( + SectionHeader( + name.strip_prefix("cts.https.html?q=").unwrap().to_owned(), + ), + test, + ) }) - .flatten() - .collect::>(); - if found_parse_err { - log::error!(concat!( - "found one or more failures while parsing metadata, ", - "see above for more details" - )); - return ExitCode::FAILURE; - } - extracted + }) { + Ok(paths) => paths, + Err(AlreadyReportedToCommandline) => return ExitCode::FAILURE, }; log::info!(concat!( @@ -709,11 +691,6 @@ fn run(cli: Cli) -> ExitCode { let mut analysis = Analysis::default(); for (_nice_name, test) in tests_by_name { - let TaggedTest { - orig_path: _, - inner: test, - } = test; - let Test { name: SectionHeader(test_name), properties,