Skip to content

Commit 3a9b59f

Browse files
committed
Auto merge of #13764 - epage:install-lock, r=ehuss
feat(install): Including Locking message ### What does this PR try to resolve? This extends #13561 to include `cargo install`, like #13759 did for `cargo update`. 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. ### How should we test and review this PR? ### Additional information This still leaves `cargo publish` and a couple other misc situations that I'm intentionally avoiding because - They hit some weird cases that can confuse the user (e.g. causing `cargo install --locked` to show that 1 package is being added) and we can't distinguish these cases too well from where this is happening - The value is lower
2 parents 6f06fe9 + 1d0c6eb commit 3a9b59f

File tree

5 files changed

+53
-17
lines changed

5 files changed

+53
-17
lines changed

src/cargo/ops/resolve.rs

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,27 @@ pub fn resolve_ws_with_opts<'gctx>(
134134
force_all_targets: ForceAllTargets,
135135
) -> CargoResult<WorkspaceResolve<'gctx>> {
136136
let mut registry = PackageRegistry::new(ws.gctx())?;
137-
let mut add_patches = true;
138-
let resolve = if ws.ignore_lock() {
139-
None
137+
let (resolve, resolved_with_overrides) = if ws.ignore_lock() {
138+
let add_patches = true;
139+
let resolve = None;
140+
let resolved_with_overrides = resolve_with_previous(
141+
&mut registry,
142+
ws,
143+
cli_features,
144+
has_dev_units,
145+
resolve.as_ref(),
146+
None,
147+
specs,
148+
add_patches,
149+
)?;
150+
ops::print_lockfile_changes(ws, None, &resolved_with_overrides, &mut registry)?;
151+
(resolve, resolved_with_overrides)
140152
} else if ws.require_optional_deps() {
141153
// First, resolve the root_package's *listed* dependencies, as well as
142154
// downloading and updating all remotes and such.
143155
let resolve = resolve_with_registry(ws, &mut registry)?;
144156
// No need to add patches again, `resolve_with_registry` has done it.
145-
add_patches = false;
157+
let add_patches = false;
146158

147159
// Second, resolve with precisely what we're doing. Filter out
148160
// transitive dependencies if necessary, specify features, handle
@@ -170,22 +182,35 @@ pub fn resolve_ws_with_opts<'gctx>(
170182
}
171183
}
172184

173-
Some(resolve)
185+
let resolved_with_overrides = resolve_with_previous(
186+
&mut registry,
187+
ws,
188+
cli_features,
189+
has_dev_units,
190+
Some(&resolve),
191+
None,
192+
specs,
193+
add_patches,
194+
)?;
195+
(Some(resolve), resolved_with_overrides)
174196
} else {
175-
ops::load_pkg_lockfile(ws)?
197+
let add_patches = true;
198+
let resolve = ops::load_pkg_lockfile(ws)?;
199+
let resolved_with_overrides = resolve_with_previous(
200+
&mut registry,
201+
ws,
202+
cli_features,
203+
has_dev_units,
204+
resolve.as_ref(),
205+
None,
206+
specs,
207+
add_patches,
208+
)?;
209+
// Skipping `print_lockfile_changes` as there are cases where this prints irrelevant
210+
// information
211+
(resolve, resolved_with_overrides)
176212
};
177213

178-
let resolved_with_overrides = resolve_with_previous(
179-
&mut registry,
180-
ws,
181-
cli_features,
182-
has_dev_units,
183-
resolve.as_ref(),
184-
None,
185-
specs,
186-
add_patches,
187-
)?;
188-
189214
let pkg_set = get_resolved_packages(&resolved_with_overrides, registry)?;
190215

191216
let member_ids = ws
@@ -252,6 +277,10 @@ fn resolve_with_registry<'gctx>(
252277
let print = if !ws.is_ephemeral() && ws.require_optional_deps() {
253278
ops::write_pkg_lockfile(ws, &mut resolve)?
254279
} else {
280+
// This mostly represents
281+
// - `cargo install --locked` and the only change is the package is no longer local but
282+
// from the registry which is noise
283+
// - publish of libraries
255284
false
256285
};
257286
if print {

tests/testsuite/directory.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ fn simple_install() {
148148
.with_stderr(
149149
"\
150150
[INSTALLING] bar v0.1.0
151+
[LOCKING] 2 packages to latest compatible versions
151152
[COMPILING] foo v0.0.1
152153
[COMPILING] bar v0.1.0
153154
[FINISHED] `release` profile [optimized] target(s) in [..]s
@@ -243,6 +244,7 @@ fn install_without_feature_dep() {
243244
.with_stderr(
244245
"\
245246
[INSTALLING] bar v0.1.0
247+
[LOCKING] 2 packages to latest compatible versions
246248
[COMPILING] foo v0.0.1
247249
[COMPILING] bar v0.1.0
248250
[FINISHED] `release` profile [optimized] target(s) in [..]s

tests/testsuite/install.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,6 +2410,8 @@ fn self_referential() {
24102410
[DOWNLOADING] crates ...
24112411
[DOWNLOADED] foo v0.0.2 (registry [..])
24122412
[INSTALLING] foo v0.0.2
2413+
[LOCKING] 2 packages to latest compatible versions
2414+
[ADDING] foo v0.0.1 (latest: v0.0.2)
24132415
[DOWNLOADING] crates ...
24142416
[DOWNLOADED] foo v0.0.1 (registry [..])
24152417
[COMPILING] foo v0.0.1
@@ -2455,6 +2457,7 @@ fn ambiguous_registry_vs_local_package() {
24552457
"\
24562458
[INSTALLING] foo v0.1.0 ([..])
24572459
[UPDATING] `[..]` index
2460+
[LOCKING] 2 packages to latest compatible versions
24582461
[DOWNLOADING] crates ...
24592462
[DOWNLOADED] foo v0.0.1 (registry [..])
24602463
[COMPILING] foo v0.0.1

tests/testsuite/publish_lockfile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ dependencies = [
415415
"\
416416
[UPDATING] `[..]` index
417417
[INSTALLING] foo v0.1.0
418+
[LOCKING] 2 packages to latest compatible versions
418419
[DOWNLOADING] crates ...
419420
[DOWNLOADED] bar v0.1.1 (registry `[..]`)
420421
[COMPILING] bar v0.1.1

tests/testsuite/required_features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"`
11291129
.with_stderr(
11301130
"\
11311131
[INSTALLING] foo v0.0.1 ([..])
1132+
[LOCKING] 2 packages to latest compatible versions
11321133
[FINISHED] `release` profile [optimized] target(s) in [..]
11331134
[WARNING] none of the package's binaries are available for install using the selected features
11341135
bin \"foo\" requires the features: `bar/a`

0 commit comments

Comments
 (0)