default_variant and conflicts: suggestion for base
David Strubbe
dstrubbe at gmail.com
Thu Oct 3 15:33:21 PDT 2013
Hi all,
As we see at https://trac.macports.org/wiki/PortfileRecipes, the
recommended code for a default variant with one of several mutually
exclusive variants is:
if {![variant_isset q8] && ![variant_isset q32]} {
default_variants +q16
}
In this case, as in the older Fortran recipe also on that page, I would
assume that +q8, +q16, and +q32 would all be mutually conflicting.
If this is so, can't MacPorts base automatically handle the code block
above? i.e. the Portfile just says default_variants +q16 without the
if-condition and marks the conflicts for the variants, and then base would
set the default except when a conflicting variant was selected. If this is
possible, it would simplify Portfiles a bit and maybe catch some errors in
how these constructs have been manually generated.
I am not sure how this is all handled internally, but perhaps something
along these lines would work (in pseudo-ish code):
Portfile:
default_variants +q16
variant q8 conflicts q16 q32
variant q16 conflicts q8 q32
variant q32 conflicts q8 q16
base:
foreach defvar ${default_variants} {
conflicting = no
foreach var conflicts(${defvar}) {
if {[variant_isset $var]} { conflicting = yes }
}
if {$conflicting == no} { add $defvar to variants}
}
I think that this logic about conflicts and default variants is probably
always what we want, because if a variant is set by default without regard
to a conflicting variant, then that conflicting variant would never be
usable. And if there is another non-conflicting variant that should make
this variant not be set by default, then that can be easily handled with
if {![variant_isset var]} { default_variant var2 }
as before.
Moreover, it seems like always if var1 conflicts with var2, then also var2
should conflict with var1. Maybe it would be helpful to have a construct
called "conflicts_group" where one could replace
variant var1 conflicts var2
variant var2 conflicts var1
with
conflict_group var1, var2
This would be particularly helpful in cases with lots of mutually
conflicting variants, such as the gcc versions in the Fortran recipe, since
one could just list all these variants once rather than have to list all
but one for each of them.
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-dev/attachments/20131003/ffcbd887/attachment-0001.html>
More information about the macports-dev
mailing list