[MacPorts] #54366: 2 variant convenience procedures

MacPorts noreply at macports.org
Thu Jun 22 10:15:56 UTC 2017


#54366: 2 variant convenience procedures
-------------------------+-----------------
 Reporter:  RJVB         |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  Normal       |  Milestone:
Component:  base         |    Version:
 Keywords:               |       Port:
-------------------------+-----------------
 Here are 2 convenience procedures for working with (mutually exclusive)
 variants which I think might be useful to include in "base". They're very
 new, so constructive feedback is welcome either way:

 {{{
 proc which_variant {args} {
     set vlist {}
     foreach v [join ${args}] {
         if {[variant_isset ${v}]} {
             set vlist [lappend vlist ${v}]
         }
     }
     return ${vlist}
 }

 proc switch_variant {args} {
     set code [lindex $args end]
     set variant [which_variant [lrange ${args} 0 end-1]]
     switch ${variant} ${code}
 }
 }}}

 Example use:

 {{{
     variant mariadb55 conflicts mysql56 mysql57 description {use MariaDB
 v5.5} {}
     variant mysql56 conflicts mariadb55 mysql57 description {use MySQL
 v5.6} {}
     variant mysql57 conflicts mariadb55 mysql56 description {use MySQL
 v5.7} {}
     # handle the depspec and set a default variant if none is requested
     switch_variant mysql56 mysql57 {
         "mysql56" -
         "mysql57" {
             depends_lib-append port:${variant}
         }
         default {
             default_variants +mariadb55
             depends_lib-append port:mariadb55
         }
     }
 }}}

 Or

 {{{
     variant mariadb55 conflicts mysql56 mysql57 description {use MariaDB
 v5.5} {}
     variant mysql56 conflicts mariadb55 mysql57 description {use MySQL
 v5.6} {}
     variant mysql57 conflicts mariadb55 mysql56 description {use MySQL
 v5.7} {}
     switch_variant mysql56 mysql57 {
         "mysql56" -
         "mysql57" {
             global qt5_dependency
             require_active_variants ${qt5_dependency} ${variant}
         }
         default {
             global qt5_dependency
             default_variants +mariadb55
             require_active_variants ${qt5_dependency} mariadb55
         }
     }
 }}}

 The 2nd example probably justifies the procedures better, probably,
 because I don't think the code in question can reliably be put directly in
 a `variant foo ... { code }` expression but needs to be evaluated "inline"
 during regular Portfile execution.
 It would be nice if there were a way to execute the `switch` statement in
 the uplevel, or if that's not feasible, a way to inject a list of global
 variable declarations (`switch_variant [-global list] variants
 codeblock`?)

--
Ticket URL: <https://trac.macports.org/ticket/54366>
MacPorts <https://www.macports.org/>
Ports system for macOS


More information about the macports-tickets mailing list