@@ -56,11 +56,12 @@ 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
- activated_features : ActivateMap ,
60
- /// Optional dependencies that should be built.
59
+ /// Map of features activated for each package.
61
60
///
62
- /// The value is the `name_in_toml` of the dependencies.
63
- activated_dependencies : ActivateMap ,
61
+ /// The presence of each key also means the package itself is activated,
62
+ /// even its associated set contains no features.
63
+ activated_features : ActivateMap ,
64
+ /// Options that change how the feature resolver operates.
64
65
opts : FeatureOpts ,
65
66
}
66
67
@@ -321,21 +322,14 @@ impl ResolvedFeatures {
321
322
. expect ( "activated_features for invalid package" )
322
323
}
323
324
324
- /// Returns if the given dependency should be included.
325
+ /// Asks the resolved features if the given package should be included.
325
326
///
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 )
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 ( )
339
333
}
340
334
341
335
/// Variant of `activated_features` that returns `None` if this is
@@ -415,8 +409,14 @@ pub struct FeatureResolver<'a, 'cfg> {
415
409
/// Options that change how the feature resolver operates.
416
410
opts : FeatureOpts ,
417
411
/// 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.
418
415
activated_features : ActivateMap ,
419
416
/// 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,7 +475,6 @@ 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 ,
479
478
opts : r. opts ,
480
479
} )
481
480
}
@@ -507,20 +506,24 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
507
506
Ok ( ( ) )
508
507
}
509
508
510
- /// Activates [`FeatureValue`]s on the given package.
509
+ /// Activates a list of [`FeatureValue`] for a given package.
511
510
///
512
- /// This is the main entrance into the recursion of feature activation
513
- /// for a package .
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 .
514
513
fn activate_pkg (
515
514
& mut self ,
516
515
pkg_id : PackageId ,
517
516
fk : FeaturesFor ,
518
517
fvs : & [ FeatureValue ] ,
519
518
) -> CargoResult < ( ) > {
520
519
log:: trace!( "activate_pkg {} {}" , pkg_id. name( ) , fk) ;
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.
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`.
524
527
self . activated_features
525
528
. entry ( ( pkg_id, fk. apply_opts ( & self . opts ) ) )
526
529
. or_insert_with ( BTreeSet :: new) ;
0 commit comments