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

Rewrite cargo-metadata support, with review comments #132

Merged
merged 4 commits into from
Aug 23, 2024

Conversation

bnjbvr
Copy link
Owner

@bnjbvr bnjbvr commented Aug 23, 2024

This makes cargo machete --with-metadata --fix work; it previously broke
with kebab-case package names and packages like xml-rs.

It also removes a hack that attempted to parse opaque source ids (last updated in #106).

The solution involves looking at .packages and not just .resolved.


Same as #122, but with review comments addressed to help with landing.

g2p and others added 4 commits August 23, 2024 12:12
Two of them fail currently, the other doesn't but is still useful
to validate the logic.
This should make cargo machete --with-metadata much more accurate.

The previous version was able to get crate names (snake_case names
usable in source files) from cargo metadata, but was unable to go
back to the dependency spec written in Cargo.toml from that.
As a result, --fix was broken.

The mapping is complex because the published package can use a
different name (see https://lib.rs/crates/md-5 for an example),
the dependency spec can rename it again (through key = { package = … }),
and keys with dashes are mapped to crate names with underscores.

Two of these cases were broken, all of them now work.

This also removes a hack that attempted to extract package names
from cargo SourceIds.  Those are opaque and have changed as
recently as Rust 1.78 (Cargo.lock v4).
With [patch] sections, this may not be the case.
@bnjbvr bnjbvr force-pushed the cargo-metadata-with-review-comments branch from c53d656 to 1953e8f Compare August 23, 2024 10:12
@bnjbvr bnjbvr merged commit 711b955 into main Aug 23, 2024
4 checks passed
@bnjbvr bnjbvr deleted the cargo-metadata-with-review-comments branch August 23, 2024 10:14
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