-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto merge of #19941 : alexcrichton/rust/issue-19767, r=brson
This commit adds support for the compiler to distinguish between different forms of lookup paths in the compiler itself. Issue #19767 has some background on this topic, as well as some sample bugs which can occur if these lookup paths are not separated. This commits extends the existing command line flag `-L` with the same trailing syntax as the `-l` flag. Each argument to `-L` can now have a trailing `:all`, `:native`, `:crate`, or `:dependency`. This suffix indicates what form of lookup path the compiler should add the argument to. The `dependency` lookup path is used when looking up crate dependencies, the `crate` lookup path is used when looking for immediate dependencies (`extern crate` statements), and the `native` lookup path is used for probing for native libraries to insert into rlibs. Paths with `all` are used for all of these purposes (the default). The default compiler lookup path (the rustlib libdir) is by default added to all of these paths. Additionally, the `RUST_PATH` lookup path is added to all of these paths. Closes #19767
- Loading branch information
Showing
20 changed files
with
251 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2014 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. | ||
|
||
use std::slice; | ||
|
||
#[deriving(Clone)] | ||
pub struct SearchPaths { | ||
paths: Vec<(PathKind, Path)>, | ||
} | ||
|
||
pub struct Iter<'a> { | ||
kind: PathKind, | ||
iter: slice::Iter<'a, (PathKind, Path)>, | ||
} | ||
|
||
#[deriving(Eq, PartialEq, Clone, Copy)] | ||
pub enum PathKind { | ||
Native, | ||
Crate, | ||
Dependency, | ||
All, | ||
} | ||
|
||
impl SearchPaths { | ||
pub fn new() -> SearchPaths { | ||
SearchPaths { paths: Vec::new() } | ||
} | ||
|
||
pub fn add_path(&mut self, path: &str) { | ||
let (kind, path) = if path.ends_with(":native") { | ||
(PathKind::Native, path.slice_to(path.len() - ":native".len())) | ||
} else if path.ends_with(":crate") { | ||
(PathKind::Crate, path.slice_to(path.len() - ":crate".len())) | ||
} else if path.ends_with(":dependency") { | ||
(PathKind::Dependency, | ||
path.slice_to(path.len() - ":dependency".len())) | ||
} else if path.ends_with(":all") { | ||
(PathKind::All, path.slice_to(path.len() - ":all".len())) | ||
} else { | ||
(PathKind::All, path) | ||
}; | ||
self.paths.push((kind, Path::new(path))); | ||
} | ||
|
||
pub fn iter(&self, kind: PathKind) -> Iter { | ||
Iter { kind: kind, iter: self.paths.iter() } | ||
} | ||
} | ||
|
||
impl<'a> Iterator<&'a Path> for Iter<'a> { | ||
fn next(&mut self) -> Option<&'a Path> { | ||
loop { | ||
match self.iter.next() { | ||
Some(&(kind, ref p)) if self.kind == PathKind::All || | ||
kind == PathKind::All || | ||
kind == self.kind => return Some(p), | ||
Some(..) => {} | ||
None => return None, | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.