about summary refs log tree commit diff
path: root/src/librustc/back
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/back
parent6741241f4046aea4014b1a23618593fb481c8606 (diff)
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/back')
-rw-r--r--src/librustc/back/link.rs73
-rw-r--r--src/librustc/back/rpath.rs110
2 files changed, 104 insertions, 79 deletions
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index c19b5a83315..d5cd78f54f7 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -70,7 +70,7 @@ pub fn WriteOutputFile(
         Target: lib::llvm::TargetMachineRef,
         PM: lib::llvm::PassManagerRef,
         M: ModuleRef,
-        Output: &str,
+        Output: &Path,
         FileType: lib::llvm::FileType) {
     unsafe {
         do Output.with_c_str |Output| {
@@ -129,15 +129,13 @@ pub mod jit {
             let cstore = sess.cstore;
             let r = cstore::get_used_crate_files(cstore);
             for cratepath in r.iter() {
-                let path = cratepath.to_str();
+                debug2!("linking: {}", cratepath.display());
 
-                debug2!("linking: {}", path);
-
-                do path.with_c_str |buf_t| {
+                do cratepath.with_c_str |buf_t| {
                     if !llvm::LLVMRustLoadCrate(manager, buf_t) {
                         llvm_err(sess, ~"Could not link");
                     }
-                    debug2!("linked: {}", path);
+                    debug2!("linked: {}", cratepath.display());
                 }
             }
 
@@ -251,7 +249,7 @@ pub mod write {
             llvm::LLVMInitializeMipsAsmParser();
 
             if sess.opts.save_temps {
-                do output.with_filetype("no-opt.bc").with_c_str |buf| {
+                do output.with_extension_str("no-opt.bc").with_c_str |buf| {
                     llvm::LLVMWriteBitcodeToFile(llmod, buf);
                 }
             }
@@ -319,7 +317,7 @@ pub mod write {
             llvm::LLVMDisposePassManager(mpm);
 
             if sess.opts.save_temps {
-                do output.with_filetype("bc").with_c_str |buf| {
+                do output.with_extension_str("bc").with_c_str |buf| {
                     llvm::LLVMWriteBitcodeToFile(llmod, buf);
                 }
             }
@@ -350,12 +348,10 @@ pub mod write {
                         }
                     }
                     output_type_assembly => {
-                        WriteOutputFile(sess, tm, cpm, llmod, output.to_str(),
-                                        lib::llvm::AssemblyFile);
+                        WriteOutputFile(sess, tm, cpm, llmod, output, lib::llvm::AssemblyFile);
                     }
                     output_type_exe | output_type_object => {
-                        WriteOutputFile(sess, tm, cpm, llmod, output.to_str(),
-                                        lib::llvm::ObjectFile);
+                        WriteOutputFile(sess, tm, cpm, llmod, output, lib::llvm::ObjectFile);
                     }
                 }
 
@@ -375,10 +371,11 @@ pub mod write {
     pub fn run_assembler(sess: Session, assembly: &Path, object: &Path) {
         let cc_prog = super::get_cc_prog(sess);
 
+        // FIXME (#9639): This needs to handle non-utf8 paths
         let cc_args = ~[
             ~"-c",
-            ~"-o", object.to_str(),
-            assembly.to_str()];
+            ~"-o", object.as_str().unwrap().to_owned(),
+            assembly.as_str().unwrap().to_owned()];
 
         let prog = run::process_output(cc_prog, cc_args);
 
@@ -612,11 +609,12 @@ pub fn build_link_meta(sess: Session,
             _ => {
                 // to_managed could go away if there was a version of
                 // filestem that returned an @str
+                // FIXME (#9639): Non-utf8 filenames will give a misleading error
                 let name = session::expect(sess,
-                                           output.filestem(),
+                                           output.filestem_str(),
                                            || format!("output file name `{}` doesn't\
                                                     appear to have a stem",
-                                                   output.to_str())).to_managed();
+                                                   output.display())).to_managed();
                 if name.is_empty() {
                     sess.fatal("missing crate link meta `name`, and the \
                                 inferred name is blank");
@@ -919,15 +917,16 @@ pub fn link_binary(sess: Session,
         let long_libname = output_dll_filename(sess.targ_cfg.os, lm);
         debug2!("link_meta.name:  {}", lm.name);
         debug2!("long_libname: {}", long_libname);
-        debug2!("out_filename: {}", out_filename.to_str());
-        debug2!("dirname(out_filename): {}", out_filename.dir_path().to_str());
+        debug2!("out_filename: {}", out_filename.display());
+        let out_dirname = out_filename.dir_path();
+        debug2!("dirname(out_filename): {}", out_dirname.display());
 
-        out_filename.dir_path().push(long_libname)
+        out_filename.with_filename_str(long_libname)
     } else {
         out_filename.clone()
     };
 
-    debug2!("output: {}", output.to_str());
+    debug2!("output: {}", output.display());
     let cc_args = link_args(sess, obj_filename, out_filename, lm);
     debug2!("{} link args: {}", cc_prog, cc_args.connect(" "));
     if (sess.opts.debugging_opts & session::print_link_args) != 0 {
@@ -947,14 +946,15 @@ pub fn link_binary(sess: Session,
 
     // Clean up on Darwin
     if sess.targ_cfg.os == session::OsMacos {
-        run::process_status("dsymutil", [output.to_str()]);
+        // FIXME (#9639): This needs to handle non-utf8 paths
+        run::process_status("dsymutil", [output.as_str().unwrap().to_owned()]);
     }
 
     // Remove the temporary object file if we aren't saving temps
     if !sess.opts.save_temps {
         if ! os::remove_file(obj_filename) {
             sess.warn(format!("failed to delete object file `{}`",
-                           obj_filename.to_str()));
+                           obj_filename.display()));
         }
     }
 }
@@ -977,20 +977,23 @@ pub fn link_args(sess: Session,
 
     let output = if *sess.building_library {
         let long_libname = output_dll_filename(sess.targ_cfg.os, lm);
-        out_filename.dir_path().push(long_libname)
+        out_filename.with_filename_str(long_libname)
     } else {
         out_filename.clone()
     };
 
     // The default library location, we need this to find the runtime.
     // The location of crates will be determined as needed.
-    let stage: ~str = ~"-L" + sess.filesearch.get_target_lib_path().to_str();
+    // FIXME (#9639): This needs to handle non-utf8 paths
+    let lib_path = sess.filesearch.get_target_lib_path();
+    let stage: ~str = ~"-L" + lib_path.as_str().unwrap();
 
     let mut args = vec::append(~[stage], sess.targ_cfg.target_strs.cc_args);
 
+    // FIXME (#9639): This needs to handle non-utf8 paths
     args.push_all([
-        ~"-o", output.to_str(),
-        obj_filename.to_str()]);
+        ~"-o", output.as_str().unwrap().to_owned(),
+        obj_filename.as_str().unwrap().to_owned()]);
 
     let lib_cmd = match sess.targ_cfg.os {
         session::OsMacos => ~"-dynamiclib",
@@ -1001,14 +1004,15 @@ pub fn link_args(sess: Session,
 
     let cstore = sess.cstore;
     let r = cstore::get_used_crate_files(cstore);
+    // FIXME (#9639): This needs to handle non-utf8 paths
     for cratepath in r.iter() {
-        if cratepath.filetype() == Some(".rlib") {
-            args.push(cratepath.to_str());
+        if cratepath.extension_str() == Some("rlib") {
+            args.push(cratepath.as_str().unwrap().to_owned());
             continue;
         }
-        let dir = cratepath.dirname();
+        let dir = cratepath.dirname_str().unwrap();
         if !dir.is_empty() { args.push("-L" + dir); }
-        let libarg = unlib(sess.targ_cfg, cratepath.filestem().unwrap().to_owned());
+        let libarg = unlib(sess.targ_cfg, cratepath.filestem_str().unwrap().to_owned());
         args.push("-l" + libarg);
     }
 
@@ -1032,12 +1036,14 @@ pub fn link_args(sess: Session,
     // forces to make sure that library can be found at runtime.
 
     for path in sess.opts.addl_lib_search_paths.iter() {
-        args.push("-L" + path.to_str());
+        // FIXME (#9639): This needs to handle non-utf8 paths
+        args.push("-L" + path.as_str().unwrap().to_owned());
     }
 
     let rustpath = filesearch::rust_path();
     for path in rustpath.iter() {
-        args.push("-L" + path.to_str());
+        // FIXME (#9639): This needs to handle non-utf8 paths
+        args.push("-L" + path.as_str().unwrap().to_owned());
     }
 
     // The names of the extern libraries
@@ -1050,8 +1056,9 @@ pub fn link_args(sess: Session,
         // On mac we need to tell the linker to let this library
         // be rpathed
         if sess.targ_cfg.os == session::OsMacos {
+            // FIXME (#9639): This needs to handle non-utf8 paths
             args.push("-Wl,-install_name,@rpath/"
-                      + output.filename().unwrap());
+                      + output.filename_str().unwrap());
         }
     }
 
diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs
index 60289e0ebe5..b3fb6be686d 100644
--- a/src/librustc/back/rpath.rs
+++ b/src/librustc/back/rpath.rs
@@ -45,23 +45,26 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path)
 
 fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
     let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
-    sess.filesearch.sysroot().push_rel(&r).push(os::dll_filename("rustrt"))
+    let mut p = sess.filesearch.sysroot().join_path(&r);
+    p.push_str(os::dll_filename("rustrt"));
+    p
 }
 
-pub fn rpaths_to_flags(rpaths: &[Path]) -> ~[~str] {
-    rpaths.iter().map(|rpath| format!("-Wl,-rpath,{}",rpath.to_str())).collect()
+pub fn rpaths_to_flags(rpaths: &[~str]) -> ~[~str] {
+    // FIXME (#9639): This needs to handle non-utf8 paths
+    rpaths.iter().map(|rpath| format!("-Wl,-rpath,{}",*rpath)).collect()
 }
 
 fn get_rpaths(os: session::Os,
               sysroot: &Path,
               output: &Path,
               libs: &[Path],
-              target_triple: &str) -> ~[Path] {
-    debug2!("sysroot: {}", sysroot.to_str());
-    debug2!("output: {}", output.to_str());
+              target_triple: &str) -> ~[~str] {
+    debug2!("sysroot: {}", sysroot.display());
+    debug2!("output: {}", output.display());
     debug2!("libs:");
     for libpath in libs.iter() {
-        debug2!("    {}", libpath.to_str());
+        debug2!("    {}", libpath.display());
     }
     debug2!("target_triple: {}", target_triple);
 
@@ -77,10 +80,10 @@ fn get_rpaths(os: session::Os,
     // And a final backup rpath to the global library location.
     let fallback_rpaths = ~[get_install_prefix_rpath(target_triple)];
 
-    fn log_rpaths(desc: &str, rpaths: &[Path]) {
+    fn log_rpaths(desc: &str, rpaths: &[~str]) {
         debug2!("{} rpaths:", desc);
         for rpath in rpaths.iter() {
-            debug2!("    {}", rpath.to_str());
+            debug2!("    {}", *rpath);
         }
     }
 
@@ -99,14 +102,14 @@ fn get_rpaths(os: session::Os,
 
 fn get_rpaths_relative_to_output(os: session::Os,
                                  output: &Path,
-                                 libs: &[Path]) -> ~[Path] {
+                                 libs: &[Path]) -> ~[~str] {
     libs.iter().map(|a| get_rpath_relative_to_output(os, output, a)).collect()
 }
 
 pub fn get_rpath_relative_to_output(os: session::Os,
                                     output: &Path,
                                     lib: &Path)
-                                 -> Path {
+                                 -> ~str {
     use std::os;
 
     assert!(not_win32(os));
@@ -119,29 +122,43 @@ pub fn get_rpath_relative_to_output(os: session::Os,
         session::OsWin32 => unreachable!()
     };
 
-    Path(prefix).push_rel(&os::make_absolute(output).get_relative_to(&os::make_absolute(lib)))
+    let mut lib = os::make_absolute(lib);
+    lib.pop();
+    let mut output = os::make_absolute(output);
+    output.pop();
+    let relative = lib.path_relative_from(&output);
+    let relative = relative.expect("could not create rpath relative to output");
+    // FIXME (#9639): This needs to handle non-utf8 paths
+    prefix+"/"+relative.as_str().expect("non-utf8 component in path")
 }
 
-fn get_absolute_rpaths(libs: &[Path]) -> ~[Path] {
+fn get_absolute_rpaths(libs: &[Path]) -> ~[~str] {
     libs.iter().map(|a| get_absolute_rpath(a)).collect()
 }
 
-pub fn get_absolute_rpath(lib: &Path) -> Path {
-    os::make_absolute(lib).dir_path()
+pub fn get_absolute_rpath(lib: &Path) -> ~str {
+    let mut p = os::make_absolute(lib);
+    p.pop();
+    // FIXME (#9639): This needs to handle non-utf8 paths
+    p.as_str().expect("non-utf8 component in rpath").to_owned()
 }
 
-pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
+pub fn get_install_prefix_rpath(target_triple: &str) -> ~str {
     let install_prefix = env!("CFG_PREFIX");
 
     let tlib = filesearch::relative_target_lib_path(target_triple);
-    os::make_absolute(&Path(install_prefix).push_rel(&tlib))
+    let mut path = Path::from_str(install_prefix);
+    path.push_path(&tlib);
+    let path = os::make_absolute(&path);
+    // FIXME (#9639): This needs to handle non-utf8 paths
+    path.as_str().expect("non-utf8 component in rpath").to_owned()
 }
 
-pub fn minimize_rpaths(rpaths: &[Path]) -> ~[Path] {
+pub fn minimize_rpaths(rpaths: &[~str]) -> ~[~str] {
     let mut set = HashSet::new();
     let mut minimized = ~[];
     for rpath in rpaths.iter() {
-        if set.insert(rpath.to_str()) {
+        if set.insert(rpath.as_slice()) {
             minimized.push(rpath.clone());
         }
     }
@@ -162,43 +179,43 @@ mod test {
 
     #[test]
     fn test_rpaths_to_flags() {
-        let flags = rpaths_to_flags([Path("path1"),
-                                     Path("path2")]);
+        let flags = rpaths_to_flags([~"path1", ~"path2"]);
         assert_eq!(flags, ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
     }
 
     #[test]
     fn test_prefix_rpath() {
         let res = get_install_prefix_rpath("triple");
-        let d = Path(env!("CFG_PREFIX"))
-            .push_rel(&Path("lib/rustc/triple/lib"));
+        let mut d = Path::from_str(env!("CFG_PREFIX"));
+        d.push_str("lib/rustc/triple/lib");
         debug2!("test_prefix_path: {} vs. {}",
                res.to_str(),
-               d.to_str());
-        assert!(res.to_str().ends_with(d.to_str()));
+               d.display());
+        assert!(ends_with(res.as_bytes(), d.as_vec()));
+        fn ends_with(v: &[u8], needle: &[u8]) -> bool {
+            v.len() >= needle.len() && v.slice_from(v.len()-needle.len()) == needle
+        }
     }
 
     #[test]
     fn test_prefix_rpath_abs() {
         let res = get_install_prefix_rpath("triple");
-        assert!(res.is_absolute);
+        assert!(Path::from_str(res).is_absolute());
     }
 
     #[test]
     fn test_minimize1() {
-        let res = minimize_rpaths([Path("rpath1"),
-                                   Path("rpath2"),
-                                   Path("rpath1")]);
-        assert_eq!(res, ~[Path("rpath1"), Path("rpath2")]);
+        let res = minimize_rpaths([~"rpath1", ~"rpath2", ~"rpath1"]);
+        assert_eq!(res.as_slice(), [~"rpath1", ~"rpath2"]);
     }
 
     #[test]
     fn test_minimize2() {
-        let res = minimize_rpaths([Path("1a"), Path("2"), Path("2"),
-                                   Path("1a"), Path("4a"),Path("1a"),
-                                   Path("2"), Path("3"), Path("4a"),
-                                   Path("3")]);
-        assert_eq!(res, ~[Path("1a"), Path("2"), Path("4a"), Path("3")]);
+        let res = minimize_rpaths([~"1a", ~"2",  ~"2",
+                                   ~"1a", ~"4a", ~"1a",
+                                   ~"2",  ~"3",  ~"4a",
+                                   ~"3"]);
+        assert_eq!(res.as_slice(), [~"1a", ~"2", ~"4a", ~"3"]);
     }
 
     #[test]
@@ -207,8 +224,8 @@ mod test {
     fn test_rpath_relative() {
       let o = session::OsLinux;
       let res = get_rpath_relative_to_output(o,
-            &Path("bin/rustc"), &Path("lib/libstd.so"));
-      assert_eq!(res.to_str(), ~"$ORIGIN/../lib");
+            &Path::from_str("bin/rustc"), &Path::from_str("lib/libstd.so"));
+      assert_eq!(res.as_slice(), "$ORIGIN/../lib");
     }
 
     #[test]
@@ -216,8 +233,8 @@ mod test {
     fn test_rpath_relative() {
         let o = session::OsFreebsd;
         let res = get_rpath_relative_to_output(o,
-            &Path("bin/rustc"), &Path("lib/libstd.so"));
-        assert_eq!(res.to_str(), ~"$ORIGIN/../lib");
+            &Path::from_str("bin/rustc"), &Path::from_str("lib/libstd.so"));
+        assert_eq!(res.as_slice(), "$ORIGIN/../lib");
     }
 
     #[test]
@@ -225,18 +242,19 @@ mod test {
     fn test_rpath_relative() {
         let o = session::OsMacos;
         let res = get_rpath_relative_to_output(o,
-                                               &Path("bin/rustc"),
-                                               &Path("lib/libstd.so"));
-        assert_eq!(res.to_str(), ~"@executable_path/../lib");
+                                               &Path::from_str("bin/rustc"),
+                                               &Path::from_str("lib/libstd.so"));
+        assert_eq!(res.as_slice(), "@executable_path/../lib");
     }
 
     #[test]
     fn test_get_absolute_rpath() {
-        let res = get_absolute_rpath(&Path("lib/libstd.so"));
+        let res = get_absolute_rpath(&Path::from_str("lib/libstd.so"));
+        let lib = os::make_absolute(&Path::from_str("lib"));
         debug2!("test_get_absolute_rpath: {} vs. {}",
-               res.to_str(),
-               os::make_absolute(&Path("lib")).to_str());
+               res.to_str(), lib.display());
 
-        assert_eq!(res, os::make_absolute(&Path("lib")));
+        // FIXME (#9639): This needs to handle non-utf8 paths
+        assert_eq!(res.as_slice(), lib.as_str().expect("non-utf8 component in path"));
     }
 }