Skip to content

Commit

Permalink
apply the correct changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yaahc committed Jul 18, 2019
1 parent f3d3318 commit 03feb61
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
}

let wrapper = util::process(util::config::clippy_driver());
compile_opts.build_config.rustc_wrapper = Some(wrapper);
compile_opts.build_config.primary_unit_rustc = Some(wrapper);

ops::compile(&ws, &compile_opts)?;
Ok(())
Expand Down
7 changes: 2 additions & 5 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::cell::RefCell;
use std::path::{Path, PathBuf};
use std::path::Path;

use serde::ser;

Expand All @@ -24,10 +24,8 @@ pub struct BuildConfig {
pub force_rebuild: bool,
/// Output a build plan to stdout instead of actually compiling.
pub build_plan: bool,
/// An optional wrapper, if any, used to wrap rustc invocations
pub rustc_wrapper: Option<ProcessBuilder>,
/// An optional override of the rustc path for primary units only
pub primary_unit_rustc: Option<PathBuf>,
pub primary_unit_rustc: Option<ProcessBuilder>,
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
/// Whether or not Cargo should cache compiler output on disk.
cache_messages: bool,
Expand Down Expand Up @@ -100,7 +98,6 @@ impl BuildConfig {
message_format: MessageFormat::Human,
force_rebuild: false,
build_plan: false,
rustc_wrapper: None,
primary_unit_rustc: None,
rustfix_diagnostic_server: RefCell::new(None),
cache_messages: config.cli_unstable().cache_messages,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
) -> CargoResult<BuildContext<'a, 'cfg>> {
let mut rustc = config.load_global_rustc(Some(ws))?;
if let Some(wrapper) = &build_config.rustc_wrapper {
if let Some(wrapper) = &build_config.primary_unit_rustc {
rustc.set_wrapper(wrapper.clone());
}

Expand Down
15 changes: 8 additions & 7 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,18 @@ impl<'cfg> Compilation<'cfg> {
pub fn new<'a>(bcx: &BuildContext<'a, 'cfg>) -> CargoResult<Compilation<'cfg>> {
let mut rustc = bcx.rustc.process();

let mut primary_unit_rustc_process = bcx
.build_config
.primary_unit_rustc
.as_ref()
.map(|primary_unit_rustc| bcx.rustc.process_with(primary_unit_rustc));
let mut primary_unit_rustc_process =
bcx.build_config.primary_unit_rustc.clone().map(|mut r| {
r.arg(&bcx.rustc.path);
r
});

if bcx.config.extra_verbose() {
rustc.display_env_vars();
primary_unit_rustc_process.as_mut().map(|rustc| {

if let Some(rustc) = primary_unit_rustc_process.as_mut() {
rustc.display_env_vars();
});
}
}

Ok(Compilation {
Expand Down
6 changes: 1 addition & 5 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,14 +591,10 @@ fn prepare_rustc<'a, 'cfg>(
unit: &Unit<'a>,
) -> CargoResult<ProcessBuilder> {
let is_primary = cx.is_primary_package(unit);

let mut base = cx
.compilation
.rustc_process(unit.pkg, unit.target, is_primary)?;

if is_primary {
base.env("CARGO_PRIMARY_PACKAGE", "1");
}

base.inherit_jobserver(&cx.jobserver);
build_base_args(cx, &mut base, unit, crate_types)?;
build_deps_args(&mut base, cx, unit)?;
Expand Down
42 changes: 17 additions & 25 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {
eprintln!("Warning: clippy-driver not found: {:?}", e);
}

opts.compile_opts.build_config.primary_unit_rustc = Some(util::config::clippy_driver());
let clippy_args = opts
.clippy_args
.as_ref()
.map_or_else(String::new, |args| serde_json::to_string(&args).unwrap());

if let Some(clippy_args) = &opts.clippy_args {
let clippy_args = serde_json::to_string(&clippy_args).unwrap();
wrapper.env(CLIPPY_FIX_ARGS, clippy_args);
}
wrapper.env(CLIPPY_FIX_ARGS, clippy_args);
}

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

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

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

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

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

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

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

for arg in env::args_os().skip(2) {
Expand Down Expand Up @@ -642,7 +636,6 @@ impl FixArgs {
}

ret.idioms = env::var(IDIOMS_ENV).is_ok();
ret.primary_package = env::var("CARGO_PRIMARY_PACKAGE").is_ok();
ret
}

Expand All @@ -658,14 +651,13 @@ impl FixArgs {
cmd.args(&self.other).arg("--cap-lints=warn");
if let Some(edition) = &self.enabled_edition {
cmd.arg("--edition").arg(edition);
if self.idioms && self.primary_package && edition == "2018" {
if self.idioms && edition == "2018" {
cmd.arg("-Wrust-2018-idioms");
}
}
if self.primary_package {
if let Some(edition) = self.prepare_for_edition_resolve() {
cmd.arg("-W").arg(format!("rust-{}-compatibility", edition));
}

if let Some(edition) = self.prepare_for_edition_resolve() {
cmd.arg("-W").arg(format!("rust-{}-compatibility", edition));
}
}

Expand Down

0 comments on commit 03feb61

Please sign in to comment.