diff --git a/.gitmodules b/.gitmodules index 21798a1d2..b6b1c7fd8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "libs/rust-toml"] path = libs/rust-toml - url = https://github.com/mneumann/rust-toml + url = https://github.com/wycats/rust-toml [submodule "libs/hammer.rs"] path = libs/hammer.rs url = https://github.com/wycats/hammer.rs.git diff --git a/libs/hammer.rs b/libs/hammer.rs index 60ec16a73..9b517eacf 160000 --- a/libs/hammer.rs +++ b/libs/hammer.rs @@ -1 +1 @@ -Subproject commit 60ec16a732abfc4dd6a090e4f47e9e2779fd9ba5 +Subproject commit 9b517eacf16ff9074dc6cc377141eb8e969540c7 diff --git a/libs/rust-toml b/libs/rust-toml index 1389ceb42..49290aedf 160000 --- a/libs/rust-toml +++ b/libs/rust-toml @@ -1 +1 @@ -Subproject commit 1389ceb42b2ae04dac40c8b2d4af8fe21823ecbc +Subproject commit 49290aedf236c365c08fbc01eb70127eb5ab4a60 diff --git a/src/bin/cargo-compile.rs b/src/bin/cargo-compile.rs index 34ca4ee19..cb41fa337 100644 --- a/src/bin/cargo-compile.rs +++ b/src/bin/cargo-compile.rs @@ -1,15 +1,16 @@ -#[crate_id="cargo-compile"]; -#[allow(deprecated_owned_vector)]; +#![crate_id="cargo-compile"] +#![allow(deprecated_owned_vector)] extern crate serialize; extern crate hammer; -// extern crate cargo; +extern crate cargo; use serialize::{Decodable}; -use hammer::{FlagDecoder,FlagConfig,FlagConfiguration}; +use hammer::{FlagDecoder,FlagConfig,FlagConfiguration,HammerError}; use std::io; -use io::{IoResult,IoError,OtherIoError,BufReader}; +use io::BufReader; use io::process::{Process,ProcessExit,ProcessOutput,InheritFd,ProcessConfig}; +use cargo::{ToCargoError,CargoResult}; #[deriving(Decodable)] struct Options { @@ -27,46 +28,40 @@ fn main() { } } -fn compile() -> IoResult<()> { +fn compile() -> CargoResult<()> { let options = try!(flags::()); - let manifest_bytes = try!(read_manifest(options.manifest_path)); + let manifest_bytes = try!(read_manifest(options.manifest_path).to_cargo_error(~"Could not read manifest", 1)); call_rustc(~BufReader::new(manifest_bytes.as_slice())) } -fn flags>() -> IoResult { +fn flags>() -> CargoResult { let mut decoder = FlagDecoder::new::(std::os::args().tail()); - let flags: T = Decodable::decode(&mut decoder); - - if decoder.error.is_some() { - Err(IoError{ kind: OtherIoError, desc: "could not decode flags", detail: Some(decoder.error.unwrap()) }) - } else { - Ok(flags) - } + Decodable::decode(&mut decoder).to_cargo_error(|e: HammerError| e.message, 1) } -fn read_manifest(manifest_path: &str) -> IoResult<~[u8]> { +fn read_manifest(manifest_path: &str) -> CargoResult<~[u8]> { Ok((try!(exec_with_output("cargo-read-manifest", [~"--manifest-path", manifest_path.to_owned()], None))).output) } -fn call_rustc(mut manifest_data: ~Reader:) -> IoResult<()> { +fn call_rustc(mut manifest_data: ~Reader:) -> CargoResult<()> { let data: &mut Reader = manifest_data; try!(exec_tty("cargo-rustc", [], Some(data))); Ok(()) } -fn exec_with_output(program: &str, args: &[~str], input: Option<&mut Reader>) -> IoResult { +fn exec_with_output(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoResult { Ok((try!(exec(program, args, input, |_| {}))).wait_with_output()) } -fn exec_tty(program: &str, args: &[~str], input: Option<&mut Reader>) -> IoResult { +fn exec_tty(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoResult { Ok((try!(exec(program, args, input, |config| { config.stdout = InheritFd(1); config.stderr = InheritFd(2); }))).wait()) } -fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator: |&mut ProcessConfig|) -> IoResult { +fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator: |&mut ProcessConfig|) -> CargoResult { let mut config = ProcessConfig::new(); config.program = program; config.args = args; @@ -74,7 +69,7 @@ fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator: println!("Executing {} {}", program, args); - let mut process = try!(Process::configure(config)); + let mut process = try!(Process::configure(config).to_cargo_error(~"Could not configure process", 1)); input.map(|mut reader| io::util::copy(&mut reader, process.stdin.get_mut_ref())); diff --git a/src/bin/cargo-read-manifest.rs b/src/bin/cargo-read-manifest.rs index a5ed0e49a..1f8c63199 100644 --- a/src/bin/cargo-read-manifest.rs +++ b/src/bin/cargo-read-manifest.rs @@ -1,5 +1,5 @@ -#[crate_id="cargo-read-manifest"]; -#[allow(deprecated_owned_vector)]; +#![crate_id="cargo-read-manifest"] +#![allow(deprecated_owned_vector)] extern crate cargo; extern crate hammer; @@ -44,7 +44,7 @@ fn execute(flags: ReadManifestFlags) -> CargoResult> { let manifest_path = flags.manifest_path; let root = try!(toml::parse_from_file(manifest_path.clone()).to_cargo_error(format!("Couldn't parse Toml file: {}", manifest_path), 1)); - let toml_manifest = from_toml::(root.clone()); + let toml_manifest = try!(from_toml::(root.clone()).to_cargo_error(|e: toml::Error| format!("{}", e), 1)); let (lib, bin) = normalize(&toml_manifest.lib, &toml_manifest.bin); @@ -64,10 +64,10 @@ fn normalize(lib: &Option<~[SerializedLibTarget]>, bin: &Option<~[SerializedExec } fn bin_targets(bins: &[SerializedExecTarget], default: |&SerializedExecTarget| -> ~str) -> ~[ExecTarget] { - bins.map(|bin| { + bins.iter().map(|bin| { let path = bin.path.clone().unwrap_or_else(|| default(bin)); ExecTarget{ path: path, name: bin.name.clone() } - }) + }).collect() } match (lib, bin) { diff --git a/src/bin/cargo-rustc.rs b/src/bin/cargo-rustc.rs index 3c0a9b0d7..9fa762236 100644 --- a/src/bin/cargo-rustc.rs +++ b/src/bin/cargo-rustc.rs @@ -1,5 +1,5 @@ -#[crate_id="cargo-rustc"]; -#[allow(deprecated_owned_vector)]; +#![crate_id="cargo-rustc"] +#![allow(deprecated_owned_vector)] extern crate toml; extern crate hammer; diff --git a/src/bin/cargo-verify-project.rs b/src/bin/cargo-verify-project.rs index 255a585e0..d6fe21056 100644 --- a/src/bin/cargo-verify-project.rs +++ b/src/bin/cargo-verify-project.rs @@ -1,5 +1,5 @@ -#[crate_id="cargo-verify-project"]; -#[allow(deprecated_owned_vector)]; +#![crate_id="cargo-verify-project"] +#![allow(deprecated_owned_vector)] extern crate toml; extern crate getopts; diff --git a/src/cargo/mod.rs b/src/cargo/mod.rs index 30d216295..ed54f4cb6 100644 --- a/src/cargo/mod.rs +++ b/src/cargo/mod.rs @@ -1,7 +1,7 @@ -#[crate_id="cargo"]; -#[crate_type="rlib"]; +#![crate_id="cargo"] +#![crate_type="rlib"] -#[allow(deprecated_owned_vector)]; +#![allow(deprecated_owned_vector)] extern crate serialize; extern crate hammer; @@ -10,28 +10,28 @@ use serialize::{Decoder,Encoder,Decodable,Encodable,json}; use std::io; use std::fmt; use std::fmt::{Show,Formatter}; -use hammer::{FlagDecoder,FlagConfig}; +use hammer::{FlagDecoder,FlagConfig,HammerError}; pub mod util; #[deriving(Decodable,Encodable,Eq,Clone,Ord)] pub struct Manifest { - project: ~Project, - root: ~str, - lib: ~[LibTarget], - bin: ~[ExecTarget] + pub project: ~Project, + pub root: ~str, + pub lib: ~[LibTarget], + pub bin: ~[ExecTarget] } #[deriving(Decodable,Encodable,Eq,Clone,Ord)] pub struct ExecTarget { - name: ~str, - path: ~str + pub name: ~str, + pub path: ~str } #[deriving(Decodable,Encodable,Eq,Clone,Ord)] pub struct LibTarget { - name: ~str, - path: ~str + pub name: ~str, + pub path: ~str } //pub type LibTarget = Target; @@ -39,9 +39,9 @@ pub struct LibTarget { #[deriving(Decodable,Encodable,Eq,Clone,Ord)] pub struct Project { - name: ~str, - version: ~str, - authors: ~[~str] + pub name: ~str, + pub version: ~str, + pub authors: ~[~str] } pub type CargoResult = Result; @@ -63,41 +63,57 @@ impl Show for CargoError { } } -pub trait ToCargoError { - fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result; +pub trait ToCargoErrorMessage { + fn to_cargo_error_message(self, error: E) -> ~str; } -impl ToCargoError for Result { - fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result { +impl ToCargoErrorMessage for ~str { + fn to_cargo_error_message(self, _: E) -> ~str { + self + } +} + +impl ToCargoErrorMessage for 'static |E| -> ~str { + fn to_cargo_error_message(self, err: E) -> ~str { + self(err) + } +} + +pub trait ToCargoError { + fn to_cargo_error>(self, to_message: M, exit_code: uint) -> Result; +} + +impl ToCargoError for Result { + fn to_cargo_error>(self, to_message: M, exit_code: uint) -> Result { match self { - Err(_) => Err(CargoError{ message: message, exit_code: exit_code }), + Err(err) => Err(CargoError{ message: to_message.to_cargo_error_message(err), exit_code: exit_code }), Ok(val) => Ok(val) } } } -impl ToCargoError for Option { - fn to_cargo_error(self, message: ~str, exit_code: uint) -> CargoResult { +impl ToCargoError> for Option { + fn to_cargo_error>>(self, to_message: M, exit_code: uint) -> Result { match self { - None => Err(CargoError{ message: message, exit_code: exit_code }), + None => Err(CargoError{ message: to_message.to_cargo_error_message(None), exit_code: exit_code }), Some(val) => Ok(val) } } } -trait RepresentsFlags : FlagConfig + Decodable {} -impl> RepresentsFlags for T {} +trait RepresentsFlags : FlagConfig + Decodable {} +impl> RepresentsFlags for T {} -trait RepresentsJSON : Decodable {} -impl > RepresentsJSON for T {} +trait RepresentsJSON : Decodable {} +impl > RepresentsJSON for T {} #[deriving(Decodable)] pub struct NoFlags; impl FlagConfig for NoFlags {} -pub fn execute_main<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable>>(exec: fn(T, U) -> CargoResult>) { - fn call<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable>>(exec: fn(T, U) -> CargoResult>) -> CargoResult> { +pub fn execute_main<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable, io::IoError>>(exec: fn(T, U) -> CargoResult>) { + fn call<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable, io::IoError>>(exec: fn(T, U) -> CargoResult>) -> CargoResult> { let flags = try!(flags_from_args::()); let json = try!(json_from_stdin::()); @@ -107,8 +123,8 @@ pub fn execute_main<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable>>(exec: fn(T) -> CargoResult>) { - fn call<'a, T: RepresentsFlags, V: Encodable>>(exec: fn(T) -> CargoResult>) -> CargoResult> { +pub fn execute_main_without_stdin<'a, T: RepresentsFlags, V: Encodable, io::IoError>>(exec: fn(T) -> CargoResult>) { + fn call<'a, T: RepresentsFlags, V: Encodable, io::IoError>>(exec: fn(T) -> CargoResult>) -> CargoResult> { let flags = try!(flags_from_args::()); exec(flags) @@ -117,7 +133,7 @@ pub fn execute_main_without_stdin<'a, T: RepresentsFlags, V: Encodable>>(result: CargoResult>) { +fn process_executed<'a, T: Encodable, io::IoError>>(result: CargoResult>) { match result { Err(e) => { let _ = write!(&mut std::io::stderr(), "{}", e.message); @@ -134,12 +150,7 @@ fn process_executed<'a, T: Encodable>>(result: CargoResult() -> CargoResult { let mut decoder = FlagDecoder::new::(std::os::args().tail()); - let flags: T = Decodable::decode(&mut decoder); - - match decoder.error { - Some(err) => Err(CargoError::new(err, 1)), - None => Ok(flags) - } + Decodable::decode(&mut decoder).to_cargo_error(|e: HammerError| e.message, 1) } fn json_from_stdin() -> CargoResult { @@ -149,5 +160,5 @@ fn json_from_stdin() -> CargoResult { let json = try!(json::from_str(input).to_cargo_error(format!("Cannot parse json: {}", input), 1)); let mut decoder = json::Decoder::new(json); - Ok(Decodable::decode(&mut decoder)) + Decodable::decode(&mut decoder).to_cargo_error(|e: json::Error| format!("{}", e), 1) }