mirror of
https://github.com/rust-lang/cargo
synced 2024-09-15 22:09:55 +00:00
PathSource - load packages in update fn
This commit is contained in:
parent
c665938dcc
commit
21b7418a38
|
@ -6,7 +6,7 @@ extern crate hammer;
|
|||
|
||||
use hammer::FlagConfig;
|
||||
use cargo::{execute_main_without_stdin,CLIResult,CLIError};
|
||||
use cargo::core::{Package,SourceId};
|
||||
use cargo::core::{Package,Source,SourceId};
|
||||
use cargo::sources::{PathSource};
|
||||
|
||||
#[deriving(PartialEq,Clone,Decodable)]
|
||||
|
@ -22,8 +22,11 @@ fn main() {
|
|||
|
||||
fn execute(options: Options) -> CLIResult<Option<Package>> {
|
||||
let source_id = SourceId::for_path(&Path::new(options.manifest_path.as_slice()));
|
||||
let mut source = PathSource::new(&source_id);
|
||||
|
||||
PathSource::new(&source_id)
|
||||
try!(source.update().map_err(|err| CLIError::new(err.get_desc(), Some(err.get_detail()), 1)));
|
||||
|
||||
source
|
||||
.get_root_package()
|
||||
.map(|pkg| Some(pkg))
|
||||
.map_err(|err| CLIError::new(err.get_desc(), Some(err.get_detail()), 1))
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
use std::os;
|
||||
use util::config::{ConfigValue};
|
||||
use core::{SourceId,PackageSet,resolver};
|
||||
use core::{Source,SourceId,PackageSet,resolver};
|
||||
use core::registry::PackageRegistry;
|
||||
use ops;
|
||||
use sources::{PathSource};
|
||||
|
@ -25,8 +25,12 @@ use util::{CargoResult,Wrap,config,other_error};
|
|||
pub fn compile(manifest_path: &Path) -> CargoResult<()> {
|
||||
log!(4, "compile; manifest-path={}", manifest_path.display());
|
||||
|
||||
let mut source = PathSource::new(&SourceId::for_path(&manifest_path.dir_path()));
|
||||
|
||||
try!(source.update());
|
||||
|
||||
// TODO: Move this into PathSource
|
||||
let package = try!(PathSource::new(&SourceId::for_path(&manifest_path.dir_path())).get_root_package());
|
||||
let package = try!(source.get_root_package());
|
||||
debug!("loaded package; package={}", package);
|
||||
|
||||
let override_ids = try!(source_ids_from_config());
|
||||
|
|
|
@ -6,7 +6,8 @@ use util::{CargoResult,simple_human};
|
|||
|
||||
pub struct PathSource {
|
||||
id: SourceId,
|
||||
path: Path,
|
||||
updated: bool,
|
||||
packages: Vec<Package>
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,26 +25,29 @@ impl PathSource {
|
|||
log!(5, "new; id={}", id);
|
||||
assert!(id.is_path(), "does not represent a path source; id={}", id);
|
||||
|
||||
let path = Path::new(id.get_url().path.as_slice());
|
||||
|
||||
PathSource {
|
||||
id: id.clone(),
|
||||
path: path
|
||||
updated: false,
|
||||
packages: Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn path(&self) -> Path {
|
||||
Path::new(self.id.get_url().path.as_slice())
|
||||
}
|
||||
|
||||
pub fn get_root_package(&self) -> CargoResult<Package> {
|
||||
log!(5, "get_root_package; source={}", self);
|
||||
|
||||
match (try!(self.packages())).as_slice().head() {
|
||||
if !self.updated {
|
||||
return Err(simple_human("source has not been updated"))
|
||||
}
|
||||
|
||||
match self.packages.as_slice().head() {
|
||||
Some(pkg) => Ok(pkg.clone()),
|
||||
None => Err(simple_human("no package found in source"))
|
||||
}
|
||||
}
|
||||
|
||||
fn packages(&self) -> CargoResult<Vec<Package>> {
|
||||
ops::read_packages(&self.path, &self.id)
|
||||
}
|
||||
}
|
||||
|
||||
impl Show for PathSource {
|
||||
|
@ -54,12 +58,19 @@ impl Show for PathSource {
|
|||
|
||||
impl Source for PathSource {
|
||||
fn update(&mut self) -> CargoResult<()> {
|
||||
if !self.updated {
|
||||
let pkgs = try!(ops::read_packages(&self.path(), &self.id));
|
||||
self.packages.push_all_move(pkgs);
|
||||
self.updated = true;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list(&self) -> CargoResult<Vec<Summary>> {
|
||||
let pkgs = try!(self.packages());
|
||||
Ok(pkgs.iter().map(|p| p.get_summary().clone()).collect())
|
||||
Ok(self.packages.iter()
|
||||
.map(|p| p.get_summary().clone())
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn download(&self, _: &[PackageId]) -> CargoResult<()>{
|
||||
|
@ -70,9 +81,7 @@ impl Source for PathSource {
|
|||
fn get(&self, ids: &[PackageId]) -> CargoResult<Vec<Package>> {
|
||||
log!(5, "getting packages; ids={}", ids);
|
||||
|
||||
let pkgs = try!(self.packages());
|
||||
|
||||
Ok(pkgs.iter()
|
||||
Ok(self.packages.iter()
|
||||
.filter(|pkg| ids.iter().any(|id| pkg.get_package_id() == id))
|
||||
.map(|pkg| pkg.clone())
|
||||
.collect())
|
||||
|
|
Loading…
Reference in a new issue