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

Fix cargo add behaving different when translating package name #13765

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dohse
Copy link

@dohse dohse commented Apr 17, 2024

Fixes #13702
Fixes #10680

TODOs

  • Fuzzy match registry dependencies in cargo remove as well
  • Don't duplicate name permutation generation
  • Shall we reject cases where multiple different permutations match?
  • Add comments that explain the behavior

@rustbot
Copy link
Collaborator

rustbot commented Apr 17, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added Command-add S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 17, 2024
@dohse dohse force-pushed the fix-13702 branch 2 times, most recently from b7d4b79 to 8340710 Compare April 17, 2024 07:24
@weihanglo weihanglo assigned epage and unassigned weihanglo Apr 18, 2024
@dohse dohse force-pushed the fix-13702 branch 2 times, most recently from 44abbff to d24d92e Compare May 1, 2024 13:32
@@ -364,7 +364,24 @@ fn resolve_dependency(
};
selected_dep = populate_dependency(selected_dep, arg);

let old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
let mut old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
if old_dep.is_none() && selected_dep.source().is_none() && selected_dep.rename().is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the selected_dep checks?

Copy link
Author

Choose a reason for hiding this comment

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

selected_dep.source().is_none() to try the mutations only on when looking for registry dependencies and selected_dep.rename().is_none() to not try permutations when adding a renamed dependency.

Comment on lines 367 to 372
let mut old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
if old_dep.is_none() && selected_dep.source().is_none() && selected_dep.rename().is_none() {
for name_permutation in [
selected_dep.name.replace('-', "_"),
selected_dep.name.replace('_', "-"),
] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of looking up old_dep and then looking it up again, could we include the user-selected name in the list of permutations?

Copy link
Author

Choose a reason for hiding this comment

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

I will try that, but I guess I have handle the rename case then separately.

Comment on lines 369 to 372
for name_permutation in [
selected_dep.name.replace('-', "_"),
selected_dep.name.replace('_', "-"),
] {
Copy link
Contributor

@epage epage May 1, 2024

Choose a reason for hiding this comment

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

Should we break this out into a function to be reused between this and the call to find_workspace_dep?

Copy link
Author

Choose a reason for hiding this comment

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

I will try that. Ideally package and workspace dependency lookup have the same logic.

Copy link
Author

Choose a reason for hiding this comment

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

I did this and pushed a new version with that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-add S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
4 participants