Skip to content

Commit 3293d22

Browse files
committed
Auto merge of #14326 - Ifropc:5707-lock-path, r=weihanglo
Add `--lockfile-path` flag This change implements a new `--lockfile-path` proposed in #5707 . Functionality added: - Add `--lockfile-path <PATH>` to all commands that support `manifest-path` with exception of: - `locate-project` (doesn't use lock file) - `verify-project` (is deprecated) - `read-manifest` (doesn't use lock file) - Behind -Zunstable-options and docs - The flag's docs / `--help` has (unstable) in them - `<PATH>` must end with `Cargo.lock`. If specified path doesn't exist (or parent director(ies), create all the parent directories and the lockfile itself Implementation TLDR: add `requested_lockfile_path` into `Workspace` and set it on `workspace(gctx)` call (setting from the context) Update `lockfile.lock_root()` to respect `requested_lockfile_path` (if set) Add test cases covering all affected commands. Tested creating lockfile, reading lockfile, overriding default (`./Cargo.lock`) lockfile, symlink tests. Extra tests for package to make sure pinned versions from path's lockfile are respected (i.e. double check correct lockfile is used) I doubt this flag will be used for any command that's not read-only, but I tried to cover all the commands.
2 parents 9a170d7 + 04f9e2d commit 3293d22

File tree

134 files changed

+1650
-224
lines changed

Some content is hidden

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

134 files changed

+1650
-224
lines changed

src/bin/cargo/commands/add.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Example uses:
8787
- Depend on crates with the same name from different registries"),
8888
])
8989
.arg_manifest_path_without_unsupported_path_tip()
90+
.arg_lockfile_path()
9091
.arg_package("Package to modify")
9192
.arg_ignore_rust_version()
9293
.arg_dry_run("Don't actually write the manifest")

src/bin/cargo/commands/bench.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub fn cli() -> Command {
5050
.arg_unit_graph()
5151
.arg_timings()
5252
.arg_manifest_path()
53+
.arg_lockfile_path()
5354
.arg_ignore_rust_version()
5455
.after_help(color_print::cstr!(
5556
"Run `<cyan,bold>cargo help bench</>` for more detailed information.\n"

src/bin/cargo/commands/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn cli() -> Command {
3939
.arg_unit_graph()
4040
.arg_timings()
4141
.arg_manifest_path()
42+
.arg_lockfile_path()
4243
.arg_ignore_rust_version()
4344
.after_help(color_print::cstr!(
4445
"Run `<cyan,bold>cargo help build</>` for more detailed information.\n"

src/bin/cargo/commands/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn cli() -> Command {
3636
.arg_unit_graph()
3737
.arg_timings()
3838
.arg_manifest_path()
39+
.arg_lockfile_path()
3940
.arg_ignore_rust_version()
4041
.after_help(color_print::cstr!(
4142
"Run `<cyan,bold>cargo help check</>` for more detailed information.\n"

src/bin/cargo/commands/clean.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn cli() -> Command {
1919
.arg_target_triple("Target triple to clean output for")
2020
.arg_target_dir()
2121
.arg_manifest_path()
22+
.arg_lockfile_path()
2223
.arg_dry_run("Display what would be deleted without deleting anything")
2324
.args_conflicts_with_subcommands(true)
2425
.subcommand(

src/bin/cargo/commands/doc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn cli() -> Command {
3939
.arg_unit_graph()
4040
.arg_timings()
4141
.arg_manifest_path()
42+
.arg_lockfile_path()
4243
.arg_ignore_rust_version()
4344
.after_help(color_print::cstr!(
4445
"Run `<cyan,bold>cargo help doc</>` for more detailed information.\n"

src/bin/cargo/commands/fetch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub fn cli() -> Command {
99
.arg_silent_suggestion()
1010
.arg_target_triple("Fetch dependencies for the target triple")
1111
.arg_manifest_path()
12+
.arg_lockfile_path()
1213
.after_help(color_print::cstr!(
1314
"Run `<cyan,bold>cargo help fetch</>` for more detailed information.\n"
1415
))

src/bin/cargo/commands/fix.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::command_prelude::*;
2-
32
use cargo::core::Workspace;
3+
44
use cargo::ops;
55

66
pub fn cli() -> Command {
@@ -54,6 +54,7 @@ pub fn cli() -> Command {
5454
.arg_target_dir()
5555
.arg_timings()
5656
.arg_manifest_path()
57+
.arg_lockfile_path()
5758
.arg_ignore_rust_version()
5859
.after_help(color_print::cstr!(
5960
"Run `<cyan,bold>cargo help fix</>` for more detailed information.\n"
@@ -71,8 +72,13 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
7172
// Unlike other commands default `cargo fix` to all targets to fix as much
7273
// code as we can.
7374
let root_manifest = args.root_manifest(gctx)?;
75+
76+
// Can't use workspace() to avoid using -Zavoid-dev-deps (if passed)
7477
let mut ws = Workspace::new(&root_manifest, gctx)?;
7578
ws.set_resolve_honors_rust_version(args.honor_rust_version());
79+
let lockfile_path = args.lockfile_path(gctx)?;
80+
ws.set_requested_lockfile_path(lockfile_path.clone());
81+
7682
let mut opts = args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;
7783

7884
if !opts.filter.is_specific() {
@@ -92,6 +98,7 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
9298
allow_no_vcs: args.flag("allow-no-vcs"),
9399
allow_staged: args.flag("allow-staged"),
94100
broken_code: args.flag("broken-code"),
101+
requested_lockfile_path: lockfile_path,
95102
},
96103
)?;
97104
Ok(())

src/bin/cargo/commands/generate_lockfile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub fn cli() -> Command {
77
.about("Generate the lockfile for a package")
88
.arg_silent_suggestion()
99
.arg_manifest_path()
10+
.arg_lockfile_path()
1011
.arg_ignore_rust_version_with_help(
1112
"Ignore `rust-version` specification in packages (unstable)",
1213
)

src/bin/cargo/commands/metadata.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::command_prelude::*;
21
use cargo::ops::{self, OutputMetadataOptions};
32

3+
use crate::command_prelude::*;
4+
45
pub fn cli() -> Command {
56
subcommand("metadata")
67
.about(
@@ -26,6 +27,7 @@ pub fn cli() -> Command {
2627
.arg_silent_suggestion()
2728
.arg_features()
2829
.arg_manifest_path()
30+
.arg_lockfile_path()
2931
.after_help(color_print::cstr!(
3032
"Run `<cyan,bold>cargo help metadata</>` for more detailed information.\n"
3133
))

0 commit comments

Comments
 (0)