Skip to content

Commit f77c744

Browse files
committed
De-@ filesearch.
1 parent eeb37b7 commit f77c744

File tree

11 files changed

+53
-54
lines changed

11 files changed

+53
-54
lines changed

src/librustc/back/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a> Archive<'a> {
206206
let unixlibname = format!("lib{}.a", name);
207207

208208
let mut rustpath = filesearch::rust_path();
209-
rustpath.push(self.sess.filesearch.get_target_lib_path());
209+
rustpath.push(self.sess.filesearch().get_target_lib_path());
210210
let addl_lib_search_paths = self.sess
211211
.opts
212212
.addl_lib_search_paths

src/librustc/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ fn link_args(sess: &Session,
10751075
// The default library location, we need this to find the runtime.
10761076
// The location of crates will be determined as needed.
10771077
// FIXME (#9639): This needs to handle non-utf8 paths
1078-
let lib_path = sess.filesearch.get_target_lib_path();
1078+
let lib_path = sess.filesearch().get_target_lib_path();
10791079
let stage: ~str = ~"-L" + lib_path.as_str().unwrap();
10801080

10811081
let mut args = vec!(stage);

src/librustc/back/rpath.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
4040

4141
debug!("preparing the RPATH!");
4242

43-
let sysroot = sess.filesearch.sysroot;
43+
let sysroot = sess.filesearch().sysroot;
4444
let output = out_filename;
4545
let libs = sess.cstore.get_used_crates(cstore::RequireDynamic);
4646
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> {
5656

5757
fn get_sysroot_absolute_rt_lib(sess: &Session) -> Path {
5858
let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
59-
let mut p = sess.filesearch.sysroot.join(&r);
59+
let mut p = sess.filesearch().sysroot.join(&r);
6060
p.push(os::dll_filename("rustrt"));
6161
p
6262
}

src/librustc/driver/driver.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ pub fn build_session_options(matches: &getopts::Matches)
871871
output_types.push(link::OutputTypeExe);
872872
}
873873

874-
let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path::new(m));
874+
let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
875875
let target = matches.opt_str("target").unwrap_or(host_triple());
876876
let opt_level = {
877877
if (debugging_opts & session::NO_OPT) != 0 {
@@ -932,14 +932,14 @@ pub fn build_session_options(matches: &getopts::Matches)
932932
matches.opt_present("crate-file-name"));
933933
let cg = build_codegen_options(matches);
934934

935-
let sopts = @session::Options {
935+
@session::Options {
936936
crate_types: crate_types,
937937
gc: gc,
938938
optimize: opt_level,
939939
debuginfo: debuginfo,
940940
lint_opts: lint_opts,
941941
output_types: output_types,
942-
addl_lib_search_paths: @RefCell::new(addl_lib_search_paths),
942+
addl_lib_search_paths: RefCell::new(addl_lib_search_paths),
943943
maybe_sysroot: sysroot_opt,
944944
target_triple: target,
945945
cfg: cfg,
@@ -951,8 +951,7 @@ pub fn build_session_options(matches: &getopts::Matches)
951951
write_dependency_info: write_dependency_info,
952952
print_metas: print_metas,
953953
cg: cg,
954-
};
955-
return sopts;
954+
}
956955
}
957956

958957
pub fn build_codegen_options(matches: &getopts::Matches)
@@ -1006,10 +1005,10 @@ pub fn build_session_(sopts: @session::Options,
10061005
let target_cfg = build_target_config(sopts);
10071006
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler, codemap);
10081007
let cstore = @CStore::new(token::get_ident_interner());
1009-
let filesearch = @filesearch::FileSearch::new(
1010-
&sopts.maybe_sysroot,
1011-
sopts.target_triple,
1012-
sopts.addl_lib_search_paths);
1008+
let default_sysroot = match sopts.maybe_sysroot {
1009+
Some(_) => None,
1010+
None => Some(filesearch::get_or_default_sysroot())
1011+
};
10131012

