Skip to content

Commit 03feb61

Browse files
committed
apply the correct changes
1 parent f3d3318 commit 03feb61

File tree

6 files changed

+30
-44
lines changed

6 files changed

+30
-44
lines changed

src/bin/cargo/commands/clippy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
7070
}
7171

7272
let wrapper = util::process(util::config::clippy_driver());
73-
compile_opts.build_config.rustc_wrapper = Some(wrapper);
73+
compile_opts.build_config.primary_unit_rustc = Some(wrapper);
7474

7575
ops::compile(&ws, &compile_opts)?;
7676
Ok(())

src/cargo/core/compiler/build_config.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::cell::RefCell;
2-
use std::path::{Path, PathBuf};
2+
use std::path::Path;
33

44
use serde::ser;
55

@@ -24,10 +24,8 @@ pub struct BuildConfig {
2424
pub force_rebuild: bool,
2525
/// Output a build plan to stdout instead of actually compiling.
2626
pub build_plan: bool,
27-
/// An optional wrapper, if any, used to wrap rustc invocations
28-
pub rustc_wrapper: Option<ProcessBuilder>,
2927
/// An optional override of the rustc path for primary units only
30-
pub primary_unit_rustc: Option<PathBuf>,
28+
pub primary_unit_rustc: Option<ProcessBuilder>,
3129
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
3230
/// Whether or not Cargo should cache compiler output on disk.
3331
cache_messages: bool,
@@ -100,7 +98,6 @@ impl BuildConfig {
10098
message_format: MessageFormat::Human,
10199
force_rebuild: false,
102100
build_plan: false,
103-
rustc_wrapper: None,
104101
primary_unit_rustc: None,
105102
rustfix_diagnostic_server: RefCell::new(None),
106103
cache_messages: config.cli_unstable().cache_messages,

src/cargo/core/compiler/build_context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
5252
extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
5353
) -> CargoResult<BuildContext<'a, 'cfg>> {
5454
let mut rustc = config.load_global_rustc(Some(ws))?;
55-
if let Some(wrapper) = &build_config.rustc_wrapper {
55+
if let Some(wrapper) = &build_config.primary_unit_rustc {
5656
rustc.set_wrapper(wrapper.clone());
5757
}
5858

src/cargo/core/compiler/compilation.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,18 @@ impl<'cfg> Compilation<'cfg> {
7878
pub fn new<'a>(bcx: &BuildContext<'a, 'cfg>) -> CargoResult<Compilation<'cfg>> {
7979
let mut rustc = bcx.rustc.process();
8080

81-
let mut primary_unit_rustc_process = bcx
82-
.build_config
83-
.primary_unit_rustc
84-
.as_ref()
85-
.map(|primary_unit_rustc| bcx.rustc.process_with(primary_unit_rustc));
81+
let mut primary_unit_rustc_process =
82+
bcx.build_config.primary_unit_rustc.clone().map(|mut r| {
83+
r.arg(&bcx.rustc.path);
84+
r
85+
});
8686

8787
if bcx.config.extra_verbose() {
8888
rustc.display_env_vars();
89-
primary_unit_rustc_process.as_mut().map(|rustc| {
89+
90+
if let Some(rustc) = primary_unit_rustc_process.as_mut() {
9091
rustc.display_env_vars();
91-
});
92+
}
9293
}
9394

9495
Ok(Compilation {

src/cargo/core/compiler/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,10 @@ fn prepare_rustc<'a, 'cfg>(
591591
unit: &Unit<'a>,
592592
) -> CargoResult<ProcessBuilder> {
593593
let is_primary = cx.is_primary_package(unit);
594+
594595
let mut base = cx
595596
.compilation
596597
.rustc_process(unit.pkg, unit.target, is_primary)?;
597-
598-
if is_primary {
599-
base.env("CARGO_PRIMARY_PACKAGE", "1");
600-
}
601-
602598
base.inherit_jobserver(&cx.jobserver);
603599
build_base_args(cx, &mut base, unit, crate_types)?;
604600
build_deps_args(&mut base, cx, unit)?;

src/cargo/ops/fix.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
106106
eprintln!("Warning: clippy-driver not found: {:?}", e);
107107
}
108108

109-
opts.compile_opts.build_config.primary_unit_rustc = Some(util::config::clippy_driver());
109+
let clippy_args = opts
110+
.clippy_args
111+
.as_ref()
112+
.map_or_else(String::new, |args| serde_json::to_string(&args).unwrap());
110113

111-
if let Some(clippy_args) = &opts.clippy_args {
112-
let clippy_args = serde_json::to_string(&clippy_args).unwrap();
113-
wrapper.env(CLIPPY_FIX_ARGS, clippy_args);
114-
}
114+
wrapper.env(CLIPPY_FIX_ARGS, clippy_args);
115115
}
116116

117117
*opts
@@ -130,7 +130,9 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
130130
server.configure(&mut wrapper);
131131
}
132132

133-
opts.compile_opts.build_config.rustc_wrapper = Some(wrapper);
133+
// primary crates are compiled using a cargo subprocess to do extra work of applying fixes and
134+
// repeating build until there are no more changes to be applied
135+
opts.compile_opts.build_config.primary_unit_rustc = Some(wrapper);
134136

135137
ops::compile(ws, &opts.compile_opts)?;
136138
Ok(())
@@ -219,18 +221,10 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
219221
trace!("cargo-fix as rustc got file {:?}", args.file);
220222
let rustc = args.rustc.as_ref().expect("fix wrapper rustc was not set");
221223

222-
// Our goal is to fix only the crates that the end user is interested in.
223-
// That's very likely to only mean the crates in the workspace the user is
224-
// working on, not random crates.io crates.
225-
//
226-
// The master cargo process tells us whether or not this is a "primary"
227-
// crate via the CARGO_PRIMARY_PACKAGE environment variable.
228224
let mut fixes = FixedCrate::default();
229225
if let Some(path) = &args.file {
230-
if args.primary_package {
231-
trace!("start rustfixing {:?}", path);
232-
fixes = rustfix_crate(&lock_addr, rustc.as_ref(), path, &args)?;
233-
}
226+
trace!("start rustfixing {:?}", path);
227+
fixes = rustfix_crate(&lock_addr, rustc.as_ref(), path, &args)?;
234228
}
235229

236230
// Ok now we have our final goal of testing out the changes that we applied.
@@ -279,7 +273,6 @@ pub fn fix_maybe_exec_rustc() -> CargoResult<bool> {
279273
}
280274

281275
// This final fall-through handles multiple cases;
282-
// - Non-primary crates, which need to be built.
283276
// - If the fix failed, show the original warnings and suggestions.
284277
// - If `--broken-code`, show the error messages.
285278
// - If the fix succeeded, show any remaining warnings.
@@ -589,7 +582,6 @@ struct FixArgs {
589582
idioms: bool,
590583
enabled_edition: Option<String>,
591584
other: Vec<OsString>,
592-
primary_package: bool,
593585
rustc: Option<PathBuf>,
594586
clippy_args: Vec<String>,
595587
}
@@ -609,10 +601,12 @@ impl Default for PrepareFor {
609601
impl FixArgs {
610602
fn get() -> FixArgs {
611603
let mut ret = FixArgs::default();
612-
ret.rustc = env::args_os().nth(1).map(PathBuf::from);
613604

614605
if let Ok(clippy_args) = env::var(CLIPPY_FIX_ARGS) {
615606
ret.clippy_args = serde_json::from_str(&clippy_args).unwrap();
607+
ret.rustc = Some(util::config::clippy_driver());
608+
} else {
609+
ret.rustc = env::args_os().nth(1).map(PathBuf::from);
616610
}
617611

618612
for arg in env::args_os().skip(2) {
@@ -642,7 +636,6 @@ impl FixArgs {
642636
}
643637

644638
ret.idioms = env::var(IDIOMS_ENV).is_ok();
645-
ret.primary_package = env::var("CARGO_PRIMARY_PACKAGE").is_ok();
646639
ret
647640
}
648641

@@ -658,14 +651,13 @@ impl FixArgs {
658651
cmd.args(&self.other).arg("--cap-lints=warn");
659652
if let Some(edition) = &self.enabled_edition {
660653
cmd.arg("--edition").arg(edition);
661-
if self.idioms && self.primary_package && edition == "2018" {
654+
if self.idioms && edition == "2018" {
662655
cmd.arg("-Wrust-2018-idioms");
663656
}
664657
}
665-
if self.primary_package {
666-
if let Some(edition) = self.prepare_for_edition_resolve() {
667-
cmd.arg("-W").arg(format!("rust-{}-compatibility", edition));
668-
}
658+
659+
if let Some(edition) = self.prepare_for_edition_resolve() {
660+
cmd.arg("-W").arg(format!("rust-{}-compatibility", edition));
669661
}
670662
}
671663

0 commit comments

Comments
 (0)