@@ -230,6 +230,20 @@ pub fn pkg_loc(name: &str, loc: &str) -> Summary {
230
230
. unwrap ( )
231
231
}
232
232
233
+ pub fn remove_dep ( sum : & Summary , ind : usize ) -> Summary {
234
+ let mut deps = sum. dependencies ( ) . to_vec ( ) ;
235
+ deps. remove ( ind) ;
236
+ // note: more things will need to be copied over in the future, but it works for now.
237
+ Summary :: new (
238
+ sum. package_id ( ) ,
239
+ deps,
240
+ & BTreeMap :: < String , Vec < String > > :: new ( ) ,
241
+ sum. links ( ) . map ( |a| a. as_str ( ) ) ,
242
+ sum. namespaced_features ( ) ,
243
+ )
244
+ . unwrap ( )
245
+ }
246
+
233
247
pub fn dep ( name : & str ) -> Dependency {
234
248
dep_req ( name, "*" )
235
249
}
@@ -400,67 +414,78 @@ pub fn registry_strategy(
400
414
401
415
let list_of_raw_dependency = vec ( raw_dependency, ..=max_deps) ;
402
416
403
- ( list_of_crates_with_versions, list_of_raw_dependency) . prop_map (
404
- |( crate_vers_by_name, raw_dependencies) | {
405
- let list_of_pkgid: Vec < _ > = crate_vers_by_name
406
- . iter ( )
407
- . flat_map ( |( name, vers) | vers. iter ( ) . map ( move |x| ( ( name. as_str ( ) , & x. 0 ) , x. 1 ) ) )
408
- . collect ( ) ;
409
- let len_all_pkgid = list_of_pkgid. len ( ) ;
410
- let mut dependency_by_pkgid = vec ! [ vec![ ] ; len_all_pkgid] ;
411
- for ( a, b, ( c, d) , k) in raw_dependencies {
412
- let ( a, b) = order_index ( a, b, len_all_pkgid) ;
413
- let ( ( dep_name, _) , _) = list_of_pkgid[ a] ;
414
- if ( list_of_pkgid[ b] . 0 ) . 0 == dep_name {
415
- continue ;
416
- }
417
- let s = & crate_vers_by_name[ dep_name] ;
418
- let s_last_index = s. len ( ) - 1 ;
419
- let ( c, d) = order_index ( c, d, s. len ( ) ) ;
420
-
421
- dependency_by_pkgid[ b] . push ( dep_req_kind (
422
- & dep_name,
423
- & if c == 0 && d == s_last_index {
424
- "*" . to_string ( )
425
- } else if c == 0 {
426
- format ! ( "<={}" , s[ d] . 0 )
427
- } else if d == s_last_index {
428
- format ! ( ">={}" , s[ c] . 0 )
429
- } else if c == d {
430
- format ! ( "={}" , s[ c] . 0 )
431
- } else {
432
- format ! ( ">={}, <={}" , s[ c] . 0 , s[ d] . 0 )
433
- } ,
434
- match k {
435
- 0 => Kind :: Normal ,
436
- 1 => Kind :: Build ,
437
- // => Kind::Development, // Development has not impact so don't gen
438
- _ => panic ! ( "bad index for Kind" ) ,
439
- } ,
440
- ) )
441
- }
417
+ // By default a package depends only on other packages that have a smaller name,
418
+ // this helps make sure that all things in the resulting index are DAGs.
419
+ // If this is true then the DAG is maintained with grater instead.
420
+ let reverse_alphabetical = any :: < bool > ( ) . no_shrink ( ) ;
442
421
443
- PrettyPrintRegistry (
444
- list_of_pkgid
445
- . into_iter ( )
446
- . zip ( dependency_by_pkgid. into_iter ( ) )
447
- . map ( |( ( ( name, ver) , allow_deps) , deps) | {
448
- pkg_dep (
449
- ( name, ver) . to_pkgid ( ) ,
450
- if !allow_deps {
451
- vec ! [ dep_req( "bad" , "*" ) ]
452
- } else {
453
- let mut deps = deps;
454
- deps. sort_by_key ( |d| d. name_in_toml ( ) ) ;
455
- deps. dedup_by_key ( |d| d. name_in_toml ( ) ) ;
456
- deps
457
- } ,
458
- )
459
- } )
460
- . collect ( ) ,
461
- )
462
- } ,
422
+ (
423
+ list_of_crates_with_versions,
424
+ list_of_raw_dependency,
425
+ reverse_alphabetical,
463
426
)
427
+ . prop_map (
428
+ |( crate_vers_by_name, raw_dependencies, reverse_alphabetical) | {
429
+ let list_of_pkgid: Vec < _ > = crate_vers_by_name
430
+ . iter ( )
431
+ . flat_map ( |( name, vers) | vers. iter ( ) . map ( move |x| ( ( name. as_str ( ) , & x. 0 ) , x. 1 ) ) )
432
+ . collect ( ) ;
433
+ let len_all_pkgid = list_of_pkgid. len ( ) ;
434
+ let mut dependency_by_pkgid = vec ! [ vec![ ] ; len_all_pkgid] ;
435
+ for ( a, b, ( c, d) , k) in raw_dependencies {
436
+ let ( a, b) = order_index ( a, b, len_all_pkgid) ;
437
+ let ( a, b) = if reverse_alphabetical { ( b, a) } else { ( a, b) } ;
438
+ let ( ( dep_name, _) , _) = list_of_pkgid[ a] ;
439
+ if ( list_of_pkgid[ b] . 0 ) . 0 == dep_name {
440
+ continue ;
441
+ }
442
+ let s = & crate_vers_by_name[ dep_name] ;
443
+ let s_last_index = s. len ( ) - 1 ;
444
+ let ( c, d) = order_index ( c, d, s. len ( ) ) ;
445
+
446
+ dependency_by_pkgid[ b] . push ( dep_req_kind (
447
+ & dep_name,
448
+ & if c == 0 && d == s_last_index {
449
+ "*" . to_string ( )
450
+ } else if c == 0 {
451
+ format ! ( "<={}" , s[ d] . 0 )
452
+ } else if d == s_last_index {
453
+ format ! ( ">={}" , s[ c] . 0 )
454
+ } else if c == d {
455
+ format ! ( "={}" , s[ c] . 0 )
456
+ } else {
457
+ format ! ( ">={}, <={}" , s[ c] . 0 , s[ d] . 0 )
458
+ } ,
459
+ match k {
460
+ 0 => Kind :: Normal ,
461
+ 1 => Kind :: Build ,
462
+ // => Kind::Development, // Development has not impact so don't gen
463
+ _ => panic ! ( "bad index for Kind" ) ,
464
+ } ,
465
+ ) )
466
+ }
467
+
468
+ PrettyPrintRegistry (
469
+ list_of_pkgid
470
+ . into_iter ( )
471
+ . zip ( dependency_by_pkgid. into_iter ( ) )
472
+ . map ( |( ( ( name, ver) , allow_deps) , deps) | {
473
+ pkg_dep (
474
+ ( name, ver) . to_pkgid ( ) ,
475
+ if !allow_deps {
476
+ vec ! [ dep_req( "bad" , "*" ) ]
477
+ } else {
478
+ let mut deps = deps;
479
+ deps. sort_by_key ( |d| d. name_in_toml ( ) ) ;
480
+ deps. dedup_by_key ( |d| d. name_in_toml ( ) ) ;
481
+ deps
482
+ } ,
483
+ )
484
+ } )
485
+ . collect ( ) ,
486
+ )
487
+ } ,
488
+ )
464
489
}
465
490
466
491
/// This test is to test the generator to ensure
0 commit comments