On Mon, May 13, 2019 at 02:51:54PM -0700, Andrew Hewus Fresh wrote:
> On Mon, May 13, 2019 at 10:05:16AM -0700, Andrew Hewus Fresh wrote:
> > 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}.
> > 
> > I think kmos@ explained this to me correctly, but if someone wants to
> > write down the why this needs to happen again I'll happily add it as a
> > comment to this magic.
> 
> So this pointed out an issue to me due to this patch. As I understood
> it, I could attach "${MODPY_FLAVOR}" indiscriminately to all the
> depends, but this error tells me that's probably not true.  Do I need to
> only add the flavor if the dependent has a python3 flavor?
> 
> ===>  Updating plist for py3-pytest-4.5.0
> Fatal: Unknown flavor(s) python3 (in devel/py-funcsigs)
>    (No flavors for this port). (in devel/py-funcsigs)
> *** Error 1 in /usr/ports/devel/py-funcsigs 
> (/usr/ports/infrastructure/mk/bsd.port.mk:3564 '.BEGIN': @exit 1)
> Problem with dependency STEM->=1.0:devel/py-funcsigs,python3


This was a bit annoying, but kmos@ explained that he really meant that
we need to tack on the MODPY_FLAVOR only if the dependency *has* a
python3 flavor.  This sounds a bit error-prone if a port suddenly
sprouts a python3 flavor, but that's unrelated to portgen.

Anyway, this patch checks the flavors of the dependency before adding
MODPY_FLAVOR, which is how I understood what kurt said.

Comments, OK?

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:48:50 
-0000
@@ -21,8 +21,10 @@ use warnings;
 
 use parent 'OpenBSD::PortGen::Port';
 
+use Cwd;
+
 use OpenBSD::PortGen::Dependency;
-use OpenBSD::PortGen::Utils qw( module_in_ports );
+use OpenBSD::PortGen::Utils qw( base_dir ports_dir module_in_ports );
 
 sub ecosystem_prefix
 {
@@ -155,11 +157,30 @@ sub get_deps
 
                next if @plat and join( " ", @plat ) !~ /OpenBSD/i;
 
-               my $port = module_in_ports( $name, 'py-' )
-                   || $self->name_new_port($name);
+               my $port = module_in_ports( $name, 'py-' );
+               my $dep_dir = ports_dir() . '/' . $port;
+
+               # don't have it in tree, port it
+               unless ( $port ) {
+                       $port = $self->name_new_port($name);
+                       $dep_dir = base_dir() . '/' . $port;
+
+                       my $o = OpenBSD::PortGen::Port::PyPI->new();
+                       $o->port($name);
+                       $self->add_notice( $o->notices );
+               }
 
                my $base_port = $port;
-               $port .= '${MODPY_FLAVOR}';
+
+               {
+                       my $old_cwd = getcwd();
+                       chdir $dep_dir || die "Unable to chdir $dep_dir: $!";
+                       my $flavors = $self->make_show('FLAVORS');
+                       chdir $old_cwd || die "Unable to chdir $old_cwd: $!";
+
+                       # Attach the flavor if the dependency has one
+                       $port .= '${MODPY_FLAVOR}' if $flavors =~ /\bpython3\b/;
+               }
 
                if ( $phase eq 'build' ) {
                        $deps->add_build( $port, $req );
@@ -175,13 +196,6 @@ sub get_deps
                                "Added $base_port as 'run' dep, wanted 
'$phase'")
                            unless $phase eq 'run';
                        $deps->add_run( $port, $req );
-               }
-
-               # don't have it in tree, port it
-               if ( $port =~ m{^pypi/} ) {
-                       my $o = OpenBSD::PortGen::Port::PyPI->new();
-                       $o->port($name);
-                       $self->add_notice( $o->notices );
                }
        }
 

Reply via email to