concretizer: maximize the number of default values used for a single variant

If a the default of a multi-valued variant is set to
multiple values either in package.py or in packages.yaml
we need to ensure that all the values are present in the
concretized spec.

Since each default value has a weight of 0 and the
variant value is set implicitly by the concretizer
we need to add a rule to maximize on the number of
default values that are used.
This commit is contained in:
Massimiliano Culpo 2020-11-12 00:31:39 +01:00 committed by Todd Gamblin
parent 9a03fd2834
commit ca31f52be3
2 changed files with 17 additions and 0 deletions

View File

@ -504,6 +504,13 @@ root(Dependency, 1) :- not root(Dependency), node(Dependency).
Weight@14,Package,Variant,Value
: variant_not_default(Package, Variant, Value, Weight), root(Package)
}.
% If the value is a multivalued variant there could be multiple
% values set as default. Since a default value has a weight of 0 we
% need to maximize their number below to ensure they're all set
#maximize {
1@13,Package,Variant,Value
: variant_not_default(Package, Variant, Value, Weight), root(Package)
}.
#minimize{
Weight@13,Provider
: provider_weight(Provider, Weight), root(Provider)
@ -538,6 +545,13 @@ root(Dependency, 1) :- not root(Dependency), node(Dependency).
Weight@9,Package,Variant,Value
: variant_not_default(Package, Variant, Value, Weight), not root(Package)
}.
% If the value is a multivalued variant there could be multiple
% values set as default. Since a default value has a weight of 0 we
% need to maximize their number below to ensure they're all set
#maximize {
1@8,Package,Variant,Value
: variant_not_default(Package, Variant, Value, Weight), not root(Package)
}.
#minimize{
Weight@8,Package : version_weight(Package, Weight)
}.

View File

@ -80,6 +80,9 @@ class TestConcretizePreferences(object):
# Use different values for the variants and check them again
('mpileaks', ['+debug', '+opt', '~shared', '-static'],
{'debug': True, 'opt': True, 'shared': False, 'static': False}),
# Check a multivalued variant with multiple values set
('multivalue-variant', ['foo=bar,baz', 'fee=bar'],
{'foo': ('bar', 'baz'), 'fee': 'bar'})
])
def test_preferred_variants(
self, package_name, variant_value, expected_results