librustc: De-`@mut` the additional library search paths

This commit is contained in:
Patrick Walton 2013-12-21 14:28:04 -08:00
parent abe2ad0ff8
commit 02d31b7d1a
8 changed files with 53 additions and 28 deletions

View File

@ -187,7 +187,11 @@ impl Archive {
let mut rustpath = filesearch::rust_path();
rustpath.push(self.sess.filesearch.get_target_lib_path());
let path = self.sess.opts.addl_lib_search_paths.iter();
let addl_lib_search_paths = self.sess
.opts
.addl_lib_search_paths
.borrow();
let path = addl_lib_search_paths.get().iter();
for path in path.chain(rustpath.iter()) {
debug!("looking for {} inside {}", name, path.display());
let test = path.join(oslibname.as_slice());

View File

@ -1109,7 +1109,8 @@ fn link_args(sess: Session,
// in the current crate. Upstream crates with native library dependencies
// may have their native library pulled in above.
fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
for path in sess.opts.addl_lib_search_paths.iter() {
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
for path in addl_lib_search_paths.get().iter() {
// FIXME (#9639): This needs to handle non-utf8 paths
args.push("-L" + path.as_str().unwrap().to_owned());
}

View File

@ -822,7 +822,7 @@ pub fn build_session_options(binary: @str,
lint_opts: lint_opts,
save_temps: save_temps,
output_type: output_type,
addl_lib_search_paths: @mut addl_lib_search_paths,
addl_lib_search_paths: @RefCell::new(addl_lib_search_paths),
ar: ar,
linker: linker,
linker_args: linker_args,

View File

@ -148,9 +148,9 @@ pub struct options {
lint_opts: ~[(lint::lint, lint::level)],
save_temps: bool,
output_type: back::link::output_type,
addl_lib_search_paths: @mut HashSet<Path>, // This is mutable for rustpkg, which
// updates search paths based on the
// parsed code
// This is mutable for rustpkg, which updates search paths based on the
// parsed code.
addl_lib_search_paths: @RefCell<HashSet<Path>>,
ar: Option<~str>,
linker: Option<~str>,
linker_args: ~[~str],
@ -385,7 +385,7 @@ pub fn basic_options() -> @options {
lint_opts: ~[],
save_temps: false,
output_type: link::output_type_exe,
addl_lib_search_paths: @mut HashSet::new(),
addl_lib_search_paths: @RefCell::new(HashSet::new()),
ar: None,
linker: None,
linker_args: ~[],

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::cell::RefCell;
use std::option;
use std::os;
use std::io;
@ -42,11 +42,11 @@ pub trait FileSearch {
pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
target_triple: &str,
addl_lib_search_paths: @mut HashSet<Path>)
addl_lib_search_paths: @RefCell<HashSet<Path>>)
-> @FileSearch {
struct FileSearchImpl {
sysroot: @Path,
addl_lib_search_paths: @mut HashSet<Path>,
addl_lib_search_paths: @RefCell<HashSet<Path>>,
target_triple: ~str
}
impl FileSearch for FileSearchImpl {
@ -56,9 +56,10 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
let mut visited_dirs = HashSet::new();
let mut found = false;
let addl_lib_search_paths = self.addl_lib_search_paths.borrow();
debug!("filesearch: searching additional lib search paths [{:?}]",
self.addl_lib_search_paths.len());
for path in self.addl_lib_search_paths.iter() {
addl_lib_search_paths.get().len());
for path in addl_lib_search_paths.get().iter() {
match f(path) {
FileMatches => found = true,
FileDoesntMatch => ()

View File

@ -17,6 +17,7 @@ use syntax::diagnostic;
use syntax::parse;
use syntax;
use std::cell::RefCell;
use std::os;
use std::local_data;
use std::hashmap::{HashSet};
@ -50,7 +51,7 @@ fn get_ast_and_resolve(cpath: &Path,
let sessopts = @driver::session::options {
binary: @"rustdoc",
maybe_sysroot: Some(@os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: @mut libs,
addl_lib_search_paths: @RefCell::new(libs),
outputs: ~[driver::session::OutputDylib],
.. (*rustc::driver::session::basic_options()).clone()
};

View File

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::cell::RefCell;
use std::hashmap::HashSet;
use std::local_data;
use std::os;
@ -34,7 +35,7 @@ pub fn run(input: &str, matches: &getopts::Matches) -> int {
let parsesess = parse::new_parse_sess(None);
let input = driver::file_input(Path::new(input));
let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice()));
let libs = @mut libs.move_iter().collect();
let libs = @RefCell::new(libs.move_iter().collect());
let sessopts = @session::options {
binary: @"rustdoc",
@ -99,7 +100,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>) {
let sessopts = @session::options {
binary: @"rustdoctest",
maybe_sysroot: Some(@os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: @mut libs,
addl_lib_search_paths: @RefCell::new(libs),
outputs: ~[session::OutputExecutable],
debugging_opts: session::prefer_dynamic,
.. (*session::basic_options()).clone()
@ -159,7 +160,7 @@ fn maketest(s: &str, cratename: &str) -> @str {
pub struct Collector {
priv tests: ~[test::TestDescAndFn],
priv names: ~[~str],
priv libs: @mut HashSet<Path>,
priv libs: @RefCell<HashSet<Path>>,
priv cnt: uint,
priv cratename: ~str,
}
@ -169,7 +170,8 @@ impl Collector {
let test = test.to_owned();
let name = format!("{}_{}", self.names.connect("::"), self.cnt);
self.cnt += 1;
let libs = (*self.libs).clone();
let libs = self.libs.borrow();
let libs = (*libs.get()).clone();
let cratename = self.cratename.to_owned();
self.tests.push(test::TestDescAndFn {
desc: test::TestDesc {

View File

@ -10,6 +10,7 @@
#[allow(dead_code)];
use std::cell::RefCell;
use std::libc;
use std::os;
use std::io;
@ -244,7 +245,8 @@ pub fn compile_input(context: &BuildContext,
optimize: opt,
test: what == Test || what == Bench,
maybe_sysroot: Some(sysroot_to_use),
addl_lib_search_paths: @mut context.additional_library_paths(),
addl_lib_search_paths:
@RefCell::new(context.additional_library_paths()),
output_type: output_type,
.. (*driver::build_session_options(binary,
&matches,
@ -254,15 +256,20 @@ pub fn compile_input(context: &BuildContext,
debug!("Created options...");
let addl_lib_search_paths = @mut options.addl_lib_search_paths;
let addl_lib_search_paths = @RefCell::new(options.addl_lib_search_paths);
// Make sure all the library directories actually exist, since the linker will complain
// otherwise
for p in addl_lib_search_paths.iter() {
if p.exists() {
assert!(p.is_dir())
}
else {
fs::mkdir_recursive(p, io::UserRWX);
{
let mut addl_lib_search_paths = addl_lib_search_paths.borrow_mut();
let addl_lib_search_paths = addl_lib_search_paths.get();
let mut addl_lib_search_paths = addl_lib_search_paths.borrow_mut();
for p in addl_lib_search_paths.get().iter() {
if p.exists() {
assert!(p.is_dir())
}
else {
fs::mkdir_recursive(p, io::UserRWX);
}
}
}
@ -285,9 +292,15 @@ pub fn compile_input(context: &BuildContext,
find_and_install_dependencies(context, pkg_id, in_file, sess, exec, &crate, deps,
|p| {
debug!("a dependency: {}", p.display());
let mut addl_lib_search_paths =
addl_lib_search_paths.borrow_mut();
let addl_lib_search_paths =
addl_lib_search_paths.get();
let mut addl_lib_search_paths =
addl_lib_search_paths.borrow_mut();
// Pass the directory containing a dependency
// as an additional lib search path
addl_lib_search_paths.insert(p);
addl_lib_search_paths.get().insert(p);
});
// Inject the pkgid attribute so we get the right package name and version
@ -376,8 +389,11 @@ pub fn compile_crate_from_input(input: &Path,
outputs.obj_filename.display(),
sess.opts.output_type);
debug!("additional libraries:");
for lib in sess.opts.addl_lib_search_paths.iter() {
debug!("an additional library: {}", lib.display());
{
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
for lib in addl_lib_search_paths.get().iter() {
debug!("an additional library: {}", lib.display());
}
}
let analysis = driver::phase_3_run_analysis_passes(sess, &crate);
if driver::stop_after_phase_3(sess) { return None; }