Auto merge of #13759 - epage:more-lock, r=weihanglo

feat(update): Include a Locking message

### What does this PR try to resolve?

This extends #13561 to `cargo update`.  I previously left it out because the locking message was redundant.  However the `Locking` message has been extended in #13754 to include the resolving policy which can be a useful point of interest (e.g. "why does `cargo update` do nothing? Oh, `-Zminimal-versions` is enabled").

I still left out the message for `--precise` because the user is overriding all of that.

I'd still like to extend all of this to `cargo install` (and maybe all resolves) but that is taking more investigation.

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

### Additional information
This commit is contained in:
bors 2024-04-16 02:35:06 +00:00
commit b9d913e532
11 changed files with 94 additions and 20 deletions

View File

@ -170,7 +170,13 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
true,
)?;
print_lockfile_updates(ws, &previous_resolve, &resolve, &mut registry)?;
print_lockfile_updates(
ws,
&previous_resolve,
&resolve,
opts.precise.is_some(),
&mut registry,
)?;
if opts.dry_run {
opts.gctx
.shell()
@ -356,10 +362,17 @@ fn print_lockfile_updates(
ws: &Workspace<'_>,
previous_resolve: &Resolve,
resolve: &Resolve,
precise: bool,
registry: &mut PackageRegistry<'_>,
) -> CargoResult<()> {
let diff = PackageDiff::diff(&previous_resolve, &resolve);
let num_pkgs: usize = diff.iter().map(|d| d.added.len()).sum();
if !precise {
status_locking(ws, num_pkgs)?;
}
let mut unchanged_behind = 0;
for diff in PackageDiff::diff(&previous_resolve, &resolve) {
for diff in diff {
fn format_latest(version: semver::Version) -> String {
let warn = style::WARN;
format!(" {warn}(latest: v{version}){warn:#}")

View File

@ -1590,6 +1590,7 @@ fn index_version_filtering() {
.with_stderr(
"\
[UPDATING] [..]
[LOCKING] 2 packages to latest compatible versions
[ADDING] artifact v1.0.0
[UPDATING] bar v1.0.0 -> v1.0.1",
)

View File

@ -616,7 +616,10 @@ fn recompilation() {
p.cargo("update")
.with_stderr(&format!(
"[UPDATING] git repository `{}`",
"\
[UPDATING] git repository `{}`
[LOCKING] 0 packages to latest compatible versions
",
git_project.url()
))
.run();
@ -636,9 +639,11 @@ fn recompilation() {
// Update the dependency and carry on!
p.cargo("update")
.with_stderr(&format!(
"[UPDATING] git repository `{}`\n\
[UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
",
"\
[UPDATING] git repository `{}`
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.5.0 ([..]) -> #[..]
",
git_project.url()
))
.run();
@ -766,6 +771,7 @@ fn update_with_shared_deps() {
.with_stderr(
"\
[UPDATING] git repository [..]
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.5.0 [..]
",
)
@ -791,16 +797,21 @@ Caused by:
println!("bar precise update");
p.cargo("update bar --precise")
.arg(&old_head.to_string())
.with_stderr("[UPDATING] bar v0.5.0 [..]")
.with_stderr(
"\
[UPDATING] bar v0.5.0 [..]",
)
.run();
// Updating recursively should, however, update the repo.
println!("dep1 recursive update");
p.cargo("update dep1 --recursive")
.with_stderr(&format!(
"[UPDATING] git repository `{}`\n\
[UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
",
"\
[UPDATING] git repository `{}`
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.5.0 ([..]) -> #[..]
",
git_project.url()
))
.run();
@ -822,7 +833,10 @@ Caused by:
// We should be able to update transitive deps
p.cargo("update bar")
.with_stderr(&format!(
"[UPDATING] git repository `{}`",
"\
[UPDATING] git repository `{}`
[LOCKING] 0 packages to latest compatible versions
",
git_project.url()
))
.run();
@ -1223,9 +1237,11 @@ fn two_deps_only_update_one() {
p.cargo("update dep1")
.with_stderr(&format!(
"[UPDATING] git repository `{}`\n\
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
",
"\
[UPDATING] git repository `{}`
[LOCKING] 1 package to latest compatible version
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]
",
git1.url()
))
.run();
@ -1411,10 +1427,12 @@ fn dep_with_changed_submodule() {
p.cargo("update")
.with_stderr("")
.with_stderr(&format!(
"[UPDATING] git repository `{}`\n\
[UPDATING] git submodule `file://[..]/dep3`\n\
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
",
"\
[UPDATING] git repository `{}`
[UPDATING] git submodule `file://[..]/dep3`
[LOCKING] 1 package to latest compatible version
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]
",
git_project.url()
))
.run();
@ -1993,7 +2011,13 @@ fn update_one_dep_in_repo_with_many_deps() {
p.cargo("generate-lockfile").run();
p.cargo("update bar")
.with_stderr(&format!("[UPDATING] git repository `{}`", bar.url()))
.with_stderr(&format!(
"\
[UPDATING] git repository `{}`
[LOCKING] 0 packages to latest compatible versions
",
bar.url()
))
.run();
}

View File

@ -1481,6 +1481,7 @@ fn clean_max_git_age() {
.with_stderr(
"\
[UPDATING] git repository [..]
[LOCKING] 1 package to latest compatible version
[UPDATING] git_a v1.0.0 [..]
",
)
@ -1562,6 +1563,7 @@ fn clean_max_src_crate_age() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v1.0.0 -> v1.0.1
",
)

View File

@ -190,7 +190,11 @@ fn multiple_versions() {
.publish();
p.cargo("update")
.with_stderr("[UPDATING] bar v0.1.0 -> v0.2.0")
.with_stderr(
"\
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.1.0 -> v0.2.0",
)
.run();
}

View File

@ -725,6 +725,7 @@ fn main(){
.with_status(0)
.with_stderr(
"\
[LOCKING] 1 package to latest compatible version
[UPDATING] present_dep v1.2.3 -> v1.2.9
",
)

View File

@ -2061,6 +2061,7 @@ fn update_unused_new_version() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[ADDING] bar v0.1.6 ([..]/bar)
[REMOVING] bar v0.1.5
",
@ -2073,6 +2074,7 @@ fn update_unused_new_version() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[ADDING] bar v0.1.6 ([..]/bar)
[REMOVING] bar v0.1.5
",
@ -2542,6 +2544,7 @@ fn can_update_with_alt_reg() {
"\
[UPDATING] `alternative` index
[UPDATING] `dummy-registry` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
)

View File

@ -833,6 +833,7 @@ required by package `foo v0.0.1 ([..])`
.with_stderr_contains(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] baz v0.0.1 -> v0.0.2
",
)
@ -1018,6 +1019,7 @@ fn update_lockfile() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.0.2 -> v0.0.3
",
)
@ -1043,6 +1045,7 @@ fn update_lockfile() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
[UPDATING] bar v0.0.3 -> v0.0.4
[ADDING] spam v0.2.5
",
@ -1055,6 +1058,7 @@ fn update_lockfile() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.0.4 -> v0.0.5
[REMOVING] spam v0.2.5
",
@ -1493,6 +1497,7 @@ fn update_transitive_dependency() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] b v0.1.0 -> v0.1.1
",
)
@ -1565,6 +1570,7 @@ fn update_backtracking_ok() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
[UPDATING] hyper v0.6.5 -> v0.6.6
[UPDATING] openssl v0.1.0 -> v0.1.1
",
@ -1617,6 +1623,7 @@ fn update_multiple_packages() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
[UPDATING] a v0.1.0 -> v0.1.1
[UPDATING] b v0.1.0 -> v0.1.1
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
@ -1628,6 +1635,7 @@ fn update_multiple_packages() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] c v0.1.0 -> v0.1.1
",
)

View File

@ -560,6 +560,7 @@ fn override_adds_some_deps() {
"\
[UPDATING] git repository `file://[..]`
[UPDATING] `dummy-registry` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
)
@ -568,6 +569,7 @@ fn override_adds_some_deps() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
)
@ -901,6 +903,7 @@ fn update() {
"\
[UPDATING] `[..]` index
[UPDATING] git repository `[..]`
[LOCKING] 0 packages to latest compatible versions
",
)
.run();

View File

@ -670,6 +670,7 @@ See https://github.com/rust-lang/cargo/issues/9930 for more information about th
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v1.5.0 -> v1.6.0
",
)

View File

@ -114,6 +114,7 @@ fn transitive_minor_update() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 2 unchanged dependencies behind latest
",
)
@ -167,6 +168,7 @@ fn conservative() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] serde v0.1.0 -> v0.1.1
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
@ -579,6 +581,7 @@ fn update_recursive() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
[UPDATING] log v0.1.0 -> v0.1.1
[UPDATING] serde v0.2.1 -> v0.2.2
",
@ -617,6 +620,7 @@ fn update_aggressive_alias_for_recursive() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 2 packages to latest compatible versions
[UPDATING] log v0.1.0 -> v0.1.1
[UPDATING] serde v0.2.1 -> v0.2.2
",
@ -926,6 +930,7 @@ fn dry_run_update() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] serde v0.1.0 -> v0.1.1
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
[WARNING] not updating lockfile due to dry run
@ -1126,6 +1131,7 @@ rustdns.workspace = true
p.cargo("update -p rootcrate")
.with_stderr(&format!(
"\
[LOCKING] 2 packages to latest compatible versions
[UPDATING] rootcrate v2.29.8 ([CWD]/rootcrate) -> v2.29.81
[UPDATING] subcrate v2.29.8 ([CWD]/subcrate) -> v2.29.81",
))
@ -1217,6 +1223,7 @@ rustdns.workspace = true
p.cargo("update -p crate2")
.with_stderr(&format!(
"\
[LOCKING] 2 packages to latest compatible versions
[UPDATING] crate1 v2.29.8 ([CWD]/crate1) -> v2.29.81
[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81",
))
@ -1308,6 +1315,7 @@ rustdns.workspace = true
p.cargo("update --workspace")
.with_stderr(
"\
[LOCKING] 2 packages to latest compatible versions
[UPDATING] crate1 v2.29.8 ([CWD]/crate1) -> v2.29.81
[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81",
)
@ -1553,6 +1561,7 @@ fn report_behind() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[UPDATING] breaking v0.1.0 -> v0.1.1 (latest: v0.2.0)
[NOTE] pass `--verbose` to see 2 unchanged dependencies behind latest
[WARNING] not updating lockfile due to dry run
@ -1564,6 +1573,7 @@ fn report_behind() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 1 package to latest compatible version
[UPDATING] breaking v0.1.0 -> v0.1.1 (latest: v0.2.0)
[UNCHANGED] pre v1.0.0-alpha.0 (latest: v1.0.0-alpha.1)
[UNCHANGED] two-ver v0.1.0 (latest: v0.2.0)
@ -1579,6 +1589,7 @@ fn report_behind() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 3 unchanged dependencies behind latest
[WARNING] not updating lockfile due to dry run
",
@ -1589,6 +1600,7 @@ fn report_behind() {
.with_stderr(
"\
[UPDATING] `dummy-registry` index
[LOCKING] 0 packages to latest compatible versions
[UNCHANGED] breaking v0.1.1 (latest: v0.2.0)
[UNCHANGED] pre v1.0.0-alpha.0 (latest: v1.0.0-alpha.1)
[UNCHANGED] two-ver v0.1.0 (latest: v0.2.0)
@ -1629,6 +1641,7 @@ fn update_with_missing_feature() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 0 packages to latest compatible versions
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
",
)
@ -1640,6 +1653,7 @@ fn update_with_missing_feature() {
.with_stderr(
"\
[UPDATING] `[..]` index
[LOCKING] 1 package to latest compatible version
[UPDATING] bar v0.1.0 -> v0.1.2
",
)