Auto merge of #30034 - brson:rust_path, r=alexcrichton
This was to support rustpkg but is unused now.
This commit is contained in:
commit
edf2198f5f
2 changed files with 4 additions and 98 deletions
|
@ -40,16 +40,12 @@ pub struct FileSearch<'a> {
|
||||||
|
|
||||||
impl<'a> FileSearch<'a> {
|
impl<'a> FileSearch<'a> {
|
||||||
pub fn for_each_lib_search_path<F>(&self, mut f: F) where
|
pub fn for_each_lib_search_path<F>(&self, mut f: F) where
|
||||||
F: FnMut(&Path, PathKind) -> FileMatch,
|
F: FnMut(&Path, PathKind)
|
||||||
{
|
{
|
||||||
let mut visited_dirs = HashSet::new();
|
let mut visited_dirs = HashSet::new();
|
||||||
let mut found = false;
|
|
||||||
|
|
||||||
for (path, kind) in self.search_paths.iter(self.kind) {
|
for (path, kind) in self.search_paths.iter(self.kind) {
|
||||||
match f(path, kind) {
|
f(path, kind);
|
||||||
FileMatches => found = true,
|
|
||||||
FileDoesntMatch => ()
|
|
||||||
}
|
|
||||||
visited_dirs.insert(path.to_path_buf());
|
visited_dirs.insert(path.to_path_buf());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,35 +53,10 @@ impl<'a> FileSearch<'a> {
|
||||||
let tlib_path = make_target_lib_path(self.sysroot,
|
let tlib_path = make_target_lib_path(self.sysroot,
|
||||||
self.triple);
|
self.triple);
|
||||||
if !visited_dirs.contains(&tlib_path) {
|
if !visited_dirs.contains(&tlib_path) {
|
||||||
match f(&tlib_path, PathKind::All) {
|
f(&tlib_path, PathKind::All);
|
||||||
FileMatches => found = true,
|
|
||||||
FileDoesntMatch => ()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visited_dirs.insert(tlib_path);
|
visited_dirs.insert(tlib_path);
|
||||||
// Try RUST_PATH
|
|
||||||
if !found {
|
|
||||||
let rustpath = rust_path();
|
|
||||||
for path in &rustpath {
|
|
||||||
let tlib_path = make_rustpkg_lib_path(
|
|
||||||
self.sysroot, path, self.triple);
|
|
||||||
debug!("is {} in visited_dirs? {}", tlib_path.display(),
|
|
||||||
visited_dirs.contains(&tlib_path));
|
|
||||||
|
|
||||||
if !visited_dirs.contains(&tlib_path) {
|
|
||||||
visited_dirs.insert(tlib_path.clone());
|
|
||||||
// Don't keep searching the RUST_PATH if one match turns up --
|
|
||||||
// if we did, we'd get a "multiple matching crates" error
|
|
||||||
match f(&tlib_path, PathKind::All) {
|
|
||||||
FileMatches => {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
FileDoesntMatch => ()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_lib_path(&self) -> PathBuf {
|
pub fn get_lib_path(&self) -> PathBuf {
|
||||||
|
@ -101,7 +72,6 @@ impl<'a> FileSearch<'a> {
|
||||||
Ok(files) => {
|
Ok(files) => {
|
||||||
let files = files.filter_map(|p| p.ok().map(|s| s.path()))
|
let files = files.filter_map(|p| p.ok().map(|s| s.path()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let mut rslt = FileDoesntMatch;
|
|
||||||
fn is_rlib(p: &Path) -> bool {
|
fn is_rlib(p: &Path) -> bool {
|
||||||
p.extension().and_then(|s| s.to_str()) == Some("rlib")
|
p.extension().and_then(|s| s.to_str()) == Some("rlib")
|
||||||
}
|
}
|
||||||
|
@ -117,16 +87,14 @@ impl<'a> FileSearch<'a> {
|
||||||
match maybe_picked {
|
match maybe_picked {
|
||||||
FileMatches => {
|
FileMatches => {
|
||||||
debug!("picked {}", path.display());
|
debug!("picked {}", path.display());
|
||||||
rslt = FileMatches;
|
|
||||||
}
|
}
|
||||||
FileDoesntMatch => {
|
FileDoesntMatch => {
|
||||||
debug!("rejected {}", path.display());
|
debug!("rejected {}", path.display());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rslt
|
|
||||||
}
|
}
|
||||||
Err(..) => FileDoesntMatch,
|
Err(..) => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -149,7 +117,6 @@ impl<'a> FileSearch<'a> {
|
||||||
let mut paths = Vec::new();
|
let mut paths = Vec::new();
|
||||||
self.for_each_lib_search_path(|lib_search_path, _| {
|
self.for_each_lib_search_path(|lib_search_path, _| {
|
||||||
paths.push(lib_search_path.to_path_buf());
|
paths.push(lib_search_path.to_path_buf());
|
||||||
FileDoesntMatch
|
|
||||||
});
|
});
|
||||||
paths
|
paths
|
||||||
}
|
}
|
||||||
|
@ -179,14 +146,6 @@ fn make_target_lib_path(sysroot: &Path,
|
||||||
sysroot.join(&relative_target_lib_path(sysroot, target_triple))
|
sysroot.join(&relative_target_lib_path(sysroot, target_triple))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_rustpkg_lib_path(sysroot: &Path,
|
|
||||||
dir: &Path,
|
|
||||||
triple: &str) -> PathBuf {
|
|
||||||
let mut p = dir.join(&find_libdir(sysroot));
|
|
||||||
p.push(triple);
|
|
||||||
p
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_or_default_sysroot() -> PathBuf {
|
pub fn get_or_default_sysroot() -> PathBuf {
|
||||||
// Follow symlinks. If the resolved path is relative, make it absolute.
|
// Follow symlinks. If the resolved path is relative, make it absolute.
|
||||||
fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
|
fn canonicalize(path: Option<PathBuf>) -> Option<PathBuf> {
|
||||||
|
@ -207,56 +166,6 @@ pub fn get_or_default_sysroot() -> PathBuf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
const PATH_ENTRY_SEPARATOR: char = ';';
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
const PATH_ENTRY_SEPARATOR: char = ':';
|
|
||||||
|
|
||||||
/// Returns RUST_PATH as a string, without default paths added
|
|
||||||
pub fn get_rust_path() -> Option<String> {
|
|
||||||
env::var("RUST_PATH").ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the value of RUST_PATH, as a list
|
|
||||||
/// of Paths. Includes default entries for, if they exist:
|
|
||||||
/// $HOME/.rust
|
|
||||||
/// DIR/.rust for any DIR that's the current working directory
|
|
||||||
/// or an ancestor of it
|
|
||||||
pub fn rust_path() -> Vec<PathBuf> {
|
|
||||||
let mut env_rust_path: Vec<PathBuf> = match get_rust_path() {
|
|
||||||
Some(env_path) => {
|
|
||||||
let env_path_components =
|
|
||||||
env_path.split(PATH_ENTRY_SEPARATOR);
|
|
||||||
env_path_components.map(|s| PathBuf::from(s)).collect()
|
|
||||||
}
|
|
||||||
None => Vec::new()
|
|
||||||
};
|
|
||||||
let cwd = env::current_dir().unwrap();
|
|
||||||
// now add in default entries
|
|
||||||
let cwd_dot_rust = cwd.join(".rust");
|
|
||||||
if !env_rust_path.contains(&cwd_dot_rust) {
|
|
||||||
env_rust_path.push(cwd_dot_rust);
|
|
||||||
}
|
|
||||||
if !env_rust_path.contains(&cwd) {
|
|
||||||
env_rust_path.push(cwd.clone());
|
|
||||||
}
|
|
||||||
let mut cur = &*cwd;
|
|
||||||
while let Some(parent) = cur.parent() {
|
|
||||||
let candidate = parent.join(".rust");
|
|
||||||
if !env_rust_path.contains(&candidate) && candidate.exists() {
|
|
||||||
env_rust_path.push(candidate.clone());
|
|
||||||
}
|
|
||||||
cur = parent;
|
|
||||||
}
|
|
||||||
if let Some(h) = env::home_dir() {
|
|
||||||
let p = h.join(".rust");
|
|
||||||
if !env_rust_path.contains(&p) && p.exists() {
|
|
||||||
env_rust_path.push(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
env_rust_path
|
|
||||||
}
|
|
||||||
|
|
||||||
// The name of the directory rustc expects libraries to be located.
|
// The name of the directory rustc expects libraries to be located.
|
||||||
fn find_libdir(sysroot: &Path) -> String {
|
fn find_libdir(sysroot: &Path) -> String {
|
||||||
// FIXME: This is a quick hack to make the rustc binary able to locate
|
// FIXME: This is a quick hack to make the rustc binary able to locate
|
||||||
|
|
|
@ -20,7 +20,6 @@ use session::config::{OutputFilenames, Input, OutputType};
|
||||||
use session::search_paths::PathKind;
|
use session::search_paths::PathKind;
|
||||||
use session::Session;
|
use session::Session;
|
||||||
use metadata::common::LinkMeta;
|
use metadata::common::LinkMeta;
|
||||||
use metadata::filesearch::FileDoesntMatch;
|
|
||||||
use metadata::loader::METADATA_FILENAME;
|
use metadata::loader::METADATA_FILENAME;
|
||||||
use metadata::{encoder, cstore, filesearch, csearch, creader};
|
use metadata::{encoder, cstore, filesearch, csearch, creader};
|
||||||
use middle::dependency_format::Linkage;
|
use middle::dependency_format::Linkage;
|
||||||
|
@ -588,7 +587,6 @@ fn archive_search_paths(sess: &Session) -> Vec<PathBuf> {
|
||||||
let mut search = Vec::new();
|
let mut search = Vec::new();
|
||||||
sess.target_filesearch(PathKind::Native).for_each_lib_search_path(|path, _| {
|
sess.target_filesearch(PathKind::Native).for_each_lib_search_path(|path, _| {
|
||||||
search.push(path.to_path_buf());
|
search.push(path.to_path_buf());
|
||||||
FileDoesntMatch
|
|
||||||
});
|
});
|
||||||
return search;
|
return search;
|
||||||
}
|
}
|
||||||
|
@ -1085,7 +1083,6 @@ fn add_local_native_libraries(cmd: &mut Linker, sess: &Session) {
|
||||||
PathKind::Framework => { cmd.framework_path(path); }
|
PathKind::Framework => { cmd.framework_path(path); }
|
||||||
_ => { cmd.include_path(&fix_windows_verbatim_for_gcc(path)); }
|
_ => { cmd.include_path(&fix_windows_verbatim_for_gcc(path)); }
|
||||||
}
|
}
|
||||||
FileDoesntMatch
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let libs = sess.cstore.get_used_libraries();
|
let libs = sess.cstore.get_used_libraries();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue