-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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.clone()) | ||
.context("[workspace.metadata.cargo-semver-checks] table is incorrect")? | ||
.map(Arc::new); | ||
|
||
selected | ||
.iter() | ||
.map(|selected| { | ||
|
@@ -506,6 +512,23 @@ 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.clone()) | ||
.with_context(|| { | ||
format!( | ||
"{} [package.metadata.cargo-semver-checks] table is incorrect", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idea: do we by any chance know the path to the This is because in some cases, projects may contain more than one crate by the same name — for example, see #462. In such cases, knowing the If it's too hard to do now, we can just open a |
||
selected.name | ||
) | ||
})?; | ||
|
||
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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> = serde_json::from_value(metadata)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to avoid the |
||
Ok(table.and_then(LintTable::into_overrides)) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{manifest::OverrideConfig, QueryOverride}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: word choice, here and below as well