This patch looks up the distname and then finds out if there are updates
for it on the CPAM. That means you can pass in the port's directory
name or likely package stub and have it update. That's useful to me for
adding automation to updating my out-of-date ports.
It allows me to update things like p5-YAML-XS and p5-libwww where the
module name and dist name are not easily guessed from the PKGPPATH.
I realize this would be a nice feature in non-CPAN modules, but I'm not
familiar enough with those ecosystems to add them easily. I could maybe
dig into it though.
Comments? Suggestions? OK?
Index: lib/OpenBSD/PortGen//Port/CPAN.pm
===================================================================
RCS file: /cvs/ports/infrastructure/lib/OpenBSD/PortGen/Port/CPAN.pm,v
retrieving revision 1.8
diff -u -p -r1.8 CPAN.pm
--- lib/OpenBSD/PortGen//Port/CPAN.pm 14 May 2019 15:00:01 -0000 1.8
+++ lib/OpenBSD/PortGen//Port/CPAN.pm 6 Dec 2020 03:38:35 -0000
@@ -21,9 +21,10 @@ use warnings;
use parent 'OpenBSD::PortGen::Port';
+use Cwd;
use File::Find qw( find );
use OpenBSD::PortGen::Dependency;
-use OpenBSD::PortGen::Utils qw( fetch module_in_ports );
+use OpenBSD::PortGen::Utils qw( fetch module_in_ports ports_dir );
sub ecosystem_prefix
{
@@ -41,6 +42,31 @@ sub get_dist_info
{
my ( $self, $module ) = @_;
+ # Check to see if the module is a "stub" of an existing PKGPATH
+ # If so, then we can check the DISTNAME without version for updates.
+ # This allows for updating p5-YAML-XS instead of p5-YAML-LibYAML
+ # or trying for LWP and getting p5-libwww-perl.
+ if ( my $pkgpath = module_in_ports($module, 'p5-') ) {
+ my $portdir = ports_dir() . "/$pkgpath";
+
+ my $old_cwd = getcwd();
+ chdir $portdir or die "couldn't chdir to $portdir: $!";
+ my $distname = $self->make_show('DISTNAME');
+ chdir $old_cwd or die "couldn't chdir to $old_cwd: $!";
+
+ # Remove the version
+ $distname =~ s/-[^-]*$//;
+
+ local $@;
+ my $di = eval { local $SIG{__DIE__};
+ $self->get_json("/release/$distname") };
+
+ if ($di) {
+ $di->{pkgpath} = $pkgpath;
+ return $di;
+ }
+ }
+
my $dist = $self->get_dist_for_module($module);
return $self->get_json("release/$dist");
@@ -63,6 +90,9 @@ sub name_new_port
{
my ( $self, $di ) = @_;
+ # If we know this out already, just return it
+ return $di->{pkgpath} if ref $di and $di->{pkgpath};
+
my $name = $self->SUPER::name_new_port(
ref $di ? $di->{metadata}->{name} : $di );
$name =~ s/::/-/g;
No comments:
Post a Comment