Skip to content

Commit

Permalink
Route the option for desugaring stdlib deps
Browse files Browse the repository at this point in the history
 - "build-stdlib" controls whether we prune stdlib deps (explicit or not)
 - "stdlib-reop" allows one to override http://githhub.com/rust-lang/rust
  • Loading branch information
Ericson2314 committed Jun 5, 2016
1 parent f39a227 commit 9716ee1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
31 changes: 22 additions & 9 deletions src/cargo/util/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::Path;

use regex::Regex;

use util::{self, CargoResult, internal, ChainError};

pub struct Rustc {
Expand Down Expand Up @@ -28,18 +30,19 @@ impl Rustc {
ret.verbose_version = try!(String::from_utf8(output.stdout).map_err(|_| {
internal("rustc -v didn't return utf8 output")
}));
ret.host = {
let triple = ret.verbose_version.lines().filter(|l| {
l.starts_with("host: ")
}).map(|l| &l[6..]).next();
let triple = try!(triple.chain_error(|| {
internal("rustc -v didn't have a line for `host:`")
}));
triple.to_string()
};
ret.host = try!({
version_get(&*ret.verbose_version, "host")
.chain_error(|| {
internal("rustc -v didn't have a line for `host:`")
})
}).to_string();
Ok(ret)
}

pub fn version_get<'a>(&'a self, key: &str) -> Option<&'a str> {
version_get(&self.verbose_version, key)
}

pub fn blank() -> Rustc {
Rustc {
verbose_version: String::new(),
Expand All @@ -48,3 +51,13 @@ impl Rustc {
}
}
}

fn version_get<'a>(verbose_version: &'a str, key: &str) -> Option<&'a str> {
let regex = Regex::new(&*format!(r"^{}: (.*)$", key)).unwrap();

verbose_version
.lines()
.filter_map(|l| regex.captures(l))
.next()
.and_then(|caps| caps.at(1))
}
29 changes: 28 additions & 1 deletion src/cargo/util/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,34 @@ pub fn to_manifest(contents: &[u8],
human(e.to_string())
}));

let pair = try!(manifest.to_manifest(source_id, &layout, None, config));
let opt_stdlib_reference = if
try!(config.get_bool("build-stdlib")).map(|v| v.val).unwrap_or(false)
{
match config.rustc_info().version_get("commit-hash") {
Some("unknown") | None => None,
Some(hash) => Some(GitReference::Rev(hash.to_string())),
}.or_else(|| match config.rustc_info().version_get("release") {
Some("unknown") | None => None,
Some(release) => Some(GitReference::Tag(release.to_string())),
})
} else {
None
};

let opt_stdlib_repo = match opt_stdlib_reference {
None => None,
Some(reference) => {
let config = try!(config.get_string("stdlib-repo"));
let url = config.as_ref().map(|s| &s.val[..])
.unwrap_or("http://github.com/rust-lang/rust.git");
let loc = try!(url.to_url().map_err(human));
Some(SourceId::for_git(&loc, reference))
},
};

let pair = try!(manifest.to_manifest(source_id, &layout,
opt_stdlib_repo,
config));
let (mut manifest, paths) = pair;
match d.toml {
Some(ref toml) => add_unused_keys(&mut manifest, toml, "".to_string()),
Expand Down

0 comments on commit 9716ee1

Please sign in to comment.