Bring up to date with Rust master

This commit is contained in:
Yehuda Katz 2014-05-05 11:32:49 -07:00
parent 71066787bf
commit 2fd7aad710
9 changed files with 41 additions and 54 deletions

@ -1 +1 @@
Subproject commit add50d98e97ef30e7264ae70b83cf5ddedbf4450 Subproject commit de700414aab1aaa4461618ce7a516cb24a8e6665

@ -1 +1 @@
Subproject commit 1702321fb1300aaf4182f4ba48d31f8eaf0a5a69 Subproject commit e248cfbd6e336c3ea1a7273bea66e2fd3e3591f6

View File

@ -31,14 +31,14 @@ fn execute() {
Err(err) => return handle_error(err) Err(err) => return handle_error(err)
}; };
if cmd == ~"config-for-key" { execute_main_without_stdin(config_for_key) } if cmd == "config-for-key".to_owned() { execute_main_without_stdin(config_for_key) }
else if cmd == ~"config-list" { execute_main_without_stdin(config_list) } else if cmd == "config-list".to_owned() { execute_main_without_stdin(config_list) }
else if cmd == ~"locate-project" { execute_main_without_stdin(locate_project) } else if cmd == "locate-project".to_owned() { execute_main_without_stdin(locate_project) }
} }
fn process(mut args: ~[~str]) -> CargoResult<(~str, ~[~str])> { fn process(mut args: ~[~str]) -> CargoResult<(~str, ~[~str])> {
args = args.tail().to_owned(); args = args.tail().to_owned();
let head = try!(args.head().to_cargo_error(~"No subcommand found", 1)).to_owned(); let head = try!(args.head().to_cargo_error("No subcommand found".to_owned(), 1)).to_owned();
let tail = args.tail().to_owned(); let tail = args.tail().to_owned();
Ok((head, tail)) Ok((head, tail))
@ -99,7 +99,7 @@ fn config_list(args: ConfigListFlags) -> CargoResult<Option<ConfigOut>> {
} }
fn locate_project(_: NoFlags) -> CargoResult<Option<ProjectLocation>> { fn locate_project(_: NoFlags) -> CargoResult<Option<ProjectLocation>> {
let root = try!(find_project(os::getcwd(), ~"Cargo.toml")); let root = try!(find_project(os::getcwd(), "Cargo.toml".to_owned()));
let string = try!(root.as_str().to_cargo_error(format!("Your project path contains characters not representable in Unicode: {}", os::getcwd().display()), 1)); let string = try!(root.as_str().to_cargo_error(format!("Your project path contains characters not representable in Unicode: {}", os::getcwd().display()), 1));
Ok(Some(ProjectLocation { root: string.to_owned() })) Ok(Some(ProjectLocation { root: string.to_owned() }))
} }

View File

@ -52,7 +52,7 @@ impl Manifest {
project: project.clone(), project: project.clone(),
lib: lib, lib: lib,
bin: bin, bin: bin,
target: ~"target", target: "target".to_owned(),
dependencies: deps dependencies: deps
}) })
} }

View File

