How to handle go dependencies

Dmitri Goutnik dg at syrec.org
Sat Jun 22 20:52:16 UTC 2019


On 19-06-22 14:31:24, Adam Weinberger wrote:
> On Sat, Jun 22, 2019 at 2:22 PM Bernhard Froehlich <decke at bluelife.at> wrote:
> >
> >
> > Am 22.06.2019 19:47 schrieb Adam Weinberger <adamw at adamw.org>:
> > >
> > > On Sat, Jun 22, 2019 at 11:10 AM Bernhard Froehlich <decke at bluelife.at> wrote:
> > > >
> > > >
> > > > Am 22.06.2019 17:56 schrieb Adam Weinberger <adamw at adamw.org>:
> > > > >
> > > > > On Sat, Jun 22, 2019 at 8:21 AM Danilo G. Baio <dbaio at freebsd.org> wrote:
> > > > > >
> > > > > > On Sat, Jun 22, 2019 at 11:58:49AM +0200, Matthias Fechner wrote:
> > > > > > > Dear all,
> > > > > > >
> > > > > > > I just prepare the gitlab-ce upgrade to version 12.0.0.
> > > > > > > But I have some problem with a package that uses go to compile.
> > > > > > >
> > > > > > > The new version of devel/gitaly has changed the way the package is defined.
> > > > > > > They removed now all files from the vendor/ folder and add dependencies
> > > > > > > in a `go.mod` file.
> > > > > > >
> > > > > > > If I now build the port it tries to fetch the files while no network
> > > > > > > access is allowed.
> > > > > > >
> > > > > > > What is the correct way to getting these dependencies fetched and
> > > > > > > correctly included into the work-source in the fetch step using go?
> > > > > > >
> > > > > > > Thanks a lot!
> > > > > > >
> > > > > > > Gruß
> > > > > > > Matthias
> > > > > > >
> > > > > >
> > > > > > Try this and remove the go.mod file
> > > > > >
> > > > > > ports-mgmt/modules2tuple
> > > > > > https://github.com/dmgk/modules2tuple
> > > > > >
> > > > > > Examples:
> > > > > > net/geoipupdate
> > > > > > shells/antibody
> > > > >
> > > > > Just a note here, both those ports are mine, and I have no idea if
> > > > > that's the right thing to do; it built right so I did it. I don't
> > > > > understand Go packaging at all, and I'd sure appreciate someone with
> > > > > Go knowledge verifying whether removing go.mod is the proper thing to
> > > > > do.
> > > >
> > > > The correct magic that you are searching is:
> > > >
> > > > MAKE_ENV+= GOFLAGS=-mod=vendor
> > > >
> > > > (like it is used in mail/smtprelay)
> > >
> > > With that I still get:
> > >
> > > $GOPATH/go.mod exists but should not
> > > *** Error code 1
> > >
> > > Stop.
> > >
> >
> > Which port is that? I had a look at shells/antibody which you mentioned and came up with that:
> >
> > --- /home/decke/dev/ports/shells/antibody/Makefile      2019-06-12 18:57:58.189631000 +0000
> > +++ /home/decke/dev/myports/shells/antibody/Makefile    2019-06-22 20:13:05.627718000 +0000
> > @@ -21,23 +21,18 @@
> >
> >  USE_GITHUB=    yes
> >  GH_ACCOUNT=    getantibody
> > -GH_SUBDIR=     src/github.com/${GH_ACCOUNT_DEFAULT}/${PORTNAME}
> >  # Not needed: go-spew, go-difflib
> > -GH_TUPLE=      alecthomas:kingpin:a39589:kingpin/src/github.com/alecthomas/kingpin \
> > -               alecthomas:template:a0175e:tempalte/src/github.com/alecthomas/template \
> > -               alecthomas:units:2efee8:units/src/github.com/alecthomas/units \
> > -               caarlos0:gohome:75f08ebc:gohome/src/github.com/caarlos0/gohome \
> > -               getantibody:folder:v1.0.0:folder/src/github.com/getantibody/folder \
> > -               golang:crypto:1a580b:crypto/src/golang.org/x/crypto \
> > -               golang:net:2491c5:net/src/golang.org/x/net \
> > -               golang:sync:1d60e4:sync/src/golang.org/x/sync \
> > -               golang:sys:7c87d1:sys/src/golang.org/x/sys
> > +GH_TUPLE=      alecthomas:kingpin:a39589:kingpin/vendor/github.com/alecthomas/kingpin \
> > +               alecthomas:template:a0175e:template/vendor/github.com/alecthomas/template \
> > +               alecthomas:units:2efee8:units/vendor/github.com/alecthomas/units \
> > +               caarlos0:gohome:75f08ebc:gohome/vendor/github.com/caarlos0/gohome \
> > +               getantibody:folder:v1.0.0:folder/vendor/github.com/getantibody/folder \
> > +               golang:crypto:1a580b:crypto/vendor/golang.org/x/crypto \
> > +               golang:net:2491c5:net/vendor/golang.org/x/net \
> > +               golang:sync:1d60e4:sync/vendor/golang.org/x/sync \
> > +               golang:sys:7c87d1:sys/vendor/golang.org/x/sys
> >
> > -do-build:
> > -       ${RM} ${WRKSRC}/go.mod
> > -       cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} ${BUILD_ENV} GOPATH=${WRKSRC} go build
> > -
> > -do-install:
> > -       ${INSTALL_PROGRAM} ${WRKSRC}/antibody-${PORTVERSION} ${STAGEDIR}${PREFIX}/bin/antibody
> > +GO_PKGNAME=    github.com/getantibody/antibody
> > +MAKE_ENV+=     GOFLAGS=-mod=vendor
> >
> >  .include <bsd.port.mk>
> >
> > It looks much more complicated than it is. In GH_TUPLE replace src with vendor to have the dependencies in the path where go will look for. Add GOFLAGS=-mod=vendor to force go to use the sources it finds there and ignore go.mod/go.sum And last but not least set GO_PKGNAME and let our Uses/go.mk do the magic.
> 
> Wow, I had no idea about any of this!
> 
> Please, can you add a Wiki page for how to do Go ports? Or send some
> text (even in plain text format) to the doc team and they can format
> it for the PHB.
> 
> # Adam
> 
> 
> -- 
> Adam Weinberger
> adamw at adamw.org
> https://www.adamw.org
> _______________________________________________
> freebsd-ports at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-ports
> To unsubscribe, send any mail to "freebsd-ports-unsubscribe at freebsd.org"

Can be further simplified by using USES=go:modules. This will remove the need 
to modify MAKE_ENV as go.mk will then add -mod=vendor flag automagically.

-- 
Dmitri Goutnik
dg at syrec.org


More information about the freebsd-ports mailing list