Move the library search into util::filesearch

This commit is contained in:
Brian Anderson 2011-10-03 13:54:13 -07:00
parent b25e78524c
commit ebcc76d68d
2 changed files with 42 additions and 25 deletions

View file

@ -1,3 +1,5 @@
// A module for searching for libraries
import std::option;
import std::fs;
import std::vec;
@ -6,6 +8,10 @@ import back::link;
export filesearch;
export mk_filesearch;
export pick;
export search;
type pick<@T> = block(path: fs::path) -> option::t<T>;
type filesearch = obj {
fn sysroot() -> fs::path;
@ -37,9 +43,28 @@ fn mk_filesearch(binary_name: fs::path,
}
let sysroot = get_sysroot(maybe_sysroot, binary_name);
log #fmt("using sysroot = %s", sysroot);
ret filesearch_impl(sysroot, addl_lib_search_paths, target_triple);
}
// FIXME #1001: This can't be an obj method
fn search<@T>(filesearch: filesearch, pick: pick<T>) -> option::t<T> {
for lib_search_path in filesearch.lib_search_paths() {
log #fmt["searching %s", lib_search_path];
for path in fs::list_dir(lib_search_path) {
log #fmt["testing %s", path];
let maybe_picked = pick(path);
if option::is_some(maybe_picked) {
log #fmt("picked %s", path);
ret maybe_picked;
} else {
log #fmt("rejected %s", path);
}
}
}
ret option::none;
}
fn make_target_lib_path(sysroot: fs::path,
target_triple: str) -> fs::path {
let path = [sysroot, "lib/rustc", target_triple, "lib"];