Skip to content
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

feat(update): Include a Locking message #13759

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/cargo/ops/cargo_generate_lockfile.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which can be a useful point of interest (e.g. "why does cargo update do nothing? Oh, -Zminimal-versions is enabled").

I can't connect the current locking message to this. It basically prints zero without any explanation. How does it help user figure out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will print

[LOCKING] 0 packages to earliest compatible versions

minimal versions, in its current form, is an odd example as its on the command line. When MSRV becomes the default, it will be "holding things back" and we want to give the users hints as to why it might be.

Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:#}")
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
58 changes: 41 additions & 17 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
weihanglo marked this conversation as resolved.
Show resolved Hide resolved
",
git_project.url()
))
.run();
Expand All @@ -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();
Expand Down Expand Up @@ -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 [..]
",
)
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/global_cache_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [..]
",
)
Expand Down Expand Up @@ -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
",
)
Expand Down
6 changes: 5 additions & 1 deletion tests/testsuite/local_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
",
)
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
",
Expand All @@ -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
",
Expand Down Expand Up @@ -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
",
)
Expand Down
8 changes: 8 additions & 0 deletions tests/testsuite/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
",
)
Expand Down Expand Up @@ -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
",
)
Expand All @@ -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
",
Expand All @@ -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
",
Expand Down Expand Up @@ -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
",
)
Expand Down Expand Up @@ -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
",
Expand Down Expand Up @@ -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
Expand All @@ -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
",
)
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
",
)
Expand All @@ -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
",
)
Expand Down Expand Up @@ -901,6 +903,7 @@ fn update() {
"\
[UPDATING] `[..]` index
[UPDATING] git repository `[..]`
[LOCKING] 0 packages to latest compatible versions
",
)
.run();
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/rust_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
",
)
Expand Down
Loading