10141013
// Make the path absolute, if necessary
10151014
let local_crate_source_file = local_crate_source_file.map(|path|
@@ -1031,7 +1030,7 @@ pub fn build_session_(sopts: @session::Options,
10311030
entry_type: Cell::new(None),
10321031
macro_registrar_fn: RefCell::new(None),
10331032
span_diagnostic: span_diagnostic_handler,
1034-
filesearch: filesearch,
1033+
default_sysroot: default_sysroot,
10351034
building_library: Cell::new(false),
10361035
local_crate_source_file: local_crate_source_file,
10371036
working_dir: os::getcwd(),

src/librustc/driver/session.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ pub struct Options {
134134
// This was mutable for rustpkg, which updates search paths based on the
135135
// parsed code. It remains mutable in case its replacements wants to use
136136
// this.
137-
addl_lib_search_paths: @RefCell<HashSet<Path>>,
138-
maybe_sysroot: Option<@Path>,
137+
addl_lib_search_paths: RefCell<HashSet<Path>>,
138+
maybe_sysroot: Option<Path>,
139139
target_triple: ~str,
140140
// User-specified cfg meta items. The compiler itself will add additional
141141
// items to the crate config, and during parsing the entire crate config
@@ -184,7 +184,7 @@ pub struct Session {
184184
entry_type: Cell<Option<EntryFnType>>,
185185
span_diagnostic: @diagnostic::SpanHandler,
186186
macro_registrar_fn: RefCell<Option<ast::DefId>>,
187-
filesearch: @filesearch::FileSearch,
187+
default_sysroot: Option<Path>,
188188
building_library: Cell<bool>,
189189
// The name of the root source file of the crate, in the local file system. The path is always
190190
// expected to be absolute. `None` means that there is no source file.
@@ -314,6 +314,17 @@ impl Session {
314314
pub fn show_span(&self) -> bool {
315315
self.debugging_opt(SHOW_SPAN)
316316
}
317+
pub fn filesearch<'a>(&'a self) -> filesearch::FileSearch<'a> {
318+
let sysroot = match self.opts.maybe_sysroot {
319+
Some(ref sysroot) => sysroot,
320+
None => self.default_sysroot.as_ref()
321+
.expect("missing sysroot and default_sysroot in Session")
322+
};
323+
filesearch::FileSearch::new(
324+
sysroot,
325+
self.opts.target_triple,
326+
&self.opts.addl_lib_search_paths)
327+
}
317328
}
318329

319330
/// Some reasonable defaults
@@ -325,7 +336,7 @@ pub fn basic_options() -> @Options {
325336
debuginfo: NoDebugInfo,
326337
lint_opts: Vec::new(),
327338
output_types: Vec::new(),
328-
addl_lib_search_paths: @RefCell::new(HashSet::new()),
339+
addl_lib_search_paths: RefCell::new(HashSet::new()),
329340
maybe_sysroot: None,
330341
target_triple: host_triple(),
331342
cfg: Vec::new(),

src/librustc/metadata/filesearch.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#[allow(non_camel_case_types)];
1212

1313
use std::cell::RefCell;
14-
use std::option;
1514
use std::os;
1615
use std::io::fs;
1716
use std::vec_ng::Vec;
@@ -27,13 +26,13 @@ pub enum FileMatch { FileMatches, FileDoesntMatch }
2726
/// a file found in that directory.
2827
pub type pick<'a> = 'a |path: &Path| -> FileMatch;
2928

30-
pub struct FileSearch {
31-
sysroot: @Path,
32-
addl_lib_search_paths: @RefCell<HashSet<Path>>,
33-
target_triple: ~str
29+
pub struct FileSearch<'a> {
30+
sysroot: &'a Path,
31+
addl_lib_search_paths: &'a RefCell<HashSet<Path>>,
32+
target_triple: &'a str
3433
}
3534

36-
impl FileSearch {
35+
impl<'a> FileSearch<'a> {
3736
pub fn for_each_lib_search_path(&self, f: |&Path| -> FileMatch) {
3837
let mut visited_dirs = HashSet::new();
3938
let mut found = false;
@@ -127,15 +126,14 @@ impl FileSearch {
127126
});
128127
}
129128

130-
pub fn new(maybe_sysroot: &Option<@Path>,
131-
target_triple: &str,
132-
addl_lib_search_paths: @RefCell<HashSet<Path>>) -> FileSearch {
133-
let sysroot = get_sysroot(maybe_sysroot);
129+
pub fn new(sysroot: &'a Path,
130+
target_triple: &'a str,
131+
addl_lib_search_paths: &'a RefCell<HashSet<Path>>) -> FileSearch<'a> {
134132
debug!("using sysroot = {}", sysroot.display());
135-
FileSearch{
133+
FileSearch {
136134
sysroot: sysroot,
137135
addl_lib_search_paths: addl_lib_search_paths,
138-
target_triple: target_triple.to_owned()
136+
target_triple: target_triple
139137
}
140138
}
141139
}
@@ -179,15 +177,8 @@ pub fn get_or_default_sysroot() -> Path {
179177
}
180178

181179
match canonicalize(os::self_exe_name()) {
182-
option::Some(p) => { let mut p = p; p.pop(); p.pop(); p }
183-
option::None => fail!("can't determine value for sysroot")
184-
}
185-
}
186-
187-
fn get_sysroot(maybe_sysroot: &Option<@Path>) -> @Path {
188-
match *maybe_sysroot {
189-
option::Some(sr) => sr,
190-
option::None => @get_or_default_sysroot()
180+
Some(mut p) => { p.pop(); p.pop(); p }
181+
None => fail!("can't determine value for sysroot")
191182
}
192183
}
193184

src/librustc/metadata/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a> Context<'a> {
110110
}
111111

112112
fn find_library_crate(&mut self) -> Option<Library> {
113-
let filesearch = self.sess.filesearch;
113+
let filesearch = self.sess.filesearch();
114114
let (dyprefix, dysuffix) = self.dylibname();
115115

116116
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"

src/librustdoc/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ fn get_ast_and_resolve(cpath: &Path,
6464
let input = FileInput(cpath.clone());
6565

6666
let sessopts = @driver::session::Options {
67-
maybe_sysroot: Some(@os::self_exe_path().unwrap().dir_path()),
68-
addl_lib_search_paths: @RefCell::new(libs),
67+
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
68+
addl_lib_search_paths: RefCell::new(libs),
6969
crate_types: vec!(driver::session::CrateTypeDylib),
7070
.. (*rustc::driver::session::basic_options()).clone()
7171
};

src/librustdoc/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ pub fn main_args(args: &[~str]) -> int {
155155
}
156156
let input = matches.free[0].as_slice();
157157

158-
let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice()));
159-
let libs = @RefCell::new(libs.move_iter().collect());
158+
let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice())).move_iter().collect();
160159

161160
let test_args = matches.opt_strs("test-args");
162161
let test_args = test_args.iter().flat_map(|s| s.words()).map(|s| s.to_owned()).to_owned_vec();

src/librustdoc/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub fn render(input: &str, mut output: Path, matches: &getopts::Matches) -> int
160160
}
161161

162162
/// Run any tests/code examples in the markdown file `input`.
163-
pub fn test(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -> int {
163+
pub fn test(input: &str, libs: HashSet<Path>, mut test_args: ~[~str]) -> int {
164164
let input_str = load_or_return!(input, 1, 2);
165165

166166
let mut collector = Collector::new(input.to_owned(), libs, true, true);

src/librustdoc/test.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ use html::markdown;
3434
use passes;
3535
use visit_ast::RustdocVisitor;
3636

37-
pub fn run(input: &str, libs: @RefCell<HashSet<Path>>, mut test_args: ~[~str]) -> int {
37+
pub fn run(input: &str, libs: HashSet<Path>, mut test_args: ~[~str]) -> int {
3838
let input_path = Path::new(input);
3939
let input = driver::FileInput(input_path.clone());
4040

4141
let sessopts = @session::Options {
42-
maybe_sysroot: Some(@os::self_exe_path().unwrap().dir_path()),
43-
addl_lib_search_paths: libs,
42+
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
43+
addl_lib_search_paths: RefCell::new(libs.clone()),
4444
crate_types: vec!(session::CrateTypeDylib),
4545
.. (*session::basic_options()).clone()
4646
};
@@ -92,8 +92,8 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
9292
let input = driver::StrInput(test);
9393

9494
let sessopts = @session::Options {
95-
maybe_sysroot: Some(@os::self_exe_path().unwrap().dir_path()),
96-
addl_lib_search_paths: @RefCell::new(libs),
95+
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
96+
addl_lib_search_paths: RefCell::new(libs),
9797
crate_types: vec!(session::CrateTypeExecutable),
9898
output_types: vec!(link::OutputTypeExe),
9999
cg: session::CodegenOptions {
@@ -194,7 +194,7 @@ fn maketest(s: &str, cratename: &str, loose_feature_gating: bool) -> ~str {
194194
pub struct Collector {
195195
tests: ~[testing::TestDescAndFn],
196196
priv names: ~[~str],
197-
priv libs: @RefCell<HashSet<Path>>,
197+
priv libs: HashSet<Path>,
198198
priv cnt: uint,
199199
priv use_headers: bool,
200200
priv current_header: Option<~str>,
@@ -204,7 +204,7 @@ pub struct Collector {
204204
}
205205

206206
impl Collector {
207-
pub fn new(cratename: ~str, libs: @RefCell<HashSet<Path>>,
207+
pub fn new(cratename: ~str, libs: HashSet<Path>,
208208
use_headers: bool, loose_feature_gating: bool) -> Collector {
209209
Collector {
210210
tests: ~[],
@@ -227,8 +227,7 @@ impl Collector {
227227
format!("{}_{}", self.names.connect("::"), self.cnt)
228228
};
229229
self.cnt += 1;
230-
let libs = self.libs.borrow();
231-
let libs = (*libs.get()).clone();
230+
let libs = self.libs.clone();
232231
let cratename = self.cratename.to_owned();
233232
let loose_feature_gating = self.loose_feature_gating;
234233
debug!("Creating test {}: {}", name, test);

0 commit comments

Comments
 (0)