Skip to content

Commit a23f811

Browse files
committed
fix comments
1 parent 47c82f0 commit a23f811

File tree

3 files changed

+13
-78
lines changed

3 files changed

+13
-78
lines changed

src/cargo/core/compiler/build_context/mod.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use log::debug;
88
use crate::core::profiles::Profiles;
99
use crate::core::{Dependency, Workspace};
1010
use crate::core::{PackageId, PackageSet, Resolve};
11+
use crate::util;
1112
use crate::util::errors::CargoResult;
12-
use crate::util::paths;
13-
use crate::util::rustc::RustcWrapper;
1413
use crate::util::{profile, Cfg, CfgExpr, Config, Rustc};
1514

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

5756
if build_config.clippy_override {
58-
let tool = config.get_tool("clippy-driver")?;
59-
let tool = paths::resolve_executable(&tool).map_err(|e| {
60-
let rustup_in_path = config
61-
.get_tool("rustup")
62-
.and_then(|tool| paths::resolve_executable(&tool))
63-
.is_ok();
64-
let has_rustup_env = std::env::var("RUSTUP_TOOLCHAIN").is_ok();
65-
if rustup_in_path || has_rustup_env {
66-
failure::format_err!("{}: please run `rustup component add clippy`", e)
67-
} else {
68-
failure::format_err!("{}: please install clippy", e)
69-
}
70-
})?;
71-
rustc.push_wrapper(RustcWrapper::new(tool));
57+
rustc.set_wrapper(util::process("clippy-driver"));
7258
} else if build_config.cargo_as_rustc_wrapper {
73-
let mut wrapper = RustcWrapper::new(env::current_exe()?);
59+
let mut wrapper = util::process(env::current_exe()?);
7460
for (k, v) in build_config.extra_rustc_env.iter() {
7561
wrapper.env(k, v);
7662
}
77-
rustc.push_wrapper(wrapper);
63+
for arg in build_config.extra_rustc_args.iter() {
64+
wrapper.arg(arg);
65+
}
66+
rustc.set_wrapper(wrapper);
7867
}
7968

8069
let host_config = TargetConfig::new(config, &rustc.host)?;

src/cargo/core/compiler/compilation.rs

-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ impl<'cfg> Compilation<'cfg> {
8080
if bcx.config.extra_verbose() {
8181
rustc.display_env_vars();
8282
}
83-
for arg in bcx.build_config.extra_rustc_args.iter() {
84-
rustc.arg(arg);
85-
}
8683
let srv = bcx.build_config.rustfix_diagnostic_server.borrow();
8784
if let Some(server) = &*srv {
8885
server.configure(&mut rustc);

src/cargo/util/rustc.rs

+6-57
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

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

32-
/// Information on the `rustc` wrapper
33-
#[derive(Debug)]
34-
pub struct RustcWrapper {
35-
path: PathBuf,
36-
env: HashMap<String, Option<OsString>>,
37-
}
38-
39-
impl RustcWrapper {
40-
pub fn new<T: Into<PathBuf>>(path: T) -> RustcWrapper {
41-
RustcWrapper {
42-
path: path.into(),
43-
env: HashMap::new(),
44-
}
45-
}
46-
47-
/// (chainable) Sets an environment variable for the process.
48-
pub fn env<T: AsRef<OsStr>>(&mut self, key: &str, val: T) -> &mut RustcWrapper {
49-
self.env
50-
.insert(key.to_string(), Some(val.as_ref().to_os_string()));
51-
self
52-
}
53-
54-
/// (chainable) Unsets an environment variable for the process.
55-
pub fn env_remove(&mut self, key: &str) -> &mut RustcWrapper {
56-
self.env.insert(key.to_string(), None);
57-
self
58-
}
59-
60-
pub fn process(&self) -> ProcessBuilder {
61-
let mut cmd = util::process(&self.path);
62-
63-
for (k, v) in &self.env {
64-
match *v {
65-
Some(ref v) => {
66-
cmd.env(k, v);
67-
}
68-
None => {
69-
cmd.env_remove(k);
70-
}
71-
}
72-
}
73-
74-
cmd
75-
}
76-
77-
pub fn is_empty(&self) -> bool {
78-
self.path.as_os_str().is_empty()
79-
}
80-
}
81-
8231
impl Rustc {
8332
/// Runs the compiler at `path` to learn various pieces of information about
8433
/// it, with an optional wrapper.
@@ -110,7 +59,7 @@ impl Rustc {
11059

11160
Ok(Rustc {
11261
path,
113-
wrapper: wrapper.map(RustcWrapper::new),
62+
wrapper: wrapper.map(util::process),
11463
verbose_version,
11564
host,
11665
cache: Mutex::new(cache),
@@ -120,8 +69,8 @@ impl Rustc {
12069
/// Gets a process builder set up to use the found rustc version, with a wrapper if `Some`.
12170
pub fn process(&self) -> ProcessBuilder {
12271
match self.wrapper {
123-
Some(ref wrapper) if !wrapper.is_empty() => {
124-
let mut cmd = wrapper.process();
72+
Some(ref wrapper) if !wrapper.get_program().is_empty() => {
73+
let mut cmd = wrapper.clone();
12574
cmd.arg(&self.path);
12675
cmd
12776
}
@@ -141,8 +90,8 @@ impl Rustc {
14190
self.cache.lock().unwrap().cached_success(cmd)
14291
}
14392

144-
pub fn push_wrapper<T: Into<Option<RustcWrapper>>>(&mut self, wrapper: T) {
145-
self.wrapper = wrapper.into();
93+
pub fn set_wrapper(&mut self, wrapper: ProcessBuilder) {
94+
self.wrapper = Some(wrapper);
14695
}
14796
}
14897

0 commit comments

Comments
 (0)