Skip to content

Commit a031b03

Browse files
author
Jon Gjengset
committed
Remove unnecessary second download phase
1 parent c3b9f56 commit a031b03

File tree

3 files changed

+9
-30
lines changed

3 files changed

+9
-30
lines changed

src/cargo/core/package.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ impl<'cfg> PackageSet<'cfg> {
434434
self.packages.keys().cloned()
435435
}
436436

437+
pub fn packages<'a>(&'a self) -> impl Iterator<Item = &'a Package> + 'a {
438+
self.packages.values().filter_map(|p| p.borrow())
439+
}
440+
437441
pub fn enable_download<'a>(&'a self) -> CargoResult<Downloads<'a, 'cfg>> {
438442
assert!(!self.downloading.replace(true));
439443
let timeout = ops::HttpTimeout::new(self.config)?;

src/cargo/ops/cargo_output_metadata.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ fn build_resolve_graph(
126126
} else {
127127
crate::core::resolver::features::ForceAllTargets::No
128128
};
129+
130+
// Note that even with --filter-platform we end up downloading host dependencies as well,
131+
// as that is the behavior of download_accessible.
129132
let ws_resolve = ops::resolve_ws_with_opts(
130133
ws,
131134
&target_data,
@@ -136,23 +139,9 @@ fn build_resolve_graph(
136139
force_all,
137140
)?;
138141

139-
// Download all Packages. This is needed to serialize the information for every package.
140-
// Note that even with --filter-platform we end up downloading host dependencies as well,
141-
// as that is the behavior of download_accessible.
142142
let package_map: BTreeMap<PackageId, Package> = ws_resolve
143143
.pkg_set
144-
.download_accessible(
145-
&ws_resolve.targeted_resolve,
146-
&ws.members_with_features(&specs, &requested_features)?
147-
.into_iter()
148-
.map(|(p, _)| p.package_id())
149-
.collect::<Vec<_>>(),
150-
HasDevUnits::Yes,
151-
&requested_kinds,
152-
&target_data,
153-
force_all,
154-
)?
155-
.into_iter()
144+
.packages()
156145
// This is a little lazy, but serde doesn't handle Rc fields very well.
157146
.map(|pkg| (pkg.package_id(), Package::clone(pkg)))
158147
.collect();

src/cargo/ops/tree/mod.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,9 @@ pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()
167167
force_all,
168168
)?;
169169

170-
// Download all Packages. Some display formats need to display package metadata.
171-
// This may trigger some unnecessary downloads, but trying to figure out a
172-
// minimal set would be difficult.
173170
let package_map: HashMap<PackageId, &Package> = ws_resolve
174171
.pkg_set
175-
.download_accessible(
176-
&ws_resolve.targeted_resolve,
177-
&ws.members_with_features(&specs, &requested_features)?
178-
.into_iter()
179-
.map(|(p, _)| p.package_id())
180-
.collect::<Vec<_>>(),
181-
has_dev,
182-
&requested_kinds,
183-
&target_data,
184-
force_all,
185-
)?
186-
.into_iter()
172+
.packages()
187173
.map(|pkg| (pkg.package_id(), pkg))
188174
.collect();
189175

0 commit comments

Comments
 (0)