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

Prefer patched versions of dependencies #9639

Merged
merged 1 commit into from
Jul 14, 2021
Merged

Conversation

djmitche
Copy link
Contributor

When selecting among several versions of a paackage, prefer versions
from [patch] sections over other versions, similar to how locked
versions are preferred.

Patches come in the form of a Dependency and not a PackageId, so this
preference is expressed with prefer_patch_deps, distinct from
try_to_use.

Fixes #9535

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 29, 2021
@Eh2406
Copy link
Contributor

Eh2406 commented Jul 8, 2021

Sorry for the tardy review! This looks exactly like what I had in mind, thank you!

Looking it over I have 2 thoughts:

  1. the revolver tests need to be updated here to pass the new argument.
  2. The linear scan here makes me a little nervous. What happens if there are hundreds of [patch]s. Probably nothing, so if we can't make something more efficient, then we should not worry about it. But if we can make prefer_patch_deps a &'a HashMap<InternedString, HashSet<Dependency>>. So then the look up can be like self.prefer_patch_deps.get(dep.package_name()).iter().any(|d| d.matches_id(*package_id)) or something...

@djmitche
Copy link
Contributor Author

djmitche commented Jul 9, 2021

Sounds good!

Maybe a followup to this would be some kind of VersionPreferences struct that abstracts away the version sort performed by the resolver? So that section would become ret.sort_by(version_prefs.compare). The VersionPreferences struct would have methods to add either PackageId's or Dependency's to its list of preferred versions. This would leave the door open to further refinements to the sorting behind that abstraction barrier.

I don't know why the cargo-fix test failed in my last push. I'll rebase in the process of making the changes you suggest, in hopes that it's been addressed on main since I branched.

When selecting among several versions of a paackage, prefer versions
from `[patch]` sections over other versions, similar to how locked
versions are preferred.

Patches come in the form of a Dependency and not a PackageId, so this
preference is expressed with `prefer_patch_deps`, distinct from
`try_to_use`.
@Eh2406
Copy link
Contributor

Eh2406 commented Jul 14, 2021

This looks good! Thank you!
@bors r+

@bors
Copy link
Contributor

bors commented Jul 14, 2021

📌 Commit bd4a353 has been approved by Eh2406

@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 Jul 14, 2021
@bors
Copy link
Contributor

bors commented Jul 14, 2021

⌛ Testing commit bd4a353 with merge f8ba1cb...

@bors
Copy link
Contributor

bors commented Jul 14, 2021

☀️ Test successful - checks-actions
Approved by: Eh2406
Pushing f8ba1cb to master...

@bors bors merged commit f8ba1cb into rust-lang:master Jul 14, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 15, 2021
Update cargo

13 commits in 3ebb5f15a940810f250b68821149387af583a79e..66a6737a0c9f3a974af2dd032a65d3e409c77aac
2021-07-02 20:35:38 +0000 to 2021-07-14 20:54:28 +0000
- Add format option to `cargo tree` to print the lib_name (rust-lang/cargo#9663)
- Prefer patched versions of dependencies (rust-lang/cargo#9639)
- When a dependency does not have a version, git or path, fails directly (rust-lang/cargo#9686)
- Spot the crate typo easily (rust-lang/cargo#9665)
- remove unnecessary 'collect' (rust-lang/cargo#9616)
- Make it easier to run testsuite with a custom toolchain. (rust-lang/cargo#9679)
- Serialize `cargo fix` (rust-lang/cargo#9677)
- Don't recommend filing issues on rust-lang/cargo for Cargo.toml errors. (rust-lang/cargo#9658)
- Update nightly failure notification. (rust-lang/cargo#9657)
- Update Windows env uppercase key check. (rust-lang/cargo#9654)
- Unignore fix_edition_2021. (rust-lang/cargo#9662)
- Warning when using features in patch (rust-lang/cargo#9666)
- Unify cargo and rustc's error reporting (rust-lang/cargo#9655)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 15, 2021
Update cargo

13 commits in 3ebb5f15a940810f250b68821149387af583a79e..66a6737a0c9f3a974af2dd032a65d3e409c77aac
2021-07-02 20:35:38 +0000 to 2021-07-14 20:54:28 +0000
- Add format option to `cargo tree` to print the lib_name (rust-lang/cargo#9663)
- Prefer patched versions of dependencies (rust-lang/cargo#9639)
- When a dependency does not have a version, git or path, fails directly (rust-lang/cargo#9686)
- Spot the crate typo easily (rust-lang/cargo#9665)
- remove unnecessary 'collect' (rust-lang/cargo#9616)
- Make it easier to run testsuite with a custom toolchain. (rust-lang/cargo#9679)
- Serialize `cargo fix` (rust-lang/cargo#9677)
- Don't recommend filing issues on rust-lang/cargo for Cargo.toml errors. (rust-lang/cargo#9658)
- Update nightly failure notification. (rust-lang/cargo#9657)
- Update Windows env uppercase key check. (rust-lang/cargo#9654)
- Unignore fix_edition_2021. (rust-lang/cargo#9662)
- Warning when using features in patch (rust-lang/cargo#9666)
- Unify cargo and rustc's error reporting (rust-lang/cargo#9655)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 15, 2021
Update cargo

13 commits in 3ebb5f15a940810f250b68821149387af583a79e..66a6737a0c9f3a974af2dd032a65d3e409c77aac
2021-07-02 20:35:38 +0000 to 2021-07-14 20:54:28 +0000
- Add format option to `cargo tree` to print the lib_name (rust-lang/cargo#9663)
- Prefer patched versions of dependencies (rust-lang/cargo#9639)
- When a dependency does not have a version, git or path, fails directly (rust-lang/cargo#9686)
- Spot the crate typo easily (rust-lang/cargo#9665)
- remove unnecessary 'collect' (rust-lang/cargo#9616)
- Make it easier to run testsuite with a custom toolchain. (rust-lang/cargo#9679)
- Serialize `cargo fix` (rust-lang/cargo#9677)
- Don't recommend filing issues on rust-lang/cargo for Cargo.toml errors. (rust-lang/cargo#9658)
- Update nightly failure notification. (rust-lang/cargo#9657)
- Update Windows env uppercase key check. (rust-lang/cargo#9654)
- Unignore fix_edition_2021. (rust-lang/cargo#9662)
- Warning when using features in patch (rust-lang/cargo#9666)
- Unify cargo and rustc's error reporting (rust-lang/cargo#9655)
@ehuss ehuss added this to the 1.55.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.

Prioritize [patch] versions the way we do for versions in the lockfile
5 participants