Skip to content

Commit

Permalink
feat(resolve): Tell the user the style of resovle done
Browse files Browse the repository at this point in the history
This is to help with #9930

Example changes:
```diff
-[LOCKING] 4 packages
+[LOCKING] 4 packages to latest version
-[LOCKING] 2 packages
+[LOCKING] 2 packages to latest Rust 1.60.0 compatible versions
-[LOCKING] 2 packages
+[LOCKING] 2 packages to earliest versions
```

Benefits
- The package count is of "added" packages and this makes that more
  logically clear
- This gives users transparency into what is happening, especially with
  - what rust-version is use
  - the transition to this feature in the new edition
  - whether the planned config was applied or not (as I don't want it to
    require an MSRV bump)
- Will make it easier in tests to show what changed
- Provides more motiviation to show this message in `cargo update` and
  `cargo install` (that will be explored in a follow up PR)

This does come at the cost of more verbose output but hopefully not too
verbose.  This is why I left off other factors, like avoid-dev-deps.
  • Loading branch information
epage committed Apr 14, 2024
1 parent 2ff60a5 commit 05ce775
Show file tree
Hide file tree
Showing 164 changed files with 540 additions and 514 deletions.
28 changes: 27 additions & 1 deletion src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,36 @@ fn print_lockfile_updates(
}

