Skip to content

Commit b65e6bf

Browse files
authored
fix(install): Ignore resolver.lockfile-path (#16823)
### What does this PR try to resolve? `[resolver]` was designed to not apply to `cargo install`, so `resolver.lockfile-path` shouldn't apply to `cargo install` also. ### How to test and review this PR? This basically reverts the last of bf37cf7
2 parents 1511866 + 973696d commit b65e6bf

3 files changed

Lines changed: 16 additions & 59 deletions

File tree

src/cargo/ops/cargo_install.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,11 @@ impl<'gctx> InstallablePackage<'gctx> {
219219

220220
let (ws, rustc, target) =
221221
make_ws_rustc_target(gctx, &original_opts, &source_id, pkg.clone())?;
222-
223-
if !gctx.lock_update_allowed() {
224-
// When --lockfile-path is set, check that passed lock file exists
225-
// (unlike the usual flag behavior, lockfile won't be created as we imply --locked)
226-
if let Some(requested_lockfile_path) = ws.requested_lockfile_path() {
227-
if !requested_lockfile_path.is_file() {
228-
bail!(
229-
"no Cargo.lock file found in the requested path {}",
230-
requested_lockfile_path.display()
231-
);
232-
}
233-
// If we're installing in --locked mode and there's no `Cargo.lock` published
234-
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
235-
} else if !ws.root().join("Cargo.lock").exists() {
236-
gctx.shell()
237-
.warn(format!("no Cargo.lock file published in {}", pkg))?;
238-
}
222+
// If we're installing in --locked mode and there's no `Cargo.lock` published
223+
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
224+
if !gctx.lock_update_allowed() && !ws.root().join("Cargo.lock").exists() {
225+
gctx.shell()
226+
.warn(format!("no Cargo.lock file published in {}", pkg))?;
239227
}
240228
let pkg = if source_id.is_git() {
241229
// Don't use ws.current() in order to keep the package source as a git source so that
@@ -941,6 +929,7 @@ fn make_ws_rustc_target<'gctx>(
941929
};
942930
ws.set_resolve_feature_unification(FeatureUnification::Selected);
943931
ws.set_ignore_lock(gctx.lock_update_allowed());
932+
ws.set_requested_lockfile_path(None);
944933
ws.set_require_optional_deps(false);
945934

946935
let rustc = gctx.load_global_rustc(Some(&ws))?;

src/doc/src/reference/unstable.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,10 @@ lockfiles should be stored in different directories.
17861786

17871787
*as a new `resolver.lockfile-path` entry in config.md*
17881788

1789+
*Keep in mind, the `[resolver]` section has this clarification:*
1790+
1791+
> *The `[resolver]` table overrides dependency resolution behavior for local development (e.g. excludes `cargo install`).*
1792+
17891793
#### `resolver.lockfile-path`
17901794

17911795
* Type: string (path)

tests/testsuite/lockfile_path.rs

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,12 @@ bar = "0.1.0"
352352
}
353353

354354
#[cargo_test]
355-
fn config_install_respects_lock_file_path() {
356-
// `cargo install` will imply --locked when lockfile path is provided
357-
Package::new("bar", "0.1.0").publish();
358-
Package::new("bar", "0.1.1")
355+
fn config_install_ignores_lock_file_path() {
356+
Package::new("bar", "0.1.0")
359357
.file("src/lib.rs", "not rust")
360358
.publish();
361-
// Publish with lockfile containing bad version of `bar` (0.1.1)
359+
Package::new("bar", "0.1.1").publish();
360+
// Publish with lockfile containing good version of `bar` (0.1.1)
362361
Package::new("foo", "0.1.0")
363362
.dep("bar", "0.1")
364363
.file("src/lib.rs", "")
@@ -386,16 +385,9 @@ dependencies = [
386385

387386
let p = project().at("install").build();
388387

389-
p.cargo("install foo --locked")
390-
.with_stderr_data(str![[r#"
391-
...
392-
[..]not rust[..]
393-
...
394-
"#]])
395-
.with_status(101)
396-
.run();
388+
p.cargo("install foo --locked").run();
397389

398-
// Create lockfile with the good `bar` version (0.1.0) and use it for install
390+
// Create lockfile with the bad `bar` version (0.1.0) and see it ignored for install
399391
project()
400392
.file(
401393
"Cargo.lock",
@@ -424,34 +416,6 @@ dependencies = [
424416
assert_has_installed_exe(paths::cargo_home(), "foo");
425417
}
426418

427-
#[cargo_test]
428-
fn config_install_lock_file_path_must_present() {
429-
// `cargo install` will imply --locked when lockfile path is provided
430-
Package::new("bar", "0.1.0").publish();
431-
Package::new("foo", "0.1.0")
432-
.dep("bar", "0.1")
433-
.file("src/lib.rs", "")
434-
.file(
435-
"src/main.rs",
436-
"extern crate foo; extern crate bar; fn main() {}",
437-
)
438-
.publish();
439-
440-
let p = project().at("install").build();
441-
442-
p.cargo("install foo --locked -Zlockfile-path")
443-
.masquerade_as_nightly_cargo(&["lockfile-path"])
444-
.arg("--config")
445-
.arg("resolver.lockfile-path='../lockfile_dir/Cargo.lock'")
446-
.with_stderr_data(str![[r#"
447-
...
448-
[ERROR] no Cargo.lock file found in the requested path [ROOT]/install/../lockfile_dir/Cargo.lock
449-
...
450-
"#]])
451-
.with_status(101)
452-
.run();
453-
}
454-
455419
#[cargo_test(nightly, reason = "-Zscript is unstable")]
456420
fn config_run_embed() {
457421
let lockfile_path = "mylockfile/Cargo.lock";

0 commit comments

Comments
 (0)