]> git.lizzy.rs Git - rust.git/commitdiff
rustc::metadata: Remove trait FileSearch
authorklutzy <klutzytheklutzy@gmail.com>
Mon, 13 Jan 2014 16:31:57 +0000 (01:31 +0900)
committerklutzy <klutzytheklutzy@gmail.com>
Fri, 17 Jan 2014 04:27:47 +0000 (13:27 +0900)
src/librustc/back/rpath.rs
src/librustc/driver/driver.rs
src/librustc/metadata/filesearch.rs
src/librustc/metadata/loader.rs

index ecf4dd95cecb4b8ff8e4546511f753290631c2ab..43ecbccfd79dcf09fee86a83b3190b3b42c633e0 100644 (file)
@@ -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
 }
index 37860888c100924e0155465429d0dab022b234c3..b5dbf0e0c35c658bd7a5a820778f403a181d7cb7 100644 (file)
@@ -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);
index 93d8249336b3fb81386fab91ca294c0afde3da51..f8e7a28d27708117066d7c43f7c2c26dd99ff7a2 100644 (file)
@@ -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 {
index 12bfcb4b1983c5c3fb52a6ce2d85a48e07c3f544..72f2e1baddd7bdd7adb4a2d742382c8b49404358 100644 (file)
@@ -17,7 +17,6 @@
 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 @@ fn find_library_crate(&self) -> Option<Library> {
         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) => {