rust/src/librustpkg/installed_packages.rs
Tim Chevalier e39ea2a5c8 rustpkg: Make rustpkg commands work without a package ID
`rustpkg build`, if executed in a package source directory inside
a workspace, will now build that package. By "inside a workspace"
I mean that the parent directory has to be called `src`, and rustpkg
will create a `build` directory in .. if there isn't already one.

Same goes for `rustpkg install` and `rustpkg clean`.

For the time being, `rustpkg build` (etc.) will still error out if
you run it inside a directory whose parent isn't called `src`.
I'm not sure whether or not it's desirable to have it do something
in a non-workspace directory.
2013-07-18 17:28:40 -07:00

47 lines
No EOL
1.5 KiB
Rust

// 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
use path_util::*;
use std::os;
pub fn list_installed_packages(f: &fn(&PkgId) -> bool) -> bool {
let workspaces = rust_path();
for workspaces.iter().advance |p| {
let binfiles = os::list_dir(&p.push("bin"));
for binfiles.iter().advance() |exec| {
let exec_path = Path(*exec).filestem();
do exec_path.iter().advance |s| {
f(&PkgId::new(*s, p))
};
}
let libfiles = os::list_dir(&p.push("lib"));
for libfiles.iter().advance() |lib| {
debug!("Full name: %s", *lib);
let lib_path = Path(*lib).filestem();
do lib_path.iter().advance |s| {
f(&PkgId::new(*s, p))
};
}
}
true
}
pub fn package_is_installed(p: &PkgId) -> bool {
let mut is_installed = false;
do list_installed_packages() |installed| {
if installed == p {
is_installed = true;
}
false
};
is_installed
}