Skip to content

Commit

Permalink
WIP: feat: add dump-json subcmd.
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed May 15, 2024
1 parent 0a2011f commit 6c51e69
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion moz-webgpu-cts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ publish = false
dist = true

[dependencies]
camino = "1.1.6"
camino = { version = "1.1.6", features = ["serde1"] }
clap = { version = "4.4.2", features = ["derive"] }
env_logger = "0.10.0"
enumset = { version = "1.1.3", features = ["serde"] }
Expand Down
40 changes: 40 additions & 0 deletions moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ enum Subcommand {
#[clap(value_enum, long, default_value_t = Default::default())]
on_zero_item: OnZeroItem,
},
/// Dump all metadata as JSON. Do so at your own risk!
DumpJson,
}

#[derive(Clone, Copy, Debug, ValueEnum)]
Expand Down Expand Up @@ -1349,6 +1351,44 @@ fn run(cli: Cli) -> ExitCode {
println!("Full analysis: {analysis:#?}");
ExitCode::SUCCESS
}
Subcommand::DumpJson => {
let mut read_err_found = false;
let metadata = read_and_parse_all_metadata(&gecko_checkout)
.map_ok(|(path, file)| {
let path = match Utf8PathBuf::from_path_buf(Arc::try_unwrap(path).unwrap()) {
Ok(path) => path,
Err(path) => panic!("ofrick, this ain't a UTF-8 path: {}", path.display()),
};
(path, file)
})
.filter_map(|res| match res {
Ok(ok) => Some(ok),
Err(AlreadyReportedToCommandline) => {
read_err_found = true;
None
}
})
.collect::<BTreeMap<_, _>>();
if read_err_found {
log::error!(concat!(
"found one or more failures while reading metadata, ",
"see above for more details"
));
return ExitCode::FAILURE;
}

log::debug!("dumping all metadata to JSON…");
match serde_json::to_writer(io::stdout().lock(), &metadata)
.into_diagnostic()
.wrap_err("error while writing JSON to `stdout`")
{
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
log::error!("{e:?}");
ExitCode::FAILURE
}
}
}
}
}

Expand Down

0 comments on commit 6c51e69

Please sign in to comment.