Skip to content

Commit c36301c

Browse files
committed
make build_deps a stand alone function
1 parent a372cae commit c36301c

File tree

4 files changed

+47
-49
lines changed

4 files changed

+47
-49
lines changed

src/cargo/core/resolver/context.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ use crate::core::{Dependency, PackageId, SourceId, Summary};
1212
use crate::util::CargoResult;
1313
use crate::util::Graph;
1414

15-
use super::dep_cache;
1615
use super::dep_cache::RegistryQueryer;
17-
use super::errors::ActivateResult;
18-
use super::types::{ConflictMap, DepInfo, Method};
16+
use super::types::{ConflictMap, Method};
1917

2018
pub use super::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
2119
pub use super::encode::{Metadata, WorkspaceResolve};
@@ -150,47 +148,6 @@ impl Context {
150148
})
151149
}
152150

153-
pub fn build_deps(
154-
&mut self,
155-
registry: &mut dep_cache::RegistryQueryer<'_>,
156-
parent: Option<PackageId>,
157-
candidate: &Summary,
158-
method: &Method,
159-
) -> ActivateResult<Vec<DepInfo>> {
160-
// First, figure out our set of dependencies based on the requested set
161-
// of features. This also calculates what features we're going to enable
162-
// for our own dependencies.
163-
let (used_features, deps) = dep_cache::resolve_features(parent, candidate, method)?;
164-
165-
// Record what list of features is active for this package.
166-
if !used_features.is_empty() {
167-
Rc::make_mut(
168-
self.resolve_features
169-
.entry(candidate.package_id())
170-
.or_insert_with(Rc::default),
171-
)
172-
.extend(used_features);
173-
}
174-
175-
// Next, transform all dependencies into a list of possible candidates
176-
// which can satisfy that dependency.
177-
let mut deps = deps
178-
.into_iter()
179-
.map(|(dep, features)| {
180-
let candidates = registry.query(&dep)?;
181-
Ok((dep, candidates, Rc::new(features)))
182-
})
183-
.collect::<CargoResult<Vec<DepInfo>>>()?;
184-
185-
// Attempt to resolve dependencies with fewer candidates before trying
186-
// dependencies with more candidates. This way if the dependency with
187-
// only one candidate can't be resolved we don't have to do a bunch of
188-
// work before we figure that out.
189-
deps.sort_by_key(|&(_, ref a, _)| a.len());
190-
191-
Ok(deps)
192-
}
193-
194151
/// Returns the `ContextAge` of this `Context`.
195152
/// For now we use (len of activations) as the age.
196153
/// See the `ContextAge` docs for more details.

src/cargo/core/resolver/dep_cache.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::core::interning::InternedString;
88
use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry, Summary};
99
use crate::util::errors::CargoResult;
1010

11-
use crate::core::resolver::types::{Candidate, ConflictReason};
11+
use crate::core::resolver::types::{Candidate, ConflictReason, DepInfo};
1212
use crate::core::resolver::{ActivateResult, Method};
1313

1414
pub struct RegistryQueryer<'a> {
@@ -177,6 +177,36 @@ impl<'a> RegistryQueryer<'a> {
177177
}
178178
}
179179

180+
pub fn build_deps(
181+
registry: &mut RegistryQueryer<'_>,
182+
parent: Option<PackageId>,
183+
candidate: &Summary,
184+
method: &Method,
185+
) -> ActivateResult<(HashSet<InternedString>, Vec<DepInfo>)> {
186+
// First, figure out our set of dependencies based on the requested set
187+
// of features. This also calculates what features we're going to enable
188+
// for our own dependencies.
189+
let (used_features, deps) = resolve_features(parent, candidate, method)?;
190+
191+
// Next, transform all dependencies into a list of possible candidates
192+
// which can satisfy that dependency.
193+
let mut deps = deps
194+
.into_iter()
195+
.map(|(dep, features)| {
196+
let candidates = registry.query(&dep)?;
197+
Ok((dep, candidates, Rc::new(features)))
198+
})
199+
.collect::<CargoResult<Vec<DepInfo>>>()?;
200+
201+
// Attempt to resolve dependencies with fewer candidates before trying
202+
// dependencies with more candidates. This way if the dependency with
203+
// only one candidate can't be resolved we don't have to do a bunch of
204+
// work before we figure that out.
205+
deps.sort_by_key(|&(_, ref a, _)| a.len());
206+
207+
Ok((used_features, deps))
208+
}
209+
180210
/// Returns all dependencies and the features we want from them.
181211
pub fn resolve_features<'b>(
182212
parent: Option<PackageId>,

src/cargo/core/resolver/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,23 @@ fn activate(
682682
};
683683

684684
let now = Instant::now();
685-
let deps = cx.build_deps(
685+
let (used_features, deps) = dep_cache::build_deps(
686686
registry,
687687
parent.map(|p| p.0.package_id()),
688688
&candidate,
689689
method,
690690
)?;
691+
692+
// Record what list of features is active for this package.
693+
if !used_features.is_empty() {
694+
Rc::make_mut(
695+
cx.resolve_features
696+
.entry(candidate.package_id())
697+
.or_insert_with(Rc::default),
698+
)
699+
.extend(used_features);
700+
}
701+
691702
let frame = DepsFrame {
692703
parent: candidate,
693704
just_for_error_messages: false,

src/cargo/core/resolver/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ impl RemainingDeps {
218218
}
219219
}
220220

221-
// Information about the dependencies for a crate, a tuple of:
222-
//
223-
// (dependency info, candidates, features activated)
221+
/// Information about the dependencies for a crate, a tuple of:
222+
///
223+
/// (dependency info, candidates, features activated)
224224
pub type DepInfo = (Dependency, Rc<Vec<Candidate>>, Rc<BTreeSet<InternedString>>);
225225

226226
/// All possible reasons that a package might fail to activate.

0 commit comments

Comments
 (0)