+impl<'a> CrateLocator<'a> {
+ crate fn new(
+ sess: &'a Session,
+ metadata_loader: &'a dyn MetadataLoader,
+ crate_name: Symbol,
+ hash: Option<Svh>,
+ host_hash: Option<Svh>,
+ extra_filename: Option<&'a str>,
+ is_host: bool,
+ path_kind: PathKind,
+ span: Span,
+ root: Option<&'a CratePaths>,
+ is_proc_macro: Option<bool>,
+ ) -> CrateLocator<'a> {
+ CrateLocator {
+ sess,
+ metadata_loader,
+ crate_name,
+ exact_paths: if hash.is_none() {
+ sess.opts.externs.get(&crate_name.as_str()).into_iter()
+ .flat_map(|entry| entry.locations.iter())
+ .filter_map(|location| location.clone().map(PathBuf::from)).collect()
+ } else {
+ // SVH being specified means this is a transitive dependency,
+ // so `--extern` options do not apply.
+ Vec::new()
+ },
+ hash,
+ host_hash,
+ extra_filename,
+ target: if is_host { &sess.host } else { &sess.target.target },
+ triple: if is_host {
+ TargetTriple::from_triple(config::host_triple())
+ } else {
+ sess.opts.target_triple.clone()
+ },
+ filesearch: if is_host {
+ sess.host_filesearch(path_kind)
+ } else {
+ sess.target_filesearch(path_kind)
+ },
+ span,
+ root,
+ is_proc_macro,
+ rejected_via_hash: Vec::new(),
+ rejected_via_triple: Vec::new(),
+ rejected_via_kind: Vec::new(),
+ rejected_via_version: Vec::new(),
+ rejected_via_filename: Vec::new(),
+ }
+ }
+