Skip to content

Commit 4044cbc

Browse files
committed
rustc_metadata: Refactor away CrateLocator::(dy,static)libname
1 parent 926ac5a commit 4044cbc

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

src/librustc_metadata/locator.rs

+19-27
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ impl<'a> CrateLocator<'a> {
495495
};
496496

497497
if !self.rejected_via_filename.is_empty() {
498-
let dylibname = self.dylibname();
499498
let mismatches = self.rejected_via_filename.iter();
500499
for &CrateMismatch { ref path, .. } in mismatches {
501500
err.note(&format!(
@@ -505,7 +504,7 @@ impl<'a> CrateLocator<'a> {
505504
))
506505
.help(&format!(
507506
"file name should be lib*.rlib or {}*.{}",
508-
dylibname.0, dylibname.1
507+
self.target.options.dll_prefix, self.target.options.dll_suffix
509508
));
510509
}
511510
}
@@ -520,13 +519,12 @@ impl<'a> CrateLocator<'a> {
520519
extra_prefix: &str,
521520
seen_paths: &mut FxHashSet<PathBuf>,
522521
) -> Option<Library> {
523-
let dypair = self.dylibname();
524-
let staticpair = self.staticlibname();
525-
526522
// want: crate_name.dir_part() + prefix + crate_name.file_part + "-"
527-
let dylib_prefix = format!("{}{}{}", dypair.0, self.crate_name, extra_prefix);
523+
let dylib_prefix =
524+
format!("{}{}{}", self.target.options.dll_prefix, self.crate_name, extra_prefix);
528525
let rlib_prefix = format!("lib{}{}", self.crate_name, extra_prefix);
529-
let staticlib_prefix = format!("{}{}{}", staticpair.0, self.crate_name, extra_prefix);
526+
let staticlib_prefix =
527+
format!("{}{}{}", self.target.options.staticlib_prefix, self.crate_name, extra_prefix);
530528

531529
let mut candidates: FxHashMap<_, (FxHashMap<_, _>, FxHashMap<_, _>, FxHashMap<_, _>)> =
532530
Default::default();
@@ -554,10 +552,18 @@ impl<'a> CrateLocator<'a> {
554552
(&file[(rlib_prefix.len())..(file.len() - ".rlib".len())], CrateFlavor::Rlib)
555553
} else if file.starts_with(&rlib_prefix) && file.ends_with(".rmeta") {
556554
(&file[(rlib_prefix.len())..(file.len() - ".rmeta".len())], CrateFlavor::Rmeta)
557-
} else if file.starts_with(&dylib_prefix) && file.ends_with(&dypair.1) {
558-
(&file[(dylib_prefix.len())..(file.len() - dypair.1.len())], CrateFlavor::Dylib)
555+
} else if file.starts_with(&dylib_prefix)
556+
&& file.ends_with(&self.target.options.dll_suffix)
557+
{
558+
(
559+
&file
560+
[(dylib_prefix.len())..(file.len() - self.target.options.dll_suffix.len())],
561+
CrateFlavor::Dylib,
562+
)
559563
} else {
560-
if file.starts_with(&staticlib_prefix) && file.ends_with(&staticpair.1) {
564+
if file.starts_with(&staticlib_prefix)
565+
&& file.ends_with(&self.target.options.staticlib_suffix)
566+
{
561567
staticlibs
562568
.push(CrateMismatch { path: spf.path.clone(), got: "static".to_string() });
563569
}
@@ -859,32 +865,19 @@ impl<'a> CrateLocator<'a> {
859865
Some(hash)
860866
}
861867

862-
// Returns the corresponding (prefix, suffix) that files need to have for
863-
// dynamic libraries
864-
fn dylibname(&self) -> (String, String) {
865-
let t = &self.target;
866-
(t.options.dll_prefix.clone(), t.options.dll_suffix.clone())
867-
}
868-
869-
// Returns the corresponding (prefix, suffix) that files need to have for
870-
// static libraries
871-
fn staticlibname(&self) -> (String, String) {
872-
let t = &self.target;
873-
(t.options.staticlib_prefix.clone(), t.options.staticlib_suffix.clone())
874-
}
875-
876868
fn find_commandline_library(&mut self) -> Option<Library> {
877869
// First, filter out all libraries that look suspicious. We only accept
878870
// files which actually exist that have the correct naming scheme for
879871
// rlibs/dylibs.
880872
let sess = self.sess;
881-
let dylibname = self.dylibname();
882873
let mut rlibs = FxHashMap::default();
883874
let mut rmetas = FxHashMap::default();
884875
let mut dylibs = FxHashMap::default();
885876
{
886877
let crate_name = self.crate_name;
887878
let rejected_via_filename = &mut self.rejected_via_filename;
879+
let dll_prefix = &self.target.options.dll_prefix;
880+
let dll_suffix = &self.target.options.dll_suffix;
888881
let locs = self.exact_paths.iter().filter(|loc| {
889882
if !loc.exists() {
890883
sess.err(&format!(
@@ -909,8 +902,7 @@ impl<'a> CrateLocator<'a> {
909902
{
910903
return true;
911904
} else {
912-
let (ref prefix, ref suffix) = dylibname;
913-
if file.starts_with(&prefix[..]) && file.ends_with(&suffix[..]) {
905+
if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) {
914906
return true;
915907
}
916908
}

0 commit comments

Comments
 (0)