Move the library search into util::filesearch
This commit is contained in:
parent
b25e78524c
commit
ebcc76d68d
|
@ -8,7 +8,7 @@ import middle::resolve;
|
||||||
import syntax::visit;
|
import syntax::visit;
|
||||||
import syntax::codemap::span;
|
import syntax::codemap::span;
|
||||||
import back::x86;
|
import back::x86;
|
||||||
import util::common;
|
import util::{common, filesearch};
|
||||||
import std::{vec, str, fs, io, option};
|
import std::{vec, str, fs, io, option};
|
||||||
import std::option::{none, some};
|
import std::option::{none, some};
|
||||||
import std::map::{hashmap, new_int_hash};
|
import std::map::{hashmap, new_int_hash};
|
||||||
|
@ -131,49 +131,41 @@ fn find_library_crate(sess: session::session, ident: ast::ident,
|
||||||
let nn = default_native_lib_naming(sess, sess.get_opts().static);
|
let nn = default_native_lib_naming(sess, sess.get_opts().static);
|
||||||
let x =
|
let x =
|
||||||
find_library_crate_aux(nn, crate_name, metas,
|
find_library_crate_aux(nn, crate_name, metas,
|
||||||
sess.filesearch().lib_search_paths());
|
sess.filesearch());
|
||||||
if x != none || sess.get_opts().static { ret x; }
|
if x != none || sess.get_opts().static { ret x; }
|
||||||
let nn2 = default_native_lib_naming(sess, true);
|
let nn2 = default_native_lib_naming(sess, true);
|
||||||
ret find_library_crate_aux(nn2, crate_name, metas,
|
ret find_library_crate_aux(nn2, crate_name, metas,
|
||||||
sess.filesearch().lib_search_paths());
|
sess.filesearch());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_library_crate_aux(nn: {prefix: str, suffix: str}, crate_name: str,
|
fn find_library_crate_aux(nn: {prefix: str, suffix: str}, crate_name: str,
|
||||||
metas: [@ast::meta_item],
|
metas: [@ast::meta_item],
|
||||||
library_search_paths: [str]) ->
|
filesearch: filesearch::filesearch) ->
|
||||||
option::t<{ident: str, data: @[u8]}> {
|
option::t<{ident: str, data: @[u8]}> {
|
||||||
let prefix: str = nn.prefix + crate_name;
|
let prefix: str = nn.prefix + crate_name;
|
||||||
let suffix: str = nn.suffix;
|
let suffix: str = nn.suffix;
|
||||||
// FIXME: we could probably use a 'glob' function in std::fs but it will
|
|
||||||
// be much easier to write once the unsafe module knows more about FFI
|
|
||||||
// tricks. Currently the glob(3) interface is a bit more than we can
|
|
||||||
// stomach from here, and writing a C++ wrapper is more work than just
|
|
||||||
// manually filtering fs::list_dir here.
|
|
||||||
|
|
||||||
for library_search_path: str in library_search_paths {
|
ret filesearch::search(filesearch, { |path|
|
||||||
log #fmt["searching %s", library_search_path];
|
let f: str = fs::basename(path);
|
||||||
for path: str in fs::list_dir(library_search_path) {
|
if !(str::starts_with(f, prefix) && str::ends_with(f, suffix)) {
|
||||||
log #fmt["searching %s", path];
|
log #fmt["skipping %s, doesn't look like %s*%s", path, prefix,
|
||||||
let f: str = fs::basename(path);
|
suffix];
|
||||||
if !(str::starts_with(f, prefix) && str::ends_with(f, suffix)) {
|
option::none
|
||||||
log #fmt["skipping %s, doesn't look like %s*%s", path, prefix,
|
} else {
|
||||||
suffix];
|
|
||||||
cont;
|
|
||||||
}
|
|
||||||
alt get_metadata_section(path) {
|
alt get_metadata_section(path) {
|
||||||
option::some(cvec) {
|
option::some(cvec) {
|
||||||
if !metadata_matches(cvec, metas) {
|
if !metadata_matches(cvec, metas) {
|
||||||
log #fmt["skipping %s, metadata doesn't match", path];
|
log #fmt["skipping %s, metadata doesn't match", path];
|
||||||
cont;
|
option::none
|
||||||
|
} else {
|
||||||
|
log #fmt["found %s with matching metadata", path];
|
||||||
|
option::some({ident: path, data: cvec})
|
||||||
}
|
}
|
||||||
log #fmt["found %s with matching metadata", path];
|
|
||||||
ret some({ident: path, data: cvec});
|
|
||||||
}
|
}
|
||||||
_ { }
|
_ { option::none }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
ret none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_metadata_section(filename: str) -> option::t<@[u8]> {
|
fn get_metadata_section(filename: str) -> option::t<@[u8]> {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// A module for searching for libraries
|
||||||
|
|
||||||
import std::option;
|
import std::option;
|
||||||
import std::fs;
|
import std::fs;
|
||||||
import std::vec;
|
import std::vec;
|
||||||
|
@ -6,6 +8,10 @@ import back::link;
|
||||||
|
|
||||||
export filesearch;
|
export filesearch;
|
||||||
export mk_filesearch;
|
export mk_filesearch;
|
||||||
|
export pick;
|
||||||
|
export search;
|
||||||
|
|
||||||
|
type pick<@T> = block(path: fs::path) -> option::t<T>;
|
||||||
|
|
||||||
type filesearch = obj {
|
type filesearch = obj {
|
||||||
fn sysroot() -> fs::path;
|
fn sysroot() -> fs::path;
|
||||||
|
@ -37,9 +43,28 @@ fn mk_filesearch(binary_name: fs::path,
|
||||||
}
|
}
|
||||||
|
|
||||||
let sysroot = get_sysroot(maybe_sysroot, binary_name);
|
let sysroot = get_sysroot(maybe_sysroot, binary_name);
|
||||||
|
log #fmt("using sysroot = %s", sysroot);
|
||||||
ret filesearch_impl(sysroot, addl_lib_search_paths, target_triple);
|
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,
|
fn make_target_lib_path(sysroot: fs::path,
|
||||||
target_triple: str) -> fs::path {
|
target_triple: str) -> fs::path {
|
||||||
let path = [sysroot, "lib/rustc", target_triple, "lib"];
|
let path = [sysroot, "lib/rustc", target_triple, "lib"];
|
||||||
|
|
Loading…
Reference in a new issue