Auto merge of #149273 - bjorn3:crate_locator_improvements, r= · rust-lang/rust@c77897e (original) (raw)

`@@ -218,7 +218,7 @@ use std::ops::Deref;

`

218

218

`use std::path::{Path, PathBuf};

`

219

219

`use std::{cmp, fmt};

`

220

220

``

221

``

`-

use rustc_data_structures::fx::{FxHashSet, FxIndexMap};

`

``

221

`+

use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};

`

222

222

`use rustc_data_structures::memmap::Mmap;

`

223

223

`use rustc_data_structures::owned_slice::{OwnedSlice, slice_owned};

`

224

224

`use rustc_data_structures::svh::Svh;

`

`@@ -401,7 +401,7 @@ impl<'a> CrateLocator<'a> {

`

401

401

``

402

402

`let mut candidates: FxIndexMap<

`

403

403

`_,

`

404

``

`-

(FxIndexMap<_, _>, FxIndexMap<_, _>, FxIndexMap<_, _>, FxIndexMap<_, _>),

`

``

404

`+

(FxIndexSet<_>, FxIndexSet<_>, FxIndexSet<_>, FxIndexSet<_>),

`

405

405

`> = Default::default();

`

406

406

``

407

407

`// First, find all possible candidate rlibs and dylibs purely based on

`

`@@ -460,10 +460,10 @@ impl<'a> CrateLocator<'a> {

`

460

460

`// filesystem code should not care, but this is nicer for diagnostics.

`

461

461

`let path = spf.path.to_path_buf();

`

462

462

`match kind {

`

463

``

`-

CrateFlavor::Rlib => rlibs.insert(path, search_path.kind),

`

464

``

`-

CrateFlavor::Rmeta => rmetas.insert(path, search_path.kind),

`

465

``

`-

CrateFlavor::Dylib => dylibs.insert(path, search_path.kind),

`

466

``

`-

CrateFlavor::SDylib => interfaces.insert(path, search_path.kind),

`

``

463

`+

CrateFlavor::Rlib => rlibs.insert(path),

`

``

464

`+

CrateFlavor::Rmeta => rmetas.insert(path),

`

``

465

`+

CrateFlavor::Dylib => dylibs.insert(path),

`

``

466

`+

CrateFlavor::SDylib => interfaces.insert(path),

`

467

467

`};

`

468

468

`}

`

469

469

`}

`

`@@ -524,10 +524,10 @@ impl<'a> CrateLocator<'a> {

`

524

524

`fn extract_lib(

`

525

525

`&self,

`

526

526

`crate_rejections: &mut CrateRejections,

`

527

``

`-

rlibs: FxIndexMap<PathBuf, PathKind>,

`

528

``

`-

rmetas: FxIndexMap<PathBuf, PathKind>,

`

529

``

`-

dylibs: FxIndexMap<PathBuf, PathKind>,

`

530

``

`-

interfaces: FxIndexMap<PathBuf, PathKind>,

`

``

527

`+

rlibs: FxIndexSet,

`

``

528

`+

rmetas: FxIndexSet,

`

``

529

`+

dylibs: FxIndexSet,

`

``

530

`+

interfaces: FxIndexSet,

`

531

531

`) -> Result<Option<(Svh, Library)>, CrateError> {

`

532

532

`let mut slot = None;

`

533

533

`// Order here matters, rmeta should come first.

`

`@@ -575,10 +575,10 @@ impl<'a> CrateLocator<'a> {

`

575

575

`fn extract_one(

`

576

576

`&self,

`

577

577

`crate_rejections: &mut CrateRejections,

`

578

``

`-

m: FxIndexMap<PathBuf, PathKind>,

`

``

578

`+

m: FxIndexSet,

`

579

579

`flavor: CrateFlavor,

`

580

580

`slot: &mut Option<(Svh, MetadataBlob, PathBuf, CrateFlavor)>,

`

581

``

`-

) -> Result<Option<(PathBuf, PathKind)>, CrateError> {

`

``

581

`+

) -> Result<Option, CrateError> {

`

582

582

`// If we are producing an rlib, and we've already loaded metadata, then

`

583

583

`// we should not attempt to discover further crate sources (unless we're

`

584

584

`// locating a proc macro; exact logic is in needs_crate_flavor). This means

`

`@@ -594,9 +594,9 @@ impl<'a> CrateLocator<'a> {

`

594

594

`}

`

595

595

`}

`

596

596

``

597

``

`-

let mut ret: Option<(PathBuf, PathKind)> = None;

`

``

597

`+

let mut ret: Option = None;

`

598

598

`let mut err_data: Option<Vec> = None;

`

599

``

`-

for (lib, kind) in m {

`

``

599

`+

for lib in m {

`

600

600

`info!("{} reading metadata from: {}", flavor, lib.display());

`

601

601

`if flavor == CrateFlavor::Rmeta && lib.metadata().is_ok_and(|m| m.len() == 0) {

`

602

602

`// Empty files will cause get_metadata_section to fail. Rmeta

`

`@@ -640,7 +640,7 @@ impl<'a> CrateLocator<'a> {

`

640

640

`info!("no metadata found: {}", err);

`

641

641

`// Metadata was loaded from interface file earlier.

`

642

642

`if let Some((.., CrateFlavor::SDylib)) = slot {

`

643

``

`-

ret = Some((lib, kind));

`

``

643

`+

ret = Some(lib);

`

644

644

`continue;

`

645

645

`}

`

646

646

`// The file was present and created by the same compiler version, but we

`

`@@ -689,7 +689,7 @@ impl<'a> CrateLocator<'a> {

`

689

689

`// As a result, we favor the sysroot crate here. Note that the

`

690

690

`// candidates are all canonicalized, so we canonicalize the sysroot

`

691

691

`// as well.

`

692

``

`-

if let Some((prev, _)) = &ret {

`

``

692

`+

if let Some(prev) = &ret {

`

693

693

`let sysroot = self.sysroot;

`

694

694

`let sysroot = try_canonicalize(sysroot).unwrap_or_else(|_| sysroot.to_path_buf());

`

695

695

`if prev.starts_with(&sysroot) {

`

`@@ -714,7 +714,7 @@ impl<'a> CrateLocator<'a> {

`

714

714

`} else {

`

715

715

`*slot = Some((hash, metadata, lib.clone(), flavor));

`

716

716

`}

`

717

``

`-

ret = Some((lib, kind));

`

``

717

`+

ret = Some(lib);

`

718

718

`}

`

719

719

``

720

720

`if let Some(candidates) = err_data {

`

`@@ -774,10 +774,10 @@ impl<'a> CrateLocator<'a> {

`

774

774

`// First, filter out all libraries that look suspicious. We only accept

`

775

775

`// files which actually exist that have the correct naming scheme for

`

776

776

`// rlibs/dylibs.

`

777

``

`-

let mut rlibs = FxIndexMap::default();

`

778

``

`-

let mut rmetas = FxIndexMap::default();

`

779

``

`-

let mut dylibs = FxIndexMap::default();

`

780

``

`-

let mut sdylib_interfaces = FxIndexMap::default();

`

``

777

`+

let mut rlibs = FxIndexSet::default();

`

``

778

`+

let mut rmetas = FxIndexSet::default();

`

``

779

`+

let mut dylibs = FxIndexSet::default();

`

``

780

`+

let mut sdylib_interfaces = FxIndexSet::default();

`

781

781

`for loc in &self.exact_paths {

`

782

782

`let loc_canon = loc.canonicalized();

`

783

783

`let loc_orig = loc.original();

`

`@@ -798,21 +798,21 @@ impl<'a> CrateLocator<'a> {

`

798

798

`};

`

799

799

`if file.starts_with("lib") {

`

800

800

`if file.ends_with(".rlib") {

`

801

``

`-

rlibs.insert(loc_canon.clone(), PathKind::ExternFlag);

`

``

801

`+

rlibs.insert(loc_canon.clone());

`

802

802

`continue;

`

803

803

`}

`

804

804

`if file.ends_with(".rmeta") {

`

805

``

`-

rmetas.insert(loc_canon.clone(), PathKind::ExternFlag);

`

``

805

`+

rmetas.insert(loc_canon.clone());

`

806

806

`continue;

`

807

807

`}

`

808

808

`if file.ends_with(".rs") {

`

809

``

`-

sdylib_interfaces.insert(loc_canon.clone(), PathKind::ExternFlag);

`

``

809

`+

sdylib_interfaces.insert(loc_canon.clone());

`

810

810

`}

`

811

811

`}

`

812

812

`let dll_prefix = self.target.dll_prefix.as_ref();

`

813

813

`let dll_suffix = self.target.dll_suffix.as_ref();

`

814

814

`if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) {

`

815

``

`-

dylibs.insert(loc_canon.clone(), PathKind::ExternFlag);

`

``

815

`+

dylibs.insert(loc_canon.clone());

`

816

816

`continue;

`

817

817

`}

`

818

818

` crate_rejections

`