51 | | == variant_isset doesn't work when variant is set == #variant_isset |
52 | | Make sure you have the variant defined, even if it is empty, in the Portfile. If all you need is to do something when the variant is set and not dedicate an entire variant section to it, variant_isset can work but you must still define the variant (or platform for things like darwin, darwin_9, etc). So just add |
53 | | {{{ |
54 | | variant myvariant { |
55 | | } |
56 | | }}} |
57 | | or |
58 | | {{{ |
59 | | platform darwin 9 { |
60 | | } |
61 | | }}} |
62 | | Then port will set the variant when selected and variant_isset should work. |
63 | | |
| 51 | == variant_isset requires the variant to exist == #variant_isset |
| 52 | Normally you write the code for a variant inside the variant declaration: |
| 53 | |
| 54 | {{{ |
| 55 | variant my_variant description {Variant description} { |
| 56 | ... |
| 57 | post-destroot { |
| 58 | [post-destroot code for when the variant is set] |
| 59 | } |
| 60 | } |
| 61 | }}} |
| 62 | |
| 63 | Sometimes it's more natural to include the variant's code in other sections of the Portfile by checking if the variant is (or is not) set: |
| 64 | |
| 65 | {{{ |
| 66 | post-destroot { |
| 67 | ... |
| 68 | if {![variant_isset my_variant]} { |
| 69 | [post-destroot code for when the variant is not set] |
| 70 | } |
| 71 | } |
| 72 | }}} |
| 73 | |
| 74 | This is fine, but if you do it this way, you must ensure the variant is still defined in your Portfile, even if it is empty: |
| 75 | |
| 76 | {{{ |
| 77 | variant my_variant description {Variant description} {} |
| 78 | }}} |