Skip to content

Commit

Permalink
Auto merge of #7533 - yaahc:clippy-banishment, r=ehuss
Browse files Browse the repository at this point in the history
Close the front door for clippy but open the back
  • Loading branch information
bors committed Mar 14, 2020
2 parents b734683 + d9a77ce commit 7302186
Show file tree
Hide file tree
Showing 19 changed files with 390 additions and 301 deletions.
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,7 @@ thread_local!(
pub static RUSTC: Rustc = Rustc::new(
PathBuf::from("rustc"),
None,
None,
Path::new("should be path to rustup rustc, but we don't care in tests"),
None,
).unwrap()
Expand Down
22 changes: 22 additions & 0 deletions crates/cargo-test-support/src/paths.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::{basic_manifest, project};
use filetime::{self, FileTime};
use lazy_static::lazy_static;
use std::cell::RefCell;
Expand Down Expand Up @@ -264,3 +265,24 @@ pub fn sysroot() -> String {
let sysroot = String::from_utf8(output.stdout).unwrap();
sysroot.trim().to_string()
}

pub fn echo_wrapper() -> std::path::PathBuf {
let p = project()
.at("rustc-echo-wrapper")
.file("Cargo.toml", &basic_manifest("rustc-echo-wrapper", "1.0.0"))
.file(
"src/main.rs",
r#"
fn main() {
let args = std::env::args().collect::<Vec<_>>();
eprintln!("WRAPPER CALLED: {}", args[1..].join(" "));
let status = std::process::Command::new(&args[1])
.args(&args[2..]).status().unwrap();
std::process::exit(status.code().unwrap_or(1));
}
"#,
)
.build();
p.cargo("build").run();
p.bin("rustc-echo-wrapper")
}
85 changes: 0 additions & 85 deletions src/bin/cargo/commands/clippy.rs

This file was deleted.

25 changes: 0 additions & 25 deletions src/bin/cargo/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,6 @@ pub fn cli() -> App {
.long("allow-staged")
.help("Fix code even if the working directory has staged changes"),
)
.arg(
Arg::with_name("clippy")
.long("clippy")
.help("Get fix suggestions from clippy instead of rustc")
.hidden(true)
.multiple(true)
.min_values(0)
.number_of_values(1),
)
.after_help(
"\
This Cargo subcommand will automatically take rustc's suggestions from
Expand Down Expand Up @@ -134,21 +125,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
// code as we can.
let mut opts = args.compile_options(config, mode, Some(&ws), ProfileChecking::Unchecked)?;

let use_clippy = args.is_present("clippy");

let clippy_args = args
.value_of("clippy")
.map(|s| s.split(' ').map(|s| s.to_string()).collect())
.or_else(|| Some(vec![]))
.filter(|_| use_clippy);

if use_clippy && !config.cli_unstable().unstable_options {
return Err(anyhow::format_err!(
"`cargo fix --clippy` is unstable, pass `-Z unstable-options` to enable it"
)
.into());
}

if let CompileFilter::Default { .. } = opts.filter {
opts.filter = CompileFilter::Only {
all_targets: true,
Expand All @@ -171,7 +147,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
allow_no_vcs: args.is_present("allow-no-vcs"),
allow_staged: args.is_present("allow-staged"),
broken_code: args.is_present("broken-code"),
clippy_args,
},
)?;
Ok(())
Expand Down
3 changes: 0 additions & 3 deletions src/bin/cargo/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub fn builtin() -> Vec<App> {
build::cli(),
check::cli(),
clean::cli(),
clippy::cli(),
doc::cli(),
fetch::cli(),
fix::cli(),
Expand Down Expand Up @@ -43,7 +42,6 @@ pub fn builtin_exec(cmd: &str) -> Option<fn(&mut Config, &ArgMatches<'_>) -> Cli
"build" => build::exec,
"check" => check::exec,
"clean" => clean::exec,
"clippy-preview" => clippy::exec,
"doc" => doc::exec,
"fetch" => fetch::exec,
"fix" => fix::exec,
Expand Down Expand Up @@ -80,7 +78,6 @@ pub mod bench;
pub mod build;
pub mod check;
pub mod clean;
pub mod clippy;
pub mod doc;
pub mod fetch;
pub mod fix;
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct BuildConfig {
pub force_rebuild: bool,
/// Output a build plan to stdout instead of actually compiling.
pub build_plan: bool,
/// An optional override of the rustc path for primary units only
/// An optional override of the rustc process for primary units
pub primary_unit_rustc: Option<ProcessBuilder>,
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
}
Expand Down
33 changes: 23 additions & 10 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ pub struct Compilation<'cfg> {
pub target: String,

config: &'cfg Config,

/// Rustc process to be used by default
rustc_process: ProcessBuilder,
primary_unit_rustc_process: Option<ProcessBuilder>,
/// Rustc process to be used for workspace crates instead of rustc_process
rustc_workspace_wrapper_process: ProcessBuilder,
/// Optional rustc process to be used for primary crates instead of either rustc_process or
/// rustc_workspace_wrapper_process
primary_rustc_process: Option<ProcessBuilder>,

target_runner: Option<(PathBuf, Vec<String>)>,
}
Expand All @@ -85,13 +91,14 @@ impl<'cfg> Compilation<'cfg> {
default_kind: CompileKind,
) -> CargoResult<Compilation<'cfg>> {
let mut rustc = bcx.rustc().process();

let mut primary_unit_rustc_process = bcx.build_config.primary_unit_rustc.clone();
let mut primary_rustc_process = bcx.build_config.primary_unit_rustc.clone();
let mut rustc_workspace_wrapper_process = bcx.rustc().workspace_process();

if bcx.config.extra_verbose() {
rustc.display_env_vars();
rustc_workspace_wrapper_process.display_env_vars();

if let Some(rustc) = primary_unit_rustc_process.as_mut() {
if let Some(rustc) = primary_rustc_process.as_mut() {
rustc.display_env_vars();
}
}
Expand Down Expand Up @@ -120,19 +127,25 @@ impl<'cfg> Compilation<'cfg> {
rustdocflags: HashMap::new(),
config: bcx.config,
rustc_process: rustc,
primary_unit_rustc_process,
rustc_workspace_wrapper_process,
primary_rustc_process,
host: bcx.host_triple().to_string(),
target: bcx.target_data.short_name(&default_kind).to_string(),
target_runner: target_runner(bcx, default_kind)?,
})
}

/// See `process`.
pub fn rustc_process(&self, pkg: &Package, is_primary: bool) -> CargoResult<ProcessBuilder> {
let rustc = if is_primary {
self.primary_unit_rustc_process
.clone()
.unwrap_or_else(|| self.rustc_process.clone())
pub fn rustc_process(
&self,
pkg: &Package,
is_primary: bool,
is_workspace: bool,
) -> CargoResult<ProcessBuilder> {
let rustc = if is_primary && self.primary_rustc_process.is_some() {
self.primary_rustc_process.clone().unwrap()
} else if is_workspace {
self.rustc_workspace_wrapper_process.clone()
} else {
self.rustc_process.clone()
};
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,11 @@ fn compute_metadata<'a, 'cfg>(

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

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

Expand Down
12 changes: 1 addition & 11 deletions src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,22 +1100,12 @@ fn calculate_normal<'a, 'cfg>(
// Fill out a bunch more information that we'll be tracking typically
// hashed to take up less space on disk as we just need to know when things
// change.
let mut extra_flags = if unit.mode.is_doc() {
let extra_flags = if unit.mode.is_doc() {
cx.bcx.rustdocflags_args(unit)
} else {
cx.bcx.rustflags_args(unit)
}
.to_vec();
if cx.is_primary_package(unit) {
// This is primarily here for clippy arguments.
if let Some(proc) = &cx.bcx.build_config.primary_unit_rustc {
let args = proc
.get_args()
.iter()
.map(|s| s.to_string_lossy().to_string());
extra_flags.extend(args);
}
}

let profile_hash = util::hash_u64((&unit.profile, unit.mode, cx.bcx.extra_args_for(unit)));
// Include metadata since it is exposed as environment variables.
Expand Down
5 changes: 4 additions & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,11 @@ fn prepare_rustc<'a, 'cfg>(
unit: &Unit<'a>,
) -> CargoResult<ProcessBuilder> {
let is_primary = cx.is_primary_package(unit);
let is_workspace = cx.bcx.ws.is_member(unit.pkg);

let mut base = cx.compilation.rustc_process(unit.pkg, is_primary)?;
let mut base = cx
.compilation
.rustc_process(unit.pkg, is_primary, is_workspace)?;
if cx.bcx.config.cli_unstable().jobserver_per_rustc {
let client = cx.new_jobserver()?;
base.inherit_jobserver(&client);
Expand Down
Loading

0 comments on commit 7302186

Please sign in to comment.