generator: filter out already enabled features from required feature flags

This commit is contained in:
Fabio Valentini 2023-08-06 11:14:45 +02:00
parent 7166b781bd
commit 3231fba9ba
No known key found for this signature in database
GPG key ID: 5AC5F572E5D410AF

View file

@ -163,10 +163,19 @@ def spec_render_crate(
if feature_flags.all_features or distconf.all_features:
cargo_args = " -a"
elif required_features := get_required_features_for_binaries(package):
# FIXME: remove features that are already part of the default feature set
# remove required features that are already part of the enabled feature set
enabled_by_default = package.get_enabled_features_transitive(feature_flags)[0]
for f in enabled_by_default:
if f in required_features:
required_features.remove(f)
# merge, de-duplicate, and re-sort lists of enabled features
enabled_features = sorted(set.union(set(required_features), set(distconf.enabled_features)))
cargo_args = f" -f {','.join(enabled_features)}"
if len(enabled_features) > 0:
cargo_args = f" -f {','.join(enabled_features)}"
else:
cargo_args = ""
elif distconf.enabled_features:
# list of features is already sorted when parsing the configuration file
cargo_args = f" -f {','.join(distconf.enabled_features)}"