Skip to content

Commit

Permalink
refactor download_accessible in package.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
epage authored and elchukc committed Oct 30, 2024
1 parent 7ec86a1 commit 24738d8
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,18 @@ impl<'gctx> PackageSet<'gctx> {
force_all_targets: ForceAllTargets,
) -> CargoResult<()> {
fn collect_used_deps(
used: &mut BTreeSet<PackageId>,
used: &mut BTreeSet<(PackageId, CompileKind)>,
resolve: &Resolve,
pkg_id: PackageId,
has_dev_units: HasDevUnits,
requested_kinds: &[CompileKind],
requested_kind: CompileKind,
target_data: &RustcTargetData<'_>,
force_all_targets: ForceAllTargets,
) -> CargoResult<()> {
if !used.insert(pkg_id) {
if !used.insert((pkg_id, requested_kind)) {
return Ok(());
}
let requested_kinds = &[requested_kind];
let filtered_deps = PackageSet::filter_deps(
pkg_id,
resolve,
Expand All @@ -524,7 +525,7 @@ impl<'gctx> PackageSet<'gctx> {
resolve,
pkg_id,
has_dev_units,
requested_kinds,
requested_kind,
target_data,
force_all_targets,
)?;
Expand All @@ -538,16 +539,22 @@ impl<'gctx> PackageSet<'gctx> {
let mut to_download = BTreeSet::new();

for id in root_ids {
collect_used_deps(
&mut to_download,
resolve,
*id,
has_dev_units,
requested_kinds,
target_data,
force_all_targets,
)?;
for requested_kind in requested_kinds {
collect_used_deps(
&mut to_download,
resolve,
*id,
has_dev_units,
*requested_kind,
target_data,
force_all_targets,
)?;
}
}
let to_download = to_download
.into_iter()
.map(|(p, _)| p)
.collect::<BTreeSet<_>>();
self.get_many(to_download.into_iter())?;
Ok(())
}
Expand Down

0 comments on commit 24738d8

Please sign in to comment.