about summary refs log tree commit diff
path: root/src/comp/util
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-10-03 13:54:13 -0700
committerBrian Anderson <banderson@mozilla.com>2011-10-04 21:35:06 -0700
commitebcc76d68d5ab13cd7abc6d47c91471740f0899e (patch)
tree05d01a29fac39209f5c21376dbc759b2ab28bf40 /src/comp/util
parentb25e78524c8de705fcd7dfe759e4a614ffa5f594 (diff)
Move the library search into util::filesearch
Diffstat (limited to 'src/comp/util')
-rw-r--r--src/comp/util/filesearch.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/comp/util/filesearch.rs b/src/comp/util/filesearch.rs
index 0ae7d82f9c1..228d1266b1f 100644
--- a/src/comp/util/filesearch.rs
+++ b/src/comp/util/filesearch.rs
@@ -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"];