Skip to content

Commit

Permalink
Auto merge of #14445 - epage:locked, r=weihanglo
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Aug 26, 2024
2 parents f2d1e37 + d2ec764 commit ef854d2
Show file tree
Hide file tree
Showing 177 changed files with 610 additions and 686 deletions.
48 changes: 36 additions & 12 deletions src/cargo/ops/cargo_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,21 @@ fn print_lockfile_generation(
resolve: &Resolve,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<()> {
let changes = PackageChange::new(resolve);
let num_pkgs: usize = changes.iter().filter(|change| change.kind.is_new()).count();
if num_pkgs <= 1 {
// just ourself, nothing worth reporting
let changes = PackageChange::new(ws, resolve);
let num_pkgs: usize = changes
.iter()
.filter(|change| change.kind.is_new() && !change.is_member.unwrap_or(false))
.count();
if num_pkgs == 0 {
// nothing worth reporting
return Ok(());
}
status_locking(ws, num_pkgs)?;

for change in changes {
if change.is_member.unwrap_or(false) {
continue;
};
match change.kind {
PackageChangeKind::Added => {
let possibilities = if let Some(query) = change.alternatives_query() {
Expand Down Expand Up @@ -547,14 +553,21 @@ fn print_lockfile_sync(
resolve: &Resolve,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<()> {
let changes = PackageChange::diff(previous_resolve, resolve);
let num_pkgs: usize = changes.iter().filter(|change| change.kind.is_new()).count();
let changes = PackageChange::diff(ws, previous_resolve, resolve);
let num_pkgs: usize = changes
.iter()
.filter(|change| change.kind.is_new() && !change.is_member.unwrap_or(false))
.count();
if num_pkgs == 0 {
// nothing worth reporting
return Ok(());
}
status_locking(ws, num_pkgs)?;

for change in changes {
if change.is_member.unwrap_or(false) {
continue;
};
match change.kind {
PackageChangeKind::Added
| PackageChangeKind::Upgraded
Expand Down Expand Up @@ -597,7 +610,7 @@ fn print_lockfile_updates(
precise: bool,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<()> {
let changes = PackageChange::diff(previous_resolve, resolve);
let changes = PackageChange::diff(ws, previous_resolve, resolve);
let num_pkgs: usize = changes.iter().filter(|change| change.kind.is_new()).count();
if !precise {
status_locking(ws, num_pkgs)?;
Expand Down Expand Up @@ -787,20 +800,23 @@ struct PackageChange {
package_id: PackageId,
previous_id: Option<PackageId>,
kind: PackageChangeKind,
is_member: Option<bool>,
}

impl PackageChange {
pub fn new(resolve: &Resolve) -> Vec<Self> {
pub fn new(ws: &Workspace<'_>, resolve: &Resolve) -> Vec<Self> {
let diff = PackageDiff::new(resolve);
Self::with_diff(diff)
Self::with_diff(diff, ws)
}

pub fn diff(previous_resolve: &Resolve, resolve: &Resolve) -> Vec<Self> {
pub fn diff(ws: &Workspace<'_>, previous_resolve: &Resolve, resolve: &Resolve) -> Vec<Self> {
let diff = PackageDiff::diff(previous_resolve, resolve);
Self::with_diff(diff)
Self::with_diff(diff, ws)
}

fn with_diff(diff: impl Iterator<Item = PackageDiff>) -> Vec<Self> {
fn with_diff(diff: impl Iterator<Item = PackageDiff>, ws: &Workspace<'_>) -> Vec<Self> {
let member_ids: HashSet<_> = ws.members().map(|p| p.package_id()).collect();

let mut changes = IndexMap::new();
for diff in diff {
if let Some((previous_id, package_id)) = diff.change() {
Expand All @@ -815,38 +831,46 @@ impl PackageChange {
} else {
PackageChangeKind::Upgraded
};
let is_member = Some(member_ids.contains(&package_id));
let change = Self {
package_id,
previous_id: Some(previous_id),
kind,
is_member,
};
changes.insert(change.package_id, change);
} else {
for package_id in diff.removed {
let kind = PackageChangeKind::Removed;
let is_member = None;
let change = Self {
package_id,
previous_id: None,
kind,
is_member,
};
changes.insert(change.package_id, change);
}
for package_id in diff.added {
let kind = PackageChangeKind::Added;
let is_member = Some(member_ids.contains(&package_id));
let change = Self {
package_id,
previous_id: None,
kind,
is_member,
};
changes.insert(change.package_id, change);
}
}
for package_id in diff.unchanged {
let kind = PackageChangeKind::Unchanged;
let is_member = Some(member_ids.contains(&package_id));
let change = Self {
package_id,
previous_id: None,
kind,
is_member,
};
changes.insert(change.package_id, change);
}
Expand Down
18 changes: 9 additions & 9 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn depend_on_alt_registry() {
p.cargo("check")
.with_stderr_data(str![[r#"
[UPDATING] `alternative` index
[LOCKING] 2 packages to latest compatible versions
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
[CHECKING] bar v0.0.1 (registry `alternative`)
Expand Down Expand Up @@ -88,7 +88,7 @@ fn depend_on_alt_registry_depends_on_same_registry_no_index() {
p.cargo("check")
.with_stderr_data(str![[r#"
[UPDATING] `alternative` index
[LOCKING] 3 packages to latest compatible versions
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] baz v0.0.1 (registry `alternative`)
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
Expand Down Expand Up @@ -131,7 +131,7 @@ fn depend_on_alt_registry_depends_on_same_registry() {
p.cargo("check")
.with_stderr_data(str![[r#"
[UPDATING] `alternative` index
[LOCKING] 3 packages to latest compatible versions
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] baz v0.0.1 (registry `alternative`)
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
Expand Down Expand Up @@ -176,7 +176,7 @@ fn depend_on_alt_registry_depends_on_crates_io() {
str![[r#"
[UPDATING] `alternative` index
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] baz v0.0.1 (registry `dummy-registry`)
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
Expand Down Expand Up @@ -217,7 +217,7 @@ fn registry_and_path_dep_works() {

p.cargo("check")
.with_stderr_data(str![[r#"
[LOCKING] 2 packages to latest compatible versions
[LOCKING] 1 package to latest compatible version
[CHECKING] bar v0.0.1 ([ROOT]/foo/bar)
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
Expand Down Expand Up @@ -435,7 +435,7 @@ fn alt_registry_and_crates_io_deps() {
str![[r#"
[UPDATING] `alternative` index
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages to latest compatible versions
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] crates_io_dep v0.0.1 (registry `dummy-registry`)
[DOWNLOADED] alt_reg_dep v0.1.0 (registry `alternative`)
Expand Down Expand Up @@ -710,7 +710,7 @@ fn patch_alt_reg() {
p.cargo("check")
.with_stderr_data(str![[r#"
[UPDATING] `alternative` index
[LOCKING] 2 packages to latest compatible versions
[LOCKING] 1 package to latest compatible version
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
Expand Down Expand Up @@ -804,7 +804,7 @@ fn no_api() {
p.cargo("check")
.with_stderr_data(str![[r#"
[UPDATING] `alternative` index
[LOCKING] 2 packages to latest compatible versions
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
[CHECKING] bar v0.0.1 (registry `alternative`)
Expand Down Expand Up @@ -1657,7 +1657,7 @@ fn registries_index_relative_url() {
p.cargo("check")
.with_stderr_data(str![[r#"
[UPDATING] `relative` index
[LOCKING] 2 packages to latest compatible versions
[LOCKING] 1 package to latest compatible version
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.0.1 (registry `relative`)
[CHECKING] bar v0.0.1 (registry `relative`)
Expand Down
Loading

0 comments on commit ef854d2

Please sign in to comment.