rustc: Add knowledge of separate lookup paths

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
This commit is contained in:
Alex Crichton
2014-12-16 14:32:02 -08:00
parent 62fb41c32b
commit d085d9d315
20 changed files with 251 additions and 60 deletions

View File

@@ -43,6 +43,7 @@ use std::rc::Rc;
use externalfiles::ExternalHtml;
use serialize::{Decodable, Encodable};
use serialize::json::{mod, Json};
use rustc::session::search_paths::SearchPaths;
// reexported from `clean` so it can be easily updated with the mod itself
pub use clean::SCHEMA_VERSION;
@@ -200,7 +201,10 @@ pub fn main_args(args: &[String]) -> int {
}
let input = matches.free[0].as_slice();
let libs = matches.opt_strs("L").iter().map(|s| Path::new(s.as_slice())).collect();
let mut libs = SearchPaths::new();
for s in matches.opt_strs("L").iter() {
libs.add_path(s.as_slice());
}
let externs = match parse_externs(&matches) {
Ok(ex) => ex,
Err(err) => {
@@ -334,10 +338,10 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
let mut plugins = matches.opt_strs("plugins");
// First, parse the crate and extract all relevant information.
let libs: Vec<Path> = matches.opt_strs("L")
.iter()
.map(|s| Path::new(s.as_slice()))
.collect();
let mut paths = SearchPaths::new();
for s in matches.opt_strs("L").iter() {
paths.add_path(s.as_slice());
}
let cfgs = matches.opt_strs("cfg");
let triple = matches.opt_str("target");
@@ -346,7 +350,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
let (mut krate, analysis) = std::thread::Thread::spawn(move |:| {
let cr = cr;
core::run_core(libs, cfgs, externs, &cr, triple)
core::run_core(paths, cfgs, externs, &cr, triple)
}).join().map_err(|_| "rustc failed").unwrap();
info!("finished with rustc");
let mut analysis = Some(analysis);