From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 36C1B138334 for ; Wed, 18 Sep 2019 21:28:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D2F86E0971; Wed, 18 Sep 2019 21:28:18 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7268BE0899 for ; Wed, 18 Sep 2019 21:28:18 +0000 (UTC) Received: from whubbs1.gaikai.biz (unknown [100.42.103.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: williamh) by smtp.gentoo.org (Postfix) with ESMTPSA id 2212334B367; Wed, 18 Sep 2019 21:28:17 +0000 (UTC) Received: (nullmailer pid 8887 invoked by uid 1000); Wed, 18 Sep 2019 21:28:14 -0000 Date: Wed, 18 Sep 2019 16:28:14 -0500 From: William Hubbs To: gentoo-dev@lists.gentoo.org Cc: mgorny@gentoo.org Subject: Re: [gentoo-dev] [PATCH 1/1] go-module.eclass: introduce new eclass to handle go modules Message-ID: <20190918212814.GB8809@whubbs1.dev.av1.gaikai.org> Mail-Followup-To: gentoo-dev@lists.gentoo.org, mgorny@gentoo.org References: <20190918202631.8667-1-williamh@gentoo.org> <20190918202631.8667-2-williamh@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="NDin8bjvE/0mNLFQ" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Archives-Salt: 06778728-d2cd-4657-b757-c69fc36b16b3 X-Archives-Hash: c8c29ba2705576b1fe57cd3caf152fc9 --NDin8bjvE/0mNLFQ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Sep 18, 2019 at 10:29:12PM +0200, Micha=C5=82 G=C3=B3rny wrote: > On Wed, 2019-09-18 at 15:26 -0500, William Hubbs wrote: > > Signed-off-by: William Hubbs > > --- > > eclass/go-module.eclass | 161 ++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 161 insertions(+) > > create mode 100644 eclass/go-module.eclass > >=20 > > diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass > > new file mode 100644 > > index 00000000000..6f609e94542 > > --- /dev/null > > +++ b/eclass/go-module.eclass > > @@ -0,0 +1,161 @@ > > +# Copyright 2019 gentoo authors > > +# Distributed under the terms of the GNU General Public License v2 > > + > > +# @ECLASS: go-module.eclass > > +# @MAINTAINER: > > +# William Hubbs > > +# @SUPPORTED_EAPIS: 7 > > +# @BLURB: basic eclass for building software written in the go > > +# programming language that uses go modules. > > +# @DESCRIPTION: > > +# This eclass provides some basic things needed by all software > > +# written in the go programming language that uses go modules. > > +# > > +# You will know the software you are packaging uses modules because > > +# it will have files named go.sum and go.mod in its top-level source > > +# directory. If it does not have these files, use the golang-* eclasse= s. > > +# > > +# This eclass provides a src_unpack function which unpacks the=20 > > +# first tarball mentioned in SRC_URI to the usual location and unpacks > > +# any modules mentioned in EGO_VENDOR to ${S}/vendor if upstream doesn= 't > > +# vendor its own dependencies. > > +# > > +# If upstream vendors its dependencies, setting EGO_VENDOR is an error. > > +# > > +# Please note that this eclass currently handles only tarballs > > +# (.tar.gz), but support for more formats may be added in the future. > > +# > > +# Since Go programs are statically linked, it is important that your e= build's > > +# LICENSE=3D setting includes the licenses of all statically linked > > +# dependencies. So please make sure it is accurate. > > +# > > +# @EXAMPLE: > > +# > > +# @CODE > > +# EGO_VENDOR=3D( > > +# "github.com/xenolf/lego 6cac0ea7d8b28c889f709ec7fa92e92b82f490dd" > > +# "golang.org/x/crypto 453249f01cfeb54c3d549ddb75ff152ca243f9d8 github= =2Ecom/golang/crypto" > > +# ) > > +# > > +# inherit go-module > > +# > > +# SRC_URI=3D"https://github.com/example/${PN}/archive/v${PV}.tar.gz ->= ${P}.tar.gz > > +# ${EGO_VENDOR_URI}" > > +# @CODE > > +# > > +# The above example will extract the tarball to ${S} and > > +# extract the contents of EGO_VENDOR to ${S}/vendor. > > + > > +case ${EAPI:-0} in > > + 7) ;; > > + *) die "${ECLASS} API in EAPI ${EAPI} not yet established." > > +esac > > + > > +if [[ -z ${_GO_MODULE} ]]; then > > + > > +_GO_MODULE=3D1 > > + > > +BDEPEND=3D">=3Ddev-lang/go-1.12" > > + > > +# Force go to build in module mode. > > +# In this mode the GOPATH environment variable is ignored. > > +# this will become the default in the future. > > +export GO111MODULE=3Don > > + > > +# The following go flags should be used for all builds. > > +# -mod=3Dvendor stopps downloading of dependencies from the internet. > > +# -v prints the names of packages as they are compiled > > +# -x prints commands as they are executed > > +export GOFLAGS=3D"-mod=3Dvendor -v -x" > > + > > +# Do not complain about CFLAGS etc since go projects do not use them. > > +QA_FLAGS_IGNORED=3D'.*' > > + > > +# Go packages should not be stripped with strip(1). > > +RESTRICT=3D"strip" > > + > > +EXPORT_FUNCTIONS src_unpack pkg_postinst > > + > > +# @ECLASS-VARIABLE: EGO_VENDOR > > +# @DESCRIPTION: > > +# This variable contains a list of vendored packages. > > +# The items of this array are strings that contain the > > +# import path and the git commit hash for a vendored package. > > +# If the import path does not start with github.com, the third argument > > +# can be used to point to a github repository. > > + > > +declare -arg EGO_VENDOR > > + > > +_go-module_set_vendor_uri() { > > + EGO_VENDOR_URI=3D > > + local lib > > + for lib in "${EGO_VENDOR[@]}"; do > > + lib=3D(${lib}) > > + if [[ -n ${lib[2]} ]]; then > > + EGO_VENDOR_URI+=3D" https://${lib[2]}/archive/${lib[1]}.tar.gz -> $= {lib[2]//\//-}-${lib[1]}.tar.gz" > > + else > > + EGO_VENDOR_URI+=3D" https://${lib[0]}/archive/${lib[1]}.tar.gz -> $= {lib[0]//\//-}-${lib[1]}.tar.gz" > > + fi > > + done > > + readonly EGO_VENDOR_URI > > +} > > + > > +_go-module_set_vendor_uri > > +unset -f _go-module_set_vendor_uri > > + > > +_go-module_dovendor() { > > + local VENDOR_PATH=3D$1 VENDORPN=3D$2 TARBALL=3D$3 > > + rm -fr "${VENDOR_PATH}/${VENDORPN}" || die > > + mkdir -p "${VENDOR_PATH}/${VENDORPN}" || die > > + tar -C "${VENDOR_PATH}/${VENDORPN}" -x --strip-components 1\ > > + -f "${DISTDIR}/${TARBALL}" || die > > +} > > + > > +# @FUNCTION: go-module_src_unpack > > +# @DESCRIPTION: > > +# Extract the first archive from ${A} to ${S}, then extract > > +# any sources mentioned in ${EGO_VENDOR} to ${S}/vendor. > > +go-module_src_unpack() { > > + local lib vendor_path x > > + set -- ${A} > > + x=3D"$1" > > + mkdir -p "${S}" || die > > + tar -C "${S}/" -x --strip-components 1 \ > > + -f "${DISTDIR}/${x}" || die > > + > > + if [[ -n "${EGO_VENDOR}" ]]; then > > + vendor_path=3D"${S}/vendor" > > + if [[ -d "${vendor_path}" ]]; then > > + eerror "Upstream for ${P}.ebuild vendors dependencies." > > + die "Remove EGO_VENDOR from the ebuild." > > + fi > > + mkdir -p "${vendor_path}" || die > > + for lib in "${EGO_VENDOR[@]}"; do > > + lib=3D(${lib}) > > + if [[ -n ${lib[2]} ]]; then > > + einfo "Vendoring ${lib[0]} ${lib[2]//\//-}-${lib[1]}.tar.gz" > > + _go-module_dovendor "${vendor_path}" ${lib[0]} \ > > + ${lib[2]//\//-}-${lib[1]}.tar.gz > > + else > > + einfo "Vendoring ${lib[0]} ${lib[0]//\//-}-${lib[1]}.tar.gz" > > + _go-module_dovendor "${vendor_path}" ${lib[0]} \ > > + ${lib[0]//\//-}-${lib[1]}.tar.gz > > + fi > > + done > > + fi > > +} > > + > > +# @FUNCTION: go-module_pkg_postinst > > +# @DESCRIPTION: > > +# Display a warning about security updates for Go programs. > > +go-module_pkg_postinst() { > > + ewarn "${PN} is written in the Go programming language." > > + ewarn "Since this language is statically linked, security" > > + ewarn "updates will be handled in individual packages and will be" > > + ewarn "difficult for us to track as a distribution." > > + ewarn "For this reason, please update any go packages asap when new" > > + ewarn "versions enter the tree or go stable if you are running the" > > + ewarn "stable tree." >=20 > I don't really understand why you're adding it to *this* eclass. Isn't > it true for all Go packages? So I suppose golang-* eclasses are > affected as well. You are correct, they are affected. No one, including myself, caught that during the review cycle for those eclasses. I'm not sure of a way we can go back and fix that without breaking compatibility. The goal here is that the go upstream world will move to modules and eventually we will be able to move off of and get rid of the golang-* eclasses. William --NDin8bjvE/0mNLFQ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQTVeuxEZo4uUHOkQAluVBb0MMRlOAUCXYKhaAAKCRBuVBb0MMRl OKlxAJkBddQQaZebPEGHKcV4gZ9ZolOFlwCaA6hLfGRDb0PMNYJLISwbe7sLiig= =thFP -----END PGP SIGNATURE----- --NDin8bjvE/0mNLFQ--