Skip to content

Commit

Permalink
Merge pull request #105 from ErichDonGubler/dump-json
Browse files Browse the repository at this point in the history
Add `dump-json` command
  • Loading branch information
ErichDonGubler authored Jun 6, 2024
2 parents 887db4d + 9cf12c6 commit b1ca831
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 18 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ format = "0.2.4"
indexmap = "2.0.0"
insta = "1.38.0"
log = "0.4.20"
serde = { version = "1.0.188", features = ["derive"] }
thiserror = "1.0.49"

# The profile that 'cargo dist' will build with
Expand Down
10 changes: 5 additions & 5 deletions moz-webgpu-cts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ 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 = "1.1.3"
enumset = { version = "1.1.3", features = ["serde"] }
format = { workspace = true }
indexmap = { workspace = true }
itertools = "0.11.0"
Expand All @@ -25,13 +25,13 @@ miette = { version = "5.10.0", features = ["fancy"] }
natord = "1.0.9"
path-dsl = "0.6.1"
rayon = "1.8.0"
serde = { version = "1.0.188", features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
serde_json = "1.0.107"
strum = { version = "0.25.0", features = ["derive"] }
thiserror = { workspace = true }
wax = { version = "0.6.0", features = ["miette"], git = "https://github.com/ErichDonGubler/wax", branch = "static-miette-diags"}
whippit = { version = "0.6.0", path = "../whippit", default-features = false }
enum-map = "2.7.3"
whippit = { version = "0.6.0", path = "../whippit", default-features = false, features = ["serde1"] }
enum-map = { version = "2.7.3", features = ["serde"] }

[dev-dependencies]
insta = { workspace = true }
41 changes: 41 additions & 0 deletions moz-webgpu-cts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ enum Subcommand {
/// The heuristic to use for identifying tests that can be promoted.
preset: UpdateBacklogPreset,
},
/// Dump all metadata as JSON. Do so at your own risk; no guarantees are made about the
/// schema of this JSON, for now.
DumpJson,
}

#[derive(Clone, Copy, Debug, ValueEnum)]
Expand Down Expand Up @@ -1464,6 +1467,44 @@ fn run(cli: Cli) -> ExitCode {
ExitCode::SUCCESS
}
}
Subcommand::DumpJson => {
let mut read_err_found = false;
let metadata = read_and_parse_all_metadata(browser, &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
26 changes: 15 additions & 11 deletions moz-webgpu-cts/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use enum_map::Enum;
use enumset::EnumSetType;
use format::lazy_format;
use joinery::JoinableIterator;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use strum::EnumIter;
use whippit::{
metadata::{
Expand All @@ -34,7 +34,7 @@ use crate::shared::{ExpandedPropertyValue, Expected, MaybeCollapsed, NormalizedP
#[cfg(test)]
use insta::assert_debug_snapshot;

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Serialize)]
pub struct File {
pub properties: FileProps,
pub tests: BTreeMap<SectionHeader, Test>,
Expand All @@ -56,7 +56,7 @@ impl<'a> metadata::File<'a> for File {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Serialize)]
pub struct FileProps {
pub is_disabled: Option<PropertyValue<Expr<Value<'static>>, String>>,
#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -562,7 +562,7 @@ fn format_file_properties(props: &FileProps) -> impl Display + '_ {
})
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize)]
pub enum ImplementationStatus {
/// Indicates that functionality governing test(s) is implemented or currently being
/// implemented, and generally expected to conform to tests.
Expand Down Expand Up @@ -631,7 +631,7 @@ impl<'a> metadata::Tests<'a> for Tests {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Serialize)]
pub struct Test {
pub properties: TestProps<TestOutcome>,
pub subtests: BTreeMap<SectionHeader, Subtest>,
Expand Down Expand Up @@ -678,7 +678,7 @@ impl<'a> metadata::Subtests<'a> for Subtests {
}
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Serialize)]
pub struct Subtest {
pub properties: TestProps<SubtestOutcome>,
}
Expand Down Expand Up @@ -844,20 +844,20 @@ where
})
}

#[derive(Clone, Copy, Debug, Enum, EnumIter, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Enum, EnumIter, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub enum Platform {
Windows,
Linux,
MacOs,
}

#[derive(Clone, Copy, Debug, Enum, EnumIter, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Enum, EnumIter, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub enum BuildProfile {
Debug,
Optimized,
}

#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct TestProps<Out>
where
Out: EnumSetType,
Expand Down Expand Up @@ -1179,7 +1179,9 @@ pub(crate) const CRASH: &str = "CRASH";
pub(crate) const OK: &str = "OK";
pub(crate) const ERROR: &str = "ERROR";

