about summary refs log tree commit diff
path: root/src/librustc/metadata
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2013-09-26 17:21:59 -0700
committerKevin Ballard <kevin@sb.org>2013-10-15 21:56:54 -0700
commit73d3d00ec437f87ac665b4e4da3bedec8ce4f9ef (patch)
tree7050b2b93e3c58d7766e9aecd7e973ea88d9210e /src/librustc/metadata
parent6741241f4046aea4014b1a23618593fb481c8606 (diff)
downloadrust-73d3d00ec437f87ac665b4e4da3bedec8ce4f9ef.tar.gz
rust-73d3d00ec437f87ac665b4e4da3bedec8ce4f9ef.zip
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.
Diffstat (limited to 'src/librustc/metadata')
-rw-r--r--src/librustc/metadata/creader.rs11
-rw-r--r--src/librustc/metadata/filesearch.rs65
-rw-r--r--src/librustc/metadata/loader.rs16
3 files changed, 52 insertions, 40 deletions
diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs
index 6df083aca4f..8ece290293b 100644
--- a/src/librustc/metadata/creader.rs
+++ b/src/librustc/metadata/creader.rs
@@ -143,14 +143,15 @@ fn visit_view_item(e: @mut Env, i: &ast::view_item) {
           let meta_items = match path_opt {
               None => meta_items.clone(),
               Some((p, _path_str_style)) => {
-                  let p_path = Path(p);
-                  match p_path.filestem() {
+                  let p_path = Path::from_str(p);
+                  match p_path.filestem_str() {
+                      None|Some("") =>
+                          e.diag.span_bug(i.span, "Bad package path in `extern mod` item"),
                       Some(s) =>
                           vec::append(
                               ~[attr::mk_name_value_item_str(@"package_id", p),
                                attr::mk_name_value_item_str(@"name", s.to_managed())],
-                              *meta_items),
-                      None => e.diag.span_bug(i.span, "Bad package path in `extern mod` item")
+                              *meta_items)
                   }
             }
           };
@@ -274,7 +275,7 @@ fn resolve_crate(e: @mut Env,
         };
         let (lident, ldata) = loader::load_library_crate(&load_ctxt);
 
-        let cfilename = Path(lident);
+        let cfilename = Path::from_str(lident);
         let cdata = ldata;
 
         let attrs = decoder::get_crate_attributes(cdata);
diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs
index 6761445b74e..4e3daa7c185 100644
--- a/src/librustc/metadata/filesearch.rs
+++ b/src/librustc/metadata/filesearch.rs
@@ -24,10 +24,10 @@ pub enum FileMatch { FileMatches, FileDoesntMatch }
 pub type pick<'self> = &'self fn(path: &Path) -> FileMatch;
 
 pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
-    if path.file_path() == file {
-        option::Some((*path).clone())
+    if path.file_path() == Some(file) {
+        Some(path.clone())
     } else {
-        option::None
+        None
     }
 }
 
@@ -60,29 +60,29 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
                     FileMatches => found = true,
                     FileDoesntMatch => ()
                 }
-                visited_dirs.insert(path.to_str());
+                visited_dirs.insert(path.as_vec().to_owned());
             }
 
             debug2!("filesearch: searching target lib path");
             let tlib_path = make_target_lib_path(self.sysroot,
                                         self.target_triple);
