}
fn execute(options: Options, _: &mut MultiShell) -> CliResult<Option<Package>> {
- let path = Path::new(options.manifest_path.as_slice());
- let source_id = SourceId::for_path(&path);
- let mut source = PathSource::new(&source_id);
+ let mut source = PathSource::for_path(&Path::new(options.manifest_path.as_slice()));
try!(source.update().map_err(|err| CliError::new(err.description(), 1)));
pub fn load(&self, config: &mut Config) -> Box<Source> {
match self.kind {
- GitKind(..) => {
- box GitSource::new(self, config) as Box<Source>
+ GitKind(..) => box GitSource::new(self, config) as Box<Source>,
+ PathKind => {
+ let path = Path::new(self.url.path.as_slice());
+ box PathSource::new(&path, self) as Box<Source>
},
- PathKind => box PathSource::new(self) as Box<Source>,
RegistryKind => unimplemented!()
}
}
pub fn compile(manifest_path: &Path, shell: &mut MultiShell) -> CargoResult<()> {
log!(4, "compile; manifest-path={}", manifest_path.display());
- let id = SourceId::for_path(&manifest_path.dir_path());
- let mut source = PathSource::new(&id);
+ let mut source = PathSource::for_path(&manifest_path.dir_path());
try!(source.update());
pub struct PathSource {
id: SourceId,
+ path: Path,
updated: bool,
packages: Vec<Package>
}
// mut and packages are discovered in update
impl PathSource {
+ pub fn for_path(path: &Path) -> PathSource {
+ PathSource::new(path, &SourceId::for_path(path))
+ }
+
/// Invoked with an absolute path to a directory that contains a Cargo.toml.
/// The source will read the manifest and find any other packages contained
/// in the directory structure reachable by the root manifest.
- pub fn new(id: &SourceId) -> PathSource {
+ pub fn new(path: &Path, id: &SourceId) -> PathSource {
log!(5, "new; id={}", id);
assert!(id.is_path(), "does not represent a path source; id={}", id);
PathSource {
id: id.clone(),
+ path: path.clone(),
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);
impl Source for PathSource {
fn update(&mut self) -> CargoResult<()> {
if !self.updated {
- let pkgs = try!(ops::read_packages(&self.path(), &self.id));
+ let pkgs = try!(ops::read_packages(&self.path, &self.id));
self.packages.push_all_move(pkgs);
self.updated = true;
}
fn fingerprint(&self) -> CargoResult<String> {
let mut max = None;
- let target_dir = self.path().join("target");
- for child in try!(fs::walk_dir(&self.path())) {
+ let target_dir = self.path.join("target");
+ for child in try!(fs::walk_dir(&self.path)) {
if target_dir.is_ancestor_of(&child) { continue }
let stat = try!(fs::stat(&child));
max = cmp::max(max, Some(stat.modified));