Skip to content

Commit ec6aba3

Browse files
committed
rustc::metadata: Remove trait FileSearch
1 parent f30a9b3 commit ec6aba3

File tree

4 files changed

+98
-114
lines changed

4 files changed

+98
-114
lines changed

src/librustc/back/rpath.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] {
3939

4040
debug!("preparing the RPATH!");
4141

42-
let sysroot = sess.filesearch.sysroot();
42+
let sysroot = sess.filesearch.sysroot;
4343
let output = out_filename;
4444
let libs = sess.cstore.get_used_crates(cstore::RequireDynamic);
4545
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] {
5555

5656
fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
5757
let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
58-
let mut p = sess.filesearch.sysroot().join(&r);
58+
let mut p = sess.filesearch.sysroot.join(&r);
5959
p.push(os::dll_filename("rustrt"));
6060
p
6161
}

src/librustc/driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ pub fn build_session_(sopts: @session::Options,
914914
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler,
915915
cm);
916916
let cstore = @CStore::new(token::get_ident_interner());
917-
let filesearch = filesearch::mk_filesearch(
917+
let filesearch = @filesearch::FileSearch::new(
918918
&sopts.maybe_sysroot,
919919
sopts.target_triple,
920920
sopts.addl_lib_search_paths);

src/librustc/metadata/filesearch.rs

+94-109
Original file line numberDiff line numberDiff line change
@@ -25,132 +25,117 @@ pub enum FileMatch { FileMatches, FileDoesntMatch }
2525
/// a file found in that directory.
2626
pub type pick<'a> = 'a |path: &Path| -> FileMatch;
2727

28-
pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
29-
if path.filename() == Some(file.as_vec()) {
30-
Some(path.clone())
31-
} else {
32-
None
33-
}
34-
}
35-
36-
pub trait FileSearch {
37-
fn sysroot(&self) -> @Path;
38-
fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch);
39-
fn get_target_lib_path(&self) -> Path;
40-
fn get_target_lib_file_path(&self, file: &Path) -> Path;
28+
pub struct FileSearch {
29+
sysroot: @Path,
30+
addl_lib_search_paths: @RefCell<HashSet<Path>>,
31+
target_triple: ~str
4132
}
4233

