diff options
Diffstat (limited to 'src/librustpkg/path_util.rs')
| -rw-r--r-- | src/librustpkg/path_util.rs | 23 |
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())) +} + + |
