Skip to content

Commit

Permalink
WIP: refactor(cli): consolidate new read_and_parse_all_metadata helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Oct 30, 2023
1 parent 835d45a commit 564a3d1
Showing 1 changed file with 65 additions and 96 deletions.
161 changes: 65 additions & 96 deletions moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,46 @@ 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) => {
found_err = true;
None
let files_by_path = read_metadata()?
.filter_map(|res| match res {
Ok((path, file_contents)) => {
found_err = true;
let file_contents = Arc::new(file_contents);

if !started_parsing {
log::info!("parsing metadata…");
started_parsing = true;
}
})
.map(|(p, fc)| (Arc::new(p), Arc::new(fc)))
.collect::<IndexMap<_, _>>();

log::debug!("parsing metadata at {}", path.display());
match chumsky::Parser::parse(&metadata::File::parser(), &*file_contents)

Check failure on line 117 in moz-webgpu-cts/src/main.rs

View workflow job for this annotation

GitHub Actions / Clippy (ubuntu-latest, stable)

`file_contents` does not live long enough

Check failure on line 117 in moz-webgpu-cts/src/main.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, beta)

`file_contents` does not live long enough

Check failure on line 117 in moz-webgpu-cts/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, beta)

`file_contents` does not live long enough
.into_result()
{
Err(errors) => {
found_err = true;
render_metadata_parse_errors(&Arc::new(path), &file_contents, errors);
None
}
Ok(file) => Some((path, file)),
}
}
Err(AlreadyReportedToCommandline) => None,
})
.collect::<IndexMap<_, File<SimpleSpan>>>();
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>(
Expand Down Expand Up @@ -233,43 +256,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::<SimpleSpan>::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::<BTreeMap<_, _>>();

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::<TestPath, TestOutcomes>::default();
Expand Down Expand Up @@ -578,7 +567,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::<SimpleSpan>::parser(),
&*file_contents,

Check failure on line 583 in moz-webgpu-cts/src/main.rs

View workflow job for this annotation

GitHub Actions / Clippy (ubuntu-latest, stable)

`file_contents` does not live long enough

Check failure on line 583 in moz-webgpu-cts/src/main.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, beta)

`file_contents` does not live long enough

Check failure on line 583 in moz-webgpu-cts/src/main.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, beta)

`file_contents` does not live long enough
Expand Down Expand Up @@ -615,47 +614,22 @@ fn run(cli: Cli) -> ExitCode {
orig_path: Arc<PathBuf>,
inner: metadata::Test<SimpleSpan>,
}
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::<BTreeMap<_, _>>();
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!(
Expand Down Expand Up @@ -728,11 +702,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,
Expand Down

0 comments on commit 564a3d1

Please sign in to comment.