From ea27ec1f96f60dd2a4fbf92e01737921237758ea Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 16 Apr 2024 12:08:57 -0500 Subject: [PATCH 1/3] docs: Clarify why we aren't printing Locking in some cases --- src/cargo/ops/resolve.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index 89b719c0491..41e789a0163 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -252,6 +252,10 @@ fn resolve_with_registry<'gctx>( let print = if !ws.is_ephemeral() && ws.require_optional_deps() { ops::write_pkg_lockfile(ws, &mut resolve)? } else { + // This mostly represents + // - `cargo install --locked` and the only change is the package is no longer local but + // from the registry which is noise + // - publish of libraries false }; if print { From c38673c66553e101dc05cd353577ce1759f50836 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 16 Apr 2024 12:28:27 -0500 Subject: [PATCH 2/3] refactor(resolve): Make it easier to customize around the resolve call --- src/cargo/ops/resolve.rs | 56 ++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index 41e789a0163..f937c31824f 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -134,15 +134,26 @@ pub fn resolve_ws_with_opts<'gctx>( force_all_targets: ForceAllTargets, ) -> CargoResult> { let mut registry = PackageRegistry::new(ws.gctx())?; - let mut add_patches = true; - let resolve = if ws.ignore_lock() { - None + let (resolve, resolved_with_overrides) = if ws.ignore_lock() { + let add_patches = true; + let resolve = None; + let resolved_with_overrides = resolve_with_previous( + &mut registry, + ws, + cli_features, + has_dev_units, + resolve.as_ref(), + None, + specs, + add_patches, + )?; + (resolve, resolved_with_overrides) } else if ws.require_optional_deps() { // First, resolve the root_package's *listed* dependencies, as well as // downloading and updating all remotes and such. let resolve = resolve_with_registry(ws, &mut registry)?; // No need to add patches again, `resolve_with_registry` has done it. - add_patches = false; + let add_patches = false; // Second, resolve with precisely what we're doing. Filter out // transitive dependencies if necessary, specify features, handle @@ -170,22 +181,33 @@ pub fn resolve_ws_with_opts<'gctx>( } } - Some(resolve) + let resolved_with_overrides = resolve_with_previous( + &mut registry, + ws, + cli_features, + has_dev_units, + Some(&resolve), + None, + specs, + add_patches, + )?; + (Some(resolve), resolved_with_overrides) } else { - ops::load_pkg_lockfile(ws)? + let add_patches = true; + let resolve = ops::load_pkg_lockfile(ws)?; + let resolved_with_overrides = resolve_with_previous( + &mut registry, + ws, + cli_features, + has_dev_units, + resolve.as_ref(), + None, + specs, + add_patches, + )?; + (resolve, resolved_with_overrides) }; - let resolved_with_overrides = resolve_with_previous( - &mut registry, - ws, - cli_features, - has_dev_units, - resolve.as_ref(), - None, - specs, - add_patches, - )?; - let pkg_set = get_resolved_packages(&resolved_with_overrides, registry)?; let member_ids = ws From 1d0c6ebd8feba1903807dfbc0b224deb60f62b9f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 16 Apr 2024 13:35:25 -0500 Subject: [PATCH 3/3] feat(install): Including Locking message As we switch to MSRV-aware resolver, this will help users work out why MSRV-aware resolving isn't helping them. This will also make it more obvious if we breaking things when developing the MSRV-aware resolver. --- src/cargo/ops/resolve.rs | 3 +++ tests/testsuite/directory.rs | 2 ++ tests/testsuite/install.rs | 3 +++ tests/testsuite/publish_lockfile.rs | 1 + tests/testsuite/required_features.rs | 1 + 5 files changed, 10 insertions(+) diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index f937c31824f..286649dc8df 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -147,6 +147,7 @@ pub fn resolve_ws_with_opts<'gctx>( specs, add_patches, )?; + ops::print_lockfile_changes(ws, None, &resolved_with_overrides, &mut registry)?; (resolve, resolved_with_overrides) } else if ws.require_optional_deps() { // First, resolve the root_package's *listed* dependencies, as well as @@ -205,6 +206,8 @@ pub fn resolve_ws_with_opts<'gctx>( specs, add_patches, )?; + // Skipping `print_lockfile_changes` as there are cases where this prints irrelevant + // information (resolve, resolved_with_overrides) }; diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 1ba7677bc63..3af475a358a 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -148,6 +148,7 @@ fn simple_install() { .with_stderr( "\ [INSTALLING] bar v0.1.0 +[LOCKING] 2 packages to latest compatible versions [COMPILING] foo v0.0.1 [COMPILING] bar v0.1.0 [FINISHED] `release` profile [optimized] target(s) in [..]s @@ -243,6 +244,7 @@ fn install_without_feature_dep() { .with_stderr( "\ [INSTALLING] bar v0.1.0 +[LOCKING] 2 packages to latest compatible versions [COMPILING] foo v0.0.1 [COMPILING] bar v0.1.0 [FINISHED] `release` profile [optimized] target(s) in [..]s diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index ec7bfe7bd9a..89d40ada954 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -2410,6 +2410,8 @@ fn self_referential() { [DOWNLOADING] crates ... [DOWNLOADED] foo v0.0.2 (registry [..]) [INSTALLING] foo v0.0.2 +[LOCKING] 2 packages to latest compatible versions +[ADDING] foo v0.0.1 (latest: v0.0.2) [DOWNLOADING] crates ... [DOWNLOADED] foo v0.0.1 (registry [..]) [COMPILING] foo v0.0.1 @@ -2455,6 +2457,7 @@ fn ambiguous_registry_vs_local_package() { "\ [INSTALLING] foo v0.1.0 ([..]) [UPDATING] `[..]` index +[LOCKING] 2 packages to latest compatible versions [DOWNLOADING] crates ... [DOWNLOADED] foo v0.0.1 (registry [..]) [COMPILING] foo v0.0.1 diff --git a/tests/testsuite/publish_lockfile.rs b/tests/testsuite/publish_lockfile.rs index 64455fd3cd1..19c783aaab5 100644 --- a/tests/testsuite/publish_lockfile.rs +++ b/tests/testsuite/publish_lockfile.rs @@ -415,6 +415,7 @@ dependencies = [ "\ [UPDATING] `[..]` index [INSTALLING] foo v0.1.0 +[LOCKING] 2 packages to latest compatible versions [DOWNLOADING] crates ... [DOWNLOADED] bar v0.1.1 (registry `[..]`) [COMPILING] bar v0.1.1 diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index 76c9cd0bc4d..f192be50d40 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -1129,6 +1129,7 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"` .with_stderr( "\ [INSTALLING] foo v0.0.1 ([..]) +[LOCKING] 2 packages to latest compatible versions [FINISHED] `release` profile [optimized] target(s) in [..] [WARNING] none of the package's binaries are available for install using the selected features bin \"foo\" requires the features: `bar/a`