Skip to content

Commit bf7e2dc

Browse files
committed
feat: lockfile path refactoring
1 parent 3da5667 commit bf7e2dc

File tree

89 files changed

+227
-220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+227
-220
lines changed

src/bin/cargo/commands/fix.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::command_prelude::*;
2+
use cargo::core::Workspace;
3+
use std::path::Path;
24

35
use cargo::ops;
46

@@ -71,7 +73,14 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
7173
// Unlike other commands default `cargo fix` to all targets to fix as much
7274
// code as we can.
7375
let root_manifest = args.root_manifest(gctx)?;
74-
let ws = args.workspace(gctx)?;
76+
77+
// Can't use workspace() to avoid using -Zavoid-dev-deps (if passed)
78+
let mut ws = Workspace::new(&root_manifest, gctx)?;
79+
ws.set_resolve_honors_rust_version(args.honor_rust_version());
80+
let lockfile_path =
81+
lockfile_path(args.get_one::<String>("lockfile-path").map(Path::new), gctx)?;
82+
ws.set_requested_lockfile_path(lockfile_path);
83+
7584
let mut opts = args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;
7685

7786
if !opts.filter.is_specific() {

src/cargo/core/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub struct Workspace<'gctx> {
103103
// file. This is set for `cargo install` without `--locked`.
104104
ignore_lock: bool,
105105

106-
// Requested path of the lockfile (i.e. passed as the cli flag)
106+
/// Requested path of the lockfile (i.e. passed as the cli flag)
107107
requested_lockfile_path: Option<PathBuf>,
108108

109109
/// The resolver behavior specified with the `resolver` field.

src/cargo/ops/lockfile.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use std::io::prelude::*;
2+
13
use crate::core::{resolver, Resolve, ResolveVersion, Workspace};
24
use crate::util::errors::CargoResult;
35
use crate::util::Filesystem;
4-
use std::io::prelude::*;
56

67
use anyhow::Context as _;
78

src/cargo/util/command_prelude.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub trait CommandExt: Sized {
299299
fn arg_lockfile_path(self) -> Self {
300300
self._arg(
301301
opt("lockfile-path", "Path to Cargo.lock (unstable)")
302-
.value_name("FILE")
302+
.value_name("PATH")
303303
.help_heading(heading::MANIFEST_OPTIONS),
304304
)
305305
}
@@ -1015,10 +1015,7 @@ pub fn lockfile_path(
10151015
let path = gctx.cwd().join(lockfile_path);
10161016

10171017
if !path.ends_with(LOCKFILE_NAME) && !crate::util::toml::is_embedded(&path) {
1018-
bail!(
1019-
"the lockfile-path must be a path to a {} file",
1020-
LOCKFILE_NAME
1021-
)
1018+
bail!("the lockfile-path must be a path to a {LOCKFILE_NAME} file")
10221019
}
10231020
if path.is_dir() {
10241021
bail!(

src/doc/man/generated_txt/cargo-add.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ OPTIONS
201201
Changes the path of the lockfile from the default
202202
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
203203
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
204-
providing --lockfile-path will ignore existing default lockfile
205-
(<workspace_root>/Cargo.lock), if exists, and instead will either
206-
use PATH lockfile (or write a new lockfile into the provided path if
207-
it doesn’t exist). This flag can be used to run most commands in
208-
read-only directories, writing lockfile into the provided PATH.
204+
providing --lockfile-path will ignore existing lockfile at the
205+
default path, and instead will either use the lockfile from PATH, or
206+
write a new lockfile into the provided PATH if it doesn’t exist.
207+
This flag can be used to run most commands in read-only directories,
208+
writing lockfile into the provided PATH.
209209

210210
This option is only available on the nightly channel
211211
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and

src/doc/man/generated_txt/cargo-bench.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,11 @@ OPTIONS
372372
Changes the path of the lockfile from the default
373373
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
374374
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
375-
providing --lockfile-path will ignore existing default lockfile
376-
(<workspace_root>/Cargo.lock), if exists, and instead will either
377-
use PATH lockfile (or write a new lockfile into the provided path if
378-
it doesn’t exist). This flag can be used to run most commands in
379-
read-only directories, writing lockfile into the provided PATH.
375+
providing --lockfile-path will ignore existing lockfile at the
376+
default path, and instead will either use the lockfile from PATH, or
377+
write a new lockfile into the provided PATH if it doesn’t exist.
378+
This flag can be used to run most commands in read-only directories,
379+
writing lockfile into the provided PATH.
380380

381381
This option is only available on the nightly channel
382382
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and

src/doc/man/generated_txt/cargo-build.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ OPTIONS
306306
Changes the path of the lockfile from the default
307307
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
308308
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
309-
providing --lockfile-path will ignore existing default lockfile
310-
(<workspace_root>/Cargo.lock), if exists, and instead will either
311-
use PATH lockfile (or write a new lockfile into the provided path if
312-
it doesn’t exist). This flag can be used to run most commands in
313-
read-only directories, writing lockfile into the provided PATH.
309+
providing --lockfile-path will ignore existing lockfile at the
310+
default path, and instead will either use the lockfile from PATH, or
311+
write a new lockfile into the provided PATH if it doesn’t exist.
312+
This flag can be used to run most commands in read-only directories,
313+
writing lockfile into the provided PATH.
314314

315315
This option is only available on the nightly channel
316316
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and

src/doc/man/generated_txt/cargo-check.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ OPTIONS
291291
Changes the path of the lockfile from the default
292292
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
293293
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
294-
providing --lockfile-path will ignore existing default lockfile
295-
(<workspace_root>/Cargo.lock), if exists, and instead will either
296-
use PATH lockfile (or write a new lockfile into the provided path if
297-
it doesn’t exist). This flag can be used to run most commands in
298-
read-only directories, writing lockfile into the provided PATH.
294+
providing --lockfile-path will ignore existing lockfile at the
295+
default path, and instead will either use the lockfile from PATH, or
296+
write a new lockfile into the provided PATH if it doesn’t exist.
297+
This flag can be used to run most commands in read-only directories,
298+
writing lockfile into the provided PATH.
299299

300300
This option is only available on the nightly channel
301301
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and

src/doc/man/generated_txt/cargo-clean.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ OPTIONS
127127
Changes the path of the lockfile from the default
128128
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
129129
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
130-
providing --lockfile-path will ignore existing default lockfile
131-
(<workspace_root>/Cargo.lock), if exists, and instead will either
132-
use PATH lockfile (or write a new lockfile into the provided path if
133-
it doesn’t exist). This flag can be used to run most commands in
134-
read-only directories, writing lockfile into the provided PATH.
130+
providing --lockfile-path will ignore existing lockfile at the
131+
default path, and instead will either use the lockfile from PATH, or
132+
write a new lockfile into the provided PATH if it doesn’t exist.
133+
This flag can be used to run most commands in read-only directories,
134+
writing lockfile into the provided PATH.
135135

136136
This option is only available on the nightly channel
137137
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and

src/doc/man/generated_txt/cargo-doc.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,11 @@ OPTIONS
262262
Changes the path of the lockfile from the default
263263
(<workspace_root>/Cargo.lock) to PATH. PATH must end with Cargo.lock
264264
(e.g. --lockfile-path /tmp/temporary-lockfile/Cargo.lock). Note that
265-
providing --lockfile-path will ignore existing default lockfile
266-
(<workspace_root>/Cargo.lock), if exists, and instead will either
267-
use PATH lockfile (or write a new lockfile into the provided path if
268-
it doesn’t exist). This flag can be used to run most commands in
269-
read-only directories, writing lockfile into the provided PATH.
265+
providing --lockfile-path will ignore existing lockfile at the
266+
default path, and instead will either use the lockfile from PATH, or
267+
write a new lockfile into the provided PATH if it doesn’t exist.
268+
This flag can be used to run most commands in read-only directories,
269+
writing lockfile into the provided PATH.
270270

271271
This option is only available on the nightly channel
272272
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html> and

0 commit comments

Comments
 (0)