Skip to content

Commit

Permalink
Remove no longer needed fields in BuildConfig
Browse files Browse the repository at this point in the history
Now the fields are just all represented as `rustc_wrapper` which
internally contains all process configuration that's later passed down
to `Rustc` as necessary.
  • Loading branch information
alexcrichton committed Apr 1, 2019
1 parent a23f811 commit 842da62
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 55 deletions.
5 changes: 4 additions & 1 deletion src/bin/cargo/commands/clippy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::command_prelude::*;

use cargo::ops;
use cargo::util;

pub fn cli() -> App {
subcommand("clippy-preview")
Expand Down Expand Up @@ -60,7 +61,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {

let mode = CompileMode::Check { test: false };
let mut compile_opts = args.compile_options(config, mode, Some(&ws))?;
compile_opts.build_config.set_clippy_override(true);

if !config.cli_unstable().unstable_options {
return Err(failure::format_err!(
Expand All @@ -69,6 +69,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
.into());
}

let wrapper = util::process("clippy-driver");
compile_opts.build_config.rustc_wrapper = Some(wrapper);

ops::compile(&ws, &compile_opts)?;
Ok(())
}
21 changes: 4 additions & 17 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::Path;

use serde::ser;

use crate::util::ProcessBuilder;
use crate::util::{CargoResult, CargoResultExt, Config, RustfixDiagnosticServer};

/// Configuration information for a rustc build.
Expand All @@ -23,15 +24,9 @@ pub struct BuildConfig {
pub force_rebuild: bool,
/// Output a build plan to stdout instead of actually compiling.
pub build_plan: bool,
/// Use Cargo itself as the wrapper around rustc, only used for `cargo fix`.
pub cargo_as_rustc_wrapper: bool,
/// Extra env vars to inject into rustc commands.
pub extra_rustc_env: Vec<(String, String)>,
/// Extra args to inject into rustc commands.
pub extra_rustc_args: Vec<String>,
/// An optional wrapper, if any, used to wrap rustc invocations
pub rustc_wrapper: Option<ProcessBuilder>,
pub rustfix_diagnostic_server: RefCell<Option<RustfixDiagnosticServer>>,
/// Use `clippy-driver` instead of `rustc`
pub clippy_override: bool,
}

impl BuildConfig {
Expand Down Expand Up @@ -100,11 +95,8 @@ impl BuildConfig {
message_format: MessageFormat::Human,
force_rebuild: false,
build_plan: false,
cargo_as_rustc_wrapper: false,
extra_rustc_env: Vec::new(),
extra_rustc_args: Vec::new(),
rustc_wrapper: None,
rustfix_diagnostic_server: RefCell::new(None),
clippy_override: false,
})
}

Expand All @@ -115,11 +107,6 @@ impl BuildConfig {
pub fn test(&self) -> bool {
self.mode == CompileMode::Test || self.mode == CompileMode::Bench
}

/// Sets the clippy override. If this is true, clippy-driver is invoked instead of rustc.
pub fn set_clippy_override(&mut self, val: bool) {
self.clippy_override = val;
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down
15 changes: 2 additions & 13 deletions src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use log::debug;
use crate::core::profiles::Profiles;
use crate::core::{Dependency, Workspace};
use crate::core::{PackageId, PackageSet, Resolve};
use crate::util;
use crate::util::errors::CargoResult;
use crate::util::{profile, Cfg, CfgExpr, Config, Rustc};

Expand Down Expand Up @@ -52,18 +51,8 @@ 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 build_config.clippy_override {
rustc.set_wrapper(util::process("clippy-driver"));
} else if build_config.cargo_as_rustc_wrapper {
let mut wrapper = util::process(env::current_exe()?);
for (k, v) in build_config.extra_rustc_env.iter() {
wrapper.env(k, v);
}
for arg in build_config.extra_rustc_args.iter() {
wrapper.arg(arg);
}
rustc.set_wrapper(wrapper);
if let Some(wrapper) = &build_config.rustc_wrapper {
rustc.set_wrapper(wrapper.clone());
}

let host_config = TargetConfig::new(config, &rustc.host)?;
Expand Down
33 changes: 9 additions & 24 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use crate::core::Workspace;
use crate::ops::{self, CompileOptions};
use crate::util::diagnostic_server::{Message, RustfixDiagnosticServer};
use crate::util::errors::CargoResult;
use crate::util::paths;
use crate::util::{self, paths};
use crate::util::{existing_vcs_repo, LockServer, LockServerClient};

const FIX_ENV: &str = "__CARGO_FIX_PLZ";
Expand All @@ -81,46 +81,31 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions<'_>) -> CargoResult<()> {

// Spin up our lock server, which our subprocesses will use to synchronize fixes.
let lock_server = LockServer::new()?;
opts.compile_opts
.build_config
.extra_rustc_env
.push((FIX_ENV.to_string(), lock_server.addr().to_string()));
let mut wrapper = util::process(env::current_exe()?);
wrapper.env(FIX_ENV, lock_server.addr().to_string());
let _started = lock_server.start()?;

opts.compile_opts.build_config.force_rebuild = true;

if opts.broken_code {
let key = BROKEN_CODE_ENV.to_string();
opts.compile_opts
.build_config
.extra_rustc_env
.push((key, "1".to_string()));
wrapper.env(BROKEN_CODE_ENV, "1");
}

if opts.edition {
let key = EDITION_ENV.to_string();
opts.compile_opts
.build_config
.extra_rustc_env
.push((key, "1".to_string()));
wrapper.env(EDITION_ENV, "1");
} else if let Some(edition) = opts.prepare_for {
opts.compile_opts
.build_config
.extra_rustc_env
.push((PREPARE_FOR_ENV.to_string(), edition.to_string()));
wrapper.env(PREPARE_FOR_ENV, edition);
}
if opts.idioms {
opts.compile_opts
.build_config
.extra_rustc_env
.push((IDIOMS_ENV.to_string(), "1".to_string()));
wrapper.env(IDIOMS_ENV, "1");
}
opts.compile_opts.build_config.cargo_as_rustc_wrapper = true;

*opts
.compile_opts
.build_config
.rustfix_diagnostic_server
.borrow_mut() = Some(RustfixDiagnosticServer::new()?);
opts.compile_opts.build_config.rustc_wrapper = Some(wrapper);

ops::compile(ws, &opts.compile_opts)?;
Ok(())
Expand Down

0 comments on commit 842da62

Please sign in to comment.