Specify the SourceId that the path source represents
authorCarl Lerche <me@carllerche.com>
Mon, 23 Jun 2014 23:16:22 +0000 (16:16 -0700)
committerCarl Lerche <me@carllerche.com>
Mon, 23 Jun 2014 23:16:22 +0000 (16:16 -0700)
src/bin/cargo-read-manifest.rs
src/cargo/core/source.rs
src/cargo/ops/cargo_compile.rs
src/cargo/sources/path.rs

index e77e9cb909bb984aefbb2ba9c8274a40d5105ba8..b8125bf843aaa120937116534d9930816805fb79 100644 (file)
@@ -24,9 +24,7 @@ fn main() {
 }
 
 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)));
 
index 31b380473655f2eebf0c4acb609005c1b91d3477..4e4f3c5689290957290ca2c68eb8c990e4996826 100644 (file)
@@ -117,10 +117,11 @@ impl SourceId {
 
     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!()
         }
     }
index cf94f186a516c7102385f89a3aa66283c9b7e9b4..ca935f4b4213a5ea7e8688214864f8e1985678f1 100644 (file)
@@ -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());
 
index 1f9ec8501a666a5618c02588e321b76f712133c0..c5dc5444c2c3fef6855efef363cb3270e49acc45 100644 (file)
@@ -9,6 +9,7 @@ use util::{CargoResult, internal};
 
 pub struct PathSource {
     id: SourceId,
+    path: Path,
     updated: bool,
     packages: Vec<Package>
 }
@@ -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<Package> {
         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<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));