2013-07-11 18:20:31 -07:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Listing installed packages
|
|
|
|
|
2013-07-31 13:47:32 -07:00
|
|
|
use rustc::metadata::filesearch::rust_path;
|
2013-07-11 18:20:31 -07:00
|
|
|
use path_util::*;
|
|
|
|
use std::os;
|
|
|
|
|
|
|
|
pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
|
|
|
|
let workspaces = rust_path();
|
2013-08-03 12:45:23 -04:00
|
|
|
for p in workspaces.iter() {
|
2013-07-11 18:20:31 -07:00
|
|
|
let binfiles = os::list_dir(&p.push("bin"));
|
2013-08-03 12:45:23 -04:00
|
|
|
for exec in binfiles.iter() {
|
2013-09-04 13:10:22 +02:00
|
|
|
let p = Path(*exec);
|
|
|
|
let exec_path = p.filestem();
|
2013-06-26 17:42:24 -07:00
|
|
|
do exec_path.iter().advance |s| {
|
2013-07-31 13:47:32 -07:00
|
|
|
f(&PkgId::new(*s))
|
2013-06-26 17:42:24 -07:00
|
|
|
};
|
2013-07-11 18:20:31 -07:00
|
|
|
}
|
|
|
|
let libfiles = os::list_dir(&p.push("lib"));
|
2013-08-03 12:45:23 -04:00
|
|
|
for lib in libfiles.iter() {
|
2013-07-31 13:47:32 -07:00
|
|
|
let lib = Path(*lib);
|
2013-09-27 23:37:25 -07:00
|
|
|
debug2!("Full name: {}", lib.to_str());
|
2013-07-31 13:47:32 -07:00
|
|
|
match has_library(&lib) {
|
|
|
|
Some(basename) => {
|
2013-09-27 23:37:25 -07:00
|
|
|
debug2!("parent = {}, child = {}",
|
|
|
|
p.push("lib").to_str(), lib.to_str());
|
2013-07-31 13:47:32 -07:00
|
|
|
let rel_p = p.push("lib/").get_relative_to(&lib);
|
2013-09-27 23:37:25 -07:00
|
|
|
debug2!("Rel: {}", rel_p.to_str());
|
2013-07-31 13:47:32 -07:00
|
|
|
let rel_path = rel_p.push(basename).to_str();
|
2013-09-27 23:37:25 -07:00
|
|
|
debug2!("Rel name: {}", rel_path);
|
2013-07-31 13:47:32 -07:00
|
|
|
f(&PkgId::new(rel_path));
|
|
|
|
}
|
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
};
|
2013-07-11 18:20:31 -07:00
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2013-07-31 13:47:32 -07:00
|
|
|
pub fn has_library(p: &Path) -> Option<~str> {
|
|
|
|
let files = os::list_dir(p);
|
|
|
|
for q in files.iter() {
|
|
|
|
let as_path = Path(*q);
|
2013-09-04 13:10:22 +02:00
|
|
|
if as_path.filetype() == Some(os::consts::DLL_SUFFIX) {
|
|
|
|
let stuff : &str = as_path.filestem().expect("has_library: weird path");
|
2013-07-31 13:47:32 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-07-11 18:20:31 -07:00
|
|
|
pub fn package_is_installed(p: &PkgId) -> bool {
|
|
|
|
let mut is_installed = false;
|
2013-07-13 13:38:07 -07:00
|
|
|
do list_installed_packages() |installed| {
|
2013-07-11 18:20:31 -07:00
|
|
|
if installed == p {
|
|
|
|
is_installed = true;
|
|
|
|
}
|
|
|
|
false
|
|
|
|
};
|
|
|
|
is_installed
|
2013-07-31 13:47:32 -07:00
|
|
|
}
|