On Thu, May 16, 2019 at 12:01:44PM -0700, Andrew Hewus Fresh wrote:
> Moving this off of tech@ because I doubt anyone there cares. 
> 
> On Mon, May 13, 2019 at 07:37:36AM +0100, Stuart Henderson wrote:
> > As far as plists go, unless the port only supports py2 or only supports py3,
> > it ought to generate the plist with FLAVOR=python3 and then prefix any lines
> > ending in ${MODPY_PYCACHE}/ with ${MODPY_COMMENT}.
> 
> Anyway, Kurt helped me realize that it would be much nicer if
> update-plist handled the MODPY_COMMENT magic and so here's a patch that
> does that.
> 
> It also fixes a possible oversight to call $context->adjust even if we
> don't have anything to unsubst, which means that brand-new PLISTs now
> get the trailing slash on MODPY_PYCACHE directories and not just after a
> second update-plist.
> 
> However, this "feels" ugly so I'm not sure if this is the best place for
> this code.  Perhaps it needs a post-plist target, I don't think that
> hook exists though.
> 
> I'm also not sure if there's a way to tell python.port.mk to use the
> pthon3 FLAVOR (if it exists) when doing update-plist automatically, but
> that would be more helpful than the special case in portgen.
> 
> 
> Index: infrastructure/lib/OpenBSD/ReverseSubst.pm
> ===================================================================
> RCS file: /cvs/ports/infrastructure/lib/OpenBSD/ReverseSubst.pm,v
> retrieving revision 1.18
> diff -u -p -r1.18 ReverseSubst.pm
> --- infrastructure/lib/OpenBSD/ReverseSubst.pm        4 Sep 2018 12:41:51 
> -0000       1.18
> +++ infrastructure/lib/OpenBSD/ReverseSubst.pm        16 May 2019 18:37:46 
> -0000
> @@ -127,6 +127,16 @@ sub adjust
>  {
>       my ($self, $rstring) = @_;
>       $$rstring =~ s,([^/])$,$1/,;
> +
> +     # Python 3 modules use a MODPY_PYCACHE subdirectory for their
> +     # pyc files, however python 2 this directory doesn't exist.
> +     # That means for python 2 we have two elements with the same name
> +     # and things blow up.  To get around that, the python 2 flavored
> +     # ports set MODPY_COMMENT to @comment to comment out the line.
> +     if ( $$rstring =~ m</\$\Q{MODPY_PYCACHE}/> ) {
> +             my $comment = '${MODPY_COMMENT}';
> +             $$rstring =~ s<^(?:\Q$comment\E)?><$comment>;
> +     }
>  }
>  
>  package Forwarder;
> @@ -354,25 +364,27 @@ sub do_backsubst
>       }
>  
>       # we can't do empty subst without an unsubst;
> -     return $string unless defined $unsubst;
> -
> -     # this part will be done repeatedly
> -     my $old;
> -     do {
> -             $old = $string;
> -             for my $k (@{$subst->{lempty}}) {
> -                     my $k2 = $k;
> -                     $k2 =~ s/^\^//;
> -                     if ($unsubst =~ m/^(.*)\$\{$k2\}/) {
> -                             my $prefix = $1;
> -                             # XXX avoid infinite loop
> -                             next if $string =~ m/\Q$prefix\E\$\{\Q$k2\E\}/;
> -                             $string =~ s/^\Q$prefix\E/$prefix\$\{$k2\}/;
> +     if ($unsubst) {
> +             # this part will be done repeatedly
> +             my $old;
> +             do {
> +                     $old = $string;
> +                     for my $k (@{$subst->{lempty}}) {
> +                             my $k2 = $k;
> +                             $k2 =~ s/^\^//;
> +                             if ($unsubst =~ m/^(.*)\$\{$k2\}/) {
> +                                     my $prefix = $1;
> +                                     # XXX avoid infinite loop
> +                                     next if $string =~ 
> m/\Q$prefix\E\$\{\Q$k2\E\}/;
> +                                     $string =~ 
> s/^\Q$prefix\E/$prefix\$\{$k2\}/;
> +                             }
> +                             # TODO we could also try based on suffixes ?
>                       }
> -                     # TODO we could also try based on suffixes ?
> -             }
> -     } while ($old ne $string);
> +             } while ($old ne $string);
> +     }
> +
>       $context->adjust(\$string);
> +
>       return $string;
>  }
>  
I'll have a closer look. 

I'm not comfortable with the update-plist part for various reasons.

One being that I would very much like not to add special cases like
these.  It should probably be redone so as to feel more generic.

(I've done most changes to specific variables as update-plist args recently)

Reply via email to