]> git.lizzy.rs Git - rust.git/commitdiff
De-@ filesearch.
authorEduard Burtescu <edy.burt@gmail.com>
Sun, 9 Mar 2014 12:24:58 +0000 (14:24 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Mon, 17 Mar 2014 07:53:07 +0000 (09:53 +0200)
src/librustc/back/archive.rs
src/librustc/back/link.rs
src/librustc/back/rpath.rs
src/librustc/driver/driver.rs
src/librustc/driver/session.rs
src/librustc/metadata/filesearch.rs
src/librustc/metadata/loader.rs
src/librustdoc/core.rs
src/librustdoc/lib.rs
src/librustdoc/markdown.rs
src/librustdoc/test.rs

index dd1c754c257181914f66ea7963954194142a5505..863b91f9b32dd4fdc6289f5e84380bfebb793eab 100644 (file)
@@ -206,7 +206,7 @@ fn find_library(&self, name: &str) -> Path {
         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
index b86f03ae36b576c8ed072d14aa7eb9a6797accfe..6830acc19601ad1d22f223b151c2d67e30c0a6bb 100644 (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);
index e4052f8cd6f0ffd610e1f72b1b3c31b68ca74b49..d8feb0a47b3b934f80818149a0b3fe17dd3d07ee 100644 (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
 }
index 6c1c38aa897336f4ca63804b7615e6e213d16ef6..9eeb5bb7ad7427a26f52adc114f5d317d538585f 100644 (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(),
index 76f6999ae75eb98b8932f117a01a2227039b442d..20bbab27434201c0508729e6e08fa85d764bd5e6 100644 (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 @@ pub fn no_landing_pads(&self) -> bool {
     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(),
index 9f6b78354e2e67c7855d543073a5055ea7dba40f..f73a3f35c2b6a86591e915701c98350826e22502 100644 (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 @@ pub fn search(&self, pick: pick) {
         });
     }
 
-    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 @@ fn canonicalize(path: Option<Path>) -> Option<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")
     }
 }
 
index e26759e2b3b616cca9aee3be31a0b4656aa5e992..5c4945a81408442a28d14ede470b989ba9f22354 100644 (file)
@@ -110,7 +110,7 @@ pub fn load_library_crate(&mut self, root_ident: Option<&str>) -> Library {
     }
 
     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 + "-"
index 41b46f2a3a48c9f1b0d0e6241c5ca4cbf545b96d..f8fa43c7050630182cd337597008132be9f203d2 100644 (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()
     };
index fff6e4dafb3035f33bb92d3d641e91ea9ca747f8..b3d6bfbc054309b514a554ca05d7a161e7dcf639 100644 (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();
index 7ab3fe017b905e86fe889291042b3e0a2b9ac2dd..657bfaaf6609806a5073986746ddd24f804e8247 100644 (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);
index ac87a4af48360dab921802dcf2c2c6c900cce346..e8cf246decb84ab889ebde16bc0e428d42d6ea93 100644 (file)
 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 @@ pub fn add_test(&mut self, test: ~str, should_fail: bool, no_run: bool) {
             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);