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

Normalize SourceID in cargo metadata. #8824

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Nov 1, 2020

The SourceID in cargo metadata can have different values, but they can be equivalent in Cargo. This results in different serialized forms, which prevents comparing the ID strings. In this particular case, SourceKind::Git(GitReference::Branch("master")) is equivalent to SourceKind::Git(GitReference::DefaultBranch), but they serialize differently.

The reason these end up differently is because the SourceId for a Package is created from the Dependency declaration. But the SourceId in Cargo.lock comes from the deserialized file. If you have an explicit branch = "master" in the dependency, then versions prior to 1.47 would not include ?branch=master in Cargo.lock. However, since 1.47, internally Cargo will use GitReference::Branch("master").

Conversely, if you have a new Cargo.lock (with ?branch=master), and then remove the explicit branch="master" from Cargo.toml, you'll end up with another mismatch in cargo metadata.

The solution here is to use the variant from the Package when serializing the resolver in cargo metadata. I chose this since the Package variant is displayed on other JSON messages (like artifact messages), and I think this is the only place that the resolver variants are exposed (other than Cargo.lock itself).

I'm not convinced that this was entirely intended, since there is code to avoid this, and at the time #8522 landed, I did not realize this would change the V2 lock format. However, it's probably too late to try to reverse that, and I don't think there are any other problems other than this cargo metadata inconsistency.

Fixes #8756

@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 1, 2020
@alexcrichton
Copy link
Member

@bors: r+

Thanks for fixing this! And sorry I didn't get a chance to get around to this :(

@bors
Copy link
Contributor

bors commented Nov 2, 2020

📌 Commit d88ed1c has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 2, 2020
@bors
Copy link
Contributor

bors commented Nov 2, 2020

⌛ Testing commit d88ed1c with merge c46c06a...

@bors
Copy link
Contributor

bors commented Nov 2, 2020

☀️ Test successful - checks-actions
Approved by: alexcrichton
Pushing c46c06a to master...

@bors bors merged commit c46c06a into rust-lang:master Nov 2, 2020
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Nov 5, 2020
Update cargo

7 commits in becb4c282b8f37469efb8f5beda45a5501f9d367..d5556aeb8405b1fe696adb6e297ad7a1f2989b62
2020-10-28 16:41:55 +0000 to 2020-11-04 22:20:36 +0000
- Implement weak dependency features. (rust-lang/cargo#8818)
- Avoid some extra downloads with new feature resolver. (rust-lang/cargo#8823)
- fix: remove install command `$`, for copying friendly (rust-lang/cargo#8828)
- Bump `anyhow` dependency to `1.0.34` in `crates-io` crate (rust-lang/cargo#8826)
- Normalize SourceID in `cargo metadata`. (rust-lang/cargo#8824)
- vendor: correct the path to cargo config (rust-lang/cargo#8822)
- Make host_root return host.root(), not host.dest() (rust-lang/cargo#8819)
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Nov 5, 2020
Update cargo

7 commits in becb4c282b8f37469efb8f5beda45a5501f9d367..d5556aeb8405b1fe696adb6e297ad7a1f2989b62
2020-10-28 16:41:55 +0000 to 2020-11-04 22:20:36 +0000
- Implement weak dependency features. (rust-lang/cargo#8818)
- Avoid some extra downloads with new feature resolver. (rust-lang/cargo#8823)
- fix: remove install command `$`, for copying friendly (rust-lang/cargo#8828)
- Bump `anyhow` dependency to `1.0.34` in `crates-io` crate (rust-lang/cargo#8826)
- Normalize SourceID in `cargo metadata`. (rust-lang/cargo#8824)
- vendor: correct the path to cargo config (rust-lang/cargo#8822)
- Make host_root return host.root(), not host.dest() (rust-lang/cargo#8819)
@ehuss ehuss added this to the 1.49.0 milestone Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

beta: cargo metadata uses inconsistent encodings of ids with branch = master dependencies
4 participants