43-
pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
44-
target_triple: &str,
45-
addl_lib_search_paths: @RefCell<HashSet<Path>>)
46-
-> @FileSearch {
47-
struct FileSearchImpl {
48-
sysroot: @Path,
49-
addl_lib_search_paths: @RefCell<HashSet<Path>>,
50-
target_triple: ~str
51-
}
52-
impl FileSearch for FileSearchImpl {
53-
fn sysroot(&self) -> @Path { self.sysroot }
54-
55-
fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) {
56-
let mut visited_dirs = HashSet::new();
57-
let mut found = false;
58-
59-
let addl_lib_search_paths = self.addl_lib_search_paths.borrow();
60-
debug!("filesearch: searching additional lib search paths [{:?}]",
61-
addl_lib_search_paths.get().len());
62-
for path in addl_lib_search_paths.get().iter() {
63-
match f(path) {
64-
FileMatches => found = true,
65-
FileDoesntMatch => ()
66-
}
67-
visited_dirs.insert(path.as_vec().to_owned());
34+
impl FileSearch {
35+
pub fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) {
36+
let mut visited_dirs = HashSet::new();
37+
let mut found = false;
38+
39+
let addl_lib_search_paths = self.addl_lib_search_paths.borrow();
40+
debug!("filesearch: searching additional lib search paths [{:?}]",
41+
addl_lib_search_paths.get().len());
42+
for path in addl_lib_search_paths.get().iter() {
43+
match f(path) {
44+
FileMatches => found = true,
45+
FileDoesntMatch => ()
6846
}
47+
visited_dirs.insert(path.as_vec().to_owned());
48+
}
6949

70-
debug!("filesearch: searching target lib path");
71-
let tlib_path = make_target_lib_path(self.sysroot,
72-
self.target_triple);
73-
if !visited_dirs.contains_equiv(&tlib_path.as_vec()) {
74-
match f(&tlib_path) {
75-
FileMatches => found = true,
76-
FileDoesntMatch => ()
77-
}
50+
debug!("filesearch: searching target lib path");
51+
let tlib_path = make_target_lib_path(self.sysroot,
52+
self.target_triple);
53+
if !visited_dirs.contains_equiv(&tlib_path.as_vec()) {
54+
match f(&tlib_path) {
55+
FileMatches => found = true,
56+
FileDoesntMatch => ()
7857
}
79-
visited_dirs.insert(tlib_path.as_vec().to_owned());
80-
// Try RUST_PATH
81-
if !found {
82-
let rustpath = rust_path();
83-
for path in rustpath.iter() {
84-
let tlib_path = make_rustpkg_target_lib_path(path, self.target_triple);
85-
debug!("is {} in visited_dirs? {:?}", tlib_path.display(),
86-
visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned()));
87-
88-
if !visited_dirs.contains_equiv(&tlib_path.as_vec()) {
89-
visited_dirs.insert(tlib_path.as_vec().to_owned());
90-
// Don't keep searching the RUST_PATH if one match turns up --
91-
// if we did, we'd get a "multiple matching crates" error
92-
match f(&tlib_path) {
93-
FileMatches => {
94-
break;
95-
}
96-
FileDoesntMatch => ()
97-
}
58+
}
59+
visited_dirs.insert(tlib_path.as_vec().to_owned());
60+
// Try RUST_PATH
61+
if !found {
62+
let rustpath = rust_path();
63+
for path in rustpath.iter() {
64+
let tlib_path = make_rustpkg_target_lib_path(path, self.target_triple);
65+
debug!("is {} in visited_dirs? {:?}", tlib_path.display(),
66+
visited_dirs.contains_equiv(&tlib_path.as_vec().to_owned()));
67+
68+
if !visited_dirs.contains_equiv(&tlib_path.as_vec()) {
69+
visited_dirs.insert(tlib_path.as_vec().to_owned());
70+
// Don't keep searching the RUST_PATH if one match turns up --
71+
// if we did, we'd get a "multiple matching crates" error
72+
match f(&tlib_path) {
73+
FileMatches => {
74+
break;
75+
}
76+
FileDoesntMatch => ()
9877
}
9978
}
10079
}
10180
}
102-
fn get_target_lib_path(&self) -> Path {
103-
make_target_lib_path(self.sysroot, self.target_triple)
104-
}
105-
fn get_target_lib_file_path(&self, file: &Path) -> Path {
106-
let mut p = self.get_target_lib_path();
107-
p.push(file);
108-
p
109-
}
11081
}
11182

112-
let sysroot = get_sysroot(maybe_sysroot);
113-
debug!("using sysroot = {}", sysroot.display());
114-
@FileSearchImpl {
115-
sysroot: sysroot,
116-
addl_lib_search_paths: addl_lib_search_paths,
117-
target_triple: target_triple.to_owned()
118-
} as @FileSearch
119-
}
83+
pub fn get_target_lib_path(&self) -> Path {
84+
make_target_lib_path(self.sysroot, self.target_triple)
85+
}
12086

121-
pub fn search(filesearch: @FileSearch, pick: pick) {
122-
filesearch.for_each_lib_search_path(|lib_search_path| {
123-
debug!("searching {}", lib_search_path.display());
124-
match io::result(|| fs::readdir(lib_search_path)) {
125-
Ok(files) => {
126-
let mut rslt = FileDoesntMatch;
127-
let is_rlib = |p: & &Path| {
128-
p.extension_str() == Some("rlib")
129-
};
130-
// Reading metadata out of rlibs is faster, and if we find both
131-
// an rlib and a dylib we only read one of the files of
132-
// metadata, so in the name of speed, bring all rlib files to
133-
// the front of the search list.
134-
let files1 = files.iter().filter(|p| is_rlib(p));
135-
let files2 = files.iter().filter(|p| !is_rlib(p));
136-
for path in files1.chain(files2) {
137-
debug!("testing {}", path.display());
138-
let maybe_picked = pick(path);
139-
match maybe_picked {
140-
FileMatches => {
141-
debug!("picked {}", path.display());
142-
rslt = FileMatches;
143-
}
144-
FileDoesntMatch => {
145-
debug!("rejected {}", path.display());
87+
pub fn get_target_lib_file_path(&self, file: &Path) -> Path {
88+
let mut p = self.get_target_lib_path();
89+
p.push(file);
90+
p
91+
}
92+
93+
pub fn search(&self, pick: pick) {
94+
self.for_each_lib_search_path(|lib_search_path| {
95+
debug!("searching {}", lib_search_path.display());
96+
match io::result(|| fs::readdir(lib_search_path)) {
97+
Ok(files) => {
98+
let mut rslt = FileDoesntMatch;
99+
let is_rlib = |p: & &Path| {
100+
p.extension_str() == Some("rlib")
101+
};
102+
// Reading metadata out of rlibs is faster, and if we find both
103+
// an rlib and a dylib we only read one of the files of
104+
// metadata, so in the name of speed, bring all rlib files to
105+
// the front of the search list.
106+
let files1 = files.iter().filter(|p| is_rlib(p));
107+
let files2 = files.iter().filter(|p| !is_rlib(p));
108+
for path in files1.chain(files2) {
109+
debug!("testing {}", path.display());
110+
let maybe_picked = pick(path);
111+
match maybe_picked {
112+
FileMatches => {
113+
debug!("picked {}", path.display());
114+
rslt = FileMatches;
115+
}
116+
FileDoesntMatch => {
117+
debug!("rejected {}", path.display());
118+
}
146119
}
147120
}
121+
rslt
148122
}
149-
rslt
123+
Err(..) => FileDoesntMatch,
150124
}
151-
Err(..) => FileDoesntMatch,
125+
});
126+
}
127+
128+
pub fn new(maybe_sysroot: &Option<@Path>,
129+
target_triple: &str,
130+
addl_lib_search_paths: @RefCell<HashSet<Path>>) -> FileSearch {
131+
let sysroot = get_sysroot(maybe_sysroot);
132+
debug!("using sysroot = {}", sysroot.display());
133+
FileSearch{
134+
sysroot: sysroot,
135+
addl_lib_search_paths: addl_lib_search_paths,
136+
target_triple: target_triple.to_owned()
152137
}
153-
});
138+
}
154139
}
155140

156141
pub fn relative_target_lib_path(target_triple: &str) -> Path {

src/librustc/metadata/loader.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use metadata::cstore::{MetadataBlob, MetadataVec, MetadataArchive};
1717
use metadata::decoder;
1818
use metadata::encoder;
1919
use metadata::filesearch::{FileMatches, FileDoesntMatch};
20-
use metadata::filesearch;
2120
use syntax::codemap::Span;
2221
use syntax::diagnostic::SpanHandler;
2322
use syntax::parse::token::IdentInterner;
@@ -89,7 +88,7 @@ impl Context {
8988
let rlib_prefix = format!("lib{}-", crate_name);
9089

9190
let mut matches = ~[];
92-
filesearch::search(filesearch, |path| {
91+
filesearch.search(|path| {
9392
match path.filename_str() {
9493
None => FileDoesntMatch,
9594
Some(file) => {

0 commit comments

Comments
 (0)