Decoder
};
+use util::{CargoError, FromError};
+
trait ToVersion {
fn to_version(self) -> Option<semver::Version>;
}
}
}
-impl<E, D: Decoder<E>> Decodable<D,E> for PackageId {
+impl<E: CargoError + FromError<E>, D: Decoder<E>> Decodable<D,E> for PackageId {
fn decode(d: &mut D) -> Result<PackageId, E> {
let vector: Vec<String> = try!(Decodable::decode(d));
)
)
-macro_rules! cargo_try (
+macro_rules! try (
($expr:expr) => ({
use util::CargoError;
match $expr.map_err(|err| err.to_error()) {
})
)
+macro_rules! raw_try (
+ ($expr:expr) => ({
+ match $expr {
+ Ok(val) => val,
+ Err(err) => return Err(err)
+ }
+ })
+)
+
pub mod core;
pub mod ops;
pub mod sources;
-> CargoResult<(Package, Vec<Path>)>
{
log!(5, "read_package; path={}; source-id={}", path.display(), source_id);
- let mut file = cargo_try!(File::open(path));
- let data = cargo_try!(file.read_to_end());
- let (manifest, nested) = cargo_try!(read_manifest(data.as_slice(),
+ let mut file = try!(File::open(path));
+ let data = try!(file.read_to_end());
+ let (manifest, nested) = try!(read_manifest(data.as_slice(),
source_id));
Ok((Package::new(manifest, path, source_id), nested))
let target_dir = pkg.get_absolute_target_dir();
let deps_target_dir = target_dir.join("deps");
- let output = cargo_try!(util::process("rustc").arg("-v").exec_with_output());
+ let output = try!(util::process("rustc").arg("-v").exec_with_output());
let rustc_version = str::from_utf8(output.output.as_slice()).unwrap();
// First ensure that the destination directory exists
// Now that everything has successfully compiled, write our new fingerprint
// to the relevant location to prevent recompilations in the future.
- cargo_try!(File::create(&fingerprint_loc).write_str(fingerprint.as_slice()));
+ try!(File::create(&fingerprint_loc).write_str(fingerprint.as_slice()));
cx.compiled_anything = true;
Ok(())
Ok(file) => file,
Err(..) => return Ok((false, new_fingerprint)),
};
- let old_fingerprint = cargo_try!(file.read_to_str());
+ let old_fingerprint = try!(file.read_to_str());
log!(5, "old fingerprint: {}", old_fingerprint);
log!(5, "new fingerprint: {}", new_fingerprint);
macro_rules! git(
($config:expr, $str:expr, $($rest:expr),*) => (
- cargo_try!(git_inherit(&$config, format!($str, $($rest),*)))
+ try!(git_inherit(&$config, format!($str, $($rest),*)))
);
($config:expr, $str:expr) => (
- cargo_try!(git_inherit(&$config, format!($str)))
+ try!(git_inherit(&$config, format!($str)))
);
)
macro_rules! git_output(
($config:expr, $str:expr, $($rest:expr),*) => (
- cargo_try!(git_output(&$config, format!($str, $($rest),*)))
+ try!(git_output(&$config, format!($str, $($rest),*)))
);
($config:expr, $str:expr) => (
- cargo_try!(git_output(&$config, format!($str)))
+ try!(git_output(&$config, format!($str)))
);
)
pub fn checkout(&self, into: &Path) -> CargoResult<GitDatabase> {
if into.exists() {
- cargo_try!(self.fetch_into(into));
+ try!(self.fetch_into(into));
} else {
- cargo_try!(self.clone_into(into));
+ try!(self.clone_into(into));
}
Ok(GitDatabase { remote: self.clone(), path: into.clone() })
fn clone_into(&self, path: &Path) -> CargoResult<()> {
let dirname = Path::new(path.dirname());
- cargo_try!(mkdir_recursive(path, UserDir));
+ try!(mkdir_recursive(path, UserDir));
Ok(git!(dirname, "clone {} {} --bare --no-hardlinks --quiet",
self.fetch_location(), path.display()))
pub fn copy_to<S: Str>(&self, reference: S,
dest: &Path) -> CargoResult<GitCheckout> {
- let checkout = cargo_try!(GitCheckout::clone_into(dest, self.clone(),
+ let checkout = try!(GitCheckout::clone_into(dest, self.clone(),
GitReference::for_str(reference.as_slice())));
- cargo_try!(checkout.fetch());
- cargo_try!(checkout.update_submodules());
+ try!(checkout.fetch());
+ try!(checkout.update_submodules());
Ok(checkout)
}
impl GitCheckout {
fn clone_into(into: &Path, database: GitDatabase,
reference: GitReference) -> CargoResult<GitCheckout> {
- let revision = cargo_try!(database.rev_for(reference.as_slice()));
+ let revision = try!(database.rev_for(reference.as_slice()));
let checkout = GitCheckout {
location: into.clone(),
database: database,
// If the git checkout already exists, we don't need to clone it again
if !checkout.location.join(".git").exists() {
- cargo_try!(checkout.clone_repo());
+ try!(checkout.clone_repo());
}
Ok(checkout)
fn clone_repo(&self) -> CargoResult<()> {
let dirname = Path::new(self.location.dirname());
- cargo_try!(mkdir_recursive(&dirname, UserDir).chain_error(|| {
+ try!(mkdir_recursive(&dirname, UserDir).chain_error(|| {
human(format!("Couldn't mkdir {}",
Path::new(self.location.dirname()).display()))
}));
if self.location.exists() {
- cargo_try!(rmdir_recursive(&self.location).chain_error(|| {
+ try!(rmdir_recursive(&self.location).chain_error(|| {
human(format!("Couldn't rmdir {}",
Path::new(&self.location).display()))
}));
git!(dirname, "clone --no-checkout --quiet {} {}",
self.get_source().display(), self.location.display());
- cargo_try!(chmod(&self.location, AllPermissions));
+ try!(chmod(&self.location, AllPermissions));
Ok(())
}
self.get_source().display());
git!(self.location, "fetch --force --quiet --tags {}",
self.get_source().display());
- cargo_try!(self.reset(self.revision.as_slice()));
+ try!(self.reset(self.revision.as_slice()));
Ok(())
}
}
fn git_output(path: &Path, str: String) -> CargoResult<String> {
- let output = cargo_try!(git(path, str.as_slice()).exec_with_output()
+ let output = try!(git(path, str.as_slice()).exec_with_output()
.chain_error(||
human(format!("Executing `git {}` failed", str))));
fn fingerprint(&self) -> CargoResult<String> {
let mut max = None;
let target_dir = self.path().join("target");
- for child in cargo_try!(fs::walk_dir(&self.path())) {
+ for child in try!(fs::walk_dir(&self.path())) {
if target_dir.is_ancestor_of(&child) { continue }
- let stat = cargo_try!(fs::stat(&child));
+ let stat = try!(fs::stat(&child));
max = cmp::max(max, Some(stat.modified));
}
match max {
impl Config {
pub fn new() -> CargoResult<Config> {
Ok(Config {
- home_path: cargo_try!(os::homedir().require(|| {
+ home_path: try!(os::homedir().require(|| {
human("Couldn't find the home directory")
}))
})
fn encode(&self, s: &mut S) -> Result<(), E> {
match self {
&String(ref string) => {
- try!(string.encode(s));
+ raw_try!(string.encode(s));
},
&List(ref list) => {
- try!(list.encode(s));
+ raw_try!(list.encode(s));
}
}
impl<E, S: Encoder<E>> Encodable<S, E> for ConfigValue {
fn encode(&self, s: &mut S) -> Result<(), E> {
s.emit_map(2, |s| {
- try!(s.emit_map_elt_key(0, |s| "value".encode(s)));
- try!(s.emit_map_elt_val(0, |s| self.value.encode(s)));
+ raw_try!(s.emit_map_elt_key(0, |s| "value".encode(s)));
+ raw_try!(s.emit_map_elt_val(0, |s| self.value.encode(s)));
Ok(())
})
}
pub fn all_configs(pwd: Path) -> CargoResult<HashMap<String, ConfigValue>> {
let mut map = HashMap::new();
- cargo_try!(walk_tree(&pwd, |file| {
+ try!(walk_tree(&pwd, |file| {
extract_all_configs(file, &mut map)
}));
loop {
let possible = current.join(".cargo").join("config");
if possible.exists() {
- let file = cargo_try!(io::fs::File::open(&possible).chain_error(|| {
+ let file = try!(io::fs::File::open(&possible).chain_error(|| {
internal("could not open file")
}));
match walk(file) {
loop {
let possible = current.join(".cargo").join("config");
if possible.exists() {
- let file = cargo_try!(io::fs::File::open(&possible).chain_error(|| {
+ let file = try!(io::fs::File::open(&possible).chain_error(|| {
internal("could not open file")
}));
match walk(file) {
fn extract_config(file: io::fs::File, key: &str) -> CargoResult<ConfigValue> {
let path = file.path().clone();
let mut buf = io::BufferedReader::new(file);
- let root = cargo_try!(toml::parse_from_buffer(&mut buf));
- let val = cargo_try!(root.lookup(key).require(|| internal("")));
+ let root = try!(toml::parse_from_buffer(&mut buf));
+ let val = try!(root.lookup(key).require(|| internal("")));
let v = match *val {
toml::String(ref val) => String(val.clone()),
map: &mut HashMap<String, ConfigValue>) -> CargoResult<()> {
let path = file.path().clone();
let mut buf = io::BufferedReader::new(file);
- let root = cargo_try!(toml::parse_from_buffer(&mut buf).chain_error(|| {
+ let root = try!(toml::parse_from_buffer(&mut buf).chain_error(|| {
internal(format!("could not parse Toml manifest; path={}",
path.display()))
}));
- let table = cargo_try!(root.get_table().require(|| {
+ let table = try!(root.get_table().require(|| {
internal(format!("could not parse Toml manifest; path={}",
path.display()))
}));
ConfigValue { path: vec!(), value: List(vec!()) }
});
- cargo_try!(merge_array(config, val.as_slice(),
+ try!(merge_array(config, val.as_slice(),
&path).chain_error(|| {
internal(format!("The `{}` key in your config", key))
}));
impl Show for Box<CargoError> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- cargo_try!(write!(f, "{}", self.description()));
+ try!(write!(f, "{}", self.description()));
Ok(())
}
}
Some(ExitStatus(i)) | Some(ExitSignal(i)) => i.to_str(),
None => "never executed".to_str()
};
- cargo_try!(write!(f, "{} (status={})", self.msg, exit));
+ try!(write!(f, "{} (status={})", self.msg, exit));
match self.output {
Some(ref out) => {
match str::from_utf8(out.output.as_slice()) {
Some(s) if s.trim().len() > 0 => {
- cargo_try!(write!(f, "\n--- stdout\n{}", s));
+ try!(write!(f, "\n--- stdout\n{}", s));
}
Some(..) | None => {}
}
match str::from_utf8(out.error.as_slice()) {
Some(s) if s.trim().len() > 0 => {
- cargo_try!(write!(f, "\n--- stderr\n{}", s));
+ try!(write!(f, "\n--- stderr\n{}", s));
}
Some(..) | None => {}
}
Ok(ref stat) if stat.kind != io::TypeSymlink => break,
Ok(..) => {
followed += 1;
- let path = cargo_try!(fs::readlink(&result));
+ let path = try!(fs::readlink(&result));
result.pop();
result.push(path);
}
impl Show for ProcessBuilder {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- cargo_try!(write!(f, "`{}", self.program));
+ try!(write!(f, "`{}", self.program));
if self.args.len() > 0 {
- cargo_try!(write!(f, " {}", self.args.connect(" ")));
+ try!(write!(f, " {}", self.args.connect(" ")));
}
write!(f, "`")
let msg = || format!("Could not execute process `{}`",
self.debug_string());
- let exit = cargo_try!(command.status().map_err(|_| {
+ let exit = try!(command.status().map_err(|_| {
process_error(msg(), &command, None, None)
}));
let msg = || format!("Could not execute process `{}`",
self.debug_string());
- let output = cargo_try!(command.output().map_err(|_| {
+ let output = try!(command.output().map_err(|_| {
process_error(msg(), &command, None, None)
}));
pub fn to_manifest(contents: &[u8],
source_id: &SourceId) -> CargoResult<(Manifest, Vec<Path>)> {
- let root = cargo_try!(toml::parse_from_bytes(contents).map_err(|_| {
+ let root = try!(toml::parse_from_bytes(contents).map_err(|_| {
human("Cargo.toml is not valid Toml")
}));
- let toml = cargo_try!(toml_to_manifest(root).map_err(|_| {
+ let toml = try!(toml_to_manifest(root).map_err(|_| {
human("Cargo.toml is not a valid manifest")
}));
toml::from_toml(root.clone())
}
- let project = cargo_try!(decode(&root, "project"));
+ let project = try!(decode(&root, "project"));
let lib = decode(&root, "lib").ok();
let bin = decode(&root, "bin").ok();
let deps = match deps {
Some(deps) => {
- let table = cargo_try!(deps.get_table().require(|| {
+ let table = try!(deps.get_table().require(|| {
human("dependencies must be a table")
})).clone();
let mut details = HashMap::<String, String>::new();
for (k, v) in table.iter() {
- let v = cargo_try!(v.get_str().require(|| {
+ let v = try!(v.get_str().require(|| {
human("dependency values must be string")
}));
details.insert(k.clone(), v.clone());
}
- let version = cargo_try!(details.find_equiv(&"version")
+ let version = try!(details.find_equiv(&"version")
.require(|| {
human("dependencies must include a version")
})).clone();
}
};
- deps.push(cargo_try!(Dependency::parse(n.as_slice(),
+ deps.push(try!(Dependency::parse(n.as_slice(),
version.as_slice(),
&source_id)))
}