2013-04-12 18:15:40 -05: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.
|
|
|
|
|
|
|
|
// rustpkg utilities having to do with paths and directories
|
|
|
|
|
2013-06-01 17:59:12 -05:00
|
|
|
pub use package_id::PkgId;
|
2013-05-27 19:45:16 -05:00
|
|
|
pub use target::{OutputType, Main, Lib, Test, Bench, Target, Build, Install};
|
2013-08-15 20:36:39 -05:00
|
|
|
pub use version::{Version, NoVersion, split_version_general, try_parsing_version};
|
2013-07-31 15:47:32 -05:00
|
|
|
pub use rustc::metadata::filesearch::rust_path;
|
2013-09-12 21:29:21 -05:00
|
|
|
use rustc::driver::driver::host_triple;
|
2013-07-31 15:47:32 -05:00
|
|
|
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR};
|
|
|
|
use std::os::mkdir_recursive;
|
|
|
|
use std::os;
|
2013-06-14 20:16:24 -05:00
|
|
|
use messages::*;
|
2013-04-22 19:54:54 -05:00
|
|
|
|
2013-07-09 20:28:00 -05:00
|
|
|
pub fn default_workspace() -> Path {
|
|
|
|
let p = rust_path();
|
|
|
|
if p.is_empty() {
|
|
|
|
fail!("Empty RUST_PATH");
|
|
|
|
}
|
|
|
|
let result = p[0];
|
|
|
|
if !os::path_is_dir(&result) {
|
|
|
|
os::mkdir_recursive(&result, U_RWX);
|
|
|
|
}
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn in_rust_path(p: &Path) -> bool {
|
|
|
|
rust_path().contains(p)
|
|
|
|
}
|
|
|
|
|
2013-06-30 22:51:13 -05:00
|
|
|
pub static U_RWX: i32 = (S_IRUSR | S_IWUSR | S_IXUSR) as i32;
|
2013-04-25 19:18:25 -05:00
|
|
|
|
2013-04-22 19:54:54 -05:00
|
|
|
/// Creates a directory that is readable, writeable,
|
|
|
|
/// and executable by the user. Returns true iff creation
|
|
|
|
/// succeeded.
|
2013-06-30 22:51:13 -05:00
|
|
|
pub fn make_dir_rwx(p: &Path) -> bool { os::make_dir(p, U_RWX) }
|
2013-04-12 18:15:40 -05:00
|
|
|
|
2013-09-08 17:59:51 -05:00
|
|
|
pub fn make_dir_rwx_recursive(p: &Path) -> bool { os::mkdir_recursive(p, U_RWX) }
|
|
|
|
|
2013-04-22 19:54:54 -05:00
|
|
|
// n.b. The next three functions ignore the package version right
|
|
|
|
// now. Should fix that.
|
|
|
|
|
|
|
|
/// True if there's a directory in <workspace> with
|
|
|
|
/// pkgid's short name
|
2013-05-14 19:46:52 -05:00
|
|
|
pub fn workspace_contains_package_id(pkgid: &PkgId, workspace: &Path) -> bool {
|
2013-08-28 16:52:37 -05:00
|
|
|
workspace_contains_package_id_(pkgid, workspace, |p| { p.push("src") }).is_some()
|
|
|
|
}
|
2013-08-23 13:51:45 -05:00
|
|
|
|
2013-08-28 16:52:37 -05:00
|
|
|
pub fn workspace_contains_package_id_(pkgid: &PkgId, workspace: &Path,
|
|
|
|
// Returns the directory it was actually found in
|
|
|
|
workspace_to_src_dir: &fn(&Path) -> Path) -> Option<Path> {
|
2013-09-11 01:25:31 -05:00
|
|
|
if !os::path_is_dir(workspace) {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2013-08-28 16:52:37 -05:00
|
|
|
let src_dir = workspace_to_src_dir(workspace);
|
2013-07-17 19:08:13 -05:00
|
|
|
|
2013-08-28 16:52:37 -05:00
|
|
|
let mut found = None;
|
2013-07-31 15:47:32 -05:00
|
|
|
do os::walk_dir(&src_dir) |p| {
|
2013-08-28 16:52:37 -05:00
|
|
|
if os::path_is_dir(p) {
|
|
|
|
if *p == src_dir.push_rel(&pkgid.path) || {
|
2013-07-31 15:47:32 -05:00
|
|
|
let pf = p.filename();
|
2013-07-17 19:08:13 -05:00
|
|
|
do pf.iter().any |pf| {
|
|
|
|
let g = pf.to_str();
|
2013-07-31 15:47:32 -05:00
|
|
|
match split_version_general(g, '-') {
|
2013-07-17 19:08:13 -05:00
|
|
|
None => false,
|
2013-07-31 15:47:32 -05:00
|
|
|
Some((ref might_match, ref vers)) => {
|
2013-07-17 19:08:13 -05:00
|
|
|
*might_match == pkgid.short_name
|
|
|
|
&& (pkgid.version == *vers || pkgid.version == NoVersion)
|
2013-06-14 20:16:24 -05:00
|
|
|
}
|
2013-07-17 19:08:13 -05:00
|
|
|
}
|
2013-06-14 20:16:24 -05:00
|
|
|
}
|
2013-08-28 16:52:37 -05:00
|
|
|
} {
|
|
|
|
found = Some(p.clone());
|
2013-06-14 20:16:24 -05:00
|
|
|
}
|
2013-07-17 19:08:13 -05:00
|
|
|
|
2013-08-28 16:52:37 -05:00
|
|
|
};
|
2013-07-31 15:47:32 -05:00
|
|
|
true
|
|
|
|
};
|
2013-08-23 13:51:45 -05:00
|
|
|
|
2013-09-06 22:29:16 -05:00
|
|
|
if found.is_some() {
|
|
|
|
debug!("Found %s in %s", pkgid.to_str(), workspace.to_str());
|
2013-09-09 00:00:49 -05:00
|
|
|
} else {
|
2013-09-06 22:29:16 -05:00
|
|
|
debug!("Didn't find %s in %s", pkgid.to_str(), workspace.to_str());
|
|
|
|
}
|
2013-07-31 15:47:32 -05:00
|
|
|
found
|
2013-04-22 19:54:54 -05:00
|
|
|
}
|
|
|
|
|
2013-09-12 21:29:21 -05:00
|
|
|
/// Return the target-specific build subdirectory, pushed onto `base`;
|
|
|
|
/// doesn't check that it exists or create it
|
|
|
|
pub fn target_build_dir(workspace: &Path) -> Path {
|
|
|
|
workspace.push("build").push(host_triple())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the target-specific lib subdirectory, pushed onto `base`;
|
|
|
|
/// doesn't check that it exists or create it
|
|
|
|
fn target_lib_dir(workspace: &Path) -> Path {
|
|
|
|
workspace.push("lib").push(host_triple())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the bin subdirectory, pushed onto `base`;
|
|
|
|
/// doesn't check that it exists or create it
|
|
|
|
/// note: this isn't target-specific
|
|
|
|
fn target_bin_dir(workspace: &Path) -> Path {
|
|
|
|
workspace.push("bin")
|
|
|
|
}
|
|
|
|
|
2013-05-02 15:09:28 -05:00
|
|
|
/// Figure out what the executable name for <pkgid> in <workspace>'s build
|
|
|
|
/// directory is, and if the file exists, return it.
|
2013-05-11 21:45:13 -05:00
|
|
|
pub fn built_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
|
2013-09-12 21:29:21 -05:00
|
|
|
let mut result = target_build_dir(workspace);
|
2013-05-02 15:09:28 -05:00
|
|
|
// should use a target-specific subdirectory
|
2013-07-30 16:58:30 -05:00
|
|
|
result = mk_output_path(Main, Build, pkgid, result);
|
2013-05-02 15:09:28 -05:00
|
|
|
debug!("built_executable_in_workspace: checking whether %s exists",
|
|
|
|
result.to_str());
|
|
|
|
if os::path_exists(&result) {
|
|
|
|
Some(result)
|
|
|
|
}
|
|
|
|
else {
|
2013-08-28 16:52:37 -05:00
|
|
|
debug!("built_executable_in_workspace: %s does not exist", result.to_str());
|
2013-05-02 15:09:28 -05:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-10 21:00:51 -05:00
|
|
|
/// Figure out what the test name for <pkgid> in <workspace>'s build
|
|
|
|
/// directory is, and if the file exists, return it.
|
2013-05-14 19:46:52 -05:00
|
|
|
pub fn built_test_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
|
2013-05-10 21:00:51 -05:00
|
|
|
output_in_workspace(pkgid, workspace, Test)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Figure out what the test name for <pkgid> in <workspace>'s build
|
2013-05-02 15:09:28 -05:00
|
|
|
/// directory is, and if the file exists, return it.
|
2013-05-14 19:46:52 -05:00
|
|
|
pub fn built_bench_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
|
2013-05-10 21:00:51 -05:00
|
|
|
output_in_workspace(pkgid, workspace, Bench)
|
|
|
|
}
|
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
fn output_in_workspace(pkgid: &PkgId, workspace: &Path, what: OutputType) -> Option<Path> {
|
2013-09-12 21:29:21 -05:00
|
|
|
let mut result = target_build_dir(workspace);
|
2013-05-02 15:09:28 -05:00
|
|
|
// should use a target-specific subdirectory
|
2013-07-30 16:58:30 -05:00
|
|
|
result = mk_output_path(what, Build, pkgid, result);
|
2013-05-10 21:00:51 -05:00
|
|
|
debug!("output_in_workspace: checking whether %s exists",
|
|
|
|
result.to_str());
|
|
|
|
if os::path_exists(&result) {
|
|
|
|
Some(result)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
error!(fmt!("output_in_workspace: %s does not exist", result.to_str()));
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Figure out what the library name for <pkgid> in <workspace>'s build
|
|
|
|
/// directory is, and if the file exists, return it.
|
2013-05-14 19:46:52 -05:00
|
|
|
pub fn built_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Option<Path> {
|
2013-08-15 20:36:39 -05:00
|
|
|
library_in_workspace(&pkgid.path, pkgid.short_name, Build, workspace, "build", &pkgid.version)
|
2013-05-27 19:45:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Does the actual searching stuff
|
2013-09-12 15:56:11 -05:00
|
|
|
pub fn installed_library_in_workspace(pkg_path: &Path, workspace: &Path) -> Option<Path> {
|
2013-08-28 16:52:37 -05:00
|
|
|
// This could break once we're handling multiple versions better -- I should add a test for it
|
2013-09-12 15:56:11 -05:00
|
|
|
match pkg_path.filename() {
|
|
|
|
None => None,
|
|
|
|
Some(short_name) => library_in_workspace(pkg_path,
|
|
|
|
short_name,
|
|
|
|
Install,
|
|
|
|
workspace,
|
|
|
|
"lib",
|
|
|
|
&NoVersion)
|
|
|
|
}
|
2013-05-27 19:45:16 -05:00
|
|
|
}
|
|
|
|
|
2013-06-14 20:16:24 -05:00
|
|
|
/// `workspace` is used to figure out the directory to search.
|
2013-05-27 19:45:16 -05:00
|
|
|
/// `short_name` is taken as the link name of the library.
|
2013-08-02 18:59:58 -05:00
|
|
|
pub fn library_in_workspace(path: &Path, short_name: &str, where: Target,
|
2013-08-15 20:36:39 -05:00
|
|
|
workspace: &Path, prefix: &str, version: &Version) -> Option<Path> {
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("library_in_workspace: checking whether a library named %s exists",
|
|
|
|
short_name);
|
2013-05-02 15:09:28 -05:00
|
|
|
|
|
|
|
// We don't know what the hash is, so we have to search through the directory
|
|
|
|
// contents
|
2013-05-27 19:45:16 -05:00
|
|
|
|
2013-06-14 20:16:24 -05:00
|
|
|
debug!("short_name = %s where = %? workspace = %s \
|
|
|
|
prefix = %s", short_name, where, workspace.to_str(), prefix);
|
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
let dir_to_search = match where {
|
2013-09-12 21:29:21 -05:00
|
|
|
Build => target_build_dir(workspace).push_rel(path),
|
|
|
|
Install => target_lib_dir(workspace)
|
2013-05-27 19:45:16 -05:00
|
|
|
};
|
2013-09-12 21:29:21 -05:00
|
|
|
|
|
|
|
library_in(short_name, version, &dir_to_search)
|
|
|
|
}
|
|
|
|
|
|
|
|
// rustc doesn't use target-specific subdirectories
|
|
|
|
pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
|
|
|
|
library_in(lib_name, &NoVersion, &sysroot.push("lib"))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("Listing directory %s", dir_to_search.to_str());
|
2013-09-12 21:29:21 -05:00
|
|
|
let dir_contents = os::list_dir(dir_to_search);
|
2013-05-02 15:09:28 -05:00
|
|
|
debug!("dir has %? entries", dir_contents.len());
|
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
let lib_prefix = fmt!("%s%s", os::consts::DLL_PREFIX, short_name);
|
|
|
|
let lib_filetype = os::consts::DLL_SUFFIX;
|
2013-05-02 15:09:28 -05:00
|
|
|
|
|
|
|
debug!("lib_prefix = %s and lib_filetype = %s", lib_prefix, lib_filetype);
|
|
|
|
|
2013-07-17 19:08:13 -05:00
|
|
|
// Find a filename that matches the pattern:
|
|
|
|
// (lib_prefix)-hash-(version)(lib_suffix)
|
|
|
|
let paths = do dir_contents.iter().map |p| {
|
|
|
|
Path((*p).clone())
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut libraries = do paths.filter |p| {
|
|
|
|
let extension = p.filetype();
|
2013-05-27 19:45:16 -05:00
|
|
|
debug!("p = %s, p's extension is %?", p.to_str(), extension);
|
|
|
|
match extension {
|
2013-07-17 19:08:13 -05:00
|
|
|
None => false,
|
|
|
|
Some(ref s) => lib_filetype == *s
|
2013-05-27 19:45:16 -05:00
|
|
|
}
|
2013-07-17 19:08:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut result_filename = None;
|
|
|
|
for p_path in libraries {
|
2013-05-02 15:09:28 -05:00
|
|
|
// Find a filename that matches the pattern: (lib_prefix)-hash-(version)(lib_suffix)
|
|
|
|
// and remember what the hash was
|
2013-08-15 20:36:39 -05:00
|
|
|
let mut f_name = match p_path.filestem() {
|
2013-05-27 19:45:16 -05:00
|
|
|
Some(s) => s, None => loop
|
|
|
|
};
|
2013-08-15 20:36:39 -05:00
|
|
|
// Already checked the filetype above
|
|
|
|
|
|
|
|
// This is complicated because library names and versions can both contain dashes
|
|
|
|
loop {
|
|
|
|
if f_name.is_empty() { break; }
|
|
|
|
match f_name.rfind('-') {
|
|
|
|
Some(i) => {
|
|
|
|
debug!("Maybe %s is a version", f_name.slice(i + 1, f_name.len()));
|
|
|
|
match try_parsing_version(f_name.slice(i + 1, f_name.len())) {
|
|
|
|
Some(ref found_vers) if version == found_vers => {
|
|
|
|
match f_name.slice(0, i).rfind('-') {
|
|
|
|
Some(j) => {
|
|
|
|
debug!("Maybe %s equals %s", f_name.slice(0, j), lib_prefix);
|
|
|
|
if f_name.slice(0, j) == lib_prefix {
|
2013-09-04 06:10:22 -05:00
|
|
|
result_filename = Some(p_path.clone());
|
2013-08-15 20:36:39 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
None => break
|
|
|
|
}
|
|
|
|
}
|
2013-09-04 06:10:22 -05:00
|
|
|
_ => { f_name = f_name.slice(0, i); }
|
2013-08-15 20:36:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
None => break
|
|
|
|
} // match
|
|
|
|
} // loop
|
|
|
|
} // for
|
2013-05-02 15:09:28 -05:00
|
|
|
|
2013-07-17 19:08:13 -05:00
|
|
|
if result_filename.is_none() {
|
2013-08-28 16:52:37 -05:00
|
|
|
debug!("warning: library_in_workspace didn't find a library in %s for %s",
|
|
|
|
dir_to_search.to_str(), short_name);
|
2013-07-17 19:08:13 -05:00
|
|
|
}
|
|
|
|
|
2013-05-02 15:09:28 -05:00
|
|
|
// Return the filename that matches, which we now know exists
|
|
|
|
// (if result_filename != None)
|
2013-07-17 19:08:13 -05:00
|
|
|
let abs_path = do result_filename.map |result_filename| {
|
|
|
|
let absolute_path = dir_to_search.push_rel(result_filename);
|
|
|
|
debug!("result_filename = %s", absolute_path.to_str());
|
|
|
|
absolute_path
|
|
|
|
};
|
|
|
|
|
|
|
|
abs_path
|
2013-05-02 15:09:28 -05:00
|
|
|
}
|
|
|
|
|
2013-04-22 19:54:54 -05:00
|
|
|
/// Returns the executable that would be installed for <pkgid>
|
|
|
|
/// in <workspace>
|
2013-05-02 15:09:28 -05:00
|
|
|
/// As a side effect, creates the bin-dir if it doesn't exist
|
2013-05-11 21:45:13 -05:00
|
|
|
pub fn target_executable_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
2013-05-27 19:45:16 -05:00
|
|
|
target_file_in_workspace(pkgid, workspace, Main, Install)
|
2013-04-22 19:54:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-14 20:16:24 -05:00
|
|
|
/// Returns the executable that would be installed for <pkgid>
|
|
|
|
/// in <workspace>
|
2013-05-27 19:45:16 -05:00
|
|
|
/// As a side effect, creates the lib-dir if it doesn't exist
|
2013-06-14 20:16:24 -05:00
|
|
|
pub fn target_library_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
2013-06-01 17:59:12 -05:00
|
|
|
use conditions::bad_path::cond;
|
2013-06-14 20:16:24 -05:00
|
|
|
if !os::path_is_dir(workspace) {
|
2013-07-02 14:47:32 -05:00
|
|
|
cond.raise(((*workspace).clone(),
|
2013-06-14 20:16:24 -05:00
|
|
|
fmt!("Workspace supplied to target_library_in_workspace \
|
|
|
|
is not a directory! %s", workspace.to_str())));
|
2013-06-01 17:59:12 -05:00
|
|
|
}
|
2013-06-14 20:16:24 -05:00
|
|
|
target_file_in_workspace(pkgid, workspace, Lib, Install)
|
2013-04-22 19:54:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the test executable that would be installed for <pkgid>
|
|
|
|
/// in <workspace>
|
2013-05-10 21:00:51 -05:00
|
|
|
/// note that we *don't* install test executables, so this is just for unit testing
|
2013-05-14 19:46:52 -05:00
|
|
|
pub fn target_test_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
2013-05-27 19:45:16 -05:00
|
|
|
target_file_in_workspace(pkgid, workspace, Test, Install)
|
2013-04-22 19:54:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the bench executable that would be installed for <pkgid>
|
|
|
|
/// in <workspace>
|
2013-05-10 21:00:51 -05:00
|
|
|
/// note that we *don't* install bench executables, so this is just for unit testing
|
2013-05-14 19:46:52 -05:00
|
|
|
pub fn target_bench_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
2013-05-27 19:45:16 -05:00
|
|
|
target_file_in_workspace(pkgid, workspace, Bench, Install)
|
2013-05-02 15:09:28 -05:00
|
|
|
}
|
|
|
|
|
2013-05-27 19:45:16 -05:00
|
|
|
|
|
|
|
/// Returns the path that pkgid `pkgid` would have if placed `where`
|
|
|
|
/// in `workspace`
|
2013-05-11 21:45:13 -05:00
|
|
|
fn target_file_in_workspace(pkgid: &PkgId, workspace: &Path,
|
2013-05-27 19:45:16 -05:00
|
|
|
what: OutputType, where: Target) -> Path {
|
2013-05-02 15:09:28 -05:00
|
|
|
use conditions::bad_path::cond;
|
|
|
|
|
2013-05-14 19:46:52 -05:00
|
|
|
let subdir = match what {
|
2013-05-10 21:00:51 -05:00
|
|
|
Lib => "lib", Main | Test | Bench => "bin"
|
2013-05-02 15:09:28 -05:00
|
|
|
};
|
2013-07-24 20:42:14 -05:00
|
|
|
// Artifacts in the build directory live in a package-ID-specific subdirectory,
|
|
|
|
// but installed ones don't.
|
2013-09-12 21:29:21 -05:00
|
|
|
let result = match (where, what) {
|
|
|
|
(Build, _) => target_build_dir(workspace).push_rel(&pkgid.path),
|
|
|
|
(Install, Lib) => target_lib_dir(workspace),
|
|
|
|
(Install, _) => target_bin_dir(workspace)
|
2013-07-24 20:42:14 -05:00
|
|
|
};
|
2013-06-30 22:51:13 -05:00
|
|
|
if !os::path_exists(&result) && !mkdir_recursive(&result, U_RWX) {
|
2013-07-02 14:47:32 -05:00
|
|
|
cond.raise((result.clone(), fmt!("target_file_in_workspace couldn't \
|
2013-06-14 20:16:24 -05:00
|
|
|
create the %s dir (pkgid=%s, workspace=%s, what=%?, where=%?",
|
|
|
|
subdir, pkgid.to_str(), workspace.to_str(), what, where)));
|
2013-05-02 15:09:28 -05:00
|
|
|
}
|
2013-07-30 16:58:30 -05:00
|
|
|
mk_output_path(what, where, pkgid, result)
|
2013-04-22 19:54:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the directory for <pkgid>'s build artifacts in <workspace>.
|
|
|
|
/// Creates it if it doesn't exist.
|
2013-05-11 21:45:13 -05:00
|
|
|
pub fn build_pkg_id_in_workspace(pkgid: &PkgId, workspace: &Path) -> Path {
|
2013-04-22 19:54:54 -05:00
|
|
|
use conditions::bad_path::cond;
|
|
|
|
|
2013-09-12 21:29:21 -05:00
|
|
|
let mut result = target_build_dir(workspace);
|
2013-08-02 18:59:58 -05:00
|
|
|
result = result.push_rel(&pkgid.path);
|
2013-09-12 21:29:21 -05:00
|
|
|
debug!("Creating build dir %s for package id %s", result.to_str(),
|
|
|
|
pkgid.to_str());
|
2013-06-30 22:51:13 -05:00
|
|
|
if os::path_exists(&result) || os::mkdir_recursive(&result, U_RWX) {
|
2013-04-22 19:54:54 -05:00
|
|
|
result
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cond.raise((result, fmt!("Could not create directory for package %s", pkgid.to_str())))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the output file for a given directory name,
|
|
|
|
/// given whether we're building a library and whether we're building tests
|
2013-05-27 19:45:16 -05:00
|
|
|
pub fn mk_output_path(what: OutputType, where: Target,
|
2013-07-30 16:58:30 -05:00
|
|
|
pkg_id: &PkgId, workspace: Path) -> Path {
|
2013-06-14 20:16:24 -05:00
|
|
|
let short_name_with_version = fmt!("%s-%s", pkg_id.short_name,
|
|
|
|
pkg_id.version.to_str());
|
2013-05-10 21:00:51 -05:00
|
|
|
// Not local_path.dir_path()! For package foo/bar/blat/, we want
|
|
|
|
// the executable blat-0.5 to live under blat/
|
2013-05-27 19:45:16 -05:00
|
|
|
let dir = match where {
|
|
|
|
// If we're installing, it just goes under <workspace>...
|
2013-07-30 16:58:30 -05:00
|
|
|
Install => workspace,
|
2013-05-27 19:45:16 -05:00
|
|
|
// and if we're just building, it goes in a package-specific subdir
|
2013-08-02 18:59:58 -05:00
|
|
|
Build => workspace.push_rel(&pkg_id.path)
|
2013-05-27 19:45:16 -05:00
|
|
|
};
|
|
|
|
debug!("[%?:%?] mk_output_path: short_name = %s, path = %s", what, where,
|
2013-07-02 14:47:32 -05:00
|
|
|
if what == Lib { short_name_with_version.clone() } else { pkg_id.short_name.clone() },
|
2013-05-14 19:46:52 -05:00
|
|
|
dir.to_str());
|
2013-05-27 19:45:16 -05:00
|
|
|
let mut output_path = match what {
|
2013-05-10 21:00:51 -05:00
|
|
|
// this code is duplicated from elsewhere; fix this
|
2013-05-14 19:46:52 -05:00
|
|
|
Lib => dir.push(os::dll_filename(short_name_with_version)),
|
|
|
|
// executable names *aren't* versioned
|
2013-06-14 20:16:24 -05:00
|
|
|
_ => dir.push(fmt!("%s%s%s", pkg_id.short_name,
|
2013-05-02 15:09:28 -05:00
|
|
|
match what {
|
|
|
|
Test => "test",
|
|
|
|
Bench => "bench",
|
|
|
|
_ => ""
|
2013-07-23 22:41:33 -05:00
|
|
|
},
|
2013-04-22 19:54:54 -05:00
|
|
|
os::EXE_SUFFIX))
|
2013-05-10 21:00:51 -05:00
|
|
|
};
|
2013-05-27 19:45:16 -05:00
|
|
|
if !output_path.is_absolute() {
|
|
|
|
output_path = os::getcwd().push_rel(&output_path).normalize();
|
|
|
|
}
|
2013-05-10 21:00:51 -05:00
|
|
|
debug!("mk_output_path: returning %s", output_path.to_str());
|
|
|
|
output_path
|
2013-04-22 19:54:54 -05:00
|
|
|
}
|
2013-07-11 20:20:31 -05:00
|
|
|
|
|
|
|
/// Removes files for the package `pkgid`, assuming it's installed in workspace `workspace`
|
|
|
|
pub fn uninstall_package_from(workspace: &Path, pkgid: &PkgId) {
|
|
|
|
let mut did_something = false;
|
|
|
|
let installed_bin = target_executable_in_workspace(pkgid, workspace);
|
|
|
|
if os::path_exists(&installed_bin) {
|
|
|
|
os::remove_file(&installed_bin);
|
|
|
|
did_something = true;
|
|
|
|
}
|
|
|
|
let installed_lib = target_library_in_workspace(pkgid, workspace);
|
|
|
|
if os::path_exists(&installed_lib) {
|
|
|
|
os::remove_file(&installed_lib);
|
|
|
|
did_something = true;
|
|
|
|
}
|
|
|
|
if !did_something {
|
|
|
|
warn(fmt!("Warning: there don't seem to be any files for %s installed in %s",
|
|
|
|
pkgid.to_str(), workspace.to_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-08-28 16:52:37 -05:00
|
|
|
|
|
|
|
fn dir_has_file(dir: &Path, file: &str) -> bool {
|
|
|
|
assert!(dir.is_absolute());
|
|
|
|
os::path_exists(&dir.push(file))
|
|
|
|
}
|
|
|
|
|
2013-09-06 22:29:16 -05:00
|
|
|
pub fn find_dir_using_rust_path_hack(p: &PkgId) -> Option<Path> {
|
2013-08-28 16:52:37 -05:00
|
|
|
let rp = rust_path();
|
|
|
|
for dir in rp.iter() {
|
|
|
|
debug!("In find_dir_using_rust_path_hack: checking dir %s", dir.to_str());
|
|
|
|
if dir_has_file(dir, "lib.rs") || dir_has_file(dir, "main.rs")
|
|
|
|
|| dir_has_file(dir, "test.rs") || dir_has_file(dir, "bench.rs") {
|
|
|
|
debug!("Did find id %s in dir %s", p.to_str(), dir.to_str());
|
|
|
|
return Some(dir.clone());
|
|
|
|
}
|
|
|
|
debug!("Didn't find id %s in dir %s", p.to_str(), dir.to_str())
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
2013-09-12 18:13:30 -05:00
|
|
|
|
|
|
|
/// True if the user set RUST_PATH to something non-empty --
|
|
|
|
/// as opposed to the default paths that rustpkg adds automatically
|
|
|
|
pub fn user_set_rust_path() -> bool {
|
|
|
|
match os::getenv("RUST_PATH") {
|
|
|
|
None | Some(~"") => false,
|
|
|
|
Some(_) => true
|
|
|
|
}
|
|
|
|
}
|