On Wed, Mar 17, 2021 at 07:44:52PM +0000, Stuart Henderson wrote:
> On 2021/03/17 12:53, Josh Rickmar wrote:
> > This portgen(1) patch allows for an optional @version suffix to a
> > ported Go module to specify a tag or branch to port.  The implied
> > default is @latest, which is the latest semver tag known by the proxy
> > server.  This is the same syntax used to refer to module versions in
> > Go's own tooling.
> > 
> > I've inlined two patches here for both the src and ports trees since
> > the portgen manpage is in src.
> 
> Works for me, I've wanted to do this a few times before and know that
> others have too so definitely useful.
> 
> > +     elsif ($at_version =~ /^v\d+\.\d+\.\d+/) {
> 
> Is this vx.y.z format fixed with go, or just a convention?

Here's an updated patch which just removes this whole elsif branch.
We can still query the proxy server with the .info endpoint even if
the version is already one of Go's pseudo-versions.  This will be
quite a bit safer as I'm imagining someone will eventually create
their own tags which match this regex but which the proxy server does
not know about, and this should force a lookup of the tag on the
origin server by the proxy.

diff 6eaf30816f4def2f40cb2b765a3aa33ae11ae4a8 /home/jrick/ports
blob - 40be89f09438e34ea14cb0d116e20663a949ea4b
file + infrastructure/lib/OpenBSD/PortGen/Port/Go.pm
--- infrastructure/lib/OpenBSD/PortGen/Port/Go.pm
+++ infrastructure/lib/OpenBSD/PortGen/Port/Go.pm
@@ -69,14 +69,13 @@ sub _go_determine_name
        my ( $self, $module ) = @_;
 
        my $json = $self->get_ver_info($module);
+       $module = $json->{Module};
        if ($module =~ m/v\d$/) {
                $json->{Name}   = ( split '/', $module )[-2];
        } else {
                $json->{Name}   = ( split '/', $module )[-1];
        }
 
-       $json->{Module} = $module;
-
        return $json;
 }
 
@@ -87,7 +86,7 @@ sub get_dist_info
        my $json = $self->_go_determine_name($module);
 
        my ($dist, $mods) = $self->_go_mod_info($json);
-       $json->{License} = $self->_go_lic_info($module);
+       $json->{License} = $self->_go_lic_info($json->{Module});
 
        $json->{Dist} = $dist if @$dist > 0;
        $json->{Mods} = $mods if @$mods > 0;
@@ -218,6 +217,13 @@ sub get_ver_info
        my $version_list = do { local $@; eval { local $SIG{__DIE__};
            $self->get( $module . '/@v/list' ) } };
 
+       # Versions can be specified on the command line with a
+       # '@<version>' suffix, which defaults to '@latest':
+       my $at_version = 'latest';
+       if ($module =~ /@/) {
+               ($module, $at_version) = split(/@/, $module);
+       }
+
        my $version_info;
        if ($version_list) {
                my %v = ( o => 
OpenBSD::PackageName::version->from_string("v0.0.0") );
@@ -235,7 +241,12 @@ sub get_ver_info
                }
        }
        else {
-               $version_info = $self->get_json( 
$self->_go_mod_normalize($module) . '/@latest' );
+               my $endpoint = '/@latest';
+               if ($at_version ne 'latest') {
+                       $endpoint = '/@v/' . "${at_version}.info";
+               }
+               $version_info = $self->get_json( 
$self->_go_mod_normalize($module) . $endpoint );
+               $version_info->{Module} = $module;
        }
 
        return $self->{version_info} = $version_info;

diff e56e9441b589bca5244719cacb862d6c2f769507 /usr/src
blob - 22ccaf2e01cffbb10cf1fb4b7fc0ade89fa16b48
file + share/man/man1/portgen.1
--- share/man/man1/portgen.1
+++ share/man/man1/portgen.1
@@ -58,6 +58,15 @@ for Ruby gems.
 for Go modules.
 .El
 .Pp
+A
+.Cm go
+module may be used with an
+.Ar @version
+suffix to specify a tag or branch to port.
+The default suffix is
+.Ar @latest ,
+which is interpreted as the latest release.
+.Pp
 The following packages must be installed prior to the invocation of
 .Nm :
 .Pp

Reply via email to