path2: Replace the path module outright

Remove the old path.
Rename path2 to path.
Update all clients for the new path.

Also make some miscellaneous changes to the Path APIs to help the
adoption process.
This commit is contained in:
Kevin Ballard 2013-09-26 17:21:59 -07:00
parent 6741241f40
commit 73d3d00ec4
63 changed files with 2501 additions and 2989 deletions

View file

@ -10,7 +10,7 @@
// rustpkg utilities having to do with workspaces
use std::{os,util};
use std::os;
use std::path::Path;
use context::Context;
use path_util::{workspace_contains_package_id, find_dir_using_rust_path_hack, default_workspace};
@ -26,8 +26,8 @@ pub fn each_pkg_parent_workspace(cx: &Context, pkgid: &PkgId, action: &fn(&Path)
// tjc: make this a condition
fail2!("Package {} not found in any of \
the following workspaces: {}",
pkgid.path.to_str(),
rust_path().to_str());
pkgid.path.display(),
rust_path().map(|p| p.to_display_str()).to_str());
}
for ws in workspaces.iter() {
if action(ws) {
@ -52,7 +52,7 @@ pub fn pkg_parent_workspaces(cx: &Context, pkgid: &PkgId) -> ~[Path] {
}
pub fn is_workspace(p: &Path) -> bool {
os::path_is_dir(&p.push("src"))
os::path_is_dir(&p.join_str("src"))
}
/// Construct a workspace and package-ID name based on the current directory.
@ -60,16 +60,13 @@ pub fn is_workspace(p: &Path) -> bool {
pub fn cwd_to_workspace() -> Option<(Path, PkgId)> {
let cwd = os::getcwd();
for path in rust_path().move_iter() {
let srcpath = path.push("src");
let srcpath = path.join_str("src");
if srcpath.is_ancestor_of(&cwd) {
// I'd love to use srcpath.get_relative_to(cwd) but it behaves wrong
// I'd say broken, but it has tests enforcing the wrong behavior.
// instead, just hack up the components vec
let mut pkgid = cwd;
pkgid.is_absolute = false;
let comps = util::replace(&mut pkgid.components, ~[]);
pkgid.components = comps.move_iter().skip(srcpath.components.len()).collect();
return Some((path, PkgId::new(pkgid.components.connect("/"))))
let rel = cwd.path_relative_from(&srcpath);
let rel_s = rel.and_then_ref(|p|p.as_str());
if rel_s.is_some() {
return Some((path, PkgId::new(rel_s.unwrap())));
}
}
}
None