1 |
On Wed, Sep 18, 2019 at 10:29:12PM +0200, Michał Górny wrote: |
2 |
> On Wed, 2019-09-18 at 15:26 -0500, William Hubbs wrote: |
3 |
> > Signed-off-by: William Hubbs <williamh@g.o> |
4 |
> > --- |
5 |
> > eclass/go-module.eclass | 161 ++++++++++++++++++++++++++++++++++++++++ |
6 |
> > 1 file changed, 161 insertions(+) |
7 |
> > create mode 100644 eclass/go-module.eclass |
8 |
> > |
9 |
> > diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass |
10 |
> > new file mode 100644 |
11 |
> > index 00000000000..6f609e94542 |
12 |
> > --- /dev/null |
13 |
> > +++ b/eclass/go-module.eclass |
14 |
> > @@ -0,0 +1,161 @@ |
15 |
> > +# Copyright 2019 gentoo authors |
16 |
> > +# Distributed under the terms of the GNU General Public License v2 |
17 |
> > + |
18 |
> > +# @ECLASS: go-module.eclass |
19 |
> > +# @MAINTAINER: |
20 |
> > +# William Hubbs <williamh@g.o> |
21 |
> > +# @SUPPORTED_EAPIS: 7 |
22 |
> > +# @BLURB: basic eclass for building software written in the go |
23 |
> > +# programming language that uses go modules. |
24 |
> > +# @DESCRIPTION: |
25 |
> > +# This eclass provides some basic things needed by all software |
26 |
> > +# written in the go programming language that 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 |
> > +# This eclass provides a src_unpack function which unpacks the |
33 |
> > +# first tarball mentioned in SRC_URI to the usual location and unpacks |
34 |
> > +# any modules mentioned in EGO_VENDOR to ${S}/vendor if upstream doesn't |
35 |
> > +# vendor its own dependencies. |
36 |
> > +# |
37 |
> > +# If upstream vendors its dependencies, setting EGO_VENDOR is an error. |
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 |
> > +# EGO_VENDOR=( |
50 |
> > +# "github.com/xenolf/lego 6cac0ea7d8b28c889f709ec7fa92e92b82f490dd" |
51 |
> > +# "golang.org/x/crypto 453249f01cfeb54c3d549ddb75ff152ca243f9d8 github.com/golang/crypto" |
52 |
> > +# ) |
53 |
> > +# |
54 |
> > +# inherit go-module |
55 |
> > +# |
56 |
> > +# SRC_URI="https://github.com/example/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz |
57 |
> > +# ${EGO_VENDOR_URI}" |
58 |
> > +# @CODE |
59 |
> > +# |
60 |
> > +# The above example will extract the tarball to ${S} and |
61 |
> > +# extract the contents of EGO_VENDOR to ${S}/vendor. |
62 |
> > + |
63 |
> > +case ${EAPI:-0} in |
64 |
> > + 7) ;; |
65 |
> > + *) die "${ECLASS} API in EAPI ${EAPI} not yet established." |
66 |
> > +esac |
67 |
> > + |
68 |
> > +if [[ -z ${_GO_MODULE} ]]; then |
69 |
> > + |
70 |
> > +_GO_MODULE=1 |
71 |
> > + |
72 |
> > +BDEPEND=">=dev-lang/go-1.12" |
73 |
> > + |
74 |
> > +# Force go to build in module mode. |
75 |
> > +# In this mode the GOPATH environment variable is ignored. |
76 |
> > +# this will become the default in the future. |
77 |
> > +export GO111MODULE=on |
78 |
> > + |
79 |
> > +# The following go flags should be used for all builds. |
80 |
> > +# -mod=vendor stopps downloading of dependencies from the internet. |
81 |
> > +# -v prints the names of packages as they are compiled |
82 |
> > +# -x prints commands as they are executed |
83 |
> > +export GOFLAGS="-mod=vendor -v -x" |
84 |
> > + |
85 |
> > +# Do not complain about CFLAGS etc since go projects do not use them. |
86 |
> > +QA_FLAGS_IGNORED='.*' |
87 |
> > + |
88 |
> > +# Go packages should not be stripped with strip(1). |
89 |
> > +RESTRICT="strip" |
90 |
> > + |
91 |
> > +EXPORT_FUNCTIONS src_unpack pkg_postinst |
92 |
> > + |
93 |
> > +# @ECLASS-VARIABLE: EGO_VENDOR |
94 |
> > +# @DESCRIPTION: |
95 |
> > +# This variable contains a list of vendored packages. |
96 |
> > +# The items of this array are strings that contain the |
97 |
> > +# import path and the git commit hash for a vendored package. |
98 |
> > +# If the import path does not start with github.com, the third argument |
99 |
> > +# can be used to point to a github repository. |
100 |
> > + |
101 |
> > +declare -arg EGO_VENDOR |
102 |
> > + |
103 |
> > +_go-module_set_vendor_uri() { |
104 |
> > + EGO_VENDOR_URI= |
105 |
> > + local lib |
106 |
> > + for lib in "${EGO_VENDOR[@]}"; do |
107 |
> > + lib=(${lib}) |
108 |
> > + if [[ -n ${lib[2]} ]]; then |
109 |
> > + EGO_VENDOR_URI+=" https://${lib[2]}/archive/${lib[1]}.tar.gz -> ${lib[2]//\//-}-${lib[1]}.tar.gz" |
110 |
> > + else |
111 |
> > + EGO_VENDOR_URI+=" https://${lib[0]}/archive/${lib[1]}.tar.gz -> ${lib[0]//\//-}-${lib[1]}.tar.gz" |
112 |
> > + fi |
113 |
> > + done |
114 |
> > + readonly EGO_VENDOR_URI |
115 |
> > +} |
116 |
> > + |
117 |
> > +_go-module_set_vendor_uri |
118 |
> > +unset -f _go-module_set_vendor_uri |
119 |
> > + |
120 |
> > +_go-module_dovendor() { |
121 |
> > + local VENDOR_PATH=$1 VENDORPN=$2 TARBALL=$3 |
122 |
> > + rm -fr "${VENDOR_PATH}/${VENDORPN}" || die |
123 |
> > + mkdir -p "${VENDOR_PATH}/${VENDORPN}" || die |
124 |
> > + tar -C "${VENDOR_PATH}/${VENDORPN}" -x --strip-components 1\ |
125 |
> > + -f "${DISTDIR}/${TARBALL}" || die |
126 |
> > +} |
127 |
> > + |
128 |
> > +# @FUNCTION: go-module_src_unpack |
129 |
> > +# @DESCRIPTION: |
130 |
> > +# Extract the first archive from ${A} to ${S}, then extract |
131 |
> > +# any sources mentioned in ${EGO_VENDOR} to ${S}/vendor. |
132 |
> > +go-module_src_unpack() { |
133 |
> > + local lib vendor_path x |
134 |
> > + set -- ${A} |
135 |
> > + x="$1" |
136 |
> > + mkdir -p "${S}" || die |
137 |
> > + tar -C "${S}/" -x --strip-components 1 \ |
138 |
> > + -f "${DISTDIR}/${x}" || die |
139 |
> > + |
140 |
> > + if [[ -n "${EGO_VENDOR}" ]]; then |
141 |
> > + vendor_path="${S}/vendor" |
142 |
> > + if [[ -d "${vendor_path}" ]]; then |
143 |
> > + eerror "Upstream for ${P}.ebuild vendors dependencies." |
144 |
> > + die "Remove EGO_VENDOR from the ebuild." |
145 |
> > + fi |
146 |
> > + mkdir -p "${vendor_path}" || die |
147 |
> > + for lib in "${EGO_VENDOR[@]}"; do |
148 |
> > + lib=(${lib}) |
149 |
> > + if [[ -n ${lib[2]} ]]; then |
150 |
> > + einfo "Vendoring ${lib[0]} ${lib[2]//\//-}-${lib[1]}.tar.gz" |
151 |
> > + _go-module_dovendor "${vendor_path}" ${lib[0]} \ |
152 |
> > + ${lib[2]//\//-}-${lib[1]}.tar.gz |
153 |
> > + else |
154 |
> > + einfo "Vendoring ${lib[0]} ${lib[0]//\//-}-${lib[1]}.tar.gz" |
155 |
> > + _go-module_dovendor "${vendor_path}" ${lib[0]} \ |
156 |
> > + ${lib[0]//\//-}-${lib[1]}.tar.gz |
157 |
> > + fi |
158 |
> > + done |
159 |
> > + fi |
160 |
> > +} |
161 |
> > + |
162 |
> > +# @FUNCTION: go-module_pkg_postinst |
163 |
> > +# @DESCRIPTION: |
164 |
> > +# Display a warning about security updates for Go programs. |
165 |
> > +go-module_pkg_postinst() { |
166 |
> > + ewarn "${PN} is written in the Go programming language." |
167 |
> > + ewarn "Since this language is statically linked, security" |
168 |
> > + ewarn "updates will be handled in individual packages and will be" |
169 |
> > + ewarn "difficult for us to track as a distribution." |
170 |
> > + ewarn "For this reason, please update any go packages asap when new" |
171 |
> > + ewarn "versions enter the tree or go stable if you are running the" |
172 |
> > + ewarn "stable tree." |
173 |
> |
174 |
> I don't really understand why you're adding it to *this* eclass. Isn't |
175 |
> it true for all Go packages? So I suppose golang-* eclasses are |
176 |
> affected as well. |
177 |
|
178 |
You are correct, they are affected. No one, including myself, caught |
179 |
that during the review cycle for those eclasses. |
180 |
I'm not sure of a way we can go back and fix that without breaking |
181 |
compatibility. |
182 |
|
183 |
The goal here is that the go upstream world will move to modules and |
184 |
eventually we will be able to move off of and get rid of the golang-* |
185 |
eclasses. |
186 |
|
187 |
William |