Source list returns summaries

This commit is contained in:
Carl Lerche 2014-05-06 16:24:00 -07:00
parent c7c6622b71
commit 937303398d
4 changed files with 18 additions and 14 deletions

View File

@ -17,6 +17,10 @@ pub use self::package::{
PackageSet
};
pub use self::source::{
Source
};
pub use self::summary::{
Summary
};

View File

@ -1,12 +1,11 @@
use core::{NameVer,Package};
use core::{Summary,NameVer,Package};
use core::errors::CargoResult;
use std::fmt::Show;
/**
* A Source finds and downloads remote packages based on names and
* versions.
*/
pub trait Source : Show {
pub trait Source {
/**
* The update method performs any network operations required to
* get the entire list of all names, versions and dependencies of
@ -20,7 +19,7 @@ pub trait Source : Show {
* already been called and no additional network operations are
* required.
*/
fn list(&self) -> CargoResult<Vec<NameVer>>;
fn list(&self) -> CargoResult<Vec<Summary>>;
/**
* The download method fetches the full package for each name and

View File

@ -18,10 +18,8 @@ use std::vec::Vec;
use std::os;
use util::config;
use util::config::{all_configs,ConfigValue};
use core::{PackageSet,Source,Dependency,NameVer};
use core::resolver::resolve;
use core::package::PackageSet;
use core::source::Source;
use core::dependency::Dependency;
use sources::path::PathSource;
use ops::cargo_rustc;
use core::errors::{CargoError,CLIError,CLIResult,ToResult};
@ -38,11 +36,14 @@ pub fn compile(manifest_path: &str) -> CLIResult<()> {
};
let source = PathSource::new(paths);
let names = try!(source.list().to_result(|err| CLIError::new(format!("Unable to list packages from {}", source), Some(err.to_str()), 1)));
try!(source.download(names.as_slice()).to_result(|err| CLIError::new(format!("Unable to download packages from {}", source), Some(err.to_str()), 1)));
let summaries = try!(source.list().to_result(|err| CLIError::new(format!("Unable to list packages from {}", source), Some(err.to_str()), 1)));
let names: Vec<NameVer> = summaries.iter().map(|s| s.get_name_ver().clone()).collect();
let deps: Vec<Dependency> = names.iter().map(|namever| {
Dependency::with_namever(namever)
// This does not need to happen
// try!(source.download(names.as_slice()).to_result(|err| CLIError::new(format!("Unable to download packages from {}", source), Some(err.to_str()), 1)));
let deps: Vec<Dependency> = summaries.iter().map(|summary| {
Dependency::with_namever(summary.get_name_ver())
}).collect();
let packages = try!(source.get(names.as_slice()).to_result(|err|

View File

@ -1,6 +1,6 @@
use std::fmt;
use std::fmt::{Show,Formatter};
use core::{NameVer,Package};
use core::{NameVer,Package,Summary};
use core::source::Source;
use core::errors::{CargoResult,CargoCLIError,ToResult};
use cargo_read_manifest = ops::cargo_read_manifest::read_manifest;
@ -24,10 +24,10 @@ impl Show for PathSource {
impl Source for PathSource {
fn update(&self) -> CargoResult<()> { Ok(()) }
fn list(&self) -> CargoResult<Vec<NameVer>> {
fn list(&self) -> CargoResult<Vec<Summary>> {
Ok(self.paths.iter().filter_map(|path| {
match read_manifest(path) {
Ok(ref pkg) => Some(pkg.get_summary().get_name_ver().clone()),
Ok(ref pkg) => Some(pkg.get_summary().clone()),
Err(_) => None
}
}).collect())