1 |
This eclass adds a src_unpack function that supports the EGO_VENDOR |
2 |
variable for vendoring modules. |
3 |
--- |
4 |
eclass/go-module-vendor.eclass | 124 +++++++++++++++++++++++++++++++++ |
5 |
1 file changed, 124 insertions(+) |
6 |
create mode 100644 eclass/go-module-vendor.eclass |
7 |
|
8 |
diff --git a/eclass/go-module-vendor.eclass b/eclass/go-module-vendor.eclass |
9 |
new file mode 100644 |
10 |
index 00000000000..ceb362d89ba |
11 |
--- /dev/null |
12 |
+++ b/eclass/go-module-vendor.eclass |
13 |
@@ -0,0 +1,124 @@ |
14 |
+# Copyright 2019 gentoo authors |
15 |
+# Distributed under the terms of the GNU General Public License v2 |
16 |
+ |
17 |
+# @ECLASS: go-module-vendor.eclass |
18 |
+# @MAINTAINER: |
19 |
+# William Hubbs <williamh@g.o> |
20 |
+# @SUPPORTED_EAPIS: 7 |
21 |
+# @BLURB: Eclass for building software written in the go |
22 |
+# programming language that uses go modules and does not vendor. |
23 |
+# @DESCRIPTION: |
24 |
+# This eclass provides a src_unpack function which supports vendoring |
25 |
+# dependencies for software written in the go programming language that |
26 |
+# uses go modules. |
27 |
+# |
28 |
+# You will know the software you are packaging uses modules because |
29 |
+# it will have files named go.sum and go.mod in its top-level source |
30 |
+# directory. If it does not have these files, use the golang-* eclasses. |
31 |
+# |
32 |
+# If there is also a directory named vendor in the top level source directory |
33 |
+# of your package, use the golang-module eclass instead of this one. |
34 |
+# |
35 |
+# This eclass provides a src_unpack function which unpacks the |
36 |
+# first tarball mentioned in SRC_URI to ${S} and unpacks any modules |
37 |
+# mentioned in EGO_VENDOR to ${S}/vendor. |
38 |
+# |
39 |
+# Please note that this eclass currently handles only tarballs |
40 |
+# (.tar.gz), but support for more formats may be added in the future. |
41 |
+# |
42 |
+# Since Go programs are statically linked, it is important that your ebuild's |
43 |
+# LICENSE= setting includes the licenses of all statically linked |
44 |
+# dependencies. So please make sure it is accurate. |
45 |
+# |
46 |
+# @EXAMPLE: |
47 |
+# |
48 |
+# @CODE |
49 |
+# inherit go-module-vendor |
50 |
+# |
51 |
+# EGO_VENDOR=( |
52 |
+# "github.com/xenolf/lego 6cac0ea7d8b28c889f709ec7fa92e92b82f490dd" |
53 |
+# "golang.org/x/crypto 453249f01cfeb54c3d549ddb75ff152ca243f9d8 github.com/golang/crypto" |
54 |
+# ) |
55 |
+# |
56 |
+# SRC_URI="https://github.com/example/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz |
57 |
+# $(go-module-vendor_get_vendor_uri)" |
58 |
+# @CODE |
59 |
+ |
60 |
+inherit go-module |
61 |
+ |
62 |
+case ${EAPI:-0} in |
63 |
+ 7) ;; |
64 |
+ *) die "${ECLASS} API in EAPI ${EAPI} not yet established." |
65 |
+esac |
66 |
+ |
67 |
+if [[ -z ${_GO_MODULE_VENDOR} ]]; then |
68 |
+ |
69 |
+_GO_MODULE_VENDOR=1 |
70 |
+ |
71 |
+EXPORT_FUNCTIONS src_unpack |
72 |
+ |
73 |
+# @ECLASS-VARIABLE: EGO_VENDOR |
74 |
+# @REQUIRED |
75 |
+# @DESCRIPTION: |
76 |
+# This variable contains a list of vendored packages. |
77 |
+# The items of this array are strings that contain the |
78 |
+# import path and the git commit hash for a vendored package. |
79 |
+# If the import path does not start with github.com, the third argument |
80 |
+# can be used to point to a github repository. |
81 |
+ |
82 |
+# @FUNCTION: go-module-vendor_get_vendor_uri |
83 |
+# @DESCRIPTION: |
84 |
+# Convert the information in EGO_VENDOR to a format suitable for |
85 |
+# SRC_URI. |
86 |
+# A call to this function should be added to SRC_URI in your ebuild. |
87 |
+go-module-vendor_get_vendor_uri() { |
88 |
+ local hash import line repo |
89 |
+ for line in "${EGO_VENDOR[@]}"; do |
90 |
+ read -r import hash repo _ <<< "${line}" |
91 |
+ if [[ -n ${repo} ]]; then |
92 |
+ echo "https://${repo}/archive/${hash}.tar.gz -> ${repo//\//-}-${hash}.tar.gz" |
93 |
+ else |
94 |
+ echo "https://${import}/archive/${hash}.tar.gz -> ${import//\//-}-${hash}.tar.gz" |
95 |
+ fi |
96 |
+ done |
97 |
+} |
98 |
+ |
99 |
+# @FUNCTION: go-module-vendor_src_unpack |
100 |
+# @DESCRIPTION: |
101 |
+# Extract all archives in ${a} which are not nentioned in ${EGO_VENDOR} |
102 |
+# to their usual locations then extract all archives mentioned in |
103 |
+# ${EGO_VENDOR} to ${S}/vendor. |
104 |
+go-module-vendor_src_unpack() { |
105 |
+ local f hash import line repo tarball vendor_uri |
106 |
+ if [[ -z "${EGO_VENDOR}" ]]; then |
107 |
+ die "EGO_VENDOR is not defined" |
108 |
+ fi |
109 |
+ |
110 |
+ vendor_uri="$(go-module-vendor_get_vendor_uri)" |
111 |
+ for f in $A; do |
112 |
+ [[ $vendor_uri == *"$f"* ]] && continue |
113 |
+ unpack $f |
114 |
+ done |
115 |
+ |
116 |
+ if [[ -d "${S}/vendor" ]]; then |
117 |
+ eerror "Upstream for ${P}.ebuild vendors dependencies." |
118 |
+ die "This ebuild should inherit go-module.eclass" |
119 |
+ fi |
120 |
+ |
121 |
+ mkdir -p "${S}/vendor" || die |
122 |
+ for line in "${EGO_VENDOR[@]}"; do |
123 |
+ read -r import hash repo _ <<< "${line}" |
124 |
+ if [[ -n ${repo} ]]; then |
125 |
+ tarball=${repo//\//-}-${hash}.tar.gz |
126 |
+ else |
127 |
+ tarball=${import//\//-}-${hash}.tar.gz |
128 |
+ fi |
129 |
+ einfo "Vendoring ${import} ${tarball}" |
130 |
+ rm -fr "${S}/vendor/${import}" || die |
131 |
+ mkdir -p "${S}/vendor/${import}" || die |
132 |
+ tar -C "${S}/vendor/${import}" -x --strip-components 1\ |
133 |
+ -f "${DISTDIR}/${tarball}" || die |
134 |
+ done |
135 |
+} |
136 |
+ |
137 |
+fi |
138 |
-- |
139 |
2.21.0 |