From 73d3d00ec437f87ac665b4e4da3bedec8ce4f9ef Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Thu, 26 Sep 2013 17:21:59 -0700 Subject: 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. --- src/librustc/back/link.rs | 73 ++++++++++++---------- src/librustc/back/rpath.rs | 110 +++++++++++++++++++-------------- src/librustc/driver/driver.rs | 30 +++++---- src/librustc/metadata/creader.rs | 11 ++-- src/librustc/metadata/filesearch.rs | 65 ++++++++++--------- src/librustc/metadata/loader.rs | 16 ++--- src/librustc/middle/trans/debuginfo.rs | 6 +- src/librustc/rustc.rs | 6 +- 8 files changed, 181 insertions(+), 136 deletions(-) (limited to 'src/librustc') 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")); } } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 0c896007fc3..fc5ff163d74 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -58,7 +58,8 @@ pub fn anon_src() -> @str { @"" } pub fn source_name(input: &input) -> @str { match *input { - file_input(ref ifile) => ifile.to_str().to_managed(), + // FIXME (#9639): This needs to handle non-utf8 paths + file_input(ref ifile) => ifile.as_str().unwrap().to_managed(), str_input(_) => anon_src() } } @@ -352,7 +353,7 @@ pub fn phase_5_run_llvm_passes(sess: Session, (sess.opts.output_type == link::output_type_object || sess.opts.output_type == link::output_type_exe) { let output_type = link::output_type_assembly; - let asm_filename = outputs.obj_filename.with_filetype("s"); + let asm_filename = outputs.obj_filename.with_extension_str("s"); time(sess.time_passes(), "LLVM passes", (), |_| link::write::run_passes(sess, @@ -721,7 +722,7 @@ pub fn build_session_options(binary: @str, } else if matches.opt_present("emit-llvm") { link::output_type_bitcode } else { link::output_type_exe }; - let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path(m)); + let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path::from_str(m)); let target = matches.opt_str("target").unwrap_or(host_triple()); let target_cpu = matches.opt_str("target-cpu").unwrap_or(~"generic"); let target_feature = matches.opt_str("target-feature").unwrap_or(~""); @@ -754,7 +755,7 @@ pub fn build_session_options(binary: @str, let statik = debugging_opts & session::statik != 0; - let addl_lib_search_paths = matches.opt_strs("L").map(|s| Path(*s)); + let addl_lib_search_paths = matches.opt_strs("L").map(|s| Path::from_str(*s)); let linker = matches.opt_str("linker"); let linker_args = matches.opt_strs("link-args").flat_map( |a| { a.split_iter(' ').map(|arg| arg.to_owned()).collect() @@ -985,7 +986,8 @@ pub fn build_output_filenames(input: &input, }; let mut stem = match *input { - file_input(ref ifile) => (*ifile).filestem().unwrap().to_managed(), + // FIXME (#9639): This needs to handle non-utf8 paths + file_input(ref ifile) => (*ifile).filestem_str().unwrap().to_managed(), str_input(_) => @"rust_out" }; @@ -1003,20 +1005,24 @@ pub fn build_output_filenames(input: &input, } if *sess.building_library { - out_path = dirpath.push(os::dll_filename(stem)); - obj_path = dirpath.push(stem).with_filetype(obj_suffix); + out_path = dirpath.join_str(os::dll_filename(stem)); + obj_path = { + let mut p = dirpath.join_str(stem); + p.set_extension_str(obj_suffix); + p + }; } else { - out_path = dirpath.push(stem); - obj_path = dirpath.push(stem).with_filetype(obj_suffix); + out_path = dirpath.join_str(stem); + obj_path = out_path.with_extension_str(obj_suffix); } } Some(ref out_file) => { - out_path = (*out_file).clone(); + out_path = out_file.clone(); obj_path = if stop_after_codegen { - (*out_file).clone() + out_file.clone() } else { - (*out_file).with_filetype(obj_suffix) + out_file.with_extension_str(obj_suffix) }; if *sess.building_library { 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 { - 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())) } } } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index a982a4767fd..fb3f215e506 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -859,7 +859,8 @@ fn compile_unit_metadata(cx: @mut CrateContext) { debug2!("compile_unit_metadata: {:?}", crate_name); - let work_dir = cx.sess.working_dir.to_str(); + // FIXME (#9639): This needs to handle non-utf8 paths + let work_dir = cx.sess.working_dir.as_str().unwrap(); let producer = format!("rustc version {}", env!("CFG_VERSION")); do crate_name.with_c_str |crate_name| { @@ -969,7 +970,8 @@ fn file_metadata(cx: &mut CrateContext, full_path: &str) -> DIFile { debug2!("file_metadata: {}", full_path); - let work_dir = cx.sess.working_dir.to_str(); + // FIXME (#9639): This needs to handle non-utf8 paths + let work_dir = cx.sess.working_dir.as_str().unwrap(); let file_name = if full_path.starts_with(work_dir) { full_path.slice(work_dir.len() + 1u, full_path.len()) diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index aa1ec26d426..460ac45cdba 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -250,7 +250,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) { let src = str::from_utf8(io::stdin().read_whole_stream()); str_input(src.to_managed()) } else { - file_input(Path(ifile)) + file_input(Path::from_str(ifile)) } } _ => early_error(demitter, "multiple input filenames provided") @@ -258,8 +258,8 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) { let sopts = build_session_options(binary, matches, demitter); let sess = build_session(sopts, demitter); - let odir = matches.opt_str("out-dir").map(|o| Path(o)); - let ofile = matches.opt_str("o").map(|o| Path(o)); + let odir = matches.opt_str("out-dir").map(|o| Path::from_str(o)); + let ofile = matches.opt_str("o").map(|o| Path::from_str(o)); let cfg = build_configuration(sess); let pretty = do matches.opt_default("pretty", "normal").map |a| { parse_pretty(sess, a) -- cgit 1.4.1-3-g733a5