diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/back/rpath.rs | 4 | ||||
| -rw-r--r-- | src/librustc/driver/driver.rs | 2 | ||||
| -rw-r--r-- | src/librustc/metadata/filesearch.rs | 203 | ||||
| -rw-r--r-- | src/librustc/metadata/loader.rs | 3 |
4 files changed, 98 insertions, 114 deletions
diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index ecf4dd95cec..43ecbccfd79 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -39,7 +39,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] { debug!("preparing the RPATH!"); - let sysroot = sess.filesearch.sysroot(); + let sysroot = sess.filesearch.sysroot; let output = out_filename; let libs = sess.cstore.get_used_crates(cstore::RequireDynamic); let libs = libs.move_iter().filter_map(|(_, l)| l.map(|p| p.clone())).collect(); @@ -55,7 +55,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] { fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path { let r = filesearch::relative_target_lib_path(sess.opts.target_triple); - let mut p = sess.filesearch.sysroot().join(&r); + let mut p = sess.filesearch.sysroot.join(&r); p.push(os::dll_filename("rustrt")); p } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 37860888c10..b5dbf0e0c35 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -914,7 +914,7 @@ pub fn build_session_(sopts: @session::Options, let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler, cm); let cstore = @CStore::new(token::get_ident_interner()); - let filesearch = filesearch::mk_filesearch( + let filesearch = @filesearch::FileSearch::new( &sopts.maybe_sysroot, sopts.target_triple, sopts.addl_lib_search_paths); diff --git a/src/librustc/metadata/filesearch.rs b/src/librustc/metadata/filesearch.rs index 93d8249336b..f8e7a28d277 100644 --- a/src/librustc/metadata/filesearch.rs +++ b/src/librustc/metadata/filesearch.rs @@ -25,132 +25,117 @@ pub enum FileMatch { FileMatches, FileDoesntMatch } /// a file found in that directory. pub type pick<'a> = 'a |path: &Path| -> FileMatch; -pub fn pick_file(file: Path, path: &Path) -> Option<Path> { - if path.filename() == Some(file.as_vec()) { - Some(path.clone()) - } else { - None - } -} - -pub trait FileSearch { - fn sysroot(&self) -> @Path; - fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch); - fn get_target_lib_path(&self) -> Path; - fn get_target_lib_file_path(&self, file: &Path) -> Path; +pub struct FileSearch { + sysroot: @Path, + addl_lib_search_paths: @RefCell<HashSet<Path>>, + target_triple: ~str } -pub fn mk_filesearch(maybe_sysroot: &Option<@Path>, - target_triple: &str, - addl_lib_search_paths: @RefCell<HashSet<Path>>) - -> @FileSearch { - struct FileSearchImpl { - sysroot: @Path, - addl_lib_search_paths: @RefCell<HashSet<Path>>, - target_triple: ~str - } - impl FileSearch for FileSearchImpl { - fn sysroot(&self) -> @Path { self.sysroot } - - fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) { - let mut visited_dirs = HashSet::new(); - let mut found = false; - - let addl_lib_search_paths = self.addl_lib_search_paths.borrow(); - debug!("filesearch: searching additional lib search paths [{:?}]", - addl_lib_search_paths.get().len()); - for path in addl_lib_search_paths.get().iter() { - match f(path) { - FileMatches => found = true, - FileDoesntMatch => () - } - visited_dirs.insert(path.as_vec().to_owned()); +impl FileSearch { + pub fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) { + let mut visited_dirs = HashSet::new(); + let mut found = false; + + let addl_lib_search_paths = self.addl_lib_search_paths.borrow(); + debug!("filesearch: searching additional lib search paths [{:?}]", + addl_lib_search_paths.get().len()); + for path in addl_lib_search_paths.get().iter() { + match f(path) { + FileMatches => found = true, + FileDoesntMatch => () } + visited_dirs.insert(path.as_vec().to_owned()); + } - debug!("filesearch: searching target lib path"); - let tlib_path = make_target_lib_path(self.sysroot, - self.target_triple); - if !visited_dirs.contains_equiv(&tlib_path.as_vec()) { - match f(&tlib_path) { - FileMatches => found = true, - FileDoesntMatch => () - } + debug!("filesearch: searching target lib path"); + let tlib_path = make_target_lib_path(self.sysroot, + self.target_triple); + if !visited_dirs.contains_equiv(&tlib_path.as_vec()) { + match f(&tlib_path) { + FileMatches => found = true, + FileDoesntMatch => () } - 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); - debug!("is {} in visited_dirs? {:?}", tlib_path.display(), - visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned())); - - 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) { - FileMatches => { - break; - } - FileDoesntMatch => () - } + } + 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); + debug!("is {} in visited_dirs? {:?}", tlib_path.display(), + visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned())); + + 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) { + FileMatches => { + break; + } + FileDoesntMatch => () } } } } - fn get_target_lib_path(&self) -> Path { - make_target_lib_path(self.sysroot, self.target_triple) - } - fn get_target_lib_file_path(&self, file: &Path) -> Path { - let mut p = self.get_target_lib_path(); - p.push(file); - p - } } - let sysroot = get_sysroot(maybe_sysroot); - debug!("using sysroot = {}", sysroot.display()); - @FileSearchImpl { - sysroot: sysroot, - addl_lib_search_paths: addl_lib_search_paths, - target_triple: target_triple.to_owned() - } as @FileSearch -} + pub fn get_target_lib_path(&self) -> Path { + make_target_lib_path(self.sysroot, self.target_triple) + } -pub fn search(filesearch: @FileSearch, pick: pick) { - filesearch.for_each_lib_search_path(|lib_search_path| { - debug!("searching {}", lib_search_path.display()); - match io::result(|| fs::readdir(lib_search_path)) { - Ok(files) => { - let mut rslt = FileDoesntMatch; - let is_rlib = |p: & &Path| { - p.extension_str() == Some("rlib") - }; - // Reading metadata out of rlibs is faster, and if we find both - // an rlib and a dylib we only read one of the files of - // metadata, so in the name of speed, bring all rlib files to - // the front of the search list. - let files1 = files.iter().filter(|p| is_rlib(p)); - let files2 = files.iter().filter(|p| !is_rlib(p)); - for path in files1.chain(files2) { - debug!("testing {}", path.display()); - let maybe_picked = pick(path); - match maybe_picked { - FileMatches => { - debug!("picked {}", path.display()); - rslt = FileMatches; - } - FileDoesntMatch => { - debug!("rejected {}", path.display()); + pub fn get_target_lib_file_path(&self, file: &Path) -> Path { + let mut p = self.get_target_lib_path(); + p.push(file); + p + } + + pub fn search(&self, pick: pick) { + self.for_each_lib_search_path(|lib_search_path| { + debug!("searching {}", lib_search_path.display()); + match io::result(|| fs::readdir(lib_search_path)) { + Ok(files) => { + let mut rslt = FileDoesntMatch; + let is_rlib = |p: & &Path| { + p.extension_str() == Some("rlib") + }; + // Reading metadata out of rlibs is faster, and if we find both + // an rlib and a dylib we only read one of the files of + // metadata, so in the name of speed, bring all rlib files to + // the front of the search list. + let files1 = files.iter().filter(|p| is_rlib(p)); + let files2 = files.iter().filter(|p| !is_rlib(p)); + for path in files1.chain(files2) { + debug!("testing {}", path.display()); + let maybe_picked = pick(path); + match maybe_picked { + FileMatches => { + debug!("picked {}", path.display()); + rslt = FileMatches; + } + FileDoesntMatch => { + debug!("rejected {}", path.display()); + } } } + rslt } - rslt + Err(..) => FileDoesntMatch, } - Err(..) => FileDoesntMatch, + }); + } + + pub fn new(maybe_sysroot: &Option<@Path>, + target_triple: &str, + addl_lib_search_paths: @RefCell<HashSet<Path>>) -> FileSearch { + let sysroot = get_sysroot(maybe_sysroot); + debug!("using sysroot = {}", sysroot.display()); + FileSearch{ + sysroot: sysroot, + addl_lib_search_paths: addl_lib_search_paths, + target_triple: target_triple.to_owned() } - }); + } } pub fn relative_target_lib_path(target_triple: &str) -> Path { diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 12bfcb4b198..72f2e1baddd 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -17,7 +17,6 @@ use metadata::cstore::{MetadataBlob, MetadataVec, MetadataArchive}; use metadata::decoder; use metadata::encoder; use metadata::filesearch::{FileMatches, FileDoesntMatch}; -use metadata::filesearch; use syntax::codemap::Span; use syntax::diagnostic::SpanHandler; use syntax::parse::token::IdentInterner; @@ -89,7 +88,7 @@ impl Context { let rlib_prefix = format!("lib{}-", crate_name); let mut matches = ~[]; - filesearch::search(filesearch, |path| { + filesearch.search(|path| { match path.filename_str() { None => FileDoesntMatch, Some(file) => { |