-            if !visited_dirs.contains(&tlib_path.to_str()) {
+            if !visited_dirs.contains_equiv(&tlib_path.as_vec()) {
                 match f(&tlib_path) {
                     FileMatches => found = true,
                     FileDoesntMatch => ()
                 }
             }
-            visited_dirs.insert(tlib_path.to_str());
+            visited_dirs.insert(tlib_path.as_vec().to_owned());
             // Try RUST_PATH
             if !found {
                 let rustpath = rust_path();
                 for path in rustpath.iter() {
                     let tlib_path = make_rustpkg_target_lib_path(path, self.target_triple);
-                    debug2!("is {} in visited_dirs? {:?}", tlib_path.to_str(),
-                            visited_dirs.contains(&tlib_path.to_str()));
+                    debug2!("is {} in visited_dirs? {:?}", tlib_path.display(),
+                            visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned()));
 
-                    if !visited_dirs.contains(&tlib_path.to_str()) {
-                        visited_dirs.insert(tlib_path.to_str());
+                    if !visited_dirs.contains_equiv(&tlib_path.as_vec()) {
+                        visited_dirs.insert(tlib_path.as_vec().to_owned());
                         // Don't keep searching the RUST_PATH if one match turns up --
                         // if we did, we'd get a "multiple matching crates" error
                         match f(&tlib_path) {
@@ -99,12 +99,14 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
             make_target_lib_path(self.sysroot, self.target_triple)
         }
         fn get_target_lib_file_path(&self, file: &Path) -> Path {
-            self.get_target_lib_path().push_rel(file)
+            let mut p = self.get_target_lib_path();
+            p.push_path(file);
+            p
         }
     }
 
     let sysroot = get_sysroot(maybe_sysroot);
-    debug2!("using sysroot = {}", sysroot.to_str());
+    debug2!("using sysroot = {}", sysroot.display());
     @FileSearchImpl {
         sysroot: sysroot,
         addl_lib_search_paths: addl_lib_search_paths,
@@ -114,19 +116,19 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
 
 pub fn search(filesearch: @FileSearch, pick: pick) {
     do filesearch.for_each_lib_search_path() |lib_search_path| {
-        debug2!("searching {}", lib_search_path.to_str());
+        debug2!("searching {}", lib_search_path.display());
         let r = os::list_dir_path(lib_search_path);
         let mut rslt = FileDoesntMatch;
         for path in r.iter() {
-            debug2!("testing {}", path.to_str());
+            debug2!("testing {}", path.display());
             let maybe_picked = pick(path);
             match maybe_picked {
                 FileMatches => {
-                    debug2!("picked {}", path.to_str());
+                    debug2!("picked {}", path.display());
                     rslt = FileMatches;
                 }
                 FileDoesntMatch => {
-                    debug2!("rejected {}", path.to_str());
+                    debug2!("rejected {}", path.display());
                 }
             }
         }
@@ -135,24 +137,30 @@ pub fn search(filesearch: @FileSearch, pick: pick) {
 }
 
 pub fn relative_target_lib_path(target_triple: &str) -> Path {
-    Path(libdir()).push_many([~"rustc",
-                              target_triple.to_owned(),
-                              libdir()])
+    let dir = libdir();
+    let mut p = Path::from_str(dir);
+    assert!(p.is_relative());
+    p.push_str("rustc");
+    p.push_str(target_triple);
+    p.push_str(dir);
+    p
 }
 
 fn make_target_lib_path(sysroot: &Path,
                         target_triple: &str) -> Path {
-    sysroot.push_rel(&relative_target_lib_path(target_triple))
+    sysroot.join_path(&relative_target_lib_path(target_triple))
 }
 
 fn make_rustpkg_target_lib_path(dir: &Path,
                         target_triple: &str) -> Path {
-    dir.push_rel(&Path(libdir()).push(target_triple.to_owned()))
+    let mut p = dir.join_str(libdir());
+    p.push_str(target_triple);
+    p
 }
 
 pub fn get_or_default_sysroot() -> Path {
     match os::self_exe_path() {
-      option::Some(ref p) => (*p).pop(),
+      option::Some(p) => { let mut p = p; p.pop(); p }
       option::None => fail2!("can't determine value for sysroot")
     }
 }
@@ -184,13 +192,13 @@ pub fn rust_path() -> ~[Path] {
         Some(env_path) => {
             let env_path_components: ~[&str] =
                 env_path.split_str_iter(PATH_ENTRY_SEPARATOR).collect();
-            env_path_components.map(|&s| Path(s))
+            env_path_components.map(|&s| Path::from_str(s))
         }
         None => ~[]
     };
     let cwd = os::getcwd();
     // now add in default entries
-    let cwd_dot_rust = cwd.push(".rust");
+    let cwd_dot_rust = cwd.join_str(".rust");
     if !env_rust_path.contains(&cwd_dot_rust) {
         env_rust_path.push(cwd_dot_rust);
     }
@@ -198,13 +206,14 @@ pub fn rust_path() -> ~[Path] {
         env_rust_path.push(cwd.clone());
     }
     do cwd.each_parent() |p| {
-        if !env_rust_path.contains(&p.push(".rust")) {
+        if !env_rust_path.contains(&p.join_str(".rust")) {
             push_if_exists(&mut env_rust_path, p);
         }
-    }
+        true
+    };
     let h = os::homedir();
     for h in h.iter() {
-        if !env_rust_path.contains(&h.push(".rust")) {
+        if !env_rust_path.contains(&h.join_str(".rust")) {
             push_if_exists(&mut env_rust_path, h);
         }
     }
@@ -214,7 +223,7 @@ pub fn rust_path() -> ~[Path] {
 
 /// Adds p/.rust into vec, only if it exists
 fn push_if_exists(vec: &mut ~[Path], p: &Path) {
-    let maybe_dir = p.push(".rust");
+    let maybe_dir = p.join_str(".rust");
     if os::path_exists(&maybe_dir) {
         vec.push(maybe_dir);
     }
diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs
index 4d69a2ffce8..593a02c9508 100644
--- a/src/librustc/metadata/loader.rs
+++ b/src/librustc/metadata/loader.rs
@@ -93,25 +93,27 @@ fn find_library_crate_aux(
     let prefix = format!("{}{}-", prefix, crate_name);
     let mut matches = ~[];
     filesearch::search(filesearch, |path| -> FileMatch {
-      let path_str = path.filename();
+      // FIXME (#9639): This needs to handle non-utf8 paths
+      let path_str = path.filename_str();
       match path_str {
           None => FileDoesntMatch,
           Some(path_str) =>
               if path_str.starts_with(prefix) && path_str.ends_with(suffix) {
-                  debug2!("{} is a candidate", path.to_str());
+                  debug2!("{} is a candidate", path.display());
                   match get_metadata_section(cx.os, path) {
                       Some(cvec) =>
                           if !crate_matches(cvec, cx.metas, cx.hash) {
                               debug2!("skipping {}, metadata doesn't match",
-                                  path.to_str());
+                                  path.display());
                               FileDoesntMatch
                           } else {
-                              debug2!("found {} with matching metadata", path.to_str());
-                              matches.push((path.to_str(), cvec));
+                              debug2!("found {} with matching metadata", path.display());
+                              // FIXME (#9639): This needs to handle non-utf8 paths
+                              matches.push((path.as_str().unwrap().to_owned(), cvec));
                               FileMatches
                           },
                       _ => {
-                          debug2!("could not load metadata for {}", path.to_str());
+                          debug2!("could not load metadata for {}", path.display());
                           FileDoesntMatch
                       }
                   }
@@ -273,7 +275,7 @@ pub fn list_file_metadata(intr: @ident_interner,
     match get_metadata_section(os, path) {
       option::Some(bytes) => decoder::list_crate_metadata(intr, bytes, out),
       option::None => {
-        out.write_str(format!("could not find metadata in {}.\n", path.to_str()))
+        out.write_str(format!("could not find metadata in {}.\n", path.display()))
       }
     }
 }