@@ -56,12 +56,11 @@ type ActivateMap = HashMap<PackageFeaturesKey, BTreeSet<InternedString>>;
56
56
57
57
/// Set of all activated features for all packages in the resolve graph.
58
58
pub struct ResolvedFeatures {
59
- /// Map of features activated for each package.
60
- ///
61
- /// The presence of each key also means the package itself is activated,
62
- /// even its associated set contains no features.
63
59
activated_features : ActivateMap ,
64
- /// Options that change how the feature resolver operates.
60
+ /// Optional dependencies that should be built.
61
+ ///
62
+ /// The value is the `name_in_toml` of the dependencies.
63
+ activated_dependencies : ActivateMap ,
65
64
opts : FeatureOpts ,
66
65
}
67
66
@@ -322,14 +321,21 @@ impl ResolvedFeatures {
322
321
. expect ( "activated_features for invalid package" )
323
322
}
324
323
325
- /// Asks the resolved features if the given package should be included.
324
+ /// Returns if the given dependency should be included.
326
325
///
327
- /// One scenario to use this function is to deteremine a optional dependency
328
- /// should be built or not.
329
- pub fn is_activated ( & self , pkg_id : PackageId , features_for : FeaturesFor ) -> bool {
330
- log:: trace!( "is_activated {} {features_for}" , pkg_id. name( ) ) ;
331
- self . activated_features_unverified ( pkg_id, features_for. apply_opts ( & self . opts ) )
332
- . is_some ( )
326
+ /// This handles dependencies disabled via `cfg` expressions and optional
327
+ /// dependencies which are not enabled.
328
+ pub fn is_dep_activated (
329
+ & self ,
330
+ pkg_id : PackageId ,
331
+ features_for : FeaturesFor ,
332
+ dep_name : InternedString ,
333
+ ) -> bool {
334
+ let key = features_for. apply_opts ( & self . opts ) ;
335
+ self . activated_dependencies
336
+ . get ( & ( pkg_id, key) )
337
+ . map ( |deps| deps. contains ( & dep_name) )
338
+ . unwrap_or ( false )
333
339
}
334
340
335
341
/// Variant of `activated_features` that returns `None` if this is
@@ -409,14 +415,8 @@ pub struct FeatureResolver<'a, 'cfg> {
409
415
/// Options that change how the feature resolver operates.
410
416
opts : FeatureOpts ,
411
417
/// Map of features activated for each package.
412
- ///
413
- /// The presence of each key also means the package itself is activated,
414
- /// even its associated set contains no features.
415
418
activated_features : ActivateMap ,
416
419
/// Map of optional dependencies activated for each package.
417
- ///
418
- /// The key is the package having their dependencies activated.
419
- /// The value comes from `dep_name` part of the feature syntax `dep:dep_name`.
420
420
activated_dependencies : ActivateMap ,
421
421
/// Keeps track of which packages have had its dependencies processed.
422
422
/// Used to avoid cycles, and to speed up processing.
@@ -475,6 +475,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
475
475
}
476
476
Ok ( ResolvedFeatures {
477
477
activated_features : r. activated_features ,
478
+ activated_dependencies : r. activated_dependencies ,
478
479
opts : r. opts ,
479
480
} )
480
481
}
@@ -506,24 +507,20 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
506
507
Ok ( ( ) )
507
508
}
508
509
509
- /// Activates a list of [`FeatureValue`] for a given package.
510
+ /// Activates [`FeatureValue`]s on the given package.
510
511
///
511
- /// This is the main entrance into the recursion of feature activation for a package.
512
- /// Other `activate_*` functions would be called inside this function accordingly .
512
+ /// This is the main entrance into the recursion of feature activation
513
+ /// for a package .
513
514
fn activate_pkg (
514
515
& mut self ,
515
516
pkg_id : PackageId ,
516
517
fk : FeaturesFor ,
517
518
fvs : & [ FeatureValue ] ,
518
519
) -> CargoResult < ( ) > {
519
520
log:: trace!( "activate_pkg {} {}" , pkg_id. name( ) , fk) ;
520
- // Cargo must insert an empty set here as the presence of an (empty) set
521
- // also means that the dependency is activated.
522
- // This `is_activated` behavior for dependencies was previously depends on field
523
- // `activated_dependencies`, which is less useful after rust-lang/cargo#11183.
524
- //
525
- // That is, we may keep or remove `activated_dependencies` in the future
526
- // if figuring out it can completely be replaced with `activated_features`.
521
+ // Add an empty entry to ensure everything is covered. This is intended for
522
+ // finding bugs where the resolver missed something it should have visited.
523
+ // Remove this in the future if `activated_features` uses an empty default.
527
524
self . activated_features
528
525
. entry ( ( pkg_id, fk. apply_opts ( & self . opts ) ) )
529
526
. or_insert_with ( BTreeSet :: new) ;
0 commit comments