@ -146,7 +146,7 @@ fn flags_from_args<T: RepresentsFlags>() -> CargoResult<T> {
fn json_from_stdin<T: RepresentsJSON>() -> CargoResult<T> { fn json_from_stdin<T: RepresentsJSON>() -> CargoResult<T> {
let mut reader = io::stdin(); let mut reader = io::stdin();
let input = try!(reader.read_to_str().to_cargo_error(~"Cannot read stdin to a string", 1)); let input = try!(reader.read_to_str().to_cargo_error("Cannot read stdin to a string".to_owned(), 1));
let json = try!(json::from_str(input).to_cargo_error(format!("Cannot parse json: {}", input), 1)); let json = try!(json::from_str(input).to_cargo_error(format!("Cannot parse json: {}", input), 1));
let mut decoder = json::Decoder::new(json); let mut decoder = json::Decoder::new(json);

View File

@ -34,24 +34,15 @@ use sources::path::PathSource;
use ops::cargo_rustc; use ops::cargo_rustc;
use {CargoError,ToCargoError,CargoResult}; use {CargoError,ToCargoError,CargoResult};
#[deriving(Decodable)]
struct Options {
manifest_path: ~str
}
impl FlagConfig for Options { pub fn compile(manifest_path: &str) -> CargoResult<()> {
fn config(_: Option<Options>, c: FlagConfiguration) -> FlagConfiguration { c } let manifest = try!(cargo_read_manifest(manifest_path));
}
pub fn compile() -> CargoResult<()> {
let options = try!(flags::<Options>());
let manifest = try!(cargo_read_manifest(options.manifest_path));
let configs = try!(all_configs(os::getcwd())); let configs = try!(all_configs(os::getcwd()));
let config_paths = configs.find(&~"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new()); let config_paths = configs.find(&("paths".to_owned())).map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new());
let paths = match config_paths.get_value() { let paths = match config_paths.get_value() {
&config::String(_) => return Err(CargoError::new(~"The path was configured as a String instead of a List", 1)), &config::String(_) => return Err(CargoError::new("The path was configured as a String instead of a List".to_owned(), 1)),
&config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect() &config::List(ref list) => list.iter().map(|path| Path::new(path.as_slice())).collect()
}; };
@ -74,13 +65,9 @@ pub fn compile() -> CargoResult<()> {
//call_rustc(~BufReader::new(manifest_bytes.as_slice())) //call_rustc(~BufReader::new(manifest_bytes.as_slice()))
} }
fn flags<T: FlagConfig + Decodable<FlagDecoder, HammerError>>() -> CargoResult<T> {
let mut decoder = FlagDecoder::new::<T>(std::os::args().tail());
Decodable::decode(&mut decoder).to_cargo_error(|e: HammerError| e.message, 1)
}
fn read_manifest(manifest_path: &str) -> CargoResult<Vec<u8>> { fn read_manifest(manifest_path: &str) -> CargoResult<Vec<u8>> {
Ok((try!(exec_with_output("cargo-read-manifest", [~"--manifest-path", manifest_path.to_owned()], None))).output) Ok((try!(exec_with_output("cargo-read-manifest", ["--manifest-path".to_owned(), manifest_path.to_owned()], None))).output)
} }
fn call_rustc(mut manifest_data: ~Reader:) -> CargoResult<()> { fn call_rustc(mut manifest_data: ~Reader:) -> CargoResult<()> {

View File

@ -51,9 +51,9 @@ fn rustc(root: &Path, src: &Path, target: &Path, deps: &[core::Package]) {
fn build_base_args(dst: &mut Args, src: &Path, target: &Path) { fn build_base_args(dst: &mut Args, src: &Path, target: &Path) {
dst.push(src.as_str().unwrap().to_owned()); dst.push(src.as_str().unwrap().to_owned());
dst.push(~"--crate-type"); dst.push("--crate-type".to_owned());
dst.push(~"lib"); dst.push("lib".to_owned());
dst.push(~"--out-dir"); dst.push("--out-dir".to_owned());
dst.push(target.as_str().unwrap().to_owned()); dst.push(target.as_str().unwrap().to_owned());
} }
@ -61,7 +61,7 @@ fn build_deps_args(dst: &mut Args, deps: &[core::Package]) {
for dep in deps.iter() { for dep in deps.iter() {
let target = dep.get_root().join(Path::new(dep.get_target())); let target = dep.get_root().join(Path::new(dep.get_target()));
dst.push(~"-L"); dst.push("-L".to_owned());
dst.push(target.as_str().unwrap().to_owned()); dst.push(target.as_str().unwrap().to_owned());
} }
} }
@ -76,20 +76,20 @@ pub fn execute(_: NoFlags, manifest: core::Manifest) -> CargoResult<Option<core:
let core::Manifest { root, lib, bin, .. } = manifest; let core::Manifest { root, lib, bin, .. } = manifest;
let (crate_type, out_dir) = if lib.len() > 0 { let (crate_type, out_dir) = if lib.len() > 0 {
( ~"lib", lib[0].path ) ( "lib".to_owned(), lib[0].path )
} else if bin.len() > 0 { } else if bin.len() > 0 {
( ~"bin", bin[0].path ) ( "bin".to_owned(), bin[0].path )
} else { } else {
return Err(CargoError::new(~"bad manifest, no lib or bin specified", 1)); return Err(CargoError::new("bad manifest, no lib or bin specified".to_owned(), 1));
}; };
let root = Path::new(root); let root = Path::new(root);
let target = join(&root, ~"target"); let target = join(&root, "target".to_owned());
let args = [ let args = [
join(&root, out_dir), join(&root, out_dir),
~"--out-dir", target, "--out-dir".to_owned(), target,
~"--crate-type", crate_type "--crate-type".to_owned(), crate_type
]; ];
match io::fs::mkdir_recursive(&root.join("target"), io::UserRWX) { match io::fs::mkdir_recursive(&root.join("target"), io::UserRWX) {

View File

@ -99,7 +99,7 @@ fn find_in_tree<T>(pwd: &Path, walk: |io::fs::File| -> CargoResult<T>) -> CargoR
loop { loop {
let possible = current.join(".cargo").join("config"); let possible = current.join(".cargo").join("config");
if possible.exists() { if possible.exists() {
let file = try!(io::fs::File::open(&possible).to_cargo_error(~"", 1)); let file = try!(io::fs::File::open(&possible).to_cargo_error("".to_owned(), 1));
match walk(file) { match walk(file) {
Ok(res) => return Ok(res), Ok(res) => return Ok(res),
_ => () _ => ()
@ -109,7 +109,7 @@ fn find_in_tree<T>(pwd: &Path, walk: |io::fs::File| -> CargoResult<T>) -> CargoR
if !current.pop() { break; } if !current.pop() { break; }
} }
Err(CargoError::new(~"", 1)) Err(CargoError::new("".to_owned(), 1))
} }
fn walk_tree(pwd: &Path, walk: |io::fs::File| -> CargoResult<()>) -> CargoResult<()> { fn walk_tree(pwd: &Path, walk: |io::fs::File| -> CargoResult<()>) -> CargoResult<()> {
@ -119,14 +119,14 @@ fn walk_tree(pwd: &Path, walk: |io::fs::File| -> CargoResult<()>) -> CargoResult
loop { loop {
let possible = current.join(".cargo").join("config"); let possible = current.join(".cargo").join("config");
if possible.exists() { if possible.exists() {
let file = try!(io::fs::File::open(&possible).to_cargo_error(~"", 1)); let file = try!(io::fs::File::open(&possible).to_cargo_error("".to_owned(), 1));
match walk(file) { match walk(file) {
Err(_) => err = false, Err(_) => err = false,
_ => () _ => ()
} }
} }
if err { return Err(CargoError::new(~"", 1)); } if err { return Err(CargoError::new("".to_owned(), 1)); }
if !current.pop() { break; } if !current.pop() { break; }
} }
@ -134,25 +134,25 @@ fn walk_tree(pwd: &Path, walk: |io::fs::File| -> CargoResult<()>) -> CargoResult
} }
fn extract_config(file: io::fs::File, key: &str) -> CargoResult<ConfigValue> { fn extract_config(file: io::fs::File, key: &str) -> CargoResult<ConfigValue> {
let path = try!(file.path().as_str().to_cargo_error(~"", 1)).to_owned(); let path = try!(file.path().as_str().to_cargo_error("".to_owned(), 1)).to_owned();
let mut buf = io::BufferedReader::new(file); let mut buf = io::BufferedReader::new(file);
let root = try!(toml::parse_from_buffer(&mut buf).to_cargo_error(~"", 1)); let root = try!(toml::parse_from_buffer(&mut buf).to_cargo_error("".to_owned(), 1));
let val = try!(root.lookup(key).to_cargo_error(~"", 1)); let val = try!(root.lookup(key).to_cargo_error("".to_owned(), 1));
let v = match val { let v = match val {
&toml::String(ref val) => String(val.to_owned()), &toml::String(ref val) => String(val.to_owned()),
&toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| s.to_str()).collect()), &toml::Array(ref val) => List(val.iter().map(|s: &toml::Value| s.to_str()).collect()),
_ => return Err(CargoError::new(~"", 1)) _ => return Err(CargoError::new("".to_owned(), 1))
}; };
Ok(ConfigValue{ value: v, path: vec!(path) }) Ok(ConfigValue{ value: v, path: vec!(path) })
} }
fn extract_all_configs(file: io::fs::File, map: &mut collections::HashMap<~str, ConfigValue>) -> CargoResult<()> { fn extract_all_configs(file: io::fs::File, map: &mut collections::HashMap<~str, ConfigValue>) -> CargoResult<()> {
let path = try!(file.path().as_str().to_cargo_error(~"", 1)).to_owned(); let path = try!(file.path().as_str().to_cargo_error("".to_owned(), 1)).to_owned();
let mut buf = io::BufferedReader::new(file); let mut buf = io::BufferedReader::new(file);
let root = try!(toml::parse_from_buffer(&mut buf).to_cargo_error(~"", 1)); let root = try!(toml::parse_from_buffer(&mut buf).to_cargo_error("".to_owned(), 1));
let table = try!(root.get_table().to_cargo_error(~"", 1)); let table = try!(root.get_table().to_cargo_error("".to_owned(), 1));
for (key, value) in table.iter() { for (key, value) in table.iter() {
match value { match value {
@ -173,11 +173,11 @@ fn extract_all_configs(file: io::fs::File, map: &mut collections::HashMap<~str,
fn merge_array(existing: &mut ConfigValue, val: &[toml::Value], path: &str) -> CargoResult<()> { fn merge_array(existing: &mut ConfigValue, val: &[toml::Value], path: &str) -> CargoResult<()> {
match existing.value { match existing.value {
String(_) => return Err(CargoError::new(~"", 1)), String(_) => return Err(CargoError::new("".to_owned(), 1)),
List(ref mut list) => { List(ref mut list) => {
let new_list: Vec<CargoResult<~str>> = val.iter().map(|s: &toml::Value| toml_string(s)).collect(); let new_list: Vec<CargoResult<~str>> = val.iter().map(|s: &toml::Value| toml_string(s)).collect();
if new_list.iter().any(|v| v.is_err()) { if new_list.iter().any(|v| v.is_err()) {
return Err(CargoError::new(~"", 1)); return Err(CargoError::new("".to_owned(), 1));
} else { } else {
let new_list: Vec<~str> = new_list.move_iter().map(|v| v.unwrap()).collect(); let new_list: Vec<~str> = new_list.move_iter().map(|v| v.unwrap()).collect();
list.push_all(new_list.as_slice()); list.push_all(new_list.as_slice());
@ -191,6 +191,6 @@ fn merge_array(existing: &mut ConfigValue, val: &[toml::Value], path: &str) -> C
fn toml_string(val: &toml::Value) -> CargoResult<~str> { fn toml_string(val: &toml::Value) -> CargoResult<~str> {
match val { match val {
&toml::String(ref str) => Ok(str.to_owned()), &toml::String(ref str) => Ok(str.to_owned()),
_ => Err(CargoError::new(~"", 1)) _ => Err(CargoError::new("".to_owned(), 1))
} }
} }

View File

@ -67,15 +67,15 @@ impl ProcessBuilder {
config.args = self.args.as_slice(); config.args = self.args.as_slice();
config.cwd = Some(&self.cwd); config.cwd = Some(&self.cwd);
let os_path = try!(os::getenv("PATH").to_cargo_error(~"Could not find the PATH environment variable", 1)); let os_path = try!(os::getenv("PATH").to_cargo_error("Could not find the PATH environment variable".to_owned(), 1));
let path = os_path + PATH_SEP + self.path.connect(PATH_SEP); let path = os_path + PATH_SEP + self.path.connect(PATH_SEP);
let path = [(~"PATH", path)]; let path = [("PATH".to_owned(), path)];
config.env = Some(path.as_slice()); config.env = Some(path.as_slice());
println!("{:?}", config); println!("{:?}", config);
Process::configure(config).map(|mut ok| ok.wait_with_output()).to_cargo_error(~"Could not spawn process", 1) Process::configure(config).map(|mut ok| ok.wait_with_output()).to_cargo_error("Could not spawn process".to_owned(), 1)
} }
} }