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

Conversation

suaviloquence
Copy link
Contributor

Deserializes lint table from the relevant [workspace.metadata] and [package.metadata] tables, if they exist.

Notes:

  • this is only possible when we have access to the Cargo.toml manifest and run the cargo metadata command - that is, we won't be able to configure lint levels when the rustdoc source is Rustdoc | Revision | VersionFromRegistry as of current without something like CLI flags:
    • here's a shim of how I plan to pass this to the run_check_release function. takeaway is that when we don't have the manifest to read the metadata, we just pass an empty OverrideStack as overrides
  • it's hard to test that we are generating the correct overrides at this state without the proposed new API. Once we actually use the overrides, we can test whether they are applied correctly by parsing the output
    • here's the beginnings of a test crate, although I just printed the passed overrides for now:

      test output run with `cargo r -- semver-checks --baseline-root test_crates/workspace-overrides/baseline --manifest-path test_crates/workspace-overrides/current/pkg/Cargo.toml -vvv`

      overrides: OverrideStack([{"function_missing": QueryOverride { required_update: Some(Minor), lint_level: Some(Warn) }, "module_missing": QueryOverride { required_update: None, lint_level: Some(Allow) }}, {"function_missing": QueryOverride { required_update: None, lint_level: Some(Deny) }, "module_missing": QueryOverride { required_update: None, lint_level: Some(Warn) }}])

Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor nits, looks good overall — should be able to merge on the next pass.

src/manifest.rs Outdated
Comment on lines 119 to 122
pub(crate) fn deserialize_lint_table(
metadata: serde_json::Value,
) -> anyhow::Result<Option<OverrideMap>> {
let table: Option<LintTable> = serde_json::from_value(metadata)?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to avoid the .clone() when calling this function by making it accept &Value and then using the trick described in this post: https://users.rust-lang.org/t/serde-from-value-moves-my-value-but-i-want-i-returned-to-me-on-err/69621

src/lib.rs Outdated
@@ -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")?
Copy link
Owner

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

Suggested change
.context("[workspace.metadata.cargo-semver-checks] table is incorrect")?
.context("[workspace.metadata.cargo-semver-checks] table is invalid")?

src/lib.rs Outdated
manifest::deserialize_lint_table(selected.metadata.clone())
.with_context(|| {
format!(
"{} [package.metadata.cargo-semver-checks] table is incorrect",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea: do we by any chance know the path to the Cargo.toml file here? If it isn't too difficult, it might be useful to not just say which crate had the invalid table but also give a path to it.

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 Cargo.toml path would be very helpful to the user.

If it's too hard to do now, we can just open a C-enhancement issue for the idea and tackle it another time.

- make `manifest::deserialize_lint_table` take a `&serde_json::Value`
- show manifest path on invalid `[package.metadata]` table
- change "incorrect table" -> "invalid table"
@obi1kenobi obi1kenobi merged commit f8f89ec into obi1kenobi:main Jun 19, 2024
35 checks passed
@obi1kenobi
Copy link
Owner

Awesome! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants