Skip to content

Commit b7ca476

Browse files
committed
---
yaml --- r: 5681 b: refs/heads/master c: ebcc76d h: refs/heads/master i: 5679: 4e1a95a v: v3
1 parent ba3db14 commit b7ca476

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: b25e78524c8de705fcd7dfe759e4a614ffa5f594
2+
refs/heads/master: ebcc76d68d5ab13cd7abc6d47c91471740f0899e

trunk/src/comp/metadata/creader.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import middle::resolve;
88
import syntax::visit;
99
import syntax::codemap::span;
1010
import back::x86;
11-
import util::common;
11+
import util::{common, filesearch};
1212
import std::{vec, str, fs, io, option};
1313
import std::option::{none, some};
1414
import std::map::{hashmap, new_int_hash};
@@ -131,49 +131,41 @@ fn find_library_crate(sess: session::session, ident: ast::ident,
131131
let nn = default_native_lib_naming(sess, sess.get_opts().static);
132132
let x =
133133
find_library_crate_aux(nn, crate_name, metas,
134-
sess.filesearch().lib_search_paths());
134+
sess.filesearch());
135135
if x != none || sess.get_opts().static { ret x; }
136136
let nn2 = default_native_lib_naming(sess, true);
137137
ret find_library_crate_aux(nn2, crate_name, metas,
138-
sess.filesearch().lib_search_paths());
138+
sess.filesearch());
139139
}
140140

141141
fn find_library_crate_aux(nn: {prefix: str, suffix: str}, crate_name: str,
142142
metas: [@ast::meta_item],
143-
library_search_paths: [str]) ->
143+
filesearch: filesearch::filesearch) ->
144144
option::t<{ident: str, data: @[u8]}> {
145145
let prefix: str = nn.prefix + crate_name;
146146
let suffix: str = nn.suffix;
147-
// FIXME: we could probably use a 'glob' function in std::fs but it will
148-
// be much easier to write once the unsafe module knows more about FFI
149-
// tricks. Currently the glob(3) interface is a bit more than we can
150-
// stomach from here, and writing a C++ wrapper is more work than just
151-
// manually filtering fs::list_dir here.
152147

153-
for library_search_path: str in library_search_paths {
154-
log #fmt["searching %s", library_search_path];
155-
for path: str in fs::list_dir(library_search_path) {
156-
log #fmt["searching %s", path];
157-
let f: str = fs::basename(path);
158-
if !(str::starts_with(f, prefix) && str::ends_with(f, suffix)) {
159-
log #fmt["skipping %s, doesn't look like %s*%s", path, prefix,
160-
suffix];
161-
cont;
162-
}
148+
ret filesearch::search(filesearch, { |path|
149+
let f: str = fs::basename(path);
150+
if !(str::starts_with(f, prefix) && str::ends_with(f, suffix)) {
151+
log #fmt["skipping %s, doesn't look like %s*%s", path, prefix,
152+
suffix];
153+
option::none
154+
} else {
163155
alt get_metadata_section(path) {
164156
option::some(cvec) {
165157
if !metadata_matches(cvec, metas) {
166158
log #fmt["skipping %s, metadata doesn't match", path];
167-
cont;
159+
option::none
160+
} else {
161+
log #fmt["found %s with matching metadata", path];
162+
option::some({ident: path, data: cvec})
168163
}
169-
log #fmt["found %s with matching metadata", path];
170-
ret some({ident: path, data: cvec});
171164
}
172-
_ { }
165+
_ { option::none }
173166
}
174167
}
175-
}
176-
ret none;
168+
});
177169
}
178170

179171
fn get_metadata_section(filename: str) -> option::t<@[u8]> {

trunk/src/comp/util/filesearch.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// A module for searching for libraries
2+
13
import std::option;
24
import std::fs;
35
import std::vec;
@@ -6,6 +8,10 @@ import back::link;
68

79
export filesearch;
810
export mk_filesearch;
11+
export pick;
12+
export search;
13+
14+
type pick<@T> = block(path: fs::path) -> option::t<T>;
915

1016
type filesearch = obj {
1117
fn sysroot() -> fs::path;
@@ -37,9 +43,28 @@ fn mk_filesearch(binary_name: fs::path,
3743
}
3844

3945
let sysroot = get_sysroot(maybe_sysroot, binary_name);
46+
log #fmt("using sysroot = %s", sysroot);
4047
ret filesearch_impl(sysroot, addl_lib_search_paths, target_triple);
4148
}
4249

50+
// FIXME #1001: This can't be an obj method
51+
fn search<@T>(filesearch: filesearch, pick: pick<T>) -> option::t<T> {
52+
for lib_search_path in filesearch.lib_search_paths() {
53+
log #fmt["searching %s", lib_search_path];
54+
for path in fs::list_dir(lib_search_path) {
55+
log #fmt["testing %s", path];
56+
let maybe_picked = pick(path);
57+
if option::is_some(maybe_picked) {
58+
log #fmt("picked %s", path);
59+
ret maybe_picked;
60+
} else {
61+
log #fmt("rejected %s", path);
62+
}
63+
}
64+
}
65+
ret option::none;
66+
}
67+
4368
fn make_target_lib_path(sysroot: fs::path,
4469
target_triple: str) -> fs::path {
4570
let path = [sysroot, "lib/rustc", target_triple, "lib"];

0 commit comments

Comments
 (0)