From 6c51e69b90faa88a4ad6c9bb7fcd0d6a06eedd73 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 15 May 2024 17:29:32 -0400 Subject: [PATCH] WIP: feat: add `dump-json` subcmd. --- Cargo.lock | 3 +++ moz-webgpu-cts/Cargo.toml | 2 +- moz-webgpu-cts/src/main.rs | 40 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3adc2fc..caa3920 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,6 +121,9 @@ name = "camino" version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +dependencies = [ + "serde", +] [[package]] name = "cc" diff --git a/moz-webgpu-cts/Cargo.toml b/moz-webgpu-cts/Cargo.toml index cf54571..faa200e 100644 --- a/moz-webgpu-cts/Cargo.toml +++ b/moz-webgpu-cts/Cargo.toml @@ -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"] } diff --git a/moz-webgpu-cts/src/main.rs b/moz-webgpu-cts/src/main.rs index 172aa9d..1fe8e45 100644 --- a/moz-webgpu-cts/src/main.rs +++ b/moz-webgpu-cts/src/main.rs @@ -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)] @@ -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::>(); + 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 + } + } + } } }