about summary refs log tree commit diff
path: root/src/librustpkg/path_util.rs
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2013-09-24 12:10:44 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2013-09-25 11:12:24 -0700
commit667adad26f9cc1cfa4eeba8aee15035da7544f8c (patch)
treee76fcb7c9bf1a09994fabb3c7be62609dc2bd95b /src/librustpkg/path_util.rs
parent22654165c697cac912159daedbfb731fbc7c175d (diff)
downloadrust-667adad26f9cc1cfa4eeba8aee15035da7544f8c.tar.gz
rust-667adad26f9cc1cfa4eeba8aee15035da7544f8c.zip
rustpkg: Search for packages correctly when using the rust_path_hack
Previously, any package would match any other package ID when searching
using the rust_path_hack, so long as the directory had one or more crate
files in it. Now, rustpkg checks that the parent directory matches the
package ID.

Closes #9273
Diffstat (limited to 'src/librustpkg/path_util.rs')
-rw-r--r--src/librustpkg/path_util.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/librustpkg/path_util.rs b/src/librustpkg/path_util.rs
index 3ed1b7a3a9c..7061345341f 100644
--- a/src/librustpkg/path_util.rs
+++ b/src/librustpkg/path_util.rs
@@ -421,11 +421,16 @@ fn dir_has_file(dir: &Path, file: &str) -> bool {
 pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option<Path> {
     let rp = rust_path();
     for dir in rp.iter() {
-        debug!("In find_dir_using_rust_path_hack: checking dir %s", dir.to_str());
-        if dir_has_file(dir, "lib.rs") || dir_has_file(dir, "main.rs")
-            || dir_has_file(dir, "test.rs") || dir_has_file(dir, "bench.rs") {
-            debug!("Did find id %s in dir %s", p.to_str(), dir.to_str());
-            return Some(dir.clone());
+        // Require that the parent directory match the package ID
+        // Note that this only matches if the package ID being searched for
+        // has a name that's a single component
+        if dir.is_parent_of(&p.path) || dir.is_parent_of(&versionize(&p.path, &p.version)) {
+            debug!("In find_dir_using_rust_path_hack: checking dir %s", dir.to_str());
+            if dir_has_file(dir, "lib.rs") || dir_has_file(dir, "main.rs")
+                || dir_has_file(dir, "test.rs") || dir_has_file(dir, "bench.rs") {
+                debug!("Did find id %s in dir %s", p.to_str(), dir.to_str());
+                return Some(dir.clone());
+            }
         }
         debug!("Didn't find id %s in dir %s", p.to_str(), dir.to_str())
     }
@@ -440,3 +445,11 @@ pub fn user_set_rust_path() -> bool {
         Some(_)         => true
     }
 }
+
+/// Append the version string onto the end of the path's filename
+fn versionize(p: &Path, v: &Version) -> Path {
+    let q = p.file_path().to_str();
+    p.with_filename(fmt!("%s-%s", q, v.to_str()))
+}
+
+