Skip to content

Commit

Permalink
feat: migrate wdl-gauntlet to the new parser implementation. (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhuene authored Jun 13, 2024
1 parent b244a93 commit 3555a5e
Show file tree
Hide file tree
Showing 43 changed files with 1,769 additions and 1,570 deletions.
1,236 changes: 991 additions & 245 deletions Arena.toml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ pretty_assertions = "1.4.0"
rayon = "1.10.0"
approx = "0.5.1"
codespan-reporting = "0.11.1"
anyhow = "1.0.86"
dirs = "5.0.1"
faster-hex = "0.9.0"
git2 = "0.18.3"
temp-dir = "0.1.13"
779 changes: 214 additions & 565 deletions Gauntlet.toml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions wdl-gauntlet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed

* Migrated `wdl-gauntlet` to use the new parser implementation ([#76](https://github.com/stjude-rust-labs/wdl/pull/76))

## 0.2.0 - 5-31-2024

### Changed
Expand Down
16 changes: 8 additions & 8 deletions wdl-gauntlet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ edition.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wdl-ast = { path = "../wdl-ast", version = "0.2.0", features = ["codespan"] }
wdl-lint = { path = "../wdl-lint", version = "0.3.0" }
clap.workspace = true
colored.workspace = true
dirs = "5.0.1"
dirs.workspace = true
env_logger.workspace = true
faster-hex = "0.9.0"
git2 = "0.18.3"
faster-hex.workspace = true
git2.workspace = true
indexmap.workspace = true
log.workspace = true
nonempty.workspace = true
serde.workspace = true
serde_with.workspace = true
temp-dir = "0.1.13"
temp-dir.workspace = true
tokio.workspace = true
toml.workspace = true
wdl-ast = { path = "../wdl-ast", version = "0.2.0" }
wdl-core = { path = "../wdl-core", version = "0.2.0" }
wdl-grammar = { path = "../wdl-grammar", version = "0.3.0" }
anyhow.workspace = true
codespan-reporting.workspace = true
59 changes: 7 additions & 52 deletions wdl-gauntlet/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ use std::path::PathBuf;
use log::debug;
use log::log_enabled;
use log::trace;
use wdl_core::Version;

pub mod inner;
pub mod reportable_concern;

pub use inner::Inner;
pub use reportable_concern::ReportableConcern;

/// The default directory name for the `wdl-gauntlet` configuration file
const DEFAULT_CONFIG_DIR: &str = "wdl-gauntlet";
Expand Down Expand Up @@ -117,16 +114,16 @@ impl Config {
///
/// In both cases, the `path` will be stored within the [`Config`]. This has
/// the effect of ensuring the value loaded here will be saved to the
/// inteded location (should [`Config::save()`] be called).
pub fn load_or_new(path: PathBuf, version: Version) -> Result<Self> {
/// intended location (should [`Config::save()`] be called).
pub fn load_or_new(path: PathBuf) -> Result<Self> {
if !path.exists() {
debug!(
"no configuration exists at {}, creating new configuration.",
path.display()
);
return Ok(Self {
path: Some(path),
inner: Inner::from(version),
inner: Inner::default(),
});
}

Expand All @@ -143,63 +140,21 @@ impl Config {
if log_enabled!(log::Level::Trace) {
trace!("Loaded configuration file with the following:");
trace!(" -> {} repositories.", result.inner().repositories().len());
let num_concerns = result.inner().concerns().len();
trace!(" -> {} ignored errors.", num_concerns);
trace!(
" -> {} ignored diagnostics.",
result.inner().diagnostics().len()
);
}

Ok(result)
}

/// Gets the [`Inner`] configuration by reference.
///
/// ```
/// use wdl_gauntlet as gauntlet;
///
/// let config = r#"version = "v1"
///
/// [repositories."Foo/Bar"]
/// identifier = "Foo/Bar""#
/// .parse::<gauntlet::Config>()?;
///
/// assert_eq!(config.inner().version(), &wdl_core::Version::V1);
/// assert_eq!(config.inner().repositories().len(), 1);
/// assert_eq!(config.inner().concerns().len(), 0);
///
/// Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn inner(&self) -> &Inner {
&self.inner
}

/// Gets the [`Inner`] configuration by mutable reference.
///
/// ```
/// use indexmap::IndexSet;
/// use wdl_gauntlet as gauntlet;
/// use wdl_gauntlet::config::reportable_concern::Kind;
/// use wdl_gauntlet::config::ReportableConcern;
///
/// let mut config = r#"version = "v1"
///
/// [repositories."Foo/Bar"]
/// identifier = "Foo/Bar"
/// commit_hash = "d8e8b48ce8faad50b24779d785cd504baadfb13f""#
/// .parse::<gauntlet::Config>()?;
///
/// let mut concerns = IndexSet::new();
/// concerns.insert(ReportableConcern::new(
/// Kind::ValidationFailure,
/// "Foo/Bar:quux.wdl",
/// "Hello, world!",
/// ));
/// config.inner_mut().set_concerns(concerns);
///
/// assert_eq!(config.inner().version(), &wdl_core::Version::V1);
/// assert_eq!(config.inner().repositories().len(), 1);
/// assert_eq!(config.inner().concerns().len(), 1);
///
/// Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn inner_mut(&mut self) -> &mut Inner {
&mut self.inner
}
Expand Down
106 changes: 50 additions & 56 deletions wdl-gauntlet/src/config/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,76 @@
use std::path::Path;

use indexmap::IndexMap;
use indexmap::IndexSet;
use serde::Deserialize;
use serde::Serialize;
use serde_with::serde_as;

use crate::config::ReportableConcern;
use crate::repository;

mod repr;
/// Represents a diagnostic reported for a document.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct Diagnostic {
/// The identifier of the document containing the diagnostic.
document: String,
/// The short-form diagnostic message.
message: String,
}

impl Diagnostic {
/// Creates a new diagnostic for the given document identifier and message.
pub fn new(document: String, message: String) -> Self {
Self { document, message }
}

pub use repr::ReportableConcernsRepr;
/// Gets the identifier of the document.
pub fn document(&self) -> &str {
&self.document
}

/// A set of concerns serialized into their string form for storage within a
/// configuration file.
pub type ReportableConcerns = IndexSet<ReportableConcern>;
/// Gets the diagnostic message.
pub fn message(&self) -> &str {
&self.message
}
}

/// The configuration object for a [`Config`](super::Config).
/// The configuration object for a [`Config`](super::Config).
///
/// This object stores the actual configuration values for this subcommand.
#[serde_as]
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct Inner {
/// The WDL version.
version: wdl_core::Version,

/// The repositories.
#[serde(default)]
repositories: IndexMap<repository::Identifier, repository::Repository>,

/// The reportable concerns.
#[serde_as(as = "ReportableConcernsRepr")]
#[serde(default, skip_serializing_if = "IndexSet::is_empty")]
concerns: ReportableConcerns,
/// The expected diagnostics across all repositories.
#[serde(default)]
diagnostics: Vec<Diagnostic>,
}

impl Inner {
/// Gets the [`Version`](wdl_core::Version) for this [`Inner`] by reference.
///
/// # Examples
///
/// ```
/// use gauntlet::config::Inner;
/// use wdl_gauntlet as gauntlet;
///
/// let config = r#"version = "v1""#;
///
/// let inner: Inner = toml::from_str(&config).unwrap();
/// assert_eq!(inner.version(), &wdl_core::Version::V1);
/// ```
pub fn version(&self) -> &wdl_core::Version {
&self.version
}

/// Gets the [`Repositories`] for this [`Inner`] by reference.
/// Gets the repositories for this [`Inner`] by reference.
pub fn repositories(&self) -> &IndexMap<repository::Identifier, repository::Repository> {
&self.repositories
}

/// Gets the list of expected diagnostics.
pub fn diagnostics(&self) -> &[Diagnostic] {
&self.diagnostics
}

/// Sets the list of expected diagnostics.
pub fn set_diagnostics(&mut self, diagnostics: Vec<Diagnostic>) {
self.diagnostics = diagnostics;
}

/// Gets the repositories for this [`Inner`] by mutable reference.
pub fn repositories_mut(
&mut self,
) -> &mut IndexMap<repository::Identifier, repository::Repository> {
&mut self.repositories
}

/// Extends the `repositories` for this [`Inner`] with the given items.
pub fn extend_repositories(
&mut self,
Expand All @@ -79,30 +91,12 @@ impl Inner {
}
}

/// Gets the [`ReportableConcerns`] for this [`Inner`] by reference.
pub fn concerns(&self) -> &ReportableConcerns {
&self.concerns
}

/// Replaces the [`ReportableConcerns`] for this [`Inner`].
pub fn set_concerns(&mut self, concerns: ReportableConcerns) {
self.concerns = concerns;
self.concerns.sort();
}

/// Sorts the [`Repositories`] and the [`ReportableConcerns`] by key.
/// Sorts the configuration.
///
/// This sorts the repositories by their identifiers and the diagnostics by
/// their document identifiers and messages (lexicographically).
pub fn sort(&mut self) {
self.repositories.sort_by(|a, _, b, _| a.cmp(b));
self.concerns.sort();
}
}

impl From<wdl_core::Version> for Inner {
fn from(version: wdl_core::Version) -> Self {
Self {
version,
repositories: Default::default(),
concerns: Default::default(),
}
self.diagnostics.sort();
}
}
29 changes: 0 additions & 29 deletions wdl-gauntlet/src/config/inner/repr.rs

This file was deleted.

Loading

0 comments on commit 3555a5e

Please sign in to comment.