passing variants to dependencies; pre-activate check

Ryan Schmidt ryandesign at macports.org
Tue Oct 13 20:49:19 PDT 2015


> On Oct 13, 2015, at 10:38 PM, David Strubbe <dstrubbe at macports.org> wrote:
> 
> Would something like this be a good idea to prevent multiple definition? This could potentially be an issue with other nested portgroups too.
> 
> Index: dports/_resources/port1.0/group/active_variants-1.1.tcl
> ===================================================================
> --- dports/_resources/port1.0/group/active_variants-1.1.tcl     (revision 141271)
> +++ dports/_resources/port1.0/group/active_variants-1.1.tcl     (working copy)
> @@ -87,6 +87,12 @@
>  #     dependencies, e.g., require_active_variants path:foo/bar:standardport
>  #     variant
>  
> +default active_variants_included {}
> +
> +# only include this PortGroup once
> +if {${active_variants_included} == ""} {
> +    set active_variants_included "yes"
> +
>  proc active_variants {depspec required {forbidden {}}} {
>         # get the port which will provide $depspec; this allows us to support e.g.,
>         # path-style dependencies. This comes from port1.0/portutil.tcl and should
> @@ -278,3 +284,5 @@
>  pre-activate {
>          _check_require_active_variants activate
>  }
> +
> +}

You're right, it's probably important for portgroup to guard against multiple inclusion.

https://en.wikipedia.org/wiki/Include_guard

"port lint" will warn you if you include a portgroup more than once, but that won't check portgroup inclusion in files other than the portfile itself, can give false positives for portgroups that are included in conditionals (including subports), and even ignores lines with leading whitespace.

We should develop a standard include guard for portgroups (possibly the one you suggested) and use it in every portgroup.



More information about the macports-dev mailing list