Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read package/workspace config from Cargo manifest #799

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use trustfall_rustdoc::{load_rustdoc, VersionedCrate};
use rustdoc_cmd::RustdocCommand;
use std::collections::{BTreeMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Instant;

pub use config::GlobalConfig;
Expand Down Expand Up @@ -484,6 +485,11 @@ note: skipped the following crates since they have no library target: {skipped}"
);
}

let workspace_overrides =
manifest::deserialize_lint_table(&metadata.workspace_metadata)
.context("[workspace.metadata.cargo-semver-checks] table is invalid")?
.map(Arc::new);

selected
.iter()
.map(|selected| {
Expand All @@ -506,6 +512,24 @@ note: skipped the following crates since they have no library target: {skipped}"
})?;
Ok((crate_name.clone(), None))
} else {
let package_overrides =
manifest::deserialize_lint_table(&selected.metadata)
.with_context(|| {
format!(
"package `{}`'s [package.metadata.cargo-semver-checks] table is invalid (at {})",
selected.name,
selected.manifest_path,
)
})?;

let mut overrides = OverrideStack::new();
if let Some(workspace) = &workspace_overrides {
overrides.push(Arc::clone(workspace));
}
if let Some(package) = package_overrides {
overrides.push(Arc::new(package));
}

let start = std::time::Instant::now();
let (current_crate, baseline_crate) = generate_versioned_crates(
config,
Expand Down
10 changes: 10 additions & 0 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ impl From<OverrideConfig> for QueryOverride {
}
}

/// Helper function to deserialize an optional lint table from a [`serde_json::Value`]
/// into a [`OverrideMap`]. Returns an `Err` if the `cargo-semver-checks` table is present
/// but invalid. Returns `Ok(None)` if the table is not present.
pub(crate) fn deserialize_lint_table(
metadata: &serde_json::Value,
) -> anyhow::Result<Option<OverrideMap>> {
let table = Option::<LintTable>::deserialize(metadata)?;
Ok(table.and_then(LintTable::into_overrides))
}

#[cfg(test)]
mod tests {
use crate::{manifest::OverrideConfig, QueryOverride};
Expand Down
Loading