rustc_metadata: reduce repetition
This commit is contained in:
parent
f395551352
commit
69be18d4e2
@ -709,40 +709,31 @@ fn find_commandline_library(&mut self) -> Result<Option<Library>, CrateError> {
|
|||||||
let mut rmetas = FxIndexMap::default();
|
let mut rmetas = FxIndexMap::default();
|
||||||
let mut dylibs = FxIndexMap::default();
|
let mut dylibs = FxIndexMap::default();
|
||||||
for loc in &self.exact_paths {
|
for loc in &self.exact_paths {
|
||||||
if !loc.canonicalized().exists() {
|
let loc_canon = loc.canonicalized();
|
||||||
return Err(CrateError::ExternLocationNotExist(
|
let loc_orig = loc.original();
|
||||||
self.crate_name,
|
if !loc_canon.exists() {
|
||||||
loc.original().clone(),
|
return Err(CrateError::ExternLocationNotExist(self.crate_name, loc_orig.clone()));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
if !loc.original().is_file() {
|
if !loc_orig.is_file() {
|
||||||
return Err(CrateError::ExternLocationNotFile(
|
return Err(CrateError::ExternLocationNotFile(self.crate_name, loc_orig.clone()));
|
||||||
self.crate_name,
|
|
||||||
loc.original().clone(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
let Some(file) = loc.original().file_name().and_then(|s| s.to_str()) else {
|
// Note to take care and match against the non-canonicalized name:
|
||||||
return Err(CrateError::ExternLocationNotFile(
|
// some systems save build artifacts into content-addressed stores
|
||||||
self.crate_name,
|
// that do not preserve extensions, and then link to them using
|
||||||
loc.original().clone(),
|
// e.g. symbolic links. If we canonicalize too early, we resolve
|
||||||
));
|
// the symlink, the file type is lost and we might treat rlibs and
|
||||||
|
// rmetas as dylibs.
|
||||||
|
let Some(file) = loc_orig.file_name().and_then(|s| s.to_str()) else {
|
||||||
|
return Err(CrateError::ExternLocationNotFile(self.crate_name, loc_orig.clone()));
|
||||||
};
|
};
|
||||||
|
|
||||||
if file.starts_with("lib") && (file.ends_with(".rlib") || file.ends_with(".rmeta"))
|
if file.starts_with("lib") && (file.ends_with(".rlib") || file.ends_with(".rmeta"))
|
||||||
|| file.starts_with(self.target.dll_prefix.as_ref())
|
|| file.starts_with(self.target.dll_prefix.as_ref())
|
||||||
&& file.ends_with(self.target.dll_suffix.as_ref())
|
&& file.ends_with(self.target.dll_suffix.as_ref())
|
||||||
{
|
{
|
||||||
// Note to take care and match against the non-canonicalized name:
|
let loc_canon = loc_canon.clone();
|
||||||
// some systems save build artifacts into content-addressed stores
|
if file.ends_with(".rlib") {
|
||||||
// that do not preserve extensions, and then link to them using
|
|
||||||
// e.g. symbolic links. If we canonicalize too early, we resolve
|
|
||||||
// the symlink, the file type is lost and we might treat rlibs and
|
|
||||||
// rmetas as dylibs.
|
|
||||||
let loc_canon = loc.canonicalized().clone();
|
|
||||||
let loc = loc.original();
|
|
||||||
if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") {
|
|
||||||
rlibs.insert(loc_canon, PathKind::ExternFlag);
|
rlibs.insert(loc_canon, PathKind::ExternFlag);
|
||||||
} else if loc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta") {
|
} else if file.ends_with(".rmeta") {
|
||||||
rmetas.insert(loc_canon, PathKind::ExternFlag);
|
rmetas.insert(loc_canon, PathKind::ExternFlag);
|
||||||
} else {
|
} else {
|
||||||
dylibs.insert(loc_canon, PathKind::ExternFlag);
|
dylibs.insert(loc_canon, PathKind::ExternFlag);
|
||||||
@ -750,7 +741,7 @@ fn find_commandline_library(&mut self) -> Result<Option<Library>, CrateError> {
|
|||||||
} else {
|
} else {
|
||||||
self.crate_rejections
|
self.crate_rejections
|
||||||
.via_filename
|
.via_filename
|
||||||
.push(CrateMismatch { path: loc.original().clone(), got: String::new() });
|
.push(CrateMismatch { path: loc_orig.clone(), got: String::new() });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user