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(install): Including Locking message #13764

Merged
merged 3 commits into from
Apr 17, 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
63 changes: 46 additions & 17 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,27 @@ pub fn resolve_ws_with_opts<'gctx>(
force_all_targets: ForceAllTargets,
) -> CargoResult<WorkspaceResolve<'gctx>> {
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,
)?;
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
// 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
Expand Down Expand Up @@ -170,22 +182,35 @@ 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,
)?;
// Skipping `print_lockfile_changes` as there are cases where this prints irrelevant
// information
(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
Expand Down Expand Up @@ -252,6 +277,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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/publish_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/required_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down