Changes between Version 66 and Version 67 of PortfileRecipes


Ignore:
Timestamp:
Aug 14, 2013, 7:13:56 AM (11 years ago)
Author:
elelay (Eric Le Lay)
Comment:

document the require_active_variants portgroup

Legend:

Unmodified
Added
Removed
Modified
  • PortfileRecipes

    v66 v67  
    112112
    113113Formerly, use of negatively-named variants (like `no_x11`) was preferred to having a default positively-named variant (like `x11`), due to a deficiency in the port registry (ticket #2377). Now that this is fixed, use of negatively-named variants should be avoided.
     114
     115== require_active_variants == #require_active_variants
     116Depending upon a specific port variant is not possible in MacPorts:
     117The quartz variant of a graphic library cannot require automatically that the quartz variant
     118of gtk is picked. It's up to the user to issue the correct command and to the port maintainer
     119to check for the installed variant.
     120
     121There was a common practice in Portfiles to check for the presence of a file known to be provided by the wanted variant
     122and to display a message requesting the user to install the correct variant if it's missing.
     123
     124example ([source:trunk/dports/devel/gtk-osx-application/Portfile@109119 gtk-osx-application])
     125{{{
     126   pre-configure {
     127        if {![file exists ${prefix}/lib/pkgconfig/gdk-quartz-3.0.pc]} {
     128            ui_error "
     129
     130****
     131**** gtk-osx-application is meant to be used only in a GTK3 quartz
     132**** development environment but your version of GTK3 does not
     133**** support quartz.  Please make sure that port gtk3 and all its
     134**** dependencies are built with variants +no_x11 +quartz and try again.
     135****
     136"
     137            error "gtk3 +no_x11 +quartz not installed."
     138        }
     139    }
     140}}}
     141
     142A PortGroup has been created to simplify this: [source:trunk/dports/_resources/port1.0/group/active_variants-1.1.tcl active_variants].
     143
     144To use it:
     1451. add {{{ PortGroup       active_variants 1.1 }}} to the top of your Portfile
     1462. add {{{ require_active_variants $depspec $required $forbidden}}}
     147   where
     148  $depspec:: is the name of the port you're trying to check (required), which can be
     149    specified as either just the port, or via "(bin:lib:path):FOO:port"
     150    as accepted by the dependency parser.
     151  $required:: is a list of variants that must be enabled for the test to succeed
     152    (required; remember this can also be a space-separated string or just
     153    a string for a single value. It's iterpreted as list, though.)
     154  $forbidden:: is a list of variants that may not be enabled for the test to succeed
     155    (default is empty list, see description of $required for values that can be
     156    interpreted as list by Tcl)
     157
     158Exemple with gtk-osx-application requiring gtk2+quartz or gtk3+quartz:
     159
     160{{{
     161PortSystem 1.0
     162PortGroup  active_variants 1.1
     163
     164(...)
     165
     166variant gtk3 conflicts python25 description {Use gtk3} {
     167   
     168    require_active_variants gtk3 quartz
     169   
     170    (...)
     171}
     172
     173if {![variant_isset gtk3]} {
     174
     175    require_active_variants gtk2 quartz
     176
     177    (...)
     178}
     179}}}
     180
     181{{{sudo port install gtk-osx-application +gtk3}}} results in
     182{{{
     183--->  Configuring gtk-osx-application
     184Error: org.macports.configure for port gtk-osx-application returned: gtk3 must be installed with +quartz.
     185To report a bug, follow the instructions in the guide:
     186    http://guide.macports.org/#project.tickets
     187Error: Processing of port gtk-osx-application failed
     188}}}
     189
     190
     191Exemple with py-cairo +x11 requiring /cairo +x11 -quartz/ ([source:trunk/dports/python/py-cairo/Portfile@106520 Portfile])
     192and selecting a default variant based on the variants of a cairo:
     193{{{
     194    variant x11 {
     195        require_active_variants path:lib/pkgconfig/cairo.pc:cairo x11 quartz
     196    }
     197
     198    if {![catch {set result [active_variants path:lib/pkgconfig/cairo.pc:cairo x11 quartz]}]} {
     199        if {$result} {
     200            default_variants +x11
     201        }
     202    } else {
     203        default_variants +x11
     204    }
     205}}}
     206
    114207
    115208== cvs/svn/git tag for consistency == #checkout_tag