On Mon, May 13, 2019 at 11:49:02PM +0200, Charlene Wendling wrote:
> On Mon, 13 May 2019 13:46:46 -0700
> Andrew Hewus Fresh <[email protected]> wrote:
> 
> > This should make portgen(1) recognize the EXTRACT_CASES in
> > bsd.port.mk(5) and set EXTRACT_SUFX correctly.
> > 
> > Anyway, Comments, OKs?
> 
> I tested against various Perl and Python ports that have EXTRACT_SUFX:
> it works well (but many of them moved to tar.gz with updated versions).
> 
> OK cwen@ but 

So, cwen@ pointed out that if we switched from something else to .tar.gz
for the EXTRACT_SUFX, as in x11/py-kiwi or net/p5-Net-Ping-External,
instead of removing it we would copy the now wrong one to the new port,
which we don't want.

How about like this?


Index: infrastructure/lib/OpenBSD/PortGen/Port.pm
===================================================================
RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Port.pm,v
retrieving revision 1.15
diff -u -p -r1.15 Port.pm
--- infrastructure/lib/OpenBSD/PortGen/Port.pm  13 May 2019 01:30:05 -0000      
1.15
+++ infrastructure/lib/OpenBSD/PortGen/Port.pm  13 May 2019 22:31:11 -0000
@@ -132,6 +132,38 @@ sub set_pkgname {
        $self->{PKGNAME} = $pkgname;
 }
 
+sub pick_distfile
+{
+       my ( $self, @files ) = @_;
+
+       my ($distname, $ext);
+       foreach my $filename (@files) {
+               # from EXTRACT_CASES
+               ($distname, $ext) = $filename =~ /^(.*)(\.(?:
+                   tar\.xz  | tar\.lzma
+                 | tar\.lz
+                 | zip
+                 | tar\.bz2 | tbz2    | tbz
+                 | shar\.gz | shar\.Z | sh\.Z | sh\.gz
+                 | shar     | shar\.sh
+                 | tar
+                 | tar\.gz  | tgz
+               ))$/xms;
+
+               next unless $ext;
+
+               # These are our preferred suffixes
+               if ( $ext eq '.tar.gz' or $ext eq '.tgz' or $ext eq '.tar' ) {
+                       last;
+               }
+       }
+
+       $self->add_notice("Failed to pick a distname from @files") unless 
$distname;
+
+       $self->set_other( EXTRACT_SUFX => $ext ) if $ext;
+       return $self->set_distname($distname);
+}
+
 sub set_distname
 {
        my ( $self, $distname ) = @_;
@@ -283,6 +315,7 @@ sub write_makefile
        if (@template) {
                %copy_values = map { $_->{key} => 1 }
                    grep { $_->{name} ne 'REVISION' }
+                   grep { $_->{name} ne 'EXTRACT_SUFX' }
                    grep { ref } @template;
        } else {
                my $tag = 'OpenBSD';
@@ -304,6 +337,10 @@ sub write_makefile
                sort { $equals{$b} <=> $equals{$a} } keys %equals;
        };
        $default_equal ||= ' =';
+
+       # If we got an EXTRACT_SUFX, we don't need to print the default
+       delete $configs{EXTRACT_SUFX}
+           if $configs{EXTRACT_SUFX} and $configs{EXTRACT_SUFX} eq '.tar.gz';
 
        my @makefile;
        foreach my $line (@template) {
Index: infrastructure/lib/OpenBSD/PortGen/Port/CPAN.pm
===================================================================
RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Port/CPAN.pm,v
retrieving revision 1.7
diff -u -p -r1.7 CPAN.pm
--- infrastructure/lib/OpenBSD/PortGen/Port/CPAN.pm     11 May 2019 19:36:27 
-0000      1.7
+++ infrastructure/lib/OpenBSD/PortGen/Port/CPAN.pm     13 May 2019 22:31:11 
-0000
@@ -182,7 +182,7 @@ sub fill_in_makefile
        my ( $self, $di, $vi ) = @_;
 
        $self->set_comment( $di->{abstract} );
-       $self->set_distname( $di->{name} );
+       $self->pick_distfile( $di->{archive} );
        $self->set_license(
                $di->{metadata}->{license}[0] eq 'unknown'
                ? ''
@@ -192,12 +192,6 @@ sub fill_in_makefile
 
        $self->set_other( 'CPAN_AUTHOR', $di->{author} )
            if $self->needs_author($di);
-
-       my ($sufx) = $di->{archive} =~ /(\.[\.A-Za-z]+)$/;
-
-       if ( defined $sufx and $sufx ne '.tar.gz' ) {
-               $self->set_other( 'EXTRACT_SUFX', $sufx );
-       }
 }
 
 sub postextract
Index: infrastructure/lib/OpenBSD/PortGen/Port/PyPI.pm
===================================================================
RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Port/PyPI.pm,v
retrieving revision 1.12
diff -u -p -r1.12 PyPI.pm
--- infrastructure/lib/OpenBSD/PortGen/Port/PyPI.pm     12 May 2019 20:23:33 
-0000      1.12
+++ infrastructure/lib/OpenBSD/PortGen/Port/PyPI.pm     13 May 2019 22:31:11 
-0000
@@ -68,9 +68,22 @@ sub fill_in_makefile
        $self->set_other( 'MODPY_PI',         'Yes' );
        $self->set_other( 'MODPY_SETUPTOOLS', 'Yes' );
        $self->set_comment( $di->{info}{summary} );
-       $self->set_other( 'MODPY_EGG_VERSION', $di->{info}{version} );
-       $self->set_distname( "$di->{info}{name}" . '-${MODPY_EGG_VERSION}' );
-       my $pkgname = $di->{info}->{name};
+
+       my $pkgname  = $di->{info}->{name};
+       my $version  = $di->{info}->{version};
+       my $distname = $self->pick_distfile(
+            map { $_->{filename} } @{ $di->{urls} || [] } );
+
+       $self->add_notice("distname $distname does not match pkgname $pkgname")
+           unless $distname =~ /^\Q$pkgname/;
+
+       $self->set_other( 'MODPY_EGG_VERSION', $version );
+       $distname =~ s/-\Q$version\E$/-\$\{MODPY_EGG_VERSION\}/
+           or $self->add_notice("Didn't set distname version to 
\${MODPY_EGG_VERSION}");
+
+       $self->set_distname($distname);
+
+       # TODO: These assume the PKGNAME is the DISTNAME
        my $to_lower = $pkgname =~ /\p{Upper}/ ? ':L' : '';
        if ($pkgname =~ /^python-/) {
                $self->set_pkgname("\${DISTNAME:S/^python-/py-/$to_lower}");
@@ -78,6 +91,7 @@ sub fill_in_makefile
        elsif ($pkgname !~ /^py-/) {
                $self->set_pkgname("py-\${DISTNAME$to_lower}");
        }
+
        $self->set_modules('lang/python');
        $self->set_other( 'HOMEPAGE', $di->{info}{home_page} );
        $self->set_license( $di->{info}{license} );

Reply via email to