From 667adad26f9cc1cfa4eeba8aee15035da7544f8c Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 24 Sep 2013 12:10:44 -0700 Subject: 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 --- src/librustpkg/path_util.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/librustpkg/path_util.rs') 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 { 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())) +} + + -- cgit 1.4.1-3-g733a5