Skip to content

Commit b0351e4

Browse files
committed
Close the front door for clippy but open the back
1 parent 2bdc879 commit b0351e4

File tree

19 files changed

+394
-301
lines changed

19 files changed

+394
-301
lines changed

crates/cargo-test-support/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,7 @@ thread_local!(
16791679
pub static RUSTC: Rustc = Rustc::new(
16801680
PathBuf::from("rustc"),
16811681
None,
1682+
None,
16821683
Path::new("should be path to rustup rustc, but we don't care in tests"),
16831684
None,
16841685
).unwrap()

crates/cargo-test-support/src/paths.rs

+19
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,22 @@ pub fn sysroot() -> String {
264264
let sysroot = String::from_utf8(output.stdout).unwrap();
265265
sysroot.trim().to_string()
266266
}
267+
268+
#[cfg(unix)]
269+
pub fn echo_wrapper() -> std::io::Result<std::path::PathBuf> {
270+
use std::os::unix::fs::PermissionsExt;
271+
let wrapper_path = root().join("rustc-echo-wrapper");
272+
std::fs::write(
273+
&wrapper_path,
274+
r#"#! /bin/bash
275+
276+
echo "WRAPPER CALLED: $*"
277+
"$@""#,
278+
)?;
279+
280+
let mut perms = std::fs::metadata(&wrapper_path)?.permissions();
281+
perms.set_mode(0o755);
282+
std::fs::set_permissions(&wrapper_path, perms)?;
283+
284+
Ok(wrapper_path)
285+
}

src/bin/cargo/commands/clippy.rs

-85
This file was deleted.

src/bin/cargo/commands/fix.rs

-25
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,6 @@ pub fn cli() -> App {
7272
.long("allow-staged")
7373
.help("Fix code even if the working directory has staged changes"),
7474
)
75-
.arg(
76-
Arg::with_name("clippy")
77-
.long("clippy")
78-
.help("Get fix suggestions from clippy instead of rustc")
79-
.hidden(true)
80-
.multiple(true)
81-
.min_values(0)
82-
.number_of_values(1),
83-
)
8475
.after_help(
8576
"\
8677
This Cargo subcommand will automatically take rustc's suggestions from
@@ -134,21 +125,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
134125
// code as we can.
135126
let mut opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Unchecked)?;
136127

137-
let use_clippy = args.is_present("clippy");
138-
139-
let clippy_args = args
140-
.value_of("clippy")
141-
.map(|s| s.split(' ').map(|s| s.to_string()).collect())
142-
.or_else(|| Some(vec![]))
143-
.filter(|_| use_clippy);
144-
145-
if use_clippy && !config.cli_unstable().unstable_options {
146-
return Err(anyhow::format_err!(
147-
"`cargo fix --clippy` is unstable, pass `-Z unstable-options` to enable it"
148-
)
149-
.into());
150-
}
151-
152128
if let CompileFilter::Default { .. } = opts.filter {
153129
opts.filter = CompileFilter::Only {
154130
all_targets: true,
@@ -171,7 +147,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
171147
allow_no_vcs: args.is_present("allow-no-vcs"),
172148
allow_staged: args.is_present("allow-staged"),
173149
broken_code: args.is_present("broken-code"),
174-
clippy_args,
175150
},
176151
)?;
177152
Ok(())

src/bin/cargo/commands/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub fn builtin() -> Vec<App> {
66
build::cli(),
77
check::cli(),
88
clean::cli(),
9-
clippy::cli(),
109
doc::cli(),
1110
fetch::cli(),
1211
fix::cli(),
@@ -43,7 +42,6 @@ pub fn builtin_exec(cmd: &str) -> Option<fn(&mut Config, &ArgMatches<'_>) -> Cli
4342
"build" => build::exec,
4443
"check" => check::exec,
4544
"clean" => clean::exec,
46-
"clippy-preview" => clippy::exec,
4745
"doc" => doc::exec,
4846
"fetch" => fetch::exec,
4947
"fix" => fix::exec,
@@ -80,7 +78,6 @@ pub mod bench;
8078
pub mod build;
8179
pub mod check;
8280
pub mod clean;
83-
pub mod clippy;
8481
pub mod doc;
8582
pub mod fetch;
8683
pub mod fix;

src/cargo/core/compiler/build_config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct BuildConfig {
2222
pub force_rebuild: bool,
2323
/// Output a build plan to stdout instead of actually compiling.
2424
pub build_plan: bool,
25-
/// An optional override of the rustc path for primary units only
25+
/// An optional override of the rustc process for primary units
2626
pub primary_unit_rustc: Option<ProcessBuilder>,
2727
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
2828
}

src/cargo/core/compiler/compilation.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@ pub struct Compilation<'cfg> {
7373
pub target: String,
7474

7575
config: &'cfg Config,
76+
77+
/// Rustc process to be used by default
7678
rustc_process: ProcessBuilder,
77-
primary_unit_rustc_process: Option<ProcessBuilder>,
79+
/// Rustc process to be used for workspace crates instead of rustc_process
80+
rustc_workspace_wrapper_process: ProcessBuilder,
81+
/// Optional rustc process to be used for primary crates instead of either rustc_process or
82+
/// rustc_workspace_wrapper_process
83+
primary_rustc_process: Option<ProcessBuilder>,
7884

7985
target_runner: Option<(PathBuf, Vec<String>)>,
8086
}
@@ -85,13 +91,14 @@ impl<'cfg> Compilation<'cfg> {
8591
default_kind: CompileKind,
8692
) -> CargoResult<Compilation<'cfg>> {
8793
let mut rustc = bcx.rustc().process();
88-
89-
let mut primary_unit_rustc_process = bcx.build_config.primary_unit_rustc.clone();
94+
let mut primary_rustc_process = bcx.build_config.primary_unit_rustc.clone();
95+
let mut rustc_workspace_wrapper_process = bcx.rustc().workspace_process();
9096

9197
if bcx.config.extra_verbose() {
9298
rustc.display_env_vars();
99+
rustc_workspace_wrapper_process.display_env_vars();
93100

94-
if let Some(rustc) = primary_unit_rustc_process.as_mut() {
101+
if let Some(rustc) = primary_rustc_process.as_mut() {
95102
rustc.display_env_vars();
96103
}
97104
}
@@ -120,19 +127,25 @@ impl<'cfg> Compilation<'cfg> {
120127
rustdocflags: HashMap::new(),
121128
config: bcx.config,
122129
rustc_process: rustc,
123-
primary_unit_rustc_process,
130+
rustc_workspace_wrapper_process,
131+
primary_rustc_process,
124132
host: bcx.host_triple().to_string(),
125133
target: bcx.target_data.short_name(&default_kind).to_string(),
126134
target_runner: target_runner(bcx, default_kind)?,
127135
})
128136
}
129137

130138
/// See `process`.
131-
pub fn rustc_process(&self, pkg: &Package, is_primary: bool) -> CargoResult<ProcessBuilder> {
132-
let rustc = if is_primary {
133-
self.primary_unit_rustc_process
134-
.clone()
135-
.unwrap_or_else(|| self.rustc_process.clone())
139+
pub fn rustc_process(
140+
&self,
141+
pkg: &Package,
142+
is_primary: bool,
143+
is_workspace: bool,
144+
) -> CargoResult<ProcessBuilder> {
145+
let rustc = if is_primary && self.primary_rustc_process.is_some() {
146+
self.primary_rustc_process.clone().unwrap()
147+
} else if is_workspace {
148+
self.rustc_workspace_wrapper_process.clone()
136149
} else {
137150
self.rustc_process.clone()
138151
};

src/cargo/core/compiler/context/compilation_files.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,11 @@ fn compute_metadata<'a, 'cfg>(
616616

617617
bcx.rustc().verbose_version.hash(&mut hasher);
618618

619-
if cx.is_primary_package(unit) {
619+
if cx.bcx.ws.is_member(unit.pkg) {
620620
// This is primarily here for clippy. This ensures that the clippy
621621
// artifacts are separate from the `check` ones.
622-
if let Some(proc) = &cx.bcx.build_config.primary_unit_rustc {
623-
proc.get_program().hash(&mut hasher);
622+
if let Some(path) = &cx.bcx.rustc().workspace_wrapper {
623+
path.hash(&mut hasher);
624624
}
625625
}
626626

src/cargo/core/compiler/fingerprint.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1100,22 +1100,12 @@ fn calculate_normal<'a, 'cfg>(
11001100
// Fill out a bunch more information that we'll be tracking typically
11011101
// hashed to take up less space on disk as we just need to know when things
11021102
// change.
1103-
let mut extra_flags = if unit.mode.is_doc() {
1103+
let extra_flags = if unit.mode.is_doc() {
11041104
cx.bcx.rustdocflags_args(unit)
11051105
} else {
11061106
cx.bcx.rustflags_args(unit)
11071107
}
11081108
.to_vec();
1109-
if cx.is_primary_package(unit) {
1110-
// This is primarily here for clippy arguments.
1111-
if let Some(proc) = &cx.bcx.build_config.primary_unit_rustc {
1112-
let args = proc
1113-
.get_args()
1114-
.iter()
1115-
.map(|s| s.to_string_lossy().to_string());
1116-
extra_flags.extend(args);
1117-
}
1118-
}
11191109

11201110
let profile_hash = util::hash_u64((&unit.profile, unit.mode, cx.bcx.extra_args_for(unit)));
11211111
// Include metadata since it is exposed as environment variables.

src/cargo/core/compiler/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,11 @@ fn prepare_rustc<'a, 'cfg>(
538538
unit: &Unit<'a>,
539539
) -> CargoResult<ProcessBuilder> {
540540
let is_primary = cx.is_primary_package(unit);
541+
let is_workspace = cx.bcx.ws.is_member(unit.pkg);
541542

542-
let mut base = cx.compilation.rustc_process(unit.pkg, is_primary)?;
543+
let mut base = cx
544+
.compilation
545+
.rustc_process(unit.pkg, is_primary, is_workspace)?;
543546
if cx.bcx.config.cli_unstable().jobserver_per_rustc {
544547
let client = cx.new_jobserver()?;
545548
base.inherit_jobserver(&client);

0 commit comments

Comments
 (0)