Skip to content

Commit b1a9616

Browse files
committed
avoid an extra cargo invocation
1 parent 784d315 commit b1a9616

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
196196
}
197197

198198
let mut with_cfg = process.clone();
199+
with_cfg.arg("--print=sysroot");
199200
with_cfg.arg("--print=cfg");
200201

201-
let mut has_cfg = true;
202+
let mut has_cfg_and_sysroot = true;
202203
let output = with_cfg.exec_with_output().or_else(|_| {
203-
has_cfg = false;
204+
has_cfg_and_sysroot = false;
204205
process.exec_with_output()
205206
}).chain_error(|| {
206207
human(format!("failed to run `rustc` to learn about \
@@ -237,14 +238,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
237238
map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
238239
}
239240

240-
let cfg = if has_cfg {
241-
Some(try!(lines.map(Cfg::from_str).collect()))
242-
} else {
243-
None
244-
};
245-
246-
if let Some(ref sysroot) = self.config.rustc()?.sysroot {
247-
let mut rustlib = sysroot.clone();
241+
if has_cfg_and_sysroot {
242+
let line = match lines.next() {
243+
Some(line) => line,
244+
None => bail!("output of --print=sysroot missing when learning about \
245+
target-specific information from rustc"),
246+
};
247+
let mut rustlib = PathBuf::from(line);
248248
if kind == Kind::Host {
249249
if cfg!(windows) {
250250
rustlib.push("bin");
@@ -259,6 +259,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
259259
rustlib.push("lib");
260260
self.compilation.target_dylib_path = Some(rustlib);
261261
}
262+
}
263+
264+
let cfg = if has_cfg_and_sysroot {
265+
Some(try!(lines.map(Cfg::from_str).collect()))
266+
} else {
267+
None
262268
};
263269

264270
let info = match kind {

src/cargo/util/rustc.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub struct Rustc {
77
pub wrapper: Option<PathBuf>,
88
pub verbose_version: String,
99
pub host: String,
10-
pub sysroot: Option<PathBuf>,
1110
}
1211

1312
impl Rustc {
@@ -36,20 +35,11 @@ impl Rustc {
3635
triple.to_string()
3736
};
3837

39-
let sysroot = {
40-
let mut cmd = util::process(&path);
41-
cmd.arg("--print=sysroot");
42-
cmd.exec_with_output().ok()
43-
.and_then(|output| String::from_utf8(output.stdout).ok() )
44-
.map(|s| PathBuf::from(s.trim()))
45-
};
46-
4738
Ok(Rustc {
4839
path: path,
4940
wrapper: wrapper,
5041
verbose_version: verbose_version,
5142
host: host,
52-
sysroot: sysroot
5343
})
5444
}
5545

0 commit comments

Comments
 (0)