diff options
| author | bors <bors@rust-lang.org> | 2014-05-18 14:41:35 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-18 14:41:35 -0700 |
| commit | e1403e1d8337cc1636471f79da4536409e2a0c2b (patch) | |
| tree | a043c3677af6799fa8e4006530940eeb3b18e29c /src/libstd | |
| parent | ea87f126bdf8de4acc4f74c14ac0ae10d95a2472 (diff) | |
| parent | 8cbda5da939e97d5dafde4a2a20927fb539bf80c (diff) | |
| download | rust-e1403e1d8337cc1636471f79da4536409e2a0c2b.tar.gz rust-e1403e1d8337cc1636471f79da4536409e2a0c2b.zip | |
auto merge of #14000 : pnkfelix/rust/fsk-fix-issue13732, r=alexcrichton
Fix #13732. This is a revised, much less hacky form of PR #13753 The changes here: * add instrumentation to aid debugging of linkage errors, * fine tune some things in the Makefile where we are telling binaries to use a host-oriented path for finding dynamic libraries, when it should be feeding the binaries a target-oriented path for dynamic libraries. * pass along the current stage number to run-make tests, and * skip certain tests when running atop stage1. Fix #13746 as well.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/unstable/dynamic_lib.rs | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/src/libstd/unstable/dynamic_lib.rs b/src/libstd/unstable/dynamic_lib.rs index 4a9c5349459..d50c63c5832 100644 --- a/src/libstd/unstable/dynamic_lib.rs +++ b/src/libstd/unstable/dynamic_lib.rs @@ -16,16 +16,16 @@ A simple wrapper over the platform's dynamic library facilities */ - +use clone::Clone; use c_str::ToCStr; +use iter::Iterator; use mem; use ops::*; use option::*; use os; -use path::GenericPath; -use path; +use path::{Path,GenericPath}; use result::*; -use slice::Vector; +use slice::{Vector,ImmutableVector}; use str; use vec::Vec; @@ -76,22 +76,55 @@ impl DynamicLibrary { } } - /// Appends a path to the system search path for dynamic libraries - pub fn add_search_path(path: &path::Path) { - let (envvar, sep) = if cfg!(windows) { - ("PATH", ';' as u8) + /// Prepends a path to this process's search path for dynamic libraries + pub fn prepend_search_path(path: &Path) { + let mut search_path = DynamicLibrary::search_path(); + search_path.insert(0, path.clone()); + let newval = DynamicLibrary::create_path(search_path.as_slice()); + os::setenv(DynamicLibrary::envvar(), + str::from_utf8(newval.as_slice()).unwrap()); + } + + /// From a slice of paths, create a new vector which is suitable to be an + /// environment variable for this platforms dylib search path. + pub fn create_path(path: &[Path]) -> Vec<u8> { + let mut newvar = Vec::new(); + for (i, path) in path.iter().enumerate() { + if i > 0 { newvar.push(DynamicLibrary::separator()); } + newvar.push_all(path.as_vec()); + } + return newvar; + } + + /// Returns the environment variable for this process's dynamic library + /// search path + pub fn envvar() -> &'static str { + if cfg!(windows) { + "PATH" } else if cfg!(target_os = "macos") { - ("DYLD_LIBRARY_PATH", ':' as u8) + "DYLD_LIBRARY_PATH" } else { - ("LD_LIBRARY_PATH", ':' as u8) - }; - let mut newenv = Vec::from_slice(path.as_vec()); - newenv.push(sep); - match os::getenv_as_bytes(envvar) { - Some(bytes) => newenv.push_all(bytes), + "LD_LIBRARY_PATH" + } + } + + fn separator() -> u8 { + if cfg!(windows) {';' as u8} else {':' as u8} + } + + /// Returns the current search path for dynamic libraries being used by this + /// process + pub fn search_path() -> Vec<Path> { + let mut ret = Vec::new(); + match os::getenv_as_bytes(DynamicLibrary::envvar()) { + Some(env) => { + for portion in env.split(|a| *a == DynamicLibrary::separator()) { + ret.push(Path::new(portion)); + } + } None => {} } - os::setenv(envvar, str::from_utf8(newenv.as_slice()).unwrap()); + return ret; } /// Access the value at the symbol of the dynamic library @@ -168,11 +201,12 @@ mod test { #[cfg(target_os = "macos")] #[cfg(target_os = "freebsd")] pub mod dl { + use prelude::*; + use c_str::ToCStr; use libc; use ptr; use str; - use result::*; pub unsafe fn open_external<T: ToCStr>(filename: T) -> *u8 { filename.with_c_str(|raw_name| { |
