10
10
//! with version `2.0`. Since we present them to pubgrub
11
11
//! as different packages, they can both appear in the final resolution.
12
12
13
- use std:: {
14
- borrow:: Borrow ,
15
- collections:: HashMap ,
16
- path:: { Path , PathBuf } ,
17
- } ;
13
+ use std:: { borrow:: Borrow , collections:: HashMap , path:: PathBuf } ;
18
14
19
15
use nickel_lang_core:: { cache:: normalize_path, identifier:: Ident , package:: PackageMap } ;
20
16
use pubgrub:: {
21
17
report:: { DefaultStringReporter , Reporter as _} ,
22
18
solver:: DependencyProvider ,
23
- version:: { SemanticVersion , Version } ,
19
+ version:: SemanticVersion ,
24
20
} ;
25
- use semver:: Comparator ;
26
21
27
22
use crate :: {
28
23
error:: { Error , IoResultExt as _} ,
29
24
index:: { Id , IndexDependency , PackageIndex } ,
30
25
lock:: LockFile ,
31
26
manifest:: Realization ,
32
- util:: semver_to_pg,
33
- Dependency , GitDependency , IndexPrecise , ManifestFile , ObjectId , Precise , UnversionedPackage ,
34
- VersionReq ,
27
+ Dependency , IndexPrecise , ManifestFile , ObjectId , Precise , VersionReq ,
35
28
} ;
36
29
37
30
type VersionRange = pubgrub:: range:: Range < SemanticVersion > ;
@@ -104,18 +97,6 @@ impl PackageRegistry {
104
97
}
105
98
}
106
99
107
- fn bucket_versions (
108
- vs : impl Iterator < Item = SemanticVersion > ,
109
- ) -> impl Iterator < Item = SemanticVersion > {
110
- let mut vs: Vec < _ > = vs
111
- . map ( BucketVersion :: from)
112
- . map ( SemanticVersion :: from)
113
- . collect ( ) ;
114
- vs. sort ( ) ;
115
- vs. dedup ( ) ;
116
- vs. into_iter ( )
117
- }
118
-
119
100
/// A bucket version represents a collection of compatible semver versions.
120
101
#[ derive( Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
121
102
pub enum BucketVersion {
@@ -298,32 +279,25 @@ impl DependencyProvider<Package, SemanticVersion> for PackageRegistry {
298
279
let deps = self
299
280
. unversioned_deps ( p)
300
281
. into_iter ( )
301
- . map ( |dep| {
302
- match dep {
303
- Dependency :: Git ( _) | Dependency :: Path { .. } => {
304
- let dep_precise = self . realized_unversioned . dependency
305
- [ & ( precise. clone ( ) , dep. clone ( ) ) ]
306
- . clone ( ) ;
307
- (
308
- Package :: Unversioned ( dep_precise. into ( ) ) ,
309
- VersionRange :: any ( ) ,
310
- )
311
- }
312
- // We're making a proxy for every dependency on a repo package, but we could skip
313
- // the proxy if the dependency range stays within a single semver range.
314
- Dependency :: Index { id, version } => {
315
- let pkg = Package :: Bucket ( Bucket {
316
- id,
317
- version : version. clone ( ) . into ( ) ,
318
- } ) ;
319
-
320
- let range = match version {
321
- VersionReq :: Compatible ( v) => VersionRange :: higher_than ( v) ,
322
- VersionReq :: Exact ( v) => VersionRange :: exact ( v) ,
323
- } ;
324
-
325
- ( pkg, range)
326
- }
282
+ . map ( |dep| match dep {
283
+ Dependency :: Git ( _) | Dependency :: Path { .. } => {
284
+ let dep_precise = self . realized_unversioned . dependency
285
+ [ & ( precise. clone ( ) , dep. clone ( ) ) ]
286
+ . clone ( ) ;
287
+ ( Package :: Unversioned ( dep_precise) , VersionRange :: any ( ) )
288
+ }
289
+ Dependency :: Index { id, version } => {
290
+ let pkg = Package :: Bucket ( Bucket {
291
+ id,
292
+ version : version. clone ( ) . into ( ) ,
293
+ } ) ;
294
+
295
+ let range = match version {
296
+ VersionReq :: Compatible ( v) => VersionRange :: higher_than ( v) ,
297
+ VersionReq :: Exact ( v) => VersionRange :: exact ( v) ,
298
+ } ;
299
+
300
+ ( pkg, range)
327
301
}
328
302
} )
329
303
. collect ( ) ;
@@ -358,13 +332,6 @@ impl DependencyProvider<Package, SemanticVersion> for PackageRegistry {
358
332
}
359
333
}
360
334
361
- fn version_req_to_range ( req : & VersionReq ) -> pubgrub:: range:: Range < SemanticVersion > {
362
- match req {
363
- VersionReq :: Compatible ( v) => VersionRange :: higher_than ( v. clone ( ) ) ,
364
- VersionReq :: Exact ( v) => VersionRange :: exact ( v. clone ( ) ) ,
365
- }
366
- }
367
-
368
335
pub struct Resolution {
369
336
pub realization : Realization ,
370
337
pub package_map : HashMap < Id , Vec < SemanticVersion > > ,
@@ -375,12 +342,12 @@ pub fn resolve(manifest: &ManifestFile) -> Result<Resolution, Error> {
375
342
resolve_with_lock ( manifest, & LockFile :: default ( ) )
376
343
}
377
344
378
- fn previously_locked ( top_level : & Package , lock : & LockFile ) -> HashMap < Package , SemanticVersion > {
345
+ fn previously_locked ( _top_level : & Package , lock : & LockFile ) -> HashMap < Package , SemanticVersion > {
379
346
fn precise_to_index ( p : & Precise ) -> Option < IndexPrecise > {
380
347
match p {
381
348
Precise :: Index { id, version } => Some ( IndexPrecise {
382
349
id : id. clone ( ) ,
383
- version : version. clone ( ) ,
350
+ version : * version,
384
351
} ) ,
385
352
_ => None ,
386
353
}
@@ -414,11 +381,10 @@ fn previously_locked(top_level: &Package, lock: &LockFile) -> HashMap<Package, S
414
381
pub fn resolve_with_lock ( manifest : & ManifestFile , lock : & LockFile ) -> Result < Resolution , Error > {
415
382
let mut realization = Realization :: default ( ) ;
416
383
417
- // FIXME: figure out how to represent the top-level package, recalling that `realization` assumes
418
- // that every time we need to look up a dependency we need a parent package.
384
+ // TODO: this assumes that the top-level package has a path. Is there a a use-case for resolving
385
+ // packages without a top-level path?
419
386
let root_path = manifest. parent_dir . as_deref ( ) ;
420
387
for dep in manifest. dependencies . values ( ) {
421
- // FIXME: unwrap
422
388
realization. realize_all ( root_path. unwrap ( ) , dep, None ) ?;
423
389
}
424
390
let top_level = UnversionedPrecise :: Path {
@@ -449,7 +415,7 @@ pub fn resolve_with_lock(manifest: &ManifestFile, lock: &LockFile) -> Result<Res
449
415
let mut selected = HashMap :: < Id , Vec < SemanticVersion > > :: new ( ) ;
450
416
for ( pkg, vers) in resolution. iter ( ) {
451
417
if let Package :: Bucket ( Bucket { id, .. } ) = pkg {
452
- selected. entry ( id. clone ( ) ) . or_default ( ) . push ( vers. clone ( ) ) ;
418
+ selected. entry ( id. clone ( ) ) . or_default ( ) . push ( * vers) ;
453
419
}
454
420
}
455
421
Ok ( Resolution {
@@ -478,12 +444,11 @@ impl Resolution {
478
444
} ,
479
445
Dependency :: Index { id, version } => Precise :: Index {
480
446
id : id. clone ( ) ,
481
- version : self . package_map [ id]
447
+ version : * self . package_map [ id]
482
448
. iter ( )
483
449
. filter ( |v| version. matches ( v) )
484
450
. max ( )
485
- . unwrap ( )
486
- . clone ( ) ,
451
+ . unwrap ( ) ,
487
452
} ,
488
453
}
489
454
}
@@ -500,7 +465,7 @@ impl Resolution {
500
465
. collect ( )
501
466
}
502
467
Precise :: Index { id, version } => {
503
- let pkg = self . index . package ( id, version. clone ( ) ) . unwrap ( ) ;
468
+ let pkg = self . index . package ( id, * version) . unwrap ( ) ;
504
469
pkg. deps
505
470
. into_iter ( )
506
471
. map ( move |( dep_name, dep) | {
@@ -529,7 +494,7 @@ impl Resolution {
529
494
let index_precises = self . package_map . iter ( ) . flat_map ( |( id, vs) | {
530
495
vs. iter ( ) . map ( |v| Precise :: Index {
531
496
id : id. clone ( ) ,
532
- version : v . clone ( ) ,
497
+ version : * v ,
533
498
} )
534
499
} ) ;
535
500
ret. extend ( index_precises) ;
0 commit comments