Skip to content

Commit b9d913e

Browse files
committed
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
2 parents add150c + bec36fc commit b9d913e

11 files changed

+94
-20
lines changed

src/cargo/ops/cargo_generate_lockfile.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
170170
true,
171171
)?;
172172

173-
print_lockfile_updates(ws, &previous_resolve, &resolve, &mut registry)?;
173+
print_lockfile_updates(
174+
ws,
175+
&previous_resolve,
176+
&resolve,
177+
opts.precise.is_some(),
178+
&mut registry,
179+
)?;
174180
if opts.dry_run {
175181
opts.gctx
176182
.shell()
@@ -356,10 +362,17 @@ fn print_lockfile_updates(
356362
ws: &Workspace<'_>,
357363
previous_resolve: &Resolve,
358364
resolve: &Resolve,
365+
precise: bool,
359366
registry: &mut PackageRegistry<'_>,
360367
) -> CargoResult<()> {
368+
let diff = PackageDiff::diff(&previous_resolve, &resolve);
369+
let num_pkgs: usize = diff.iter().map(|d| d.added.len()).sum();
370+
if !precise {
371+
status_locking(ws, num_pkgs)?;
372+
}
373+
361374
let mut unchanged_behind = 0;
362-
for diff in PackageDiff::diff(&previous_resolve, &resolve) {
375+
for diff in diff {
363376
fn format_latest(version: semver::Version) -> String {
364377
let warn = style::WARN;
365378
format!(" {warn}(latest: v{version}){warn:#}")

tests/testsuite/artifact_dep.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,7 @@ fn index_version_filtering() {
15901590
.with_stderr(
15911591
"\
15921592
[UPDATING] [..]
1593+
[LOCKING] 2 packages to latest compatible versions
15931594
[ADDING] artifact v1.0.0
15941595
[UPDATING] bar v1.0.0 -> v1.0.1",
15951596
)

tests/testsuite/git.rs

+41-17
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,10 @@ fn recompilation() {
616616

617617
p.cargo("update")
618618
.with_stderr(&format!(
619-
"[UPDATING] git repository `{}`",
619+
"\
620+
[UPDATING] git repository `{}`
621+
[LOCKING] 0 packages to latest compatible versions
622+
",
620623
git_project.url()
621624
))
622625
.run();
@@ -636,9 +639,11 @@ fn recompilation() {
636639
// Update the dependency and carry on!
637640
p.cargo("update")
638641
.with_stderr(&format!(
639-
"[UPDATING] git repository `{}`\n\
640-
[UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
641-
",
642+
"\
643+
[UPDATING] git repository `{}`
644+
[LOCKING] 1 package to latest compatible version
645+
[UPDATING] bar v0.5.0 ([..]) -> #[..]
646+
",
642647
git_project.url()
643648
))
644649
.run();
@@ -766,6 +771,7 @@ fn update_with_shared_deps() {
766771
.with_stderr(
767772
"\
768773
[UPDATING] git repository [..]
774+
[LOCKING] 1 package to latest compatible version
769775
[UPDATING] bar v0.5.0 [..]
770776
",
771777
)
@@ -791,16 +797,21 @@ Caused by:
791797
println!("bar precise update");
792798
p.cargo("update bar --precise")
793799
.arg(&old_head.to_string())
794-
.with_stderr("[UPDATING] bar v0.5.0 [..]")
800+
.with_stderr(
801+
"\
802+
[UPDATING] bar v0.5.0 [..]",
803+
)
795804
.run();
796805

797806
// Updating recursively should, however, update the repo.
798807
println!("dep1 recursive update");
799808
p.cargo("update dep1 --recursive")
800809
.with_stderr(&format!(
801-
"[UPDATING] git repository `{}`\n\
802-
[UPDATING] bar v0.5.0 ([..]) -> #[..]\n\
803-
",
810+
"\
811+
[UPDATING] git repository `{}`
812+
[LOCKING] 1 package to latest compatible version
813+
[UPDATING] bar v0.5.0 ([..]) -> #[..]
814+
",
804815
git_project.url()
805816
))
806817
.run();
@@ -822,7 +833,10 @@ Caused by:
822833
// We should be able to update transitive deps
823834
p.cargo("update bar")
824835
.with_stderr(&format!(
825-
"[UPDATING] git repository `{}`",
836+
"\
837+
[UPDATING] git repository `{}`
838+
[LOCKING] 0 packages to latest compatible versions
839+
",
826840
git_project.url()
827841
))
828842
.run();
@@ -1223,9 +1237,11 @@ fn two_deps_only_update_one() {
12231237

12241238
p.cargo("update dep1")
12251239
.with_stderr(&format!(
1226-
"[UPDATING] git repository `{}`\n\
1227-
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
1228-
",
1240+
"\
1241+
[UPDATING] git repository `{}`
1242+
[LOCKING] 1 package to latest compatible version
1243+
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]
1244+
",
12291245
git1.url()
12301246
))
12311247
.run();
@@ -1411,10 +1427,12 @@ fn dep_with_changed_submodule() {
14111427
p.cargo("update")
14121428
.with_stderr("")
14131429
.with_stderr(&format!(
1414-
"[UPDATING] git repository `{}`\n\
1415-
[UPDATING] git submodule `file://[..]/dep3`\n\
1416-
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]\n\
1417-
",
1430+
"\
1431+
[UPDATING] git repository `{}`
1432+
[UPDATING] git submodule `file://[..]/dep3`
1433+
[LOCKING] 1 package to latest compatible version
1434+
[UPDATING] dep1 v0.5.0 ([..]) -> #[..]
1435+
",
14181436
git_project.url()
14191437
))
14201438
.run();
@@ -1993,7 +2011,13 @@ fn update_one_dep_in_repo_with_many_deps() {
19932011

19942012
p.cargo("generate-lockfile").run();
19952013
p.cargo("update bar")
1996-
.with_stderr(&format!("[UPDATING] git repository `{}`", bar.url()))
2014+
.with_stderr(&format!(
2015+
"\
2016+
[UPDATING] git repository `{}`
2017+
[LOCKING] 0 packages to latest compatible versions
2018+
",
2019+
bar.url()
2020+
))
19972021
.run();
19982022
}
19992023

tests/testsuite/global_cache_tracker.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,7 @@ fn clean_max_git_age() {
14811481
.with_stderr(
14821482
"\
14831483
[UPDATING] git repository [..]
1484+
[LOCKING] 1 package to latest compatible version
14841485
[UPDATING] git_a v1.0.0 [..]
14851486
",
14861487
)
@@ -1562,6 +1563,7 @@ fn clean_max_src_crate_age() {
15621563
.with_stderr(
15631564
"\
15641565
[UPDATING] `dummy-registry` index
1566+
[LOCKING] 1 package to latest compatible version
15651567
[UPDATING] bar v1.0.0 -> v1.0.1
15661568
",
15671569
)

tests/testsuite/local_registry.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ fn multiple_versions() {
190190
.publish();
191191

192192
p.cargo("update")
193-
.with_stderr("[UPDATING] bar v0.1.0 -> v0.2.0")
193+
.with_stderr(
194+
"\
195+
[LOCKING] 1 package to latest compatible version
196+
[UPDATING] bar v0.1.0 -> v0.2.0",
197+
)
194198
.run();
195199
}
196200

tests/testsuite/offline.rs

+1
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ fn main(){
725725
.with_status(0)
726726
.with_stderr(
727727
"\
728+
[LOCKING] 1 package to latest compatible version
728729
[UPDATING] present_dep v1.2.3 -> v1.2.9
729730
",
730731
)

tests/testsuite/patch.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ fn update_unused_new_version() {
20612061
.with_stderr(
20622062
"\
20632063
[UPDATING] `dummy-registry` index
2064+
[LOCKING] 1 package to latest compatible version
20642065
[ADDING] bar v0.1.6 ([..]/bar)
20652066
[REMOVING] bar v0.1.5
20662067
",
@@ -2073,6 +2074,7 @@ fn update_unused_new_version() {
20732074
.with_stderr(
20742075
"\
20752076
[UPDATING] `dummy-registry` index
2077+
[LOCKING] 1 package to latest compatible version
20762078
[ADDING] bar v0.1.6 ([..]/bar)
20772079
[REMOVING] bar v0.1.5
20782080
",
@@ -2542,6 +2544,7 @@ fn can_update_with_alt_reg() {
25422544
"\
25432545
[UPDATING] `alternative` index
25442546
[UPDATING] `dummy-registry` index
2547+
[LOCKING] 0 packages to latest compatible versions
25452548
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
25462549
",
25472550
)

tests/testsuite/registry.rs

+8
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ required by package `foo v0.0.1 ([..])`
833833
.with_stderr_contains(
834834
"\
835835
[UPDATING] `[..]` index
836+
[LOCKING] 1 package to latest compatible version
836837
[UPDATING] baz v0.0.1 -> v0.0.2
837838
",
838839
)
@@ -1018,6 +1019,7 @@ fn update_lockfile() {
10181019
.with_stderr(
10191020
"\
10201021
[UPDATING] `[..]` index
1022+
[LOCKING] 1 package to latest compatible version
10211023
[UPDATING] bar v0.0.2 -> v0.0.3
10221024
",
10231025
)
@@ -1043,6 +1045,7 @@ fn update_lockfile() {
10431045
.with_stderr(
10441046
"\
10451047
[UPDATING] `[..]` index
1048+
[LOCKING] 2 packages to latest compatible versions
10461049
[UPDATING] bar v0.0.3 -> v0.0.4
10471050
[ADDING] spam v0.2.5
10481051
",
@@ -1055,6 +1058,7 @@ fn update_lockfile() {
10551058
.with_stderr(
10561059
"\
10571060
[UPDATING] `[..]` index
1061+
[LOCKING] 1 package to latest compatible version
10581062
[UPDATING] bar v0.0.4 -> v0.0.5
10591063
[REMOVING] spam v0.2.5
10601064
",
@@ -1493,6 +1497,7 @@ fn update_transitive_dependency() {
14931497
.with_stderr(
14941498
"\
14951499
[UPDATING] `[..]` index
1500+
[LOCKING] 1 package to latest compatible version
14961501
[UPDATING] b v0.1.0 -> v0.1.1
14971502
",
14981503
)
@@ -1565,6 +1570,7 @@ fn update_backtracking_ok() {
15651570
.with_stderr(
15661571
"\
15671572
[UPDATING] `[..]` index
1573+
[LOCKING] 2 packages to latest compatible versions
15681574
[UPDATING] hyper v0.6.5 -> v0.6.6
15691575
[UPDATING] openssl v0.1.0 -> v0.1.1
15701576
",
@@ -1617,6 +1623,7 @@ fn update_multiple_packages() {
16171623
.with_stderr(
16181624
"\
16191625
[UPDATING] `[..]` index
1626+
[LOCKING] 2 packages to latest compatible versions
16201627
[UPDATING] a v0.1.0 -> v0.1.1
16211628
[UPDATING] b v0.1.0 -> v0.1.1
16221629
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
@@ -1628,6 +1635,7 @@ fn update_multiple_packages() {
16281635
.with_stderr(
16291636
"\
16301637
[UPDATING] `[..]` index
1638+
[LOCKING] 1 package to latest compatible version
16311639
[UPDATING] c v0.1.0 -> v0.1.1
16321640
",
16331641
)

tests/testsuite/replace.rs

+3
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ fn override_adds_some_deps() {
560560
"\
561561
[UPDATING] git repository `file://[..]`
562562
[UPDATING] `dummy-registry` index
563+
[LOCKING] 0 packages to latest compatible versions
563564
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
564565
",
565566
)
@@ -568,6 +569,7 @@ fn override_adds_some_deps() {
568569
.with_stderr(
569570
"\
570571
[UPDATING] `dummy-registry` index
572+
[LOCKING] 0 packages to latest compatible versions
571573
[NOTE] pass `--verbose` to see 1 unchanged dependencies behind latest
572574
",
573575
)
@@ -901,6 +903,7 @@ fn update() {
901903
"\
902904
[UPDATING] `[..]` index
903905
[UPDATING] git repository `[..]`
906+
[LOCKING] 0 packages to latest compatible versions
904907
",
905908
)
906909
.run();

tests/testsuite/rust_version.rs

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

0 commit comments

Comments
 (0)