Skip to content
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
23 changes: 6 additions & 17 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,11 @@ impl<'gctx> InstallablePackage<'gctx> {

let (ws, rustc, target) =
make_ws_rustc_target(gctx, &original_opts, &source_id, pkg.clone())?;

if !gctx.lock_update_allowed() {
// When --lockfile-path is set, check that passed lock file exists
// (unlike the usual flag behavior, lockfile won't be created as we imply --locked)
if let Some(requested_lockfile_path) = ws.requested_lockfile_path() {
if !requested_lockfile_path.is_file() {
bail!(
"no Cargo.lock file found in the requested path {}",
requested_lockfile_path.display()
);
}
// If we're installing in --locked mode and there's no `Cargo.lock` published
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
} else if !ws.root().join("Cargo.lock").exists() {
gctx.shell()
.warn(format!("no Cargo.lock file published in {}", pkg))?;
}
// If we're installing in --locked mode and there's no `Cargo.lock` published
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
if !gctx.lock_update_allowed() && !ws.root().join("Cargo.lock").exists() {
gctx.shell()
.warn(format!("no Cargo.lock file published in {}", pkg))?;
}
let pkg = if source_id.is_git() {
// Don't use ws.current() in order to keep the package source as a git source so that
Expand Down Expand Up @@ -941,6 +929,7 @@ fn make_ws_rustc_target<'gctx>(
};
ws.set_resolve_feature_unification(FeatureUnification::Selected);
ws.set_ignore_lock(gctx.lock_update_allowed());
ws.set_requested_lockfile_path(None);
ws.set_require_optional_deps(false);

let rustc = gctx.load_global_rustc(Some(&ws))?;
Expand Down
4 changes: 4 additions & 0 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,10 @@ lockfiles should be stored in different directories.

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

*Keep in mind, the `[resolver]` section has this clarification:*

> *The `[resolver]` table overrides dependency resolution behavior for local development (e.g. excludes `cargo install`).*

#### `resolver.lockfile-path`

* Type: string (path)
Expand Down
48 changes: 6 additions & 42 deletions tests/testsuite/lockfile_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,12 @@ bar = "0.1.0"
}

#[cargo_test]
fn config_install_respects_lock_file_path() {
// `cargo install` will imply --locked when lockfile path is provided
Package::new("bar", "0.1.0").publish();
Package::new("bar", "0.1.1")
fn config_install_ignores_lock_file_path() {
Package::new("bar", "0.1.0")
.file("src/lib.rs", "not rust")
.publish();
// Publish with lockfile containing bad version of `bar` (0.1.1)
Package::new("bar", "0.1.1").publish();
// Publish with lockfile containing good version of `bar` (0.1.1)
Package::new("foo", "0.1.0")
.dep("bar", "0.1")
.file("src/lib.rs", "")
Expand Down Expand Up @@ -386,16 +385,9 @@ dependencies = [

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

p.cargo("install foo --locked")
.with_stderr_data(str![[r#"
...
[..]not rust[..]
...
"#]])
.with_status(101)
.run();
p.cargo("install foo --locked").run();

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

#[cargo_test]
fn config_install_lock_file_path_must_present() {
// `cargo install` will imply --locked when lockfile path is provided
Package::new("bar", "0.1.0").publish();
Package::new("foo", "0.1.0")
.dep("bar", "0.1")
.file("src/lib.rs", "")
.file(
"src/main.rs",
"extern crate foo; extern crate bar; fn main() {}",
)
.publish();

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

p.cargo("install foo --locked -Zlockfile-path")
.masquerade_as_nightly_cargo(&["lockfile-path"])
.arg("--config")
.arg("resolver.lockfile-path='../lockfile_dir/Cargo.lock'")
.with_stderr_data(str![[r#"
...
[ERROR] no Cargo.lock file found in the requested path [ROOT]/install/../lockfile_dir/Cargo.lock
...
"#]])
.with_status(101)
.run();
}

#[cargo_test(nightly, reason = "-Zscript is unstable")]
fn config_run_embed() {
let lockfile_path = "mylockfile/Cargo.lock";
Expand Down