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 CF351138334 for ; Mon, 23 Sep 2019 23:38:13 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2FA1DE09BB; Mon, 23 Sep 2019 23:37:39 +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 ACB36E09B7 for ; Mon, 23 Sep 2019 23:37:38 +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 C3E6E34B4BE; Mon, 23 Sep 2019 23:37:37 +0000 (UTC) Received: (nullmailer pid 13482 invoked by uid 1000); Mon, 23 Sep 2019 23:37:31 -0000 From: William Hubbs To: gentoo-dev@lists.gentoo.org Cc: William Hubbs Subject: [gentoo-dev] [PATCH 2/2] go-module-vendor.eclass: new eclass for go modules that do not vendor Date: Mon, 23 Sep 2019 18:36:49 -0500 Message-Id: <20190923233649.13427-3-williamh@gentoo.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190923233649.13427-1-williamh@gentoo.org> References: <20190923233649.13427-1-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-Transfer-Encoding: 8bit X-Archives-Salt: eed6b6fb-feaf-4c3d-9155-04d816ec9113 X-Archives-Hash: 4bf5b622811c2e24f03935637c147daa This eclass adds a src_unpack function that supports the EGO_VENDOR variable for vendoring modules. --- eclass/go-module-vendor.eclass | 124 +++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 eclass/go-module-vendor.eclass diff --git a/eclass/go-module-vendor.eclass b/eclass/go-module-vendor.eclass new file mode 100644 index 00000000000..ceb362d89ba --- /dev/null +++ b/eclass/go-module-vendor.eclass @@ -0,0 +1,124 @@ +# Copyright 2019 gentoo authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: go-module-vendor.eclass +# @MAINTAINER: +# William Hubbs +# @SUPPORTED_EAPIS: 7 +# @BLURB: Eclass for building software written in the go +# programming language that uses go modules and does not vendor. +# @DESCRIPTION: +# This eclass provides a src_unpack function which supports vendoring +# dependencies for 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-* eclasses. +# +# If there is also a directory named vendor in the top level source directory +# of your package, use the golang-module eclass instead of this one. +# +# This eclass provides a src_unpack function which unpacks the +# first tarball mentioned in SRC_URI to ${S} and unpacks any modules +# mentioned in EGO_VENDOR to ${S}/vendor. +# +# 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 ebuild's +# LICENSE= setting includes the licenses of all statically linked +# dependencies. So please make sure it is accurate. +# +# @EXAMPLE: +# +# @CODE +# inherit go-module-vendor +# +# EGO_VENDOR=( +# "github.com/xenolf/lego 6cac0ea7d8b28c889f709ec7fa92e92b82f490dd" +# "golang.org/x/crypto 453249f01cfeb54c3d549ddb75ff152ca243f9d8 github.com/golang/crypto" +# ) +# +# SRC_URI="https://github.com/example/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz +# $(go-module-vendor_get_vendor_uri)" +# @CODE + +inherit go-module + +case ${EAPI:-0} in + 7) ;; + *) die "${ECLASS} API in EAPI ${EAPI} not yet established." +esac + +if [[ -z ${_GO_MODULE_VENDOR} ]]; then + +_GO_MODULE_VENDOR=1 + +EXPORT_FUNCTIONS src_unpack + +# @ECLASS-VARIABLE: EGO_VENDOR +# @REQUIRED +# @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. + +# @FUNCTION: go-module-vendor_get_vendor_uri +# @DESCRIPTION: +# Convert the information in EGO_VENDOR to a format suitable for +# SRC_URI. +# A call to this function should be added to SRC_URI in your ebuild. +go-module-vendor_get_vendor_uri() { + local hash import line repo + for line in "${EGO_VENDOR[@]}"; do + read -r import hash repo _ <<< "${line}" + if [[ -n ${repo} ]]; then + echo "https://${repo}/archive/${hash}.tar.gz -> ${repo//\//-}-${hash}.tar.gz" + else + echo "https://${import}/archive/${hash}.tar.gz -> ${import//\//-}-${hash}.tar.gz" + fi + done +} + +# @FUNCTION: go-module-vendor_src_unpack +# @DESCRIPTION: +# Extract all archives in ${a} which are not nentioned in ${EGO_VENDOR} +# to their usual locations then extract all archives mentioned in +# ${EGO_VENDOR} to ${S}/vendor. +go-module-vendor_src_unpack() { + local f hash import line repo tarball vendor_uri + if [[ -z "${EGO_VENDOR}" ]]; then + die "EGO_VENDOR is not defined" + fi + + vendor_uri="$(go-module-vendor_get_vendor_uri)" + for f in $A; do + [[ $vendor_uri == *"$f"* ]] && continue + unpack $f + done + + if [[ -d "${S}/vendor" ]]; then + eerror "Upstream for ${P}.ebuild vendors dependencies." + die "This ebuild should inherit go-module.eclass" + fi + + mkdir -p "${S}/vendor" || die + for line in "${EGO_VENDOR[@]}"; do + read -r import hash repo _ <<< "${line}" + if [[ -n ${repo} ]]; then + tarball=${repo//\//-}-${hash}.tar.gz + else + tarball=${import//\//-}-${hash}.tar.gz + fi + einfo "Vendoring ${import} ${tarball}" + rm -fr "${S}/vendor/${import}" || die + mkdir -p "${S}/vendor/${import}" || die + tar -C "${S}/vendor/${import}" -x --strip-components 1\ + -f "${DISTDIR}/${tarball}" || die + done +} + +fi -- 2.21.0