Skip to content

Commit

Permalink
avoid an extra cargo invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgoo committed May 8, 2017
1 parent 784d315 commit b1a9616
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
26 changes: 16 additions & 10 deletions src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
}

let mut with_cfg = process.clone();
with_cfg.arg("--print=sysroot");
with_cfg.arg("--print=cfg");

let mut has_cfg = true;
let mut has_cfg_and_sysroot = true;
let output = with_cfg.exec_with_output().or_else(|_| {
has_cfg = false;
has_cfg_and_sysroot = false;
process.exec_with_output()
}).chain_error(|| {
human(format!("failed to run `rustc` to learn about \
Expand Down Expand Up @@ -237,14 +238,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
map.insert(crate_type.to_string(), Some((prefix.to_string(), suffix.to_string())));
}

let cfg = if has_cfg {
Some(try!(lines.map(Cfg::from_str).collect()))
} else {
None
};

if let Some(ref sysroot) = self.config.rustc()?.sysroot {
let mut rustlib = sysroot.clone();
if has_cfg_and_sysroot {
let line = match lines.next() {
Some(line) => line,
None => bail!("output of --print=sysroot missing when learning about \
target-specific information from rustc"),
};
let mut rustlib = PathBuf::from(line);
if kind == Kind::Host {
if cfg!(windows) {
rustlib.push("bin");
Expand All @@ -259,6 +259,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
rustlib.push("lib");
self.compilation.target_dylib_path = Some(rustlib);
}
}

let cfg = if has_cfg_and_sysroot {
Some(try!(lines.map(Cfg::from_str).collect()))
} else {
None
};

let info = match kind {
Expand Down
10 changes: 0 additions & 10 deletions src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub struct Rustc {
pub wrapper: Option<PathBuf>,
pub verbose_version: String,
pub host: String,
pub sysroot: Option<PathBuf>,
}

impl Rustc {
Expand Down Expand Up @@ -36,20 +35,11 @@ impl Rustc {
triple.to_string()
};

let sysroot = {
let mut cmd = util::process(&path);
cmd.arg("--print=sysroot");
cmd.exec_with_output().ok()
.and_then(|output| String::from_utf8(output.stdout).ok() )
.map(|s| PathBuf::from(s.trim()))
};

Ok(Rustc {
path: path,
wrapper: wrapper,
verbose_version: verbose_version,
host: host,
sysroot: sysroot
})
}

Expand Down

0 comments on commit b1a9616

Please sign in to comment.