-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 up workspace dependencies after cargo remove #11242
Conversation
r? @weihanglo (rust-highfive has picked a reviewer for you, use r? to override) |
96a8229
to
2fd2648
Compare
2fd2648
to
69828aa
Compare
Recent push should fix these issues. No rush though, I know you've got a lot on your plate! :) |
src/cargo/ops/cargo_remove.rs
Outdated
if let Some(parent_manifest) = parent_manifest { | ||
cargo_util::paths::write( | ||
options.workspace.root_manifest(), | ||
parent_manifest.to_string().as_bytes(), | ||
)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this approach is fairly complicated
- Managing two different workspace manifests with different lifetimes
- Predicting our action as we try to see if something is unused
I feel like this would be a lot cleaner if we just accumulated the removed workspace dependency names and removed them all at once at the end. This would be a gc step working off of what the workspace does in practice and not what we've predicted it will look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still has a lot of the complexity I'm concerned about by trying to predict when a dependency is no longer needed for removal. imo we shouldn't call dependency_in_workspace
in the loop but instead just accumulate into to_remove_workspace
if dependency_is_workspace
. In the follow-up loop we then check dependency_in_workspace
and remove from workspace.dependencies
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still has a lot of the complexity I'm concerned about by trying to predict when a dependency is no longer needed for removal. imo we shouldn't call
dependency_in_workspace
in the loop but instead just accumulate intoto_remove_workspace
ifdependency_is_workspace
. In the follow-up loop we then checkdependency_in_workspace
and remove fromworkspace.dependencies
.
Oh yes I agree, I didn't mean for the pushed commit to be reviewed yet. I didn't realize you'd be notified. It should be better now.
c86997d
to
8a5161e
Compare
I believe @epage will be unavailable for the time being, so @weihanglo do you think you could take over reviewing this? It'd be nice to get this and #11194 (blocked on this PR) merged before the upcoming 1.66 cutoff so that it lands with cargo remove. |
Absolutely yes! Will review it ASAP. r? @weihanglo |
8022dda
to
2fb096b
Compare
2fb096b
to
4ff02f4
Compare
src/bin/cargo/commands/remove.rs
Outdated
.into_iter() | ||
.map(String::from) | ||
.collect::<Vec<_>>(); | ||
dep_is_workspace(&d.package_name(), &dep_table, manifest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be d.name_in_toml()
?
src/bin/cargo/commands/remove.rs
Outdated
members.iter().any(|(pkg, manifest)| { | ||
pkg.dependencies() | ||
.iter() | ||
.filter(|d| d.name_in_toml() == dep) | ||
.map(|d| (d, dep_to_table(d))) | ||
.any(|(d, t)| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for where the dependency was removed, we are relying on the undocumented behavior for when dep_is_workspace
does not find the promised dependency. Ideally, we would make this explicit. This could be done either by
- Having
dep_is_workspace
returnOption<bool>
- Iterate over the dependencies in
manifest
rather thanpkg
.LocalManifest
should have fairly friendly accessors to help with that
Personally, I would prefer that both happen. If both are done, we could do a .expect()
on dep_is_workspace
or turn it into an internal error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing the first should be easy. It's important to note that dep_is_workspace
will return None
on the recently removed dependency (as it hasn't been updated in the Workspace
but has in the manifest), so doing unwrap_or(false)
would make more sense. That's essentially what is going on right now, although poorly documented.
We could inspect each manifest with LocalManifest
rather than Package
, but that would require adding support for manually searching through dependencies
, dev-dependencies
, target.xyz.build-dependencies
, etc. Using Package
/Dependency
was an intentional choice to avoid this. Do you still think it is worth the rewrite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hat would require adding support for manually searching through dependencies, dev-dependencies, target.xyz.build-dependencies, etc.
Manifest::get_sections
will let us iterate over all dependency sections and then we just need to check if the returned table-likes contain the dependency key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
[workspace] | ||
members = [ "my-member" ] | ||
|
||
[package] | ||
name = "my-package" | ||
version = "0.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably have at least one test where we ensure workspace.dependencies.semver
is not removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The workspace tests are now as follows:
workspace
(previouslyworkspace_virtual
): virtual workspaceworkspace_non_virtual
(previouslyworkspace
): non-virtual workspaceworkspace_preserved
: non-virtual workspace which does not modify[workspace.dependencies]
4ff02f4
to
7910298
Compare
The failing tests seem to be spurious and unrelated, although I don't have a way to retry. |
See https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/latest.20nightly.20broken |
CI is fixed and you can see fresh results if you rebase. |
7910298
to
38b23d5
Compare
Okay, great! Tests seem to be passing now. |
@bors r+ |
☀️ Test successful - checks-actions |
14 commits in 7e484fc1a766f56dbc95380f45719698e0c82749..810cbad9a123ad4ee0a55a96171b8f8478ff1c03 2022-10-27 15:20:57 +0000 to 2022-11-02 21:04:31 +0000 - Update curl-sys (rust-lang/cargo#11326) - Mention fix on build script deadlock (rust-lang/cargo#11325) - Make cargo forward pre-existing CARGO if set (rust-lang/cargo#11285) - Clean up workspace dependencies after cargo remove (rust-lang/cargo#11242) - Update the outdated link for rust-semverver (rust-lang/cargo#11322) - Fix broken link to compilation entry point (rust-lang/cargo#11317) - Only remove fingerprints and build script artifacts of the requested package (rust-lang/cargo#10621) - Newer anyhow features are required (rust-lang/cargo#11316) - Clean stale git temp files (rust-lang/cargo#11308) - Report crate size on package and publish (rust-lang/cargo#11270) - add a note that some warnings (and/or errors) can be auto-fixed (rust-lang/cargo#10989) - Update libcurl (rust-lang/cargo#11307) - artifact deps shoud works when target field specified coexists with `optional = true` (rust-lang/cargo#11183) - Fix singular verb in tests page (rust-lang/cargo#11300)
Update cargo 14 commits in 7e484fc1a766f56dbc95380f45719698e0c82749..810cbad9a123ad4ee0a55a96171b8f8478ff1c03 2022-10-27 15:20:57 +0000 to 2022-11-02 21:04:31 +0000 - Update curl-sys (rust-lang/cargo#11326) - Mention fix on build script deadlock (rust-lang/cargo#11325) - Make cargo forward pre-existing CARGO if set (rust-lang/cargo#11285) - Clean up workspace dependencies after cargo remove (rust-lang/cargo#11242) - Update the outdated link for rust-semverver (rust-lang/cargo#11322) - Fix broken link to compilation entry point (rust-lang/cargo#11317) - Only remove fingerprints and build script artifacts of the requested package (rust-lang/cargo#10621) - Newer anyhow features are required (rust-lang/cargo#11316) - Clean stale git temp files (rust-lang/cargo#11308) - Report crate size on package and publish (rust-lang/cargo#11270) - add a note that some warnings (and/or errors) can be auto-fixed (rust-lang/cargo#10989) - Update libcurl (rust-lang/cargo#11307) - artifact deps shoud works when target field specified coexists with `optional = true` (rust-lang/cargo#11183) - Fix singular verb in tests page (rust-lang/cargo#11300) r? `@ghost`
20 commits in 7e484fc1a766f56dbc95380f45719698e0c82749..9286a1beba5b28b115bad67de2ae91fb1c61eb0b 2022-10-27 15:20:57 +0000 to 2022-11-04 06:41:49 +0000 - chore: Upgrade dependencies (rust-lang/cargo#11328) - Clean more aggressively in CI (rust-lang/cargo#11335) - Remove remove_dir_all (rust-lang/cargo#11333) - test(publish): Cover more wait-for-publish cases (rust-lang/cargo#11327) - Revert rust-lang/cargo#11183 (rust-lang/cargo#11331) - fix(semver-check): adapt to a different error for variant not covered (rust-lang/cargo#11332) - Update curl-sys (rust-lang/cargo#11326) - Mention fix on build script deadlock (rust-lang/cargo#11325) - Make cargo forward pre-existing CARGO if set (rust-lang/cargo#11285) - Clean up workspace dependencies after cargo remove (rust-lang/cargo#11242) - Update the outdated link for rust-semverver (rust-lang/cargo#11322) - Fix broken link to compilation entry point (rust-lang/cargo#11317) - Only remove fingerprints and build script artifacts of the requested package (rust-lang/cargo#10621) - Newer anyhow features are required (rust-lang/cargo#11316) - Clean stale git temp files (rust-lang/cargo#11308) - Report crate size on package and publish (rust-lang/cargo#11270) - add a note that some warnings (and/or errors) can be auto-fixed (rust-lang/cargo#10989) - Update libcurl (rust-lang/cargo#11307) - artifact deps shoud works when target field specified coexists with `optional = true` (rust-lang/cargo#11183) - Fix singular verb in tests page (rust-lang/cargo#11300)
Update cargo 20 commits in 7e484fc1a766f56dbc95380f45719698e0c82749..9286a1beba5b28b115bad67de2ae91fb1c61eb0b 2022-10-27 15:20:57 +0000 to 2022-11-04 06:41:49 +0000 - chore: Upgrade dependencies (rust-lang/cargo#11328) - Clean more aggressively in CI (rust-lang/cargo#11335) - Remove remove_dir_all (rust-lang/cargo#11333) - test(publish): Cover more wait-for-publish cases (rust-lang/cargo#11327) - Revert rust-lang/cargo#11183 (rust-lang/cargo#11331) - fix(semver-check): adapt to a different error for variant not covered (rust-lang/cargo#11332) - Update curl-sys (rust-lang/cargo#11326) - Mention fix on build script deadlock (rust-lang/cargo#11325) - Make cargo forward pre-existing CARGO if set (rust-lang/cargo#11285) - Clean up workspace dependencies after cargo remove (rust-lang/cargo#11242) - Update the outdated link for rust-semverver (rust-lang/cargo#11322) - Fix broken link to compilation entry point (rust-lang/cargo#11317) - Only remove fingerprints and build script artifacts of the requested package (rust-lang/cargo#10621) - Newer anyhow features are required (rust-lang/cargo#11316) - Clean stale git temp files (rust-lang/cargo#11308) - Report crate size on package and publish (rust-lang/cargo#11270) - add a note that some warnings (and/or errors) can be auto-fixed (rust-lang/cargo#10989) - Update libcurl (rust-lang/cargo#11307) - artifact deps shoud works when target field specified coexists with `optional = true` (rust-lang/cargo#11183) - Fix singular verb in tests page (rust-lang/cargo#11300) r? `@ghost`
Should we backport this to 1.66 beta? |
Bah, we didn't make the cut off? We also have #11194 which is almost done. Probably a topic for the next team meeting of whether
If we are fine with these behavior changes after 1.66 (which I think I am fine with), I lean towards letting them go into 1.67. I tend to treat the bar for backports as high but am open to where others set the bar. |
We discussed the options in the meeting, and I think we are comfortable with just continuing with this and #11194 landing in the next release. I think the impact should be small, and is unlikely to be a significant problem for users. That is:
|
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.