public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [patch] golang-vcs-snapshot.eclass: add vendoring of external dependencies
@ 2017-03-09 17:58 William Hubbs
  2017-03-09 18:21 ` William L. Thomson Jr.
  2017-03-13 14:06 ` William Hubbs
  0 siblings, 2 replies; 12+ messages in thread
From: William Hubbs @ 2017-03-09 17:58 UTC (permalink / raw
  To: gentoo development


[-- Attachment #1.1: Type: text/plain, Size: 390 bytes --]

All,

things like this are already being done in the tree (by app-admin/consul
for example), and I'n sure by other go ebuilds as well.

I would like to add this functionality to golang-vcs-snapshot.eclass as
a way to remove duplicate code from ebuilds and make this available to
other ebuilds as well.

If there are no objections, I'll commit on Sunday after the council
meeting.

William


[-- Attachment #1.2: golang-vcs-snapshot.patch --]
[-- Type: text/x-diff, Size: 3800 bytes --]

diff --git a/eclass/golang-vcs-snapshot.eclass b/eclass/golang-vcs-snapshot.eclass
index 3ec1d36..f384c38 100644
--- a/eclass/golang-vcs-snapshot.eclass
+++ b/eclass/golang-vcs-snapshot.eclass
@@ -10,9 +10,12 @@
 # This eclass provides a convenience src_unpack() which unpacks the
 # first tarball mentioned in SRC_URI to its appropriate location in
 # ${WORKDIR}/${P}, treating ${WORKDIR}/${P} as a go workspace.
+# Also, it provides a downstream method of vendoring packages.
 #
 # The location where the tarball is extracted is defined as
-# ${WORKDIR}/${P}/src/${EGO_PN}.
+# ${WORKDIR}/${P}/src/${EGO_PN}. The location of vendored packages is
+# defined as ${WORKDIR}/${P}/src/${EGO_PN%/*}/vendor to match Go's
+# vendoring setup.
 #
 # The typical use case is VCS snapshots coming from github, bitbucket
 # and similar services.
@@ -24,13 +27,20 @@
 #
 # @CODE
 # EGO_PN=github.com/user/package
+# EGO_VENDOR=(
+#	"github.com/xenolf/lego 6cac0ea7d8b28c889f709ec7fa92e92b82f490dd"
+# "golang.org/x/crypto 453249f01cfeb54c3d549ddb75ff152ca243f9d8 github.com/golang/crypto"
+# )
+#
 # inherit golang-vcs-snapshot
 #
-# SRC_URI="http://github.com/example/${PN}/tarball/v${PV} -> ${P}.tar.gz"
+# SRC_URI="http://github.com/example/${PN}/tarball/v${PV} -> ${P}.tar.gz
+# ${EGO_VENDOR_URI}"
 # @CODE
 #
 # The above example will extract the tarball to
 # ${WORKDIR}/${P}/src/github.com/user/package
+# and add the vendored tarballs to ${WORKDIR}/src/${EGO_PN}/vendor
 
 inherit golang-base
 
@@ -41,15 +51,67 @@ esac
 
 EXPORT_FUNCTIONS src_unpack
 
+# @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
+
+_golang-vcs-snapshot_set_vendor_uri() {
+	EGO_VENDOR_URI=
+	local lib
+	for lib in "${EGO_VENDOR[@]}"; do
+		lib=(${lib})
+		if [[ -n ${lib[2]} ]]; then
+			EGO_VENDOR_URI+=" https://${lib[2]}/archive/${lib[1]}.tar.gz -> ${lib[2]//\//-}-${lib[1]}.tar.gz"
+		else
+			EGO_VENDOR_URI+=" https://${lib[0]}/archive/${lib[1]}.tar.gz -> ${lib[0]//\//-}-${lib[1]}.tar.gz"
+		fi
+	done
+	readonly EGO_VENDOR_URI
+}
+
+_golang-vcs-snapshot_set_vendor_uri
+unset -f _golang-vcs-snapshot_set_vendor_uri
+
+_golang-vcs-snapshot_dovendor() {
+	local VENDOR_PATH=$1 VENDORPN=$2 TARBALL=$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: golang-vcs-snapshot_src_unpack
 # @DESCRIPTION:
 # Extract the first archive from ${A} to the appropriate location for GOPATH.
 golang-vcs-snapshot_src_unpack() {
-	local x
+	local lib vendor_path x
 	ego_pn_check
 	set -- ${A}
 	x="$1"
 	mkdir -p "${WORKDIR}/${P}/src/${EGO_PN%/...}" || die
 	tar -C "${WORKDIR}/${P}/src/${EGO_PN%/...}" -x --strip-components 1 \
 		-f "${DISTDIR}/${x}" || die
+
+	if [[ -n "${EGO_VENDOR}" ]]; then
+		vendor_path="${WORKDIR}/${P}/src/${EGO_PN%/...}/vendor"
+		mkdir -p "${vendor_path}" || die
+		for lib in "${EGO_VENDOR[@]}"; do
+			lib=(${lib})
+			if [[ -n ${lib[2]} ]]; then
+				einfo "Vendoring ${lib[0]} ${lib[2]//\//-}-${lib[1]}.tar.gz"
+				_golang-vcs-snapshot_dovendor "${VENDOR_PATH}" ${lib[0]} \
+					${lib[2]//\//-}-${lib[1]}.tar.gz
+			else
+				einfo "Vendoring ${lib[0]} ${lib[0]//\//-}-${lib[1]}.tar.gz"
+				_golang-vcs-snapshot_dovendor "${VENDOR_PATH}" ${lib[0]} \
+				${lib[0]//\//-}-${lib[1]}.tar.gz
+			fi
+		done
+	fi
 }

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-03-13 14:06 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-09 17:58 [gentoo-dev] [patch] golang-vcs-snapshot.eclass: add vendoring of external dependencies William Hubbs
2017-03-09 18:21 ` William L. Thomson Jr.
2017-03-09 18:29   ` Michael Orlitzky
2017-03-09 19:00     ` William L. Thomson Jr.
2017-03-09 19:28       ` Michael Orlitzky
2017-03-09 23:16         ` William L. Thomson Jr.
2017-03-10  0:08           ` Michael Orlitzky
2017-03-10  0:43             ` William L. Thomson Jr.
2017-03-10  1:03               ` William L. Thomson Jr.
2017-03-10  7:38                 ` Ulrich Mueller
2017-03-12  2:00           ` Kent Fredric
2017-03-13 14:06 ` William Hubbs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox