On Fri, 17 Apr 2020 13:29:12 -0700
Andrew Hewus Fresh <[email protected]> wrote:
> Try this patch with `portgen ruby activesupport` and you'll see that
> it it still doesn't find it.
>
> You would have to add the same logic in the name_new_ports sub as
> the parent module looks for the *current* port being ported.

I moved the logic to name_new_ports, but `portgen ruby activesupport`
still duplicates activesupport to mystuff (but with in the same
directory as in /usr/ports). I don't think portgen checks whether the
gem it is called with is already ported.

> I also don't really like hard-coding the list of possible ruby flavors
> here in PortGen as nobody will remember to update them.  I'm OK doing
> it for "py" vs "py3" because a major Python version number change is
> a big deal, a new Ruby 2.8 is significantly less so.  If we can find
> a nice way to grab this list from ruby.port.mk, I would go for a
> patch to fix the places that need it to use that.

I see. How about this?

diff --git infrastructure/lib/OpenBSD/PortGen/Port/Ruby.pm 
infrastructure/lib/OpenBSD/PortGen/Port/Ruby.pm
index 1703fba5b89..bf9ff286467 100644
--- infrastructure/lib/OpenBSD/PortGen/Port/Ruby.pm
+++ infrastructure/lib/OpenBSD/PortGen/Port/Ruby.pm
@@ -21,9 +21,19 @@ use warnings;

 use parent 'OpenBSD::PortGen::Port';

+use List::Util qw( reduce );
+
 use OpenBSD::PortGen::Dependency;
 use OpenBSD::PortGen::Utils qw( module_in_ports );

+my ( $portsdir, @rubyversions );
+
+BEGIN {
+       $portsdir = $ENV{PORTSDIR} || '/usr/ports';
+       @rubyversions = `ECHO_MSG=true make -C $portsdir/lang/ruby show=BINREV`;
+       chomp for @rubyversions;
+}
+
 sub ecosystem_prefix
 {
        my $self = shift;
@@ -57,8 +67,9 @@ sub name_new_port
 {
        my ( $self, $di ) = @_;

-       my $name = $self->SUPER::name_new_port(
-           ref $di ? $di->{name} : $di );
+       my $gem = ref $di ? $di->{name} : $di;
+       my $name = reduce { $a || module_in_ports( $gem, "ruby$b-" ) } 0, 
@rubyversions;
+       $name = $self->SUPER::name_new_port( $gem ) unless $name;
        $name = "ruby/$name" unless $name =~ m{/};

        return $name;
@@ -97,8 +108,7 @@ sub get_deps

                next if $self->is_standard_module($name);

-               my $port = module_in_ports( $name, 'ruby-' )
-                   || $self->name_new_port($name);
+               my $port = $self->name_new_port($name);

                $req =~ s/ //g;

Reply via email to