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 27, 2023
1 parent 976ce24 commit 9f8f255
Showing 1 changed file with 68 additions and 91 deletions.
159 changes: 68 additions & 91 deletions moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)| {

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

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, beta)

cannot borrow `found_err` as mutable more than once at a time

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

View workflow job for this annotation

GitHub Actions / Clippy (ubuntu-latest, beta)

cannot borrow `found_err` as mutable more than once at a time

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

View workflow job for this annotation

GitHub Actions / Clippy (ubuntu-latest, stable)

cannot borrow `found_err` as mutable more than once at a time

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

View workflow job for this annotation

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

cannot borrow `found_err` as mutable more than once at a time
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),

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

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, beta)

cannot move out of `file_contents` because it is borrowed

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

View workflow job for this annotation

GitHub Actions / Clippy (ubuntu-latest, beta)

cannot move out of `file_contents` because it is borrowed

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

View workflow job for this annotation

GitHub Actions / Clippy (ubuntu-latest, stable)

cannot move out of `file_contents` because it is borrowed

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

View workflow job for this annotation

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

cannot move out of `file_contents` because it is borrowed
errors,
);
None
}
})
.map(|(p, fc)| (Arc::new(p), Arc::new(fc)))
.collect::<IndexMap<_, _>>();
Ok(file) => Some((path, file)),
}
})
.collect::<IndexMap<_, File>>();
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 @@ -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::<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 @@ -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)

Check failure on line 554 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 554 in moz-webgpu-cts/src/main.rs

View workflow job for this annotation

GitHub Actions / Clippy (ubuntu-latest, beta)

`file_contents` does not live long enough

Check failure on line 554 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 554 in moz-webgpu-cts/src/main.rs

View workflow job for this annotation

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

`file_contents` does not live long enough
.into_result()
{
Expand Down Expand Up @@ -596,47 +603,22 @@ fn run(cli: Cli) -> ExitCode {
orig_path: Arc<PathBuf>,
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::<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 @@ -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,
Expand Down

0 comments on commit 9f8f255

Please sign in to comment.