Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix comments
  • Loading branch information
yaahc committed Mar 30, 2019
commit a23f8115c5a2882e43382ed0ab0ae13b64bf8635
25 changes: 7 additions & 18 deletions src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ 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::paths;
use crate::util::rustc::RustcWrapper;
use crate::util::{profile, Cfg, CfgExpr, Config, Rustc};

use super::{BuildConfig, BuildOutput, Kind, Unit};
Expand Down Expand Up @@ -55,26 +54,16 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
let mut rustc = config.load_global_rustc(Some(ws))?;

if build_config.clippy_override {
let tool = config.get_tool("clippy-driver")?;
let tool = paths::resolve_executable(&tool).map_err(|e| {
let rustup_in_path = config
.get_tool("rustup")
.and_then(|tool| paths::resolve_executable(&tool))
.is_ok();
let has_rustup_env = std::env::var("RUSTUP_TOOLCHAIN").is_ok();
if rustup_in_path || has_rustup_env {
failure::format_err!("{}: please run `rustup component add clippy`", e)
} else {
failure::format_err!("{}: please install clippy", e)
}
})?;
rustc.push_wrapper(RustcWrapper::new(tool));
rustc.set_wrapper(util::process("clippy-driver"));
} else if build_config.cargo_as_rustc_wrapper {
let mut wrapper = RustcWrapper::new(env::current_exe()?);
let mut wrapper = util::process(env::current_exe()?);
for (k, v) in build_config.extra_rustc_env.iter() {
wrapper.env(k, v);
}
rustc.push_wrapper(wrapper);
for arg in build_config.extra_rustc_args.iter() {
wrapper.arg(arg);
}
rustc.set_wrapper(wrapper);
}

let host_config = TargetConfig::new(config, &rustc.host)?;
Expand Down
3 changes: 0 additions & 3 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ impl<'cfg> Compilation<'cfg> {
if bcx.config.extra_verbose() {
rustc.display_env_vars();
}
for arg in bcx.build_config.extra_rustc_args.iter() {
rustc.arg(arg);
}
let srv = bcx.build_config.rustfix_diagnostic_server.borrow();
if let Some(server) = &*srv {
server.configure(&mut rustc);
Expand Down
63 changes: 6 additions & 57 deletions src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::collections::hash_map::{Entry, HashMap};
use std::env;
use std::ffi::{OsStr, OsString};
use std::hash::{Hash, Hasher, SipHasher};
use std::path::{Path, PathBuf};
use std::process::Stdio;
Expand All @@ -21,64 +20,14 @@ pub struct Rustc {
pub path: PathBuf,
/// An optional program that will be passed the path of the rust exe as its first argument, and
/// rustc args following this.
pub wrapper: Option<RustcWrapper>,
pub wrapper: Option<ProcessBuilder>,
/// Verbose version information (the output of `rustc -vV`)
pub verbose_version: String,
/// The host triple (arch-platform-OS), this comes from verbose_version.
pub host: String,
cache: Mutex<Cache>,
}

/// Information on the `rustc` wrapper
#[derive(Debug)]
pub struct RustcWrapper {
path: PathBuf,
env: HashMap<String, Option<OsString>>,
}

impl RustcWrapper {
pub fn new<T: Into<PathBuf>>(path: T) -> RustcWrapper {
RustcWrapper {
path: path.into(),
env: HashMap::new(),
}
}

/// (chainable) Sets an environment variable for the process.
pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut RustcWrapper {
self.env
.insert(key.to_string(), Some(val.as_ref().to_os_string()));
self
}

/// (chainable) Unsets an environment variable for the process.
pub fn env_remove(&mut self, key: &str) -> &mut RustcWrapper {
self.env.insert(key.to_string(), None);
self
}

pub fn process(&self) -> ProcessBuilder {
let mut cmd = util::process(&self.path);

for (k, v) in &self.env {
match *v {
Some(ref v) => {
cmd.env(k, v);
}
None => {
cmd.env_remove(k);
}
}
}

cmd
}

pub fn is_empty(&self) -> bool {
self.path.as_os_str().is_empty()
}
}

impl Rustc {
/// Runs the compiler at `path` to learn various pieces of information about
/// it, with an optional wrapper.
Expand Down Expand Up @@ -110,7 +59,7 @@ impl Rustc {

Ok(Rustc {
path,
wrapper: wrapper.map(RustcWrapper::new),
wrapper: wrapper.map(util::process),
verbose_version,
host,
cache: Mutex::new(cache),
Expand All @@ -120,8 +69,8 @@ impl Rustc {
/// Gets a process builder set up to use the found rustc version, with a wrapper if `Some`.
pub fn process(&self) -> ProcessBuilder {
match self.wrapper {
Some(ref wrapper) if !wrapper.is_empty() => {
let mut cmd = wrapper.process();
Some(ref wrapper) if !wrapper.get_program().is_empty() => {
let mut cmd = wrapper.clone();
cmd.arg(&self.path);
cmd
}
Expand All @@ -141,8 +90,8 @@ impl Rustc {
self.cache.lock().unwrap().cached_success(cmd)
}

pub fn push_wrapper<T: Into<Option<RustcWrapper>>>(&mut self, wrapper: T) {
self.wrapper = wrapper.into();
pub fn set_wrapper(&mut self, wrapper: ProcessBuilder) {
self.wrapper = Some(wrapper);
}
}

Expand Down