| 114 | |
| 115 | == require_active_variants == #require_active_variants |
| 116 | Depending upon a specific port variant is not possible in MacPorts: |
| 117 | The quartz variant of a graphic library cannot require automatically that the quartz variant |
| 118 | of gtk is picked. It's up to the user to issue the correct command and to the port maintainer |
| 119 | to check for the installed variant. |
| 120 | |
| 121 | There was a common practice in Portfiles to check for the presence of a file known to be provided by the wanted variant |
| 122 | and to display a message requesting the user to install the correct variant if it's missing. |
| 123 | |
| 124 | example ([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 | |
| 142 | A PortGroup has been created to simplify this: [source:trunk/dports/_resources/port1.0/group/active_variants-1.1.tcl active_variants]. |
| 143 | |
| 144 | To use it: |
| 145 | 1. add {{{ PortGroup active_variants 1.1 }}} to the top of your Portfile |
| 146 | 2. 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 | |
| 158 | Exemple with gtk-osx-application requiring gtk2+quartz or gtk3+quartz: |
| 159 | |
| 160 | {{{ |
| 161 | PortSystem 1.0 |
| 162 | PortGroup active_variants 1.1 |
| 163 | |
| 164 | (...) |
| 165 | |
| 166 | variant gtk3 conflicts python25 description {Use gtk3} { |
| 167 | |
| 168 | require_active_variants gtk3 quartz |
| 169 | |
| 170 | (...) |
| 171 | } |
| 172 | |
| 173 | if {![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 |
| 184 | Error: org.macports.configure for port gtk-osx-application returned: gtk3 must be installed with +quartz. |
| 185 | To report a bug, follow the instructions in the guide: |
| 186 | http://guide.macports.org/#project.tickets |
| 187 | Error: Processing of port gtk-osx-application failed |
| 188 | }}} |
| 189 | |
| 190 | |
| 191 | Exemple with py-cairo +x11 requiring /cairo +x11 -quartz/ ([source:trunk/dports/python/py-cairo/Portfile@106520 Portfile]) |
| 192 | and 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 | |