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

Clean profile, patch, and replace in cargo remove #11194

Merged
merged 1 commit into from
Nov 19, 2022

Conversation

cassaundra
Copy link
Contributor

@cassaundra cassaundra commented Oct 8, 2022

What does this PR try to resolve?

This PR is part of the continued work on cargo remove (#11099, see deferred work).

After a successful removal of a dependency, clean up the profile, patch, and replace sections to remove all references to it.

Note the GC process was expanded to clean up not just references to the dependencies just removed, but also references of all dependencies. This was because there's not an easy way to determine which dependencies correspond to the given TOML keys, without either 1) figuring that out before the removal (therefore having to predict the behavior), or 2) returning that information from the remove function (somewhat unorthodox for an op).

How should we review and test this PR?

Verify that the implementation makes sense and that the tests are sufficient.

@rust-highfive
Copy link

r? @epage

(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 Oct 8, 2022
src/cargo/util/toml_mut/manifest.rs Outdated Show resolved Hide resolved
src/cargo/util/toml_mut/manifest.rs Outdated Show resolved Hide resolved
src/cargo/util/toml_mut/manifest.rs Outdated Show resolved Hide resolved
@cassaundra cassaundra force-pushed the cargo-remove-gc branch 2 times, most recently from 7ee5928 to b0b86a3 Compare October 9, 2022 22:57
@epage epage added S-blocked and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 10, 2022
@epage epage mentioned this pull request Oct 10, 2022
5 tasks
bors added a commit that referenced this pull request Nov 1, 2022
Clean up workspace dependencies after cargo remove

### What does this PR try to resolve?

After successful removal of an inherited dependency from a workspace member, clean up the root workspace manifest.

This PR is part of the continued working on cargo remove (#11099, see deferred work).

### How should we test and review this PR?

Make sure the tests cover all possible use cases. After posting this PR, I will post a short self-review regarding some design concerns.

### Additional information

#11194 is currently blocked on this feature.
@cassaundra
Copy link
Contributor Author

No longer blocked on #11242, so I've (hopefully) finished up the work on this feature. Here's what's new:

  • replace GC moved out to the same level as workspace.dependencies GC. Both now share some code, although I think this could be cleaned up some more.
  • replace GC now takes into account version requirements. It should also operate on the actual package name (not the TOML name).
  • cargo_remove::gc_replace test is now based on a workspace to test this functionality.

@epage epage removed the S-blocked label Nov 5, 2022
@cassaundra
Copy link
Contributor Author

Okay, I fixed a these issues last night, but I found another bug pertaining to the replace section: since get_dependency_versions takes a TOML key and returns associated Dependencys, dependencies with a package field get ignored. I'll see if I can find a solution for this and commit then.

@cassaundra
Copy link
Contributor Author

After more investigation, it turns out profile and patch also have similar issues. The profile override also needs to support the package ID spec as well.

@cassaundra
Copy link
Contributor Author

Issues have been fixed. A few notes to help with review:

  • Workspace dependencies work off of TOML keys, whereas patch, profile, and replace match on package names.
  • Replace and patch overrides take package ID spec, so need to be matched both on package name and version.

src/cargo/ops/cargo_remove.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/remove.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/remove.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/remove.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/remove.rs Outdated Show resolved Hide resolved
tests/testsuite/cargo_remove/gc_profile/in/Cargo.toml Outdated Show resolved Hide resolved
@bors
Copy link
Collaborator

bors commented Nov 15, 2022

☔ The latest upstream changes (presumably #11375) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. label Nov 15, 2022
@cassaundra cassaundra force-pushed the cargo-remove-gc branch 3 times, most recently from c05bd27 to 5d3ed21 Compare November 15, 2022 09:21
src/bin/cargo/commands/remove.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/remove.rs Outdated Show resolved Hide resolved
src/bin/cargo/commands/remove.rs Show resolved Hide resolved
@cassaundra
Copy link
Contributor Author

Changes made.

I also noticed that workspace dependencies might not be properly handled by the likes of spec_has_match/source_has_match, so I modified the workspace.dependencies pass to replace each instance of these with the corresponding definition.

After a successful removal of a dependency, clean up the profile, patch, and
replace sections to remove all references to the dependency.
@epage
Copy link
Contributor

epage commented Nov 19, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 19, 2022

📌 Commit 299252c has been approved by epage

It is now in the queue for this repository.

@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-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. labels Nov 19, 2022
@bors
Copy link
Collaborator

bors commented Nov 19, 2022

⌛ Testing commit 299252c with merge 43689d3...

@bors
Copy link
Collaborator

bors commented Nov 19, 2022

☀️ Test successful - checks-actions
Approved by: epage
Pushing 43689d3 to master...

@bors bors merged commit 43689d3 into rust-lang:master Nov 19, 2022
weihanglo added a commit to weihanglo/rust that referenced this pull request Nov 23, 2022
7 commits in eb5d35917b2395194593c9ca70c3778f60c1573b..ba607b23db8398723d659249d9abf5536bc322e5
2022-11-17 22:08:43 +0000 to 2022-11-22 20:52:39 +0000

- Fix failure to parse rustc's JSON output if it is too nested (rust-lang/cargo#11368)
- Add suggestions when `cargo add` multiple packages (rust-lang/cargo#11186)
- Update mod.rs (rust-lang/cargo#11395)
- Fix typo `try use` -> `try to use` (rust-lang/cargo#11394)
- Add warning when `cargo tree -i <spec>` can not find packages (rust-lang/cargo#11377)
- Clean profile, patch, and replace in cargo remove (rust-lang/cargo#11194)
- chore: Upgrade miow (rust-lang/cargo#11391)
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2022
Update cargo

7 commits in eb5d35917b2395194593c9ca70c3778f60c1573b..ba607b23db8398723d659249d9abf5536bc322e5 2022-11-17 22:08:43 +0000 to 2022-11-22 20:52:39 +0000

- Fix failure to parse rustc's JSON output if it is too nested (rust-lang/cargo#11368)
- Add suggestions when `cargo add` multiple packages (rust-lang/cargo#11186)
- Update mod.rs (rust-lang/cargo#11395)
- Fix typo `try use` -> `try to use` (rust-lang/cargo#11394)
- Add warning when `cargo tree -i <spec>` can not find packages (rust-lang/cargo#11377)
- Clean profile, patch, and replace in cargo remove (rust-lang/cargo#11194)
- chore: Upgrade miow (rust-lang/cargo#11391)
@ehuss ehuss added this to the 1.67.0 milestone Dec 14, 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.

5 participants