forked from rust-lang/cargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix.rs
More file actions
107 lines (98 loc) · 3.66 KB
/
Copy pathfix.rs
File metadata and controls
107 lines (98 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use crate::command_prelude::*;
use cargo::core::Workspace;
use cargo::ops;
pub fn cli() -> Command {
subcommand("fix")
.about("Automatically fix lint warnings reported by rustc")
.arg(flag("edition", "Fix in preparation for the next edition"))
.arg(flag(
"edition-idioms",
"Fix warnings to migrate to the idioms of an edition",
))
.arg(flag(
"broken-code",
"Fix code even if it already has compiler errors",
))
.arg(flag(
"allow-no-vcs",
"Fix code even if a VCS was not detected",
))
.arg(flag(
"allow-dirty",
"Fix code even if the working directory is dirty or has staged changes",
))
.arg(flag(
"allow-staged",
"Fix code even if the working directory has staged changes",
))
.arg_message_format()
.arg_silent_suggestion()
.arg_package_spec(
"Package(s) to fix",
"Fix all packages in the workspace",
"Exclude packages from the fixes",
)
.arg_targets_all(
"Fix only this package's library",
"Fix only the specified binary",
"Fix all binaries",
"Fix only the specified example",
"Fix all examples",
"Fix only the specified test target",
"Fix all targets that have `test = true` set",
"Fix only the specified bench target",
"Fix all targets that have `bench = true` set",
"Fix all targets (default)",
)
.arg_features()
.arg_parallel()
.arg_release("Fix artifacts in release mode, with optimizations")
.arg_profile("Build artifacts with the specified profile")
.arg_target_triple("Fix for the target triple")
.arg_target_dir()
.arg_timings()
.arg_manifest_path()
.arg_lockfile_path()
.arg_ignore_rust_version()
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help fix</>` for more detailed information.\n"
))
}
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
// This is a legacy behavior that causes `cargo fix` to pass `--test`.
let test = matches!(
args.get_one::<String>("profile").map(String::as_str),
Some("test")
);
let mode = CompileMode::Check { test };
// Unlike other commands default `cargo fix` to all targets to fix as much
// code as we can.
let root_manifest = args.root_manifest(gctx)?;
// Can't use workspace() to avoid using -Zavoid-dev-deps (if passed)
let mut ws = Workspace::new(&root_manifest, gctx)?;
ws.set_resolve_honors_rust_version(args.honor_rust_version());
let lockfile_path = args.lockfile_path(gctx)?;
ws.set_requested_lockfile_path(lockfile_path.clone());
let mut opts = args.compile_options(gctx, mode, Some(&ws), ProfileChecking::LegacyTestOnly)?;
if !opts.filter.is_specific() {
// cargo fix with no target selection implies `--all-targets`.
opts.filter = ops::CompileFilter::new_all_targets();
}
let allow_dirty = args.flag("allow-dirty");
ops::fix(
gctx,
&ws,
&root_manifest,
&mut ops::FixOptions {
edition: args.flag("edition"),
idioms: args.flag("edition-idioms"),
compile_opts: opts,
allow_dirty,
allow_staged: allow_dirty || args.flag("allow-staged"),
allow_no_vcs: args.flag("allow-no-vcs"),
broken_code: args.flag("broken-code"),
requested_lockfile_path: lockfile_path,
},
)?;
Ok(())
}