From: Carl Lerche Date: Mon, 23 Jun 2014 23:16:22 +0000 (-0700) Subject: Specify the SourceId that the path source represents X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~975 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3948538018ec33e7fe1b6719d09ed8ddb5a1fec3;p=cargo.git Specify the SourceId that the path source represents --- diff --git a/src/bin/cargo-read-manifest.rs b/src/bin/cargo-read-manifest.rs index e77e9cb90..b8125bf84 100644 --- a/src/bin/cargo-read-manifest.rs +++ b/src/bin/cargo-read-manifest.rs @@ -24,9 +24,7 @@ fn main() { } fn execute(options: Options, _: &mut MultiShell) -> CliResult> { - 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))); diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index 31b380473..4e4f3c568 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -117,10 +117,11 @@ impl SourceId { pub fn load(&self, config: &mut Config) -> Box { match self.kind { - GitKind(..) => { - box GitSource::new(self, config) as Box + GitKind(..) => box GitSource::new(self, config) as Box, + PathKind => { + let path = Path::new(self.url.path.as_slice()); + box PathSource::new(&path, self) as Box }, - PathKind => box PathSource::new(self) as Box, RegistryKind => unimplemented!() } } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index cf94f186a..ca935f4b4 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -33,8 +33,7 @@ use util::{CargoResult, Wrap, config, internal, human}; 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()); diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 1f9ec8501..c5dc5444c 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -9,6 +9,7 @@ use util::{CargoResult, internal}; pub struct PathSource { id: SourceId, + path: Path, updated: bool, packages: Vec } @@ -17,24 +18,25 @@ pub struct PathSource { // 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 { log!(5, "get_root_package; source={}", self); @@ -58,7 +60,7 @@ 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)); + let pkgs = try!(ops::read_packages(&self.path, &self.id)); self.packages.push_all_move(pkgs); self.updated = true; } @@ -88,8 +90,8 @@ impl Source for PathSource { fn fingerprint(&self) -> CargoResult { 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));