mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Up to date with master
This commit is contained in:
parent
1b1044b639
commit
e705d507e6
2
.gitmodules
vendored
2
.gitmodules
vendored
@ -1,6 +1,6 @@
|
|||||||
[submodule "libs/rust-toml"]
|
[submodule "libs/rust-toml"]
|
||||||
path = 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"]
|
[submodule "libs/hammer.rs"]
|
||||||
path = libs/hammer.rs
|
path = libs/hammer.rs
|
||||||
url = https://github.com/wycats/hammer.rs.git
|
url = https://github.com/wycats/hammer.rs.git
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 60ec16a732abfc4dd6a090e4f47e9e2779fd9ba5
|
Subproject commit 9b517eacf16ff9074dc6cc377141eb8e969540c7
|
@ -1 +1 @@
|
|||||||
Subproject commit 1389ceb42b2ae04dac40c8b2d4af8fe21823ecbc
|
Subproject commit 49290aedf236c365c08fbc01eb70127eb5ab4a60
|
@ -1,15 +1,16 @@
|
|||||||
#[crate_id="cargo-compile"];
|
#![crate_id="cargo-compile"]
|
||||||
#[allow(deprecated_owned_vector)];
|
#![allow(deprecated_owned_vector)]
|
||||||
|
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate hammer;
|
extern crate hammer;
|
||||||
// extern crate cargo;
|
extern crate cargo;
|
||||||
|
|
||||||
use serialize::{Decodable};
|
use serialize::{Decodable};
|
||||||
use hammer::{FlagDecoder,FlagConfig,FlagConfiguration};
|
use hammer::{FlagDecoder,FlagConfig,FlagConfiguration,HammerError};
|
||||||
use std::io;
|
use std::io;
|
||||||
use io::{IoResult,IoError,OtherIoError,BufReader};
|
use io::BufReader;
|
||||||
use io::process::{Process,ProcessExit,ProcessOutput,InheritFd,ProcessConfig};
|
use io::process::{Process,ProcessExit,ProcessOutput,InheritFd,ProcessConfig};
|
||||||
|
use cargo::{ToCargoError,CargoResult};
|
||||||
|
|
||||||
#[deriving(Decodable)]
|
#[deriving(Decodable)]
|
||||||
struct Options {
|
struct Options {
|
||||||
@ -27,46 +28,40 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile() -> IoResult<()> {
|
fn compile() -> CargoResult<()> {
|
||||||
let options = try!(flags::<Options>());
|
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()))
|
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 mut decoder = FlagDecoder::new::<T>(std::os::args().tail());
|
||||||
let flags: T = Decodable::decode(&mut decoder);
|
Decodable::decode(&mut decoder).to_cargo_error(|e: HammerError| e.message, 1)
|
||||||
|
|
||||||
if decoder.error.is_some() {
|
|
||||||
Err(IoError{ kind: OtherIoError, desc: "could not decode flags", detail: Some(decoder.error.unwrap()) })
|
|
||||||
} else {
|
|
||||||
Ok(flags)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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;
|
let data: &mut Reader = manifest_data;
|
||||||
try!(exec_tty("cargo-rustc", [], Some(data)));
|
try!(exec_tty("cargo-rustc", [], Some(data)));
|
||||||
Ok(())
|
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())
|
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| {
|
Ok((try!(exec(program, args, input, |config| {
|
||||||
config.stdout = InheritFd(1);
|
config.stdout = InheritFd(1);
|
||||||
config.stderr = InheritFd(2);
|
config.stderr = InheritFd(2);
|
||||||
}))).wait())
|
}))).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();
|
let mut config = ProcessConfig::new();
|
||||||
config.program = program;
|
config.program = program;
|
||||||
config.args = args;
|
config.args = args;
|
||||||
@ -74,7 +69,7 @@ fn exec(program: &str, args: &[~str], input: Option<&mut Reader>, configurator:
|
|||||||
|
|
||||||
println!("Executing {} {}", program, args);
|
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()));
|
input.map(|mut reader| io::util::copy(&mut reader, process.stdin.get_mut_ref()));
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[crate_id="cargo-read-manifest"];
|
#![crate_id="cargo-read-manifest"]
|
||||||
#[allow(deprecated_owned_vector)];
|
#![allow(deprecated_owned_vector)]
|
||||||
|
|
||||||
extern crate cargo;
|
extern crate cargo;
|
||||||
extern crate hammer;
|
extern crate hammer;
|
||||||
@ -44,7 +44,7 @@ fn execute(flags: ReadManifestFlags) -> CargoResult<Option<Manifest>> {
|
|||||||
let manifest_path = flags.manifest_path;
|
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 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);
|
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] {
|
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));
|
let path = bin.path.clone().unwrap_or_else(|| default(bin));
|
||||||
ExecTarget{ path: path, name: bin.name.clone() }
|
ExecTarget{ path: path, name: bin.name.clone() }
|
||||||
})
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
match (lib, bin) {
|
match (lib, bin) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[crate_id="cargo-rustc"];
|
#![crate_id="cargo-rustc"]
|
||||||
#[allow(deprecated_owned_vector)];
|
#![allow(deprecated_owned_vector)]
|
||||||
|
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
extern crate hammer;
|
extern crate hammer;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[crate_id="cargo-verify-project"];
|
#![crate_id="cargo-verify-project"]
|
||||||
#[allow(deprecated_owned_vector)];
|
#![allow(deprecated_owned_vector)]
|
||||||
|
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#[crate_id="cargo"];
|
#![crate_id="cargo"]
|
||||||
#[crate_type="rlib"];
|
#![crate_type="rlib"]
|
||||||
|
|
||||||
#[allow(deprecated_owned_vector)];
|
#![allow(deprecated_owned_vector)]
|
||||||
|
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate hammer;
|
extern crate hammer;
|
||||||
@ -10,28 +10,28 @@ use serialize::{Decoder,Encoder,Decodable,Encodable,json};
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::{Show,Formatter};
|
use std::fmt::{Show,Formatter};
|
||||||
use hammer::{FlagDecoder,FlagConfig};
|
use hammer::{FlagDecoder,FlagConfig,HammerError};
|
||||||
|
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||||
pub struct Manifest {
|
pub struct Manifest {
|
||||||
project: ~Project,
|
pub project: ~Project,
|
||||||
root: ~str,
|
pub root: ~str,
|
||||||
lib: ~[LibTarget],
|
pub lib: ~[LibTarget],
|
||||||
bin: ~[ExecTarget]
|
pub bin: ~[ExecTarget]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||||
pub struct ExecTarget {
|
pub struct ExecTarget {
|
||||||
name: ~str,
|
pub name: ~str,
|
||||||
path: ~str
|
pub path: ~str
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||||
pub struct LibTarget {
|
pub struct LibTarget {
|
||||||
name: ~str,
|
pub name: ~str,
|
||||||
path: ~str
|
pub path: ~str
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub type LibTarget = Target;
|
//pub type LibTarget = Target;
|
||||||
@ -39,9 +39,9 @@ pub struct LibTarget {
|
|||||||
|
|
||||||
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
#[deriving(Decodable,Encodable,Eq,Clone,Ord)]
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
name: ~str,
|
pub name: ~str,
|
||||||
version: ~str,
|
pub version: ~str,
|
||||||
authors: ~[~str]
|
pub authors: ~[~str]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CargoResult<T> = Result<T, CargoError>;
|
pub type CargoResult<T> = Result<T, CargoError>;
|
||||||
@ -63,41 +63,57 @@ impl Show for CargoError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToCargoError<T> {
|
pub trait ToCargoErrorMessage<E> {
|
||||||
fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result<T, CargoError>;
|
fn to_cargo_error_message(self, error: E) -> ~str;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T,U> ToCargoError<T> for Result<T,U> {
|
impl<E> ToCargoErrorMessage<E> for ~str {
|
||||||
fn to_cargo_error(self, message: ~str, exit_code: uint) -> Result<T, CargoError> {
|
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 {
|
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)
|
Ok(val) => Ok(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ToCargoError<T> for Option<T> {
|
impl<T> ToCargoError<T, Option<T>> for Option<T> {
|
||||||
fn to_cargo_error(self, message: ~str, exit_code: uint) -> CargoResult<T> {
|
fn to_cargo_error<M: ToCargoErrorMessage<Option<T>>>(self, to_message: M, exit_code: uint) -> Result<T, CargoError> {
|
||||||
match self {
|
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)
|
Some(val) => Ok(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait RepresentsFlags : FlagConfig + Decodable<FlagDecoder> {}
|
trait RepresentsFlags : FlagConfig + Decodable<FlagDecoder, HammerError> {}
|
||||||
impl<T: FlagConfig + Decodable<FlagDecoder>> RepresentsFlags for T {}
|
impl<T: FlagConfig + Decodable<FlagDecoder, HammerError>> RepresentsFlags for T {}
|
||||||
|
|
||||||
trait RepresentsJSON : Decodable<json::Decoder> {}
|
trait RepresentsJSON : Decodable<json::Decoder, json::Error> {}
|
||||||
impl <T: Decodable<json::Decoder>> RepresentsJSON for T {}
|
impl <T: Decodable<json::Decoder, json::Error>> RepresentsJSON for T {}
|
||||||
|
|
||||||
#[deriving(Decodable)]
|
#[deriving(Decodable)]
|
||||||
pub struct NoFlags;
|
pub struct NoFlags;
|
||||||
|
|
||||||
impl FlagConfig for 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>>) {
|
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>>>(exec: fn(T, U) -> CargoResult<Option<V>>) -> 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 flags = try!(flags_from_args::<T>());
|
||||||
let json = try!(json_from_stdin::<U>());
|
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))
|
process_executed(call(exec))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute_main_without_stdin<'a, T: RepresentsFlags, V: Encodable<json::Encoder<'a>>>(exec: fn(T) -> 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>>>(exec: fn(T) -> CargoResult<Option<V>>) -> 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>());
|
let flags = try!(flags_from_args::<T>());
|
||||||
|
|
||||||
exec(flags)
|
exec(flags)
|
||||||
@ -117,7 +133,7 @@ pub fn execute_main_without_stdin<'a, T: RepresentsFlags, V: Encodable<json::Enc
|
|||||||
process_executed(call(exec))
|
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 {
|
match result {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = write!(&mut std::io::stderr(), "{}", e.message);
|
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> {
|
fn flags_from_args<T: RepresentsFlags>() -> CargoResult<T> {
|
||||||
let mut decoder = FlagDecoder::new::<T>(std::os::args().tail());
|
let mut decoder = FlagDecoder::new::<T>(std::os::args().tail());
|
||||||
let flags: T = Decodable::decode(&mut decoder);
|
Decodable::decode(&mut decoder).to_cargo_error(|e: HammerError| e.message, 1)
|
||||||
|
|
||||||
match decoder.error {
|
|
||||||
Some(err) => Err(CargoError::new(err, 1)),
|
|
||||||
None => Ok(flags)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn json_from_stdin<T: RepresentsJSON>() -> CargoResult<T> {
|
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 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);
|
||||||
|
|
||||||
Ok(Decodable::decode(&mut decoder))
|
Decodable::decode(&mut decoder).to_cargo_error(|e: json::Error| format!("{}", e), 1)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user