#[derive(Debug, Deserialize, EnumSetType, Hash)]
#[derive(Debug, Deserialize, EnumSetType, Hash, Serialize)]
#[enumset(serialize_repr = "list")]
#[enumset(serialize_deny_unknown)]
#[serde(rename_all = "UPPERCASE")]
pub enum TestOutcome {
Ok,
Expand Down Expand Up @@ -1234,7 +1236,9 @@ impl<'a> Properties<'a> for TestProps<TestOutcome> {
}
}

#[derive(Debug, Deserialize, EnumSetType, Hash)]
#[derive(Debug, Deserialize, EnumSetType, Hash, Serialize)]
#[enumset(serialize_repr = "list")]
#[enumset(serialize_deny_unknown)]
#[serde(rename_all = "UPPERCASE")]
pub enum SubtestOutcome {
Pass,
Expand Down
5 changes: 3 additions & 2 deletions moz-webgpu-cts/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use enumset::{EnumSet, EnumSetType};
use format::lazy_format;
use itertools::Itertools;
use joinery::JoinableIterator;
use serde::Serialize;

use crate::metadata::{BuildProfile, Platform};

Expand All @@ -25,7 +26,7 @@ use crate::metadata::{BuildProfile, Platform};
///
/// [`Test`]: crate::metadata::Test
/// [`Subtest`]: crate::metadata::Subtest
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Serialize)]
pub struct Expected<Out>(EnumSet<Out>)
where
Out: EnumSetType;
Expand Down Expand Up @@ -231,7 +232,7 @@ where

/// A completely flat representation of [`NormalizedPropertyValue`] suitable for byte
/// representation in memory.
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Serialize)]
pub struct ExpandedPropertyValue<T>(ExpandedPropertyValueData<T>);

impl<T> Index<(Platform, BuildProfile)> for ExpandedPropertyValue<T> {
Expand Down
2 changes: 2 additions & 0 deletions whippit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ publish = false
[features]
default = ["unstructured-properties"]
unstructured-properties = ["dep:indexmap"]
serde1 = ["dep:serde"]

[dependencies]
chumsky = { version = "1.0.0-alpha.6", features = ["label", "pratt"] }
format = { workspace = true }
indexmap = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }

[dev-dependencies]
insta = { workspace = true }
1 change: 1 addition & 0 deletions whippit/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ fn test_indent() {
}

#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde1", derive(serde::Deserialize, serde::Serialize))]
pub struct SectionHeader(pub String);

impl Debug for SectionHeader {
Expand Down
1 change: 1 addition & 0 deletions whippit/src/metadata/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::metadata::{indent, ParseError};
/// [`Test`]: crate::metadata::Test
/// [`Subtest`]: crate::metadata::Subtest
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Deserialize, serde::Serialize))]
pub enum PropertyValue<C, V> {
/// A property value that is only ever a specific value.
Unconditional(V),
Expand Down
1 change: 1 addition & 0 deletions whippit/src/metadata/properties/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ fn test_conditional_fallback() {

/// Values placed into a [`super::PropertyValue::Conditional`].
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Deserialize, serde::Serialize))]
pub struct ConditionalValue<C, V> {
/// Conditional clauses and their resulting values if evaluated to true.
pub conditions: Vec<(C, V)>,
Expand Down
3 changes: 3 additions & 0 deletions whippit/src/metadata/properties/conditional/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::metadata::ParseError;

/// Values that can be placed into [`Value::Literal`].
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Deserialize, serde::Serialize))]
pub enum Literal<'a> {
/// At time of writing, no escaping is used for string values in this implementation.
String(Cow<'a, str>),
Expand Down Expand Up @@ -42,6 +43,7 @@ impl<'a> Literal<'a> {
/// Variable and literal values supported by [WPT metadata
/// properties](crate::metadata::properties). Usually the terminal of a [`Expr`] expression.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Deserialize, serde::Serialize))]
pub enum Value<'a> {
Variable(Cow<'a, str>),
Literal(Literal<'a>),
Expand Down Expand Up @@ -74,6 +76,7 @@ impl<'a> Value<'a> {
/// [`Properties`]: crate::metadata::properties::Properties
/// [`Properties::property_parser`]: crate::metadata::properties::Properties::property_parser
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde1", derive(serde::Deserialize, serde::Serialize))]
pub enum Expr<V> {
Value(V),
And(Box<Expr<V>>, Box<Expr<V>>),
Expand Down

0 comments on commit b1ca831

Please sign in to comment.