about summary refs log tree commit diff
path: root/src/librustpkg/installed_packages.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustpkg/installed_packages.rs')
-rw-r--r--src/librustpkg/installed_packages.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/librustpkg/installed_packages.rs b/src/librustpkg/installed_packages.rs
index cec64f36947..7c3cde65517 100644
--- a/src/librustpkg/installed_packages.rs
+++ b/src/librustpkg/installed_packages.rs
@@ -10,6 +10,7 @@
 
 // Listing installed packages
 
+use rustc::metadata::filesearch::rust_path;
 use path_util::*;
 use std::os;
 
@@ -20,21 +21,46 @@ pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool  {
         for exec in binfiles.iter() {
             let exec_path = Path(*exec).filestem();
             do exec_path.iter().advance |s| {
-                f(&PkgId::new(*s, p))
+                f(&PkgId::new(*s))
             };
         }
         let libfiles = os::list_dir(&p.push("lib"));
         for lib in libfiles.iter() {
-            debug!("Full name: %s", *lib);
-            let lib_path = Path(*lib).filestem();
-            do lib_path.iter().advance |s| {
-                f(&PkgId::new(*s, p))
-            };
-        }
+            let lib = Path(*lib);
+            debug!("Full name: %s", lib.to_str());
+            match has_library(&lib) {
+                Some(basename) => {
+                    debug!("parent = %s, child = %s",
+                           p.push("lib").to_str(), lib.to_str());
+                    let rel_p = p.push("lib/").get_relative_to(&lib);
+                    debug!("Rel: %s", rel_p.to_str());
+                    let rel_path = rel_p.push(basename).to_str();
+                    debug!("Rel name: %s", rel_path);
+                    f(&PkgId::new(rel_path));
+                }
+                None => ()
+            }
+        };
     }
     true
 }
 
+pub fn has_library(p: &Path) -> Option<~str> {
+    let files = os::list_dir(p);
+    for q in files.iter() {
+        let as_path = Path(*q);
+        if as_path.filetype() == Some(os::consts::DLL_SUFFIX.to_owned()) {
+            let stuff : ~str = as_path.filestem().expect("has_library: weird path");
+            let mut stuff2 = stuff.split_str_iter(&"-");
+            let stuff3: ~[&str] = stuff2.collect();
+            // argh
+            let chars_to_drop = os::consts::DLL_PREFIX.len();
+            return Some(stuff3[0].slice(chars_to_drop, stuff3[0].len()).to_owned());
+        }
+    }
+    None
+}
+
 pub fn package_is_installed(p: &PkgId) -> bool {
     let mut is_installed = false;
     do list_installed_packages() |installed| {
@@ -44,4 +70,4 @@ pub fn package_is_installed(p: &PkgId) -> bool {
         false
     };
     is_installed
-}
\ No newline at end of file
+}