@@ -20,7 +20,6 @@ use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry,
20
20
use crate :: sources:: source:: QueryKind ;
21
21
use crate :: util:: errors:: CargoResult ;
22
22
use crate :: util:: interning:: InternedString ;
23
- use crate :: util:: RustVersion ;
24
23
25
24
use anyhow:: Context as _;
26
25
use std:: collections:: { BTreeSet , HashMap , HashSet } ;
@@ -32,16 +31,11 @@ pub struct RegistryQueryer<'a> {
32
31
pub registry : & ' a mut ( dyn Registry + ' a ) ,
33
32
replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
34
33
version_prefs : & ' a VersionPreferences ,
35
- /// If set the list of dependency candidates will be sorted by minimal
36
- /// versions first. That allows `cargo update -Z minimal-versions` which will
37
- /// specify minimum dependency versions to be used.
38
- minimal_versions : bool ,
39
- max_rust_version : Option < RustVersion > ,
40
- /// a cache of `Candidate`s that fulfil a `Dependency` (and whether `first_minimal_version`)
41
- registry_cache : HashMap < ( Dependency , bool ) , Poll < Rc < Vec < Summary > > > > ,
34
+ /// a cache of `Candidate`s that fulfil a `Dependency` (and whether `first_version`)
35
+ registry_cache : HashMap < ( Dependency , Option < VersionOrdering > ) , Poll < Rc < Vec < Summary > > > > ,
42
36
/// a cache of `Dependency`s that are required for a `Summary`
43
37
///
44
- /// HACK: `first_minimal_version ` is not kept in the cache key is it is 1:1 with
38
+ /// HACK: `first_version ` is not kept in the cache key is it is 1:1 with
45
39
/// `parent.is_none()` (the first element of the cache key) as it doesn't change through
46
40
/// execution.
47
41
summary_cache : HashMap <
@@ -57,15 +51,11 @@ impl<'a> RegistryQueryer<'a> {
57
51
registry : & ' a mut dyn Registry ,
58
52
replacements : & ' a [ ( PackageIdSpec , Dependency ) ] ,
59
53
version_prefs : & ' a VersionPreferences ,
60
- minimal_versions : bool ,
61
- max_rust_version : Option < & RustVersion > ,
62
54
) -> Self {
63
55
RegistryQueryer {
64
56
registry,
65
57
replacements,
66
58
version_prefs,
67
- minimal_versions,
68
- max_rust_version : max_rust_version. cloned ( ) ,
69
59
registry_cache : HashMap :: new ( ) ,
70
60
summary_cache : HashMap :: new ( ) ,
71
61
used_replacements : HashMap :: new ( ) ,
@@ -106,23 +96,20 @@ impl<'a> RegistryQueryer<'a> {
106
96
pub fn query (
107
97
& mut self ,
108
98
dep : & Dependency ,
109
- first_minimal_version : bool ,
99
+ first_version : Option < VersionOrdering > ,
110
100
) -> Poll < CargoResult < Rc < Vec < Summary > > > > {
111
- let registry_cache_key = ( dep. clone ( ) , first_minimal_version ) ;
101
+ let registry_cache_key = ( dep. clone ( ) , first_version ) ;
112
102
if let Some ( out) = self . registry_cache . get ( & registry_cache_key) . cloned ( ) {
113
103
return out. map ( Result :: Ok ) ;
114
104
}
115
105
116
106
let mut ret = Vec :: new ( ) ;
117
107
let ready = self . registry . query ( dep, QueryKind :: Exact , & mut |s| {
118
- if self . max_rust_version . is_none ( ) || s. rust_version ( ) <= self . max_rust_version . as_ref ( )
119
- {
120
- ret. push ( s) ;
121
- }
108
+ ret. push ( s) ;
122
109
} ) ?;
123
110
if ready. is_pending ( ) {
124
111
self . registry_cache
125
- . insert ( ( dep. clone ( ) , first_minimal_version ) , Poll :: Pending ) ;
112
+ . insert ( ( dep. clone ( ) , first_version ) , Poll :: Pending ) ;
126
113
return Poll :: Pending ;
127
114
}
128
115
for summary in ret. iter ( ) {
@@ -144,7 +131,7 @@ impl<'a> RegistryQueryer<'a> {
144
131
Poll :: Ready ( s) => s. into_iter ( ) ,
145
132
Poll :: Pending => {
146
133
self . registry_cache
147
- . insert ( ( dep. clone ( ) , first_minimal_version ) , Poll :: Pending ) ;
134
+ . insert ( ( dep. clone ( ) , first_version ) , Poll :: Pending ) ;
148
135
return Poll :: Pending ;
149
136
}
150
137
} ;
@@ -215,16 +202,8 @@ impl<'a> RegistryQueryer<'a> {
215
202
}
216
203
}
217
204
218
- // When we attempt versions for a package we'll want to do so in a sorted fashion to pick
219
- // the "best candidates" first. VersionPreferences implements this notion.
220
- let ordering = if first_minimal_version || self . minimal_versions {
221
- VersionOrdering :: MinimumVersionsFirst
222
- } else {
223
- VersionOrdering :: MaximumVersionsFirst
224
- } ;
225
- let first_version = first_minimal_version;
226
- self . version_prefs
227
- . sort_summaries ( & mut ret, ordering, first_version) ;
205
+ let first_version = first_version;
206
+ self . version_prefs . sort_summaries ( & mut ret, first_version) ;
228
207
229
208
let out = Poll :: Ready ( Rc :: new ( ret) ) ;
230
209
@@ -243,7 +222,7 @@ impl<'a> RegistryQueryer<'a> {
243
222
parent : Option < PackageId > ,
244
223
candidate : & Summary ,
245
224
opts : & ResolveOpts ,
246
- first_minimal_version : bool ,
225
+ first_version : Option < VersionOrdering > ,
247
226
) -> ActivateResult < Rc < ( HashSet < InternedString > , Rc < Vec < DepInfo > > ) > > {
248
227
// if we have calculated a result before, then we can just return it,
249
228
// as it is a "pure" query of its arguments.
@@ -263,24 +242,22 @@ impl<'a> RegistryQueryer<'a> {
263
242
let mut all_ready = true ;
264
243
let mut deps = deps
265
244
. into_iter ( )
266
- . filter_map (
267
- |( dep, features) | match self . query ( & dep, first_minimal_version) {
268
- Poll :: Ready ( Ok ( candidates) ) => Some ( Ok ( ( dep, candidates, features) ) ) ,
269
- Poll :: Pending => {
270
- all_ready = false ;
271
- // we can ignore Pending deps, resolve will be repeatedly called
272
- // until there are none to ignore
273
- None
274
- }
275
- Poll :: Ready ( Err ( e) ) => Some ( Err ( e) . with_context ( || {
276
- format ! (
277
- "failed to get `{}` as a dependency of {}" ,
278
- dep. package_name( ) ,
279
- describe_path_in_context( cx, & candidate. package_id( ) ) ,
280
- )
281
- } ) ) ,
282
- } ,
283
- )
245
+ . filter_map ( |( dep, features) | match self . query ( & dep, first_version) {
246
+ Poll :: Ready ( Ok ( candidates) ) => Some ( Ok ( ( dep, candidates, features) ) ) ,
247
+ Poll :: Pending => {
248
+ all_ready = false ;
249
+ // we can ignore Pending deps, resolve will be repeatedly called
250
+ // until there are none to ignore
251
+ None
252
+ }
253
+ Poll :: Ready ( Err ( e) ) => Some ( Err ( e) . with_context ( || {
254
+ format ! (
255
+ "failed to get `{}` as a dependency of {}" ,
256
+ dep. package_name( ) ,
257
+ describe_path_in_context( cx, & candidate. package_id( ) ) ,
258
+ )
259
+ } ) ) ,
260
+ } )
284
261
. collect :: < CargoResult < Vec < DepInfo > > > ( ) ?;
285
262
286
263
// Attempt to resolve dependencies with fewer candidates before trying
0 commit comments