diff options
| author | Graydon Hoare <graydon@mozilla.com> | 2012-08-24 15:28:43 -0700 |
|---|---|---|
| committer | Graydon Hoare <graydon@mozilla.com> | 2012-08-24 15:51:16 -0700 |
| commit | c284b8b1dc348ab8b9c82350dd1b4e53fac1225c (patch) | |
| tree | 99de39b149969275f6f9ddebd7a9f555d91c5bff /src/rustc/metadata | |
| parent | a8f1bee4574b8427a052e2fad93a90839288584b (diff) | |
| download | rust-c284b8b1dc348ab8b9c82350dd1b4e53fac1225c.tar.gz rust-c284b8b1dc348ab8b9c82350dd1b4e53fac1225c.zip | |
Start using core::path2::Path in a lot of places.
Diffstat (limited to 'src/rustc/metadata')
| -rw-r--r-- | src/rustc/metadata/creader.rs | 4 | ||||
| -rw-r--r-- | src/rustc/metadata/cstore.rs | 10 | ||||
| -rw-r--r-- | src/rustc/metadata/filesearch.rs | 83 | ||||
| -rw-r--r-- | src/rustc/metadata/loader.rs | 32 |
4 files changed, 64 insertions, 65 deletions
diff --git a/src/rustc/metadata/creader.rs b/src/rustc/metadata/creader.rs index 5867dc12672..685717e8e8d 100644 --- a/src/rustc/metadata/creader.rs +++ b/src/rustc/metadata/creader.rs @@ -199,7 +199,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: ~[@ast::meta_item], }; let cinfo = loader::load_library_crate(load_ctxt); - let cfilename = cinfo.ident; + let cfilename = Path(cinfo.ident); let cdata = cinfo.data; let attrs = decoder::get_crate_attributes(cdata); @@ -225,7 +225,7 @@ fn resolve_crate(e: env, ident: ast::ident, metas: ~[@ast::meta_item], let cstore = e.cstore; cstore::set_crate_data(cstore, cnum, cmeta); - cstore::add_used_crate_file(cstore, cfilename); + cstore::add_used_crate_file(cstore, &cfilename); return cnum; } some(cnum) => { diff --git a/src/rustc/metadata/cstore.rs b/src/rustc/metadata/cstore.rs index 4b65953781a..d2cab8c3177 100644 --- a/src/rustc/metadata/cstore.rs +++ b/src/rustc/metadata/cstore.rs @@ -56,7 +56,7 @@ type cstore_private = @{metas: map::hashmap<ast::crate_num, crate_metadata>, use_crate_map: use_crate_map, mod_path_map: mod_path_map, - mut used_crate_files: ~[~str], + mut used_crate_files: ~[Path], mut used_libraries: ~[~str], mut used_link_args: ~[~str], intr: ident_interner}; @@ -114,13 +114,13 @@ fn iter_crate_data(cstore: cstore, i: fn(ast::crate_num, crate_metadata)) { for p(cstore).metas.each |k,v| { i(k, v);}; } -fn add_used_crate_file(cstore: cstore, lib: ~str) { - if !vec::contains(p(cstore).used_crate_files, lib) { - vec::push(p(cstore).used_crate_files, lib); +fn add_used_crate_file(cstore: cstore, lib: &Path) { + if !vec::contains(p(cstore).used_crate_files, copy *lib) { + vec::push(p(cstore).used_crate_files, copy *lib); } } -fn get_used_crate_files(cstore: cstore) -> ~[~str] { +fn get_used_crate_files(cstore: cstore) -> ~[Path] { return p(cstore).used_crate_files; } diff --git a/src/rustc/metadata/filesearch.rs b/src/rustc/metadata/filesearch.rs index 72661891163..de0c31b9c3d 100644 --- a/src/rustc/metadata/filesearch.rs +++ b/src/rustc/metadata/filesearch.rs @@ -14,12 +14,10 @@ export get_cargo_root; export get_cargo_root_nearest; export libdir; -import path::Path; +type pick<T> = fn(path: &Path) -> option<T>; -type pick<T> = fn(path: Path) -> option<T>; - -fn pick_file(file: Path, path: Path) -> option<Path> { - if path::basename(path) == file { option::some(path) } +fn pick_file(file: Path, path: &Path) -> option<Path> { + if path.file_path() == file { option::some(copy *path) } else { option::none } } @@ -27,11 +25,11 @@ trait filesearch { fn sysroot() -> Path; fn lib_search_paths() -> ~[Path]; fn get_target_lib_path() -> Path; - fn get_target_lib_file_path(file: Path) -> Path; + fn get_target_lib_file_path(file: &Path) -> Path; } fn mk_filesearch(maybe_sysroot: option<Path>, - target_triple: ~str, + target_triple: &str, addl_lib_search_paths: ~[Path]) -> filesearch { type filesearch_impl = {sysroot: Path, addl_lib_search_paths: ~[Path], @@ -42,7 +40,8 @@ fn mk_filesearch(maybe_sysroot: option<Path>, let mut paths = self.addl_lib_search_paths; vec::push(paths, - make_target_lib_path(self.sysroot, self.target_triple)); + make_target_lib_path(&self.sysroot, + self.target_triple)); match get_cargo_lib_path_nearest() { result::ok(p) => vec::push(paths, p), result::err(p) => () @@ -54,33 +53,33 @@ fn mk_filesearch(maybe_sysroot: option<Path>, paths } fn get_target_lib_path() -> Path { - make_target_lib_path(self.sysroot, self.target_triple) + make_target_lib_path(&self.sysroot, self.target_triple) } - fn get_target_lib_file_path(file: Path) -> Path { - path::connect(self.get_target_lib_path(), file) + fn get_target_lib_file_path(file: &Path) -> Path { + self.get_target_lib_path().push_rel(file) } } let sysroot = get_sysroot(maybe_sysroot); - debug!("using sysroot = %s", sysroot); + debug!("using sysroot = %s", sysroot.to_str()); {sysroot: sysroot, addl_lib_search_paths: addl_lib_search_paths, - target_triple: target_triple} as filesearch + target_triple: str::from_slice(target_triple)} as filesearch } fn search<T: copy>(filesearch: filesearch, pick: pick<T>) -> option<T> { let mut rslt = none; for filesearch.lib_search_paths().each |lib_search_path| { - debug!("searching %s", lib_search_path); - for os::list_dir_path(lib_search_path).each |path| { - debug!("testing %s", path); + debug!("searching %s", lib_search_path.to_str()); + for os::list_dir_path(&lib_search_path).each |path| { + debug!("testing %s", path.to_str()); let maybe_picked = pick(path); if option::is_some(maybe_picked) { - debug!("picked %s", path); + debug!("picked %s", path.to_str()); rslt = maybe_picked; break; } else { - debug!("rejected %s", path); + debug!("rejected %s", path.to_str()); } } if option::is_some(rslt) { break; } @@ -88,21 +87,20 @@ fn search<T: copy>(filesearch: filesearch, pick: pick<T>) -> option<T> { return rslt; } -fn relative_target_lib_path(target_triple: ~str) -> ~[Path] { - ~[libdir(), ~"rustc", target_triple, libdir()] +fn relative_target_lib_path(target_triple: &str) -> Path { + Path(libdir()).push_many([~"rustc", + str::from_slice(target_triple), + libdir()]) } -fn make_target_lib_path(sysroot: Path, - target_triple: ~str) -> Path { - let path = vec::append(~[sysroot], - relative_target_lib_path(target_triple)); - let path = path::connect_many(path); - return path; +fn make_target_lib_path(sysroot: &Path, + target_triple: &str) -> Path { + sysroot.push_rel(&relative_target_lib_path(target_triple)) } fn get_default_sysroot() -> Path { match os::self_exe_path() { - option::some(p) => path::normalize(path::connect(p, ~"..")), + option::some(p) => p.pop(), option::none => fail ~"can't determine value for sysroot" } } @@ -115,15 +113,14 @@ fn get_sysroot(maybe_sysroot: option<Path>) -> Path { } fn get_cargo_sysroot() -> result<Path, ~str> { - let path = ~[get_default_sysroot(), libdir(), ~"cargo"]; - result::ok(path::connect_many(path)) + result::ok(get_default_sysroot().push_many([libdir(), ~"cargo"])) } fn get_cargo_root() -> result<Path, ~str> { match os::getenv(~"CARGO_ROOT") { - some(_p) => result::ok(_p), + some(_p) => result::ok(Path(_p)), none => match os::homedir() { - some(_q) => result::ok(path::connect(_q, ~".cargo")), + some(_q) => result::ok(_q.push(".cargo")), none => result::err(~"no CARGO_ROOT or home directory") } } @@ -132,21 +129,21 @@ fn get_cargo_root() -> result<Path, ~str> { fn get_cargo_root_nearest() -> result<Path, ~str> { do result::chain(get_cargo_root()) |p| { let cwd = os::getcwd(); - let mut dirname = path::dirname(cwd); - let mut dirpath = path::split(dirname); - let cwd_cargo = path::connect(cwd, ~".cargo"); - let mut par_cargo = path::connect(dirname, ~".cargo"); + let cwd_cargo = cwd.push(".cargo"); + let mut par_cargo = cwd.pop().push(".cargo"); let mut rslt = result::ok(cwd_cargo); - if !os::path_is_dir(cwd_cargo) && cwd_cargo != p { - while vec::is_not_empty(dirpath) && par_cargo != p { - if os::path_is_dir(par_cargo) { + if !os::path_is_dir(&cwd_cargo) && cwd_cargo != p { + while par_cargo != p { + if os::path_is_dir(&par_cargo) { rslt = result::ok(par_cargo); break; } - vec::pop(dirpath); - dirname = path::dirname(dirname); - par_cargo = path::connect(dirname, ~".cargo"); + if par_cargo.components.len() == 1 { + // We just checked /.cargo, stop now. + break; + } + par_cargo = par_cargo.pop().pop().push(".cargo"); } } rslt @@ -155,13 +152,13 @@ fn get_cargo_root_nearest() -> result<Path, ~str> { fn get_cargo_lib_path() -> result<Path, ~str> { do result::chain(get_cargo_root()) |p| { - result::ok(path::connect(p, libdir())) + result::ok(p.push(libdir())) } } fn get_cargo_lib_path_nearest() -> result<Path, ~str> { do result::chain(get_cargo_root_nearest()) |p| { - result::ok(path::connect(p, libdir())) + result::ok(p.push(libdir())) } } diff --git a/src/rustc/metadata/loader.rs b/src/rustc/metadata/loader.rs index f010b7e9754..513b4dd4216 100644 --- a/src/rustc/metadata/loader.rs +++ b/src/rustc/metadata/loader.rs @@ -74,27 +74,28 @@ fn find_library_crate_aux(cx: ctxt, let mut matches = ~[]; filesearch::search(filesearch, |path| { - debug!("inspecting file %s", path); - let f: ~str = path::basename(path); + debug!("inspecting file %s", path.to_str()); + let f: ~str = option::get(path.filename()); if !(str::starts_with(f, prefix) && str::ends_with(f, suffix)) { - debug!("skipping %s, doesn't look like %s*%s", path, prefix, - suffix); + debug!("skipping %s, doesn't look like %s*%s", path.to_str(), + prefix, suffix); option::none::<()> } else { - debug!("%s is a candidate", path); + debug!("%s is a candidate", path.to_str()); match get_metadata_section(cx.os, path) { option::some(cvec) => { if !crate_matches(cvec, cx.metas, cx.hash) { - debug!("skipping %s, metadata doesn't match", path); + debug!("skipping %s, metadata doesn't match", + path.to_str()); option::none::<()> } else { - debug!("found %s with matching metadata", path); - vec::push(matches, {ident: path, data: cvec}); + debug!("found %s with matching metadata", path.to_str()); + vec::push(matches, {ident: path.to_str(), data: cvec}); option::none::<()> } } _ => { - debug!("could not load metadata for %s", path); + debug!("could not load metadata for %s", path.to_str()); option::none::<()> } } @@ -168,10 +169,10 @@ fn metadata_matches(extern_metas: ~[@ast::meta_item], } fn get_metadata_section(os: os, - filename: ~str) -> option<@~[u8]> unsafe { - let mb = str::as_c_str(filename, |buf| { + filename: &Path) -> option<@~[u8]> unsafe { + let mb = str::as_c_str(filename.to_str(), |buf| { llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf) - }); + }); if mb as int == 0 { return option::none::<@~[u8]>; } let of = match mk_object_file(mb) { option::some(of) => of, @@ -204,12 +205,13 @@ fn meta_section_name(os: os) -> ~str { } // A diagnostic function for dumping crate metadata to an output stream -fn list_file_metadata(intr: ident_interner, os: os, path: ~str, - out: io::Writer) { +fn list_file_metadata(intr: ident_interner, + os: os, path: &Path, out: io::Writer) { match get_metadata_section(os, path) { option::some(bytes) => decoder::list_crate_metadata(intr, bytes, out), option::none => { - out.write_str(~"could not find metadata in " + path + ~".\n"); + out.write_str(~"could not find metadata in " + + path.to_str() + ~".\n"); } } } |