fn status_locking(ws: &Workspace<'_>, num_pkgs: usize) -> CargoResult<()> {
use std::fmt::Write as _;

let plural = if num_pkgs == 1 { "" } else { "s" };

let mut cfg = String::new();
// Don't have a good way to describe `direct_minimal_versions` atm
if !ws.gctx().cli_unstable().direct_minimal_versions {
write!(&mut cfg, " to")?;
if ws.gctx().cli_unstable().minimal_versions {
write!(&mut cfg, " earliest")?;
} else {
write!(&mut cfg, " latest")?;
}

if ws.resolve_honors_rust_version() {
let rust_version = if let Some(ver) = ws.rust_version() {
ver.clone().into_partial()
} else {
let rustc = ws.gctx().load_global_rustc(Some(ws))?;
let rustc_version = rustc.version.clone().into();
rustc_version
};
write!(&mut cfg, " Rust {rust_version}")?;
}
write!(&mut cfg, " compatible version{plural}")?;
}

ws.gctx()
.shell()
.status("Locking", format!("{num_pkgs} package{plural}"))?;
.status("Locking", format!("{num_pkgs} package{plural}{cfg}"))?;
Ok(())
}

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 @@ -33,7 +33,7 @@ fn depend_on_alt_registry() {
.with_stderr(
"\
[UPDATING] `alternative` index
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[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() {
.with_stderr(
"\
[UPDATING] `alternative` index
[LOCKING] 3 packages
[LOCKING] 3 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] [..] v0.0.1 (registry `alternative`)
[DOWNLOADED] [..] v0.0.1 (registry `alternative`)
Expand Down Expand Up @@ -132,7 +132,7 @@ fn depend_on_alt_registry_depends_on_same_registry() {
.with_stderr(
"\
[UPDATING] `alternative` index
[LOCKING] 3 packages
[LOCKING] 3 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] [..] v0.0.1 (registry `alternative`)
[DOWNLOADED] [..] v0.0.1 (registry `alternative`)
Expand Down Expand Up @@ -177,7 +177,7 @@ fn depend_on_alt_registry_depends_on_crates_io() {
"\
[UPDATING] `alternative` index
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages
[LOCKING] 3 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(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[CHECKING] bar v0.0.1 ([CWD]/bar)
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
Expand Down Expand Up @@ -421,7 +421,7 @@ fn alt_registry_and_crates_io_deps() {
"\
[UPDATING] `alternative` index
[UPDATING] `dummy-registry` index
[LOCKING] 3 packages
[LOCKING] 3 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 @@ -698,7 +698,7 @@ fn patch_alt_reg() {
.with_stderr(
"\
[UPDATING] `alternative` index
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[CHECKING] bar v0.1.0 ([CWD]/bar)
[CHECKING] foo v0.0.1 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -791,7 +791,7 @@ fn no_api() {
.with_stderr(
"\
[UPDATING] `alternative` index
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
[CHECKING] bar v0.0.1 (registry `alternative`)
Expand Down Expand Up @@ -1354,7 +1354,7 @@ fn registries_index_relative_url() {
.with_stderr(
"\
[UPDATING] `relative` index
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[DOWNLOADING] crates ...
[DOWNLOADED] bar v0.0.1 (registry `relative`)
[CHECKING] bar v0.0.1 (registry `relative`)
Expand Down
40 changes: 20 additions & 20 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn disallow_artifact_and_no_artifact_dep_to_same_package_within_the_same_dep_cat
.masquerade_as_nightly_cargo(&["bindeps"])
.with_status(101)
.with_stderr("\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[WARNING] foo v0.0.0 ([CWD]) ignoring invalid dependency `bar_stable` which is missing a lib target
[ERROR] the crate `foo v0.0.0 ([CWD])` depends on crate `bar v0.5.0 ([CWD]/bar)` multiple times with different names",
)
Expand Down Expand Up @@ -323,7 +323,7 @@ fn features_are_unified_among_lib_and_bin_dep_of_same_target() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 3 packages
[LOCKING] 3 packages to latest compatible versions
[COMPILING] d2 v0.0.1 ([CWD]/d2)
[COMPILING] d1 v0.0.1 ([CWD]/d1)
[COMPILING] foo v0.0.1 ([CWD])
Expand Down Expand Up @@ -775,7 +775,7 @@ fn build_script_with_selected_dashed_bin_artifact_and_lib_true() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar-baz v0.5.0 ([CWD]/bar)
[COMPILING] foo [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]",
Expand Down Expand Up @@ -877,7 +877,7 @@ fn lib_with_selected_dashed_bin_artifact_and_lib_true() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar-baz v0.5.0 ([CWD]/bar)
[COMPILING] foo [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]",
Expand Down Expand Up @@ -998,7 +998,7 @@ fn disallow_using_example_binaries_as_artifacts() {
.with_status(101)
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[ERROR] dependency `bar` in package `foo` requires a `bin:one-example` artifact to be present.",
)
.run();
Expand Down Expand Up @@ -1169,7 +1169,7 @@ fn build_script_deps_adopt_do_not_allow_multiple_targets_under_different_name_an
.with_status(101)
.with_stderr(format!(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
error: the crate `foo v0.0.0 ([CWD])` depends on crate `bar v0.5.0 ([CWD]/bar)` multiple times with different names",
))
.run();
Expand Down Expand Up @@ -1274,7 +1274,7 @@ fn no_cross_doctests_works_with_artifacts() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(&format!(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar v0.5.0 ([CWD]/bar)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -1757,7 +1757,7 @@ fn allow_artifact_and_non_artifact_dependency_to_same_crate_if_these_are_not_the
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar [..]
[COMPILING] foo [..]
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -1794,7 +1794,7 @@ fn prevent_no_lib_warning_with_artifact_dependencies() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages\n\
[LOCKING] 2 packages to latest compatible versions\n\
[COMPILING] bar v0.5.0 ([CWD]/bar)\n\
[CHECKING] foo v0.0.0 ([CWD])\n\
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]",
Expand Down Expand Up @@ -1895,7 +1895,7 @@ fn check_missing_crate_type_in_package_fails() {
.with_status(101)
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[ERROR] dependency `bar` in package `foo` requires a `[..]` artifact to be present.",
)
.run();
Expand Down Expand Up @@ -2042,7 +2042,7 @@ fn env_vars_and_build_products_for_various_build_targets() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar [..]
[COMPILING] foo [..]
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -2219,7 +2219,7 @@ fn doc_lib_true() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar v0.0.1 ([CWD]/bar)
[DOCUMENTING] bar v0.0.1 ([CWD]/bar)
[DOCUMENTING] foo v0.0.1 ([CWD])
Expand Down Expand Up @@ -2302,7 +2302,7 @@ fn rustdoc_works_on_libs_with_artifacts_and_lib_false() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar v0.5.0 ([CWD]/bar)
[DOCUMENTING] foo v0.0.1 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -2510,7 +2510,7 @@ fn calc_bin_artifact_fingerprint() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar v0.5.0 ([CWD]/bar)
[CHECKING] foo v0.1.0 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -2592,7 +2592,7 @@ fn with_target_and_optional() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] d1 v0.0.1 [..]
[RUNNING] `rustc --crate-name d1 [..]--crate-type bin[..]
[CHECKING] foo v0.0.1 [..]
Expand Down Expand Up @@ -2642,7 +2642,7 @@ fn with_assumed_host_target_and_optional_build_dep() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_unordered(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] foo v0.0.1 ([CWD])
[COMPILING] d1 v0.0.1 ([CWD]/d1)
[RUNNING] `rustc --crate-name build_script_build --edition=2021 [..]--crate-type bin[..]
Expand Down Expand Up @@ -2770,7 +2770,7 @@ fn decouple_same_target_transitive_dep_from_artifact_dep() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 5 packages
[LOCKING] 5 packages to latest compatible versions
[COMPILING] c v0.1.0 ([CWD]/c)
[COMPILING] b v0.1.0 ([CWD]/b)
[COMPILING] a v0.1.0 ([CWD]/a)
Expand Down Expand Up @@ -2874,7 +2874,7 @@ fn decouple_same_target_transitive_dep_from_artifact_dep_lib() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 4 packages
[LOCKING] 4 packages to latest compatible versions
[COMPILING] b v0.1.0 ([CWD]/b)
[COMPILING] a v0.1.0 ([CWD]/a)
[COMPILING] bar v0.1.0 ([CWD]/bar)
Expand Down Expand Up @@ -3001,7 +3001,7 @@ fn decouple_same_target_transitive_dep_from_artifact_dep_and_proc_macro() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_unordered(
"\
[LOCKING] 6 packages
[LOCKING] 6 packages to latest compatible versions
[COMPILING] d v0.1.0 ([CWD]/d)
[COMPILING] a v0.1.0 ([CWD]/a)
[COMPILING] b v0.1.0 ([CWD]/b)
Expand Down Expand Up @@ -3067,7 +3067,7 @@ fn same_target_artifact_dep_sharing() {
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr(
"\
[LOCKING] 3 packages
[LOCKING] 3 packages to latest compatible versions
[COMPILING] a v0.1.0 ([CWD]/a)
[COMPILING] bar v0.1.0 ([CWD]/bar)
[COMPILING] foo v0.1.0 ([CWD])
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ fn bench_with_deep_lib_dep() {
p.cargo("bench")
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] foo v0.0.1 ([..])
[COMPILING] bar v0.0.1 ([CWD])
[FINISHED] `bench` profile [optimized] target(s) in [..]
Expand Down Expand Up @@ -904,7 +904,7 @@ fn bench_dylib() {
p.cargo("bench -v")
.with_stderr(
"\
[LOCKING] 2 packages
[LOCKING] 2 packages to latest compatible versions
[COMPILING] bar v0.0.1 ([CWD]/bar)
[RUNNING] [..] -C opt-level=3 [..]
[COMPILING] foo v0.0.1 ([CWD])
Expand Down
Loading

0 comments on commit 05ce775

Please sign in to comment.