Skip to content

Commit ef854d2

Browse files
committed
Auto merge of #14445 - epage:locked, r=weihanglo
fix(resolve): Dont show locking workspace members ### What does this PR try to resolve? This is for `cargo generate-lockfile` and when syncing the lockfile with the manifest. We still show it for `cargo update` because of `cargo update --workspace`. We hacked around this previously by filtering out the `num_pkgs==1` case for single packages but this didn't help with workspaces. ### How should we test and review this PR? ### Additional information This builds on #14440
2 parents f2d1e37 + d2ec764 commit ef854d2

File tree

177 files changed

+610
-686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+610
-686
lines changed

src/cargo/ops/cargo_update.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,21 @@ fn print_lockfile_generation(
492492
resolve: &Resolve,
493493
registry: &mut PackageRegistry<'_>,
494494
) -> CargoResult<()> {
495-
let changes = PackageChange::new(resolve);
496-
let num_pkgs: usize = changes.iter().filter(|change| change.kind.is_new()).count();
497-
if num_pkgs <= 1 {
498-
// just ourself, nothing worth reporting
495+
let changes = PackageChange::new(ws, resolve);
496+
let num_pkgs: usize = changes
497+
.iter()
498+
.filter(|change| change.kind.is_new() && !change.is_member.unwrap_or(false))
499+
.count();
500+
if num_pkgs == 0 {
501+
// nothing worth reporting
499502
return Ok(());
500503
}
501504
status_locking(ws, num_pkgs)?;
502505

503506
for change in changes {
507+
if change.is_member.unwrap_or(false) {
508+
continue;
509+
};
504510
match change.kind {
505511
PackageChangeKind::Added => {
506512
let possibilities = if let Some(query) = change.alternatives_query() {
@@ -547,14 +553,21 @@ fn print_lockfile_sync(
547553
resolve: &Resolve,
548554
registry: &mut PackageRegistry<'_>,
549555
) -> CargoResult<()> {
550-
let changes = PackageChange::diff(previous_resolve, resolve);
551-
let num_pkgs: usize = changes.iter().filter(|change| change.kind.is_new()).count();
556+
let changes = PackageChange::diff(ws, previous_resolve, resolve);
557+
let num_pkgs: usize = changes
558+
.iter()
559+
.filter(|change| change.kind.is_new() && !change.is_member.unwrap_or(false))
560+
.count();
552561
if num_pkgs == 0 {
562+
// nothing worth reporting
553563
return Ok(());
554564
}
555565
status_locking(ws, num_pkgs)?;
556566

557567
for change in changes {
568+
if change.is_member.unwrap_or(false) {
569+
continue;
570+
};
558571
match change.kind {
559572
PackageChangeKind::Added
560573
| PackageChangeKind::Upgraded
@@ -597,7 +610,7 @@ fn print_lockfile_updates(
597610
precise: bool,
598611
registry: &mut PackageRegistry<'_>,
599612
) -> CargoResult<()> {
600-
let changes = PackageChange::diff(previous_resolve, resolve);
613+
let changes = PackageChange::diff(ws, previous_resolve, resolve);
601614
let num_pkgs: usize = changes.iter().filter(|change| change.kind.is_new()).count();
602615
if !precise {
603616
status_locking(ws, num_pkgs)?;
@@ -787,20 +800,23 @@ struct PackageChange {
787800
package_id: PackageId,
788801
previous_id: Option<PackageId>,
789802
kind: PackageChangeKind,
803+
is_member: Option<bool>,
790804
}
791805

792806
impl PackageChange {
793-
pub fn new(resolve: &Resolve) -> Vec<Self> {
807+
pub fn new(ws: &Workspace<'_>, resolve: &Resolve) -> Vec<Self> {
794808
let diff = PackageDiff::new(resolve);
795-
Self::with_diff(diff)
809+
Self::with_diff(diff, ws)
796810
}
797811

798-
pub fn diff(previous_resolve: &Resolve, resolve: &Resolve) -> Vec<Self> {
812+
pub fn diff(ws: &Workspace<'_>, previous_resolve: &Resolve, resolve: &Resolve) -> Vec<Self> {
799813
let diff = PackageDiff::diff(previous_resolve, resolve);
800-
Self::with_diff(diff)
814+
Self::with_diff(diff, ws)
801815
}
802816

803-
fn with_diff(diff: impl Iterator<Item = PackageDiff>) -> Vec<Self> {
817+
fn with_diff(diff: impl Iterator<Item = PackageDiff>, ws: &Workspace<'_>) -> Vec<Self> {
818+
let member_ids: HashSet<_> = ws.members().map(|p| p.package_id()).collect();
819+
804820
let mut changes = IndexMap::new();
805821
for diff in diff {
806822
if let Some((previous_id, package_id)) = diff.change() {
@@ -815,38 +831,46 @@ impl PackageChange {
815831
} else {
816832
PackageChangeKind::Upgraded
817833
};
834+
let is_member = Some(member_ids.contains(&package_id));
818835
let change = Self {
819836
package_id,
820837
previous_id: Some(previous_id),
821838
kind,
839+
is_member,
822840
};
823841
changes.insert(change.package_id, change);
824842
} else {
825843
for package_id in diff.removed {
826844
let kind = PackageChangeKind::Removed;
845+
let is_member = None;
827846
let change = Self {
828847
package_id,
829848
previous_id: None,
830849
kind,
850+
is_member,
831851
};
832852
changes.insert(change.package_id, change);
833853
}
834854
for package_id in diff.added {
835855
let kind = PackageChangeKind::Added;
856+
let is_member = Some(member_ids.contains(&package_id));
836857
let change = Self {
837858
package_id,
838859
previous_id: None,
839860
kind,
861+
is_member,
840862
};
841863
changes.insert(change.package_id, change);
842864
}
843865
}
844866
for package_id in diff.unchanged {
845867
let kind = PackageChangeKind::Unchanged;
868+
let is_member = Some(member_ids.contains(&package_id));
846869
let change = Self {
847870
package_id,
848871
previous_id: None,
849872
kind,
873+
is_member,
850874
};
851875
changes.insert(change.package_id, change);
852876
}

tests/testsuite/alt_registry.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn depend_on_alt_registry() {
3535
p.cargo("check")
3636
.with_stderr_data(str![[r#"
3737
[UPDATING] `alternative` index
38-
[LOCKING] 2 packages to latest compatible versions
38+
[LOCKING] 1 package to latest compatible version
3939
[DOWNLOADING] crates ...
4040
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
4141
[CHECKING] bar v0.0.1 (registry `alternative`)
@@ -88,7 +88,7 @@ fn depend_on_alt_registry_depends_on_same_registry_no_index() {
8888
p.cargo("check")
8989
.with_stderr_data(str![[r#"
9090
[UPDATING] `alternative` index
91-
[LOCKING] 3 packages to latest compatible versions
91+
[LOCKING] 2 packages to latest compatible versions
9292
[DOWNLOADING] crates ...
9393
[DOWNLOADED] baz v0.0.1 (registry `alternative`)
9494
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
@@ -131,7 +131,7 @@ fn depend_on_alt_registry_depends_on_same_registry() {
131131
p.cargo("check")
132132
.with_stderr_data(str![[r#"
133133
[UPDATING] `alternative` index
134-
[LOCKING] 3 packages to latest compatible versions
134+
[LOCKING] 2 packages to latest compatible versions
135135
[DOWNLOADING] crates ...
136136
[DOWNLOADED] baz v0.0.1 (registry `alternative`)
137137
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
@@ -176,7 +176,7 @@ fn depend_on_alt_registry_depends_on_crates_io() {
176176
str![[r#"
177177
[UPDATING] `alternative` index
178178
[UPDATING] `dummy-registry` index
179-
[LOCKING] 3 packages to latest compatible versions
179+
[LOCKING] 2 packages to latest compatible versions
180180
[DOWNLOADING] crates ...
181181
[DOWNLOADED] baz v0.0.1 (registry `dummy-registry`)
182182
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
@@ -217,7 +217,7 @@ fn registry_and_path_dep_works() {
217217

218218
p.cargo("check")
219219
.with_stderr_data(str![[r#"
220-
[LOCKING] 2 packages to latest compatible versions
220+
[LOCKING] 1 package to latest compatible version
221221
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
222222
[CHECKING] foo v0.0.1 ([ROOT]/foo)
223223
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -435,7 +435,7 @@ fn alt_registry_and_crates_io_deps() {
435435
str![[r#"
436436
[UPDATING] `alternative` index
437437
[UPDATING] `dummy-registry` index
438-
[LOCKING] 3 packages to latest compatible versions
438+
[LOCKING] 2 packages to latest compatible versions
439439
[DOWNLOADING] crates ...
440440
[DOWNLOADED] crates_io_dep v0.0.1 (registry `dummy-registry`)
441441
[DOWNLOADED] alt_reg_dep v0.1.0 (registry `alternative`)
@@ -710,7 +710,7 @@ fn patch_alt_reg() {
710710
p.cargo("check")
711711
.with_stderr_data(str![[r#"
712712
[UPDATING] `alternative` index
713-
[LOCKING] 2 packages to latest compatible versions
713+
[LOCKING] 1 package to latest compatible version
714714
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
715715
[CHECKING] foo v0.0.1 ([ROOT]/foo)
716716
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -804,7 +804,7 @@ fn no_api() {
804804
p.cargo("check")
805805
.with_stderr_data(str![[r#"
806806
[UPDATING] `alternative` index
807-
[LOCKING] 2 packages to latest compatible versions
807+
[LOCKING] 1 package to latest compatible version
808808
[DOWNLOADING] crates ...
809809
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
810810
[CHECKING] bar v0.0.1 (registry `alternative`)
@@ -1657,7 +1657,7 @@ fn registries_index_relative_url() {
16571657
p.cargo("check")
16581658
.with_stderr_data(str![[r#"
16591659
[UPDATING] `relative` index
1660-
[LOCKING] 2 packages to latest compatible versions
1660+
[LOCKING] 1 package to latest compatible version
16611661
[DOWNLOADING] crates ...
16621662
[DOWNLOADED] bar v0.0.1 (registry `relative`)
16631663
[CHECKING] bar v0.0.1 (registry `relative`)

0 commit comments

Comments
 (0)