De-@ filesearch.

This commit is contained in:
Eduard Burtescu 2014-03-09 14:24:58 +02:00
parent eeb37b76af
commit f77c744142
11 changed files with 53 additions and 54 deletions

View File

@ -206,7 +206,7 @@ impl<'a> Archive<'a> {
let unixlibname = format!("lib{}.a", name);
let mut rustpath = filesearch::rust_path();
rustpath.push(self.sess.filesearch.get_target_lib_path());
rustpath.push(self.sess.filesearch().get_target_lib_path());
let addl_lib_search_paths = self.sess
.opts
.addl_lib_search_paths

View File

@ -1075,7 +1075,7 @@ fn link_args(sess: &Session,
// The default library location, we need this to find the runtime.
// The location of crates will be determined as needed.
// FIXME (#9639): This needs to handle non-utf8 paths
let lib_path = sess.filesearch.get_target_lib_path();
let lib_path = sess.filesearch().get_target_lib_path();
let stage: ~str = ~"-L" + lib_path.as_str().unwrap();
let mut args = vec!(stage);

View File

@ -40,7 +40,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
debug!("preparing the RPATH!");
let sysroot = sess.filesearch.sysroot;
let sysroot = sess.filesearch().sysroot;
let output = out_filename;
let libs = sess.cstore.get_used_crates(cstore::RequireDynamic);
let libs = libs.move_iter().filter_map(|(_, l)| l.map(|p| p.clone())).collect();
@ -56,7 +56,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
fn get_sysroot_absolute_rt_lib(sess: &Session) -> Path {
let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
let mut p = sess.filesearch.sysroot.join(&r);
let mut p = sess.filesearch().sysroot.join(&r);
p.push(os::dll_filename("rustrt"));
p
}

View File

@ -871,7 +871,7 @@ pub fn build_session_options(matches: &getopts::Matches)
output_types.push(link::OutputTypeExe);
}
let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path::new(m));
let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
let target = matches.opt_str("target").unwrap_or(host_triple());
let opt_level = {
if (debugging_opts & session::NO_OPT) != 0 {
@ -932,14 +932,14 @@ pub fn build_session_options(matches: &getopts::Matches)
matches.opt_present("crate-file-name"));
let cg = build_codegen_options(matches);
let sopts = @session::Options {
@session::Options {
crate_types: crate_types,
gc: gc,
optimize: opt_level,
debuginfo: debuginfo,
lint_opts: lint_opts,
output_types: output_types,
addl_lib_search_paths: @RefCell::new(addl_lib_search_paths),
addl_lib_search_paths: RefCell::new(addl_lib_search_paths),
maybe_sysroot: sysroot_opt,
target_triple: target,
cfg: cfg,
@ -951,8 +951,7 @@ pub fn build_session_options(matches: &getopts::Matches)
write_dependency_info: write_dependency_info,
print_metas: print_metas,
cg: cg,
};
return sopts;
}
}
pub fn build_codegen_options(matches: &getopts::Matches)
@ -1006,10 +1005,10 @@ pub fn build_session_(sopts: @session::Options,
let target_cfg = build_target_config(sopts);
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler, codemap);
let cstore = @CStore::new(token::get_ident_interner());
let filesearch = @filesearch::FileSearch::new(
&sopts.maybe_sysroot,
sopts.target_triple,
sopts.addl_lib_search_paths);
let default_sysroot = match sopts.maybe_sysroot {
Some(_) => None,
None => Some(filesearch::get_or_default_sysroot())
};
// Make the path absolute, if necessary
let local_crate_source_file = local_crate_source_file.map(|path|
@ -1031,7 +1030,7 @@ pub fn build_session_(sopts: @session::Options,
entry_type: Cell::new(None),
macro_registrar_fn: RefCell::new(None),
span_diagnostic: span_diagnostic_handler,
filesearch: filesearch,
default_sysroot: default_sysroot,
building_library: Cell::new(false),
local_crate_source_file: local_crate_source_file,
working_dir: os::getcwd(),

View File

@ -134,8 +134,8 @@ pub struct Options {
// This was mutable for rustpkg, which updates search paths based on the
// parsed code. It remains mutable in case its replacements wants to use
// this.
addl_lib_search_paths: @RefCell<HashSet<Path>>,
maybe_sysroot: Option<@Path>,
addl_lib_search_paths: RefCell<HashSet<Path>>,
maybe_sysroot: Option<Path>,
target_triple: ~str,
// User-specified cfg meta items. The compiler itself will add additional
// items to the crate config, and during parsing the entire crate config
@ -184,7 +184,7 @@ pub struct Session {
entry_type: Cell<Option<EntryFnType>>,
span_diagnostic: @diagnostic::SpanHandler,
macro_registrar_fn: RefCell<Option<ast::DefId>>,
filesearch: @filesearch::FileSearch,
default_sysroot: Option<Path>,
building_library: Cell<bool>,
// The name of the root source file of the crate, in the local file system. The path is always
// expected to be absolute. `None` means that there is no source file.
@ -314,6 +314,17 @@ impl Session {
pub fn show_span(&self) -> bool {
self.debugging_opt(SHOW_SPAN)
}
pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
let sysroot = match self.opts.maybe_sysroot {
Some(ref sysroot) => sysroot,
None => self.default_sysroot.as_ref()
.expect("missing sysroot and default_sysroot in Session")
};
filesearch::FileSearch::new(
sysroot,
self.opts.target_triple,
&self.opts.addl_lib_search_paths)
}
}
/// Some reasonable defaults
@ -325,7 +336,7 @@ pub fn basic_options() -> @Options {
debuginfo: NoDebugInfo,
lint_opts: Vec::new(),
output_types: Vec::new(),
addl_lib_search_paths: @RefCell::new(HashSet::new()),
addl_lib_search_paths: RefCell::new(HashSet::new()),
maybe_sysroot: None,
target_triple: host_triple(),
cfg: Vec::new(),

View File

@ -11,7 +11,6 @@
#[allow(non_camel_case_types)];
use std::cell::RefCell;
use std::option;
use std::os;
use std::io::fs;
use std::vec_ng::Vec;
@ -27,13 +26,13 @@ pub enum FileMatch { FileMatches, FileDoesntMatch }
/// a file found in that directory.
pub type pick<'a> = 'a |path: &Path| -> FileMatch;
pub struct FileSearch {
sysroot: @Path,
addl_lib_search_paths: @RefCell<HashSet<Path>>,
target_triple: ~str
pub struct FileSearch<'a> {
sysroot: &'a Path,
addl_lib_search_paths: &'a RefCell<HashSet<Path>>,
target_triple: &'a str
}
impl FileSearch {
impl<'a> FileSearch<'a> {
pub fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) {
let mut visited_dirs = HashSet::new();
let mut found = false;
@ -127,15 +126,14 @@ impl FileSearch {
});
}
pub fn new(maybe_sysroot: &Option<@Path>,
target_triple: &str,
addl_lib_search_paths: @RefCell<HashSet<Path>>) -> FileSearch {
let sysroot = get_sysroot(maybe_sysroot);
pub fn new(sysroot: &'a Path,
target_triple: &'a str,
addl_lib_search_paths: &'a RefCell<HashSet<Path>>) -> FileSearch<'a> {
debug!("using sysroot = {}", sysroot.display());
FileSearch{
FileSearch {
sysroot: sysroot,
addl_lib_search_paths: addl_lib_search_paths,
target_triple: target_triple.to_owned()
target_triple: target_triple
}
}
}
@ -179,15 +177,8 @@ pub fn get_or_default_sysroot() -> Path {
}
match canonicalize(os::self_exe_name()) {
option::Some(p) => { let mut p = p; p.pop(); p.pop(); p }
option::None => fail!("can't determine value for sysroot")
}
}
fn get_sysroot(maybe_sysroot: &Option<@Path>) -> @Path {
match *maybe_sysroot {
option::Some(sr) => sr,
option::None => @get_or_default_sysroot()
Some(mut p) => { p.pop(); p.pop(); p }
None => fail!("can't determine value for sysroot")
}
}

View File

@ -110,7 +110,7 @@ impl<'a> Context<'a> {
}
fn find_library_crate(&mut self) -> Option<Library> {
let filesearch = self.sess.filesearch;
let filesearch = self.sess.filesearch();
let (dyprefix, dysuffix) = self.dylibname();
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"

View File

@ -64,8 +64,8 @@ fn get_ast_and_resolve(cpath: &Path,
let input = FileInput(cpath.clone());
let sessopts = @driver::session::Options {
maybe_sysroot: Some(@os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: @RefCell::new(libs),
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: RefCell::new(libs),
crate_types: vec!(driver::session::CrateTypeDylib),
.. (*rustc::driver::session::basic_options()).clone()
};

View File

@ -155,8 +155,7 @@ pub fn main_args(args: &[~str]) -> int {
}
let input = matches.free[0].as_slice();
let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice()));
let libs = @RefCell::new(libs.move_iter().collect());
let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice())).move_iter().collect();
let test_args = matches.opt_strs("test-args");
let test_args = test_args.iter().flat_map(|s| s.words()).map(|s| s.to_owned()).to_owned_vec();

View File

@ -160,7 +160,7 @@ pub fn render(input: &str, mut output: Path, matches: &getopts::Matches) -> int
}
/// Run any tests/code examples in the markdown file `input`.
pub fn test(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -> int {
pub fn test(input: &str, libs: HashSet<Path>, mut test_args: ~[~str]) -> int {
let input_str = load_or_return!(input, 1, 2);
let mut collector = Collector::new(input.to_owned(), libs, true, true);

View File

@ -34,13 +34,13 @@ use html::markdown;
use passes;
use visit_ast::RustdocVisitor;
pub fn run(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -> int {
pub fn run(input: &str, libs: HashSet<Path>, mut test_args: ~[~str]) -> int {
let input_path = Path::new(input);
let input = driver::FileInput(input_path.clone());
let sessopts = @session::Options {
maybe_sysroot: Some(@os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: libs,
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: RefCell::new(libs.clone()),
crate_types: vec!(session::CrateTypeDylib),
.. (*session::basic_options()).clone()
};
@ -92,8 +92,8 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
let input = driver::StrInput(test);
let sessopts = @session::Options {
maybe_sysroot: Some(@os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: @RefCell::new(libs),
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: RefCell::new(libs),
crate_types: vec!(session::CrateTypeExecutable),
output_types: vec!(link::OutputTypeExe),
cg: session::CodegenOptions {
@ -194,7 +194,7 @@ fn maketest(s: &str, cratename: &str, loose_feature_gating: bool) -> ~str {
pub struct Collector {
tests: ~[testing::TestDescAndFn],
priv names: ~[~str],
priv libs: @RefCell<HashSet<Path>>,
priv libs: HashSet<Path>,
priv cnt: uint,
priv use_headers: bool,
priv current_header: Option<~str>,
@ -204,7 +204,7 @@ pub struct Collector {
}
impl Collector {
pub fn new(cratename: ~str, libs: @RefCell<HashSet<Path>>,
pub fn new(cratename: ~str, libs: HashSet<Path>,
use_headers: bool, loose_feature_gating: bool) -> Collector {
Collector {
tests: ~[],
@ -227,8 +227,7 @@ impl Collector {
format!("{}_{}", self.names.connect("::"), self.cnt)
};
self.cnt += 1;
let libs = self.libs.borrow();
let libs = (*libs.get()).clone();
let libs = self.libs.clone();
let cratename = self.cratename.to_owned();
let loose_feature_gating = self.loose_feature_gating;
debug!("Creating test {}: {}", name, test);