Up to date with master
authorYehuda Katz <wycats@gmail.com>
Wed, 2 Apr 2014 05:31:11 +0000 (22:31 -0700)
committerYehuda Katz <wycats@gmail.com>
Wed, 2 Apr 2014 05:31:11 +0000 (22:31 -0700)
.gitmodules
libs/hammer.rs
libs/rust-toml
src/bin/cargo-compile.rs
src/bin/cargo-read-manifest.rs
src/bin/cargo-rustc.rs
src/bin/cargo-verify-project.rs
src/cargo/mod.rs

index 21798a1d2cadc477e8a7f5fe473630e9470cc82c..b6b1c7fd8b7d591524846eeb67f32fe52e835ad6 100644 (file)
@@ -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
index 60ec16a732abfc4dd6a090e4f47e9e2779fd9ba5..9b517eacf16ff9074dc6cc377141eb8e969540c7 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 60ec16a732abfc4dd6a090e4f47e9e2779fd9ba5
+Subproject commit 9b517eacf16ff9074dc6cc377141eb8e969540c7
index 1389ceb42b2ae04dac40c8b2d4af8fe21823ecbc..49290aedf236c365c08fbc01eb70127eb5ab4a60 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 1389ceb42b2ae04dac40c8b2d4af8fe21823ecbc
+Subproject commit 49290aedf236c365c08fbc01eb70127eb5ab4a60
index 34ca4ee196d5862ce7126381e802aadf6589f3e2..cb41fa337a72952f7e56da18c31d1c56750d637c 100644 (file)
@@ -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::<Options>());
-    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<T: FlagConfig + Decodable<FlagDecoder>>() -> IoResult<T> {
+fn flags<T: FlagConfig + Decodable<FlagDecoder, HammerError>>() -> CargoResult<T> {
     let mut decoder = FlagDecoder::new::<T>(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<ProcessOutput> {
+fn exec_with_output(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoResult<ProcessOutput> {
     Ok((try!(exec(program, args, input, |_| {}))).wait_with_output())
 }
 
-fn exec_tty(program: &str, args: &[~str], input: Option<&mut Reader>) -> IoResult<ProcessExit> {
+fn exec_tty(program: &str, args: &[~str], input: Option<&mut Reader>) -> CargoResult<ProcessExit> {
     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<Process> {
+fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator: |&mut ProcessConfig|) -> CargoResult<Process> {
     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()));
 
index a5ed0e49accb48159bed8b3e35a9a008654d80f8..1f8c631992f61ec067ed8fa774e7425962dc6647 100644 (file)
@@ -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<Option<Manifest>> {
     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::<SerializedManifest>(root.clone());
+    let toml_manifest = try!(from_toml::<SerializedManifest>(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) {
index 3c0a9b0d7eba3a2d71a75ca02d245855d06bda12..9fa76223619c2256745ecc0391faedc0034154ca 100644 (file)
@@ -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;
index 255a585e02672f26cad04a583ad805e22aa5f7b1..d6fe21056a52a13a390025e54256c1233704b223 100644 (file)
@@ -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;
index 30d21629576c0d4762778dd8d06a8cdbd5e05ee2..ed54f4cb66c3a30fad38bfe374858d0229e55109 100644 (file)
@@ -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<T> = Result<T, CargoError>;
@@ -63,41 +63,57 @@ impl Show for CargoError {
     }
 }
 
-pub trait ToCargoError<T> {
-    fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result<T, CargoError>;
+pub trait ToCargoErrorMessage<E> {
+    fn to_cargo_error_message(self, error: E) -> ~str;
 }
 
-impl<T,U> ToCargoError<T> for Result<T,U> {
-    fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result<T, CargoError> {
+impl<E> ToCargoErrorMessage<E> for ~str {
+    fn to_cargo_error_message(self, _: E) -> ~str {
+        self
+    }
+}
+
+impl<E> ToCargoErrorMessage<E> for 'static |E| -> ~str {
+    fn to_cargo_error_message(self, err: E) -> ~str {
+        self(err)
+    }
+}
+
+pub trait ToCargoError<T, E> {
+    fn to_cargo_error<M: ToCargoErrorMessage<E>>(self, to_message: M, exit_code: uint) -> Result<T, CargoError>;
+}
+
+impl<T,E> ToCargoError<T, E> for Result<T,E> {
+    fn to_cargo_error<M: ToCargoErrorMessage<E>>(self, to_message: M, exit_code: uint) -> Result<T, CargoError> {
         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<T> ToCargoError<T> for Option<T> {
-    fn to_cargo_error(self, message: ~str, exit_code: uint) -> CargoResult<T> {
+impl<T> ToCargoError<T, Option<T>> for Option<T> {
+    fn to_cargo_error<M: ToCargoErrorMessage<Option<T>>>(self, to_message: M, exit_code: uint) -> Result<T, CargoError> {
         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<FlagDecoder> {}
-impl<T: FlagConfig + Decodable<FlagDecoder>> RepresentsFlags for T {}
+trait RepresentsFlags : FlagConfig + Decodable<FlagDecoder, HammerError> {}
+impl<T: FlagConfig + Decodable<FlagDecoder, HammerError>> RepresentsFlags for T {}
 
-trait RepresentsJSON : Decodable<json::Decoder> {}
-impl <T: Decodable<json::Decoder>> RepresentsJSON for T {}
+trait RepresentsJSON : Decodable<json::Decoder, json::Error> {}
+impl <T: Decodable<json::Decoder, json::Error>> RepresentsJSON for T {}
 
 #[deriving(Decodable)]
 pub struct NoFlags;
 
 impl FlagConfig for NoFlags {}
 
-pub fn execute_main<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable<json::Encoder<'a>>>(exec: fn(T, U) -> CargoResult<Option<V>>) {
-    fn call<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable<json::Encoder<'a>>>(exec: fn(T, U) -> CargoResult<Option<V>>) -> CargoResult<Option<V>> {
+pub fn execute_main<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable<json::Encoder<'a>, io::IoError>>(exec: fn(T, U) -> CargoResult<Option<V>>) {
+    fn call<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable<json::Encoder<'a>, io::IoError>>(exec: fn(T, U) -> CargoResult<Option<V>>) -> CargoResult<Option<V>> {
         let flags = try!(flags_from_args::<T>());
         let json = try!(json_from_stdin::<U>());
 
@@ -107,8 +123,8 @@ pub fn execute_main<'a, T: RepresentsFlags, U: RepresentsJSON, V: Encodable<json
     process_executed(call(exec))
 }
 
-pub fn execute_main_without_stdin<'a, T: RepresentsFlags, V: Encodable<json::Encoder<'a>>>(exec: fn(T) -> CargoResult<Option<V>>) {
-    fn call<'a, T: RepresentsFlags, V: Encodable<json::Encoder<'a>>>(exec: fn(T) -> CargoResult<Option<V>>) -> CargoResult<Option<V>> {
+pub fn execute_main_without_stdin<'a, T: RepresentsFlags, V: Encodable<json::Encoder<'a>, io::IoError>>(exec: fn(T) -> CargoResult<Option<V>>) {
+    fn call<'a, T: RepresentsFlags, V: Encodable<json::Encoder<'a>, io::IoError>>(exec: fn(T) -> CargoResult<Option<V>>) -> CargoResult<Option<V>> {
         let flags = try!(flags_from_args::<T>());
 
         exec(flags)
@@ -117,7 +133,7 @@ pub fn execute_main_without_stdin<'a, T: RepresentsFlags, V: Encodable<json::Enc
     process_executed(call(exec))
 }
 
-fn process_executed<'a, T: Encodable<json::Encoder<'a>>>(result: CargoResult<Option<T>>) {
+fn process_executed<'a, T: Encodable<json::Encoder<'a>, io::IoError>>(result: CargoResult<Option<T>>) {
     match result {
         Err(e) => {
             let _ = write!(&mut std::io::stderr(), "{}", e.message);
@@ -134,12 +150,7 @@ fn process_executed<'a, T: Encodable<json::Encoder<'a>>>(result: CargoResult<Opt
 
 fn flags_from_args<T: RepresentsFlags>() -> CargoResult<T> {
     let mut decoder = FlagDecoder::new::<T>(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<T: RepresentsJSON>() -> CargoResult<T> {
@@ -149,5 +160,5 @@ fn json_from_stdin<T: RepresentsJSON>() -> CargoResult<T> {
     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)
 }