Hi,

This teaches portgen and go.port.mk how to handle module URLs that
contain uppercase characters.

Go has chosen to translate module names like
'github.com/poolpOrg/filter-rspamd' to
'github.com/ploop!org/filter-rspamd'.

They had reasons:

  > To avoid ambiguity when serving from case-insensitive file systems,
  > the $module and $version elements are case-encoded by replacing
  > every uppercase letter with an exclamation mark followed by the
  > corresponding lower-case letter. This allows modules example.com/M
  > and example.com/m to both be stored on disk, since the former is
  > encoded as example.com/!m.

Because of the need for escaping, a port like that looks like the one
below would not work:
  MODGO_MODNAME =        github.com/poolpOrg/filter-rspamd
  MODGO_VERSION =        v0.1.7

Same goes for `portgen go github.com/poolpOrg/filter-rspamd` - this
errors because it can't find the distfile.

The make magic is from espie@ / naddy@ - I am not clever enough to come
up with such voodoo myself! :D

I have tested a handful of existing MODGO_ ports with this diff, as well
as existing and new ports that were built with 'portgen go'.

OK?

Cheers,
Aaron

diff 7e3d98f862f0227602e41951ba307f467353d929 /usr/ports
blob - 16116f9b0525e89d7f4b115e7517cb913f107760
file + infrastructure/lib/OpenBSD/PortGen/Port/Go.pm
--- infrastructure/lib/OpenBSD/PortGen/Port/Go.pm
+++ infrastructure/lib/OpenBSD/PortGen/Port/Go.pm
@@ -31,6 +31,8 @@ use Carp;
 use Cwd;
 use File::Temp qw/ tempdir /;
 
+use Data::Dumper;
+
 use OpenBSD::PortGen::Dependency;
 
 my $license_map = {
@@ -67,7 +69,7 @@ sub _go_determine_name
 	# Some modules end in "v1" or "v2", if we find one of these, we need
 	# to set PKGNAME to something up a level
 	my ( $self, $module ) = @_;
-	my $json = $self->get_json( $module . '/@latest' );
+	my $json = $self->get_json( $self->_go_mod_normalize($module) . '/@latest' );
 
 	if ($json->{Version} =~ m/incompatible/) {
 		my $msg = "${module} $json->{Version} is incompatible with Go modules.";
@@ -131,7 +133,7 @@ sub _go_mod_info
 	my ($self, $json) = @_;
 	my $dir = tempdir(CLEANUP => 0);
 
-	my $mod = $self->get("$json->{Module}/\@v/$json->{Version}.mod");
+	my $mod = $self->get($self->_go_mod_normalize($json->{Module}) . "/\@v/$json->{Version}.mod");
 	my ($module) = $mod =~ /\bmodule\s+(.*?)\s/;
 
 	unless ( $json->{Module} eq $module ) {
@@ -169,9 +171,10 @@ sub _go_mod_info
 	foreach my $mod (@raw_mods) {
 		foreach my $m (split(/ /, $mod)) {
 			$m =~ s/@/ /;
+			next if $m eq $json->{Module};
 			$m = $self->_go_mod_normalize($m);
 			if (! defined $all_deps->{$m}) {
-				push @mods, $m unless $m eq $json->{Module};
+				push @mods, $m;
 				$all_deps->{$m} = 1;
 			}
 		}
@@ -220,7 +223,7 @@ sub get_ver_info
 	# semver, this means we will have to fallback to @latest to get the
 	# version information.
 	if ($version_list eq "") {
-		$ret = $self->get_json( $module . '/@latest' );
+		$ret = $self->get_json( $self->_go_mod_normalize($module) . '/@latest' );
 	} else {
 		my @parts = split("\n", $version_list);
 		for my $v ( @parts ) {
blob - 865c52df510ac8cc64f8f455ecbb8862e001f6d8
file + lang/go/go.port.mk
--- lang/go/go.port.mk
+++ lang/go/go.port.mk
@@ -14,6 +14,10 @@ MASTER_SITES${MODGO_MASTER_SITESN} ?= ${MASTER_SITE_AT
 MODGO_RUN_DEPENDS =	lang/go
 MODGO_BUILD_DEPENDS =	lang/go
 
+.for l in a b c d e f g h i j k l m n o p q r s t u v w x y z
+_subst := ${_subst}:S/${l:U}/!$l/g
+.endfor
+
 .if ${NO_BUILD:L} == "no" && ${MODGO_BUILDDEP:L} == "yes"
 BUILD_DEPENDS +=	${MODGO_BUILD_DEPENDS}
 .endif
@@ -57,13 +61,18 @@ MODGO_TEST_CMD +=	-ldflags="${MODGO_LDFLAGS}"
 .endif
 
 .if defined(MODGO_MODNAME)
+.for _s in ${_subst}
+MODGO_MODNAME_ESC = ${MODGO_MODNAME${_s}}
+DISTNAME_ESC = ${DISTNAME${_s}}
+.endfor
+
 EXTRACT_SUFX ?=		.zip
-PKGNAME ?=		${DISTNAME:S/-v/-/}
+PKGNAME ?=		${DISTNAME_ESC:S/-v/-/}
 ALL_TARGET ?=		${MODGO_MODNAME}
 MODGO_FLAGS +=		-modcacherw
-DISTFILES =		${DISTNAME}${EXTRACT_SUFX}{${MODGO_VERSION}${EXTRACT_SUFX}}
-EXTRACT_ONLY =		${DISTNAME}${EXTRACT_SUFX}
-MASTER_SITES ?=		${MASTER_SITE_ATHENS}${MODGO_MODNAME}/@v/
+DISTFILES =		${DISTNAME_ESC}${EXTRACT_SUFX}{${MODGO_VERSION}${EXTRACT_SUFX}}
+EXTRACT_ONLY =		${DISTNAME_ESC}${EXTRACT_SUFX}
+MASTER_SITES ?=		${MASTER_SITE_ATHENS}${MODGO_MODNAME_ESC}/@v/
 .  for _modpath _modver in ${MODGO_MODULES}
 DISTFILES +=	${MODGO_DIST_SUBDIR}/${_modpath}/@v/${_modver}.zip{${_modpath}/@v/${_modver}.zip}:${MODGO_MASTER_SITESN}
 DISTFILES +=	${MODGO_DIST_SUBDIR}/${_modpath}/@v/${_modver}.mod{${_modpath}/@v/${_modver}.mod}:${MODGO_MASTER_SITESN}

Reply via email to