tl;dr, fixes portgen(1) for python modules that have distnames that
start with py-.


I'm not quite sure why things were done this way, I'm assuming it was
for ruby, but it was getting us into a loop that unsurprisingly confuses
the ports system.

$ portgen py py-cpuinfo                                    
Problem with variable expansion chain: FULLPKGNAME -> PKGNAME -> DISTNAME -> 
PKGNAME
        Variable PKGNAME is recursive.

and we get this, which is definitely not right:
DISTNAME =      py-${PKGNAME}
PKGNAME =       py-${DISTNAME}

With this patch, we instead get the much better looking:
DISTNAME =      py-cpuinfo-${MODPY_EGG_VERSION}
(and no PKGNAME line)

The different languages all handle the prefix slightly differently. Ruby
ports don't include a prefix on the PKGNAME, only the FULLPKGNAME. While
perl ports get p5- on the PKGNAME automatically. Python ports
specify py- manually which is converted to py3- for the FULLPKGNAME of
he python3 FLAVOR.

Since ruby ports don't expect `ruby-` to be part of the PKGNAME I
patched Ruby.pm to strip it if necessary.  There are 9 ports I found
where DISTNAME starts with ruby- and four of them strip it from PKGNAME
and set DISTNAME=ruby-${PKGNAME} while the other five set
PKGNAME=${DISTNAME:S/^ruby-//}, so I used the easier one that is used
more times.  Tested with ruby-hmac and at least the DISTNAME/PKGNAME
seem right.  We could fix it in ruby.port.mk to default PKGNAME to
${DISTNAME:S/^ruby-//}, but not sure it's that important.

A perl DISTNAME that starts with p5- will cause it to create a PKGNAME
that starts with a duplicated p5-p5-, but I didn't find anything in-tree
that has that and although I'm not sure if it's required by the CPAN,
the dist's name is, at least by convention, the same as the main module
with the "::" converted to "-".  I'd probably fix that in cpan.port.mk
by changing to `PKGNAME ?= p5-${DISTNAME:S/^p5-//}`.

We could probably remove a lot of `PKGNAME = py-${DISTNAME}` lines from
the Makefiles with a `PKGNAME ?= py-${DISTNAME:S/^py-//}` in python.port.mk.
$ grep -l 'py-${DISTNAME}' /usr/ports/*/py-*/Makefile | wc -l
     324


OK?


Index: infrastructure/lib/OpenBSD/PortGen/Port.pm
===================================================================
RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Port.pm,v
retrieving revision 1.4
diff -u -p -r1.4 Port.pm
--- infrastructure/lib/OpenBSD/PortGen/Port.pm  2 May 2017 11:30:03 -0000       
1.4
+++ infrastructure/lib/OpenBSD/PortGen/Port.pm  21 Apr 2019 01:47:25 -0000
@@ -115,15 +115,7 @@ sub set_distname
 {
        my ( $self, $distname ) = @_;
 
-       my $prefix = $self->ecosystem_prefix();
-
-       # use foo-bar instead of foo-foo-bar as PKGNAME
-       if ( $distname =~ /^$prefix/ ) {
-               $self->{PKGNAME}  = ( $distname =~ s/^$prefix//r );
-               $self->{DISTNAME} = $prefix . '${PKGNAME}';
-       } else {
-               $self->{DISTNAME} = $distname;
-       }
+       $self->{DISTNAME} = $distname;
 }
 
 sub set_license
Index: infrastructure/lib/OpenBSD/PortGen/Port/PyPI.pm
===================================================================
RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Port/PyPI.pm,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 PyPI.pm
--- infrastructure/lib/OpenBSD/PortGen/Port/PyPI.pm     18 Jan 2016 18:08:20 
-0000      1.1.1.1
+++ infrastructure/lib/OpenBSD/PortGen/Port/PyPI.pm     21 Apr 2019 01:47:25 
-0000
@@ -66,7 +66,8 @@ sub fill_in_makefile
        $self->set_comment( $di->{info}{summary} );
        $self->set_other( 'MODPY_EGG_VERSION', $di->{info}{version} );
        $self->set_distname( "$di->{info}{name}" . '-${MODPY_EGG_VERSION}' );
-       $self->set_other( 'PKGNAME', 'py-${DISTNAME}' );
+       $self->set_other( 'PKGNAME', 'py-${DISTNAME}' )
+           unless $di->{info}->{name} =~ /^py-/;
        $self->set_modules('lang/python');
        $self->set_categories('pypi');
        $self->set_other( 'HOMEPAGE', $di->{info}{home_page} );
Index: infrastructure/lib/OpenBSD/PortGen/Port/Ruby.pm
===================================================================
RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Port/Ruby.pm,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 Ruby.pm
--- infrastructure/lib/OpenBSD/PortGen/Port/Ruby.pm     18 Jan 2016 18:08:20 
-0000      1.1.1.1
+++ infrastructure/lib/OpenBSD/PortGen/Port/Ruby.pm     21 Apr 2019 01:47:25 
-0000
@@ -69,6 +69,8 @@ sub fill_in_makefile
 
        $self->set_comment( $vi->{summary} );
        $self->set_distname("$di->{name}-$di->{version}");
+       $self->set_other( 'PKGNAME', '${DISTNAME:S/ruby-//}' )
+           if $di->{name} =~ /^ruby-/;
        $self->set_modules('lang/ruby');
        $self->set_categories('ruby');
        $self->set_other( 'HOMEPAGE', $di->{homepage_uri} );

Reply via email to