Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o, William Hubbs <williamh@g.o>
Subject: Re: [gentoo-dev] [PATCH 1/3] go-module.eclass: introduce new eclass to handle go modules
Date: Thu, 12 Sep 2019 05:39:59
Message-Id: 06381929-4520-4284-B868-EB83D5AE3D6B@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH 1/3] go-module.eclass: introduce new eclass to handle go modules by William Hubbs
1 Dnia September 11, 2019 11:11:15 PM UTC, William Hubbs <williamh@g.o> napisał(a):
2 >On Wed, Sep 11, 2019 at 07:47:04PM +0000, Michał Górny wrote:
3 >> Dnia September 11, 2019 7:40:41 PM UTC, William Hubbs
4 ><williamh@g.o> napisał(a):
5 >> >On Wed, Sep 11, 2019 at 08:31:16PM +0200, Michał Górny wrote:
6 >> >> On Wed, 2019-09-11 at 13:22 -0500, William Hubbs wrote:
7 >> >> > On Wed, Sep 11, 2019 at 07:38:17PM +0200, Michał Górny wrote:
8 >> >> > > On Wed, 2019-09-11 at 12:21 -0500, William Hubbs wrote:
9 >> >> > > > Copyright: Sony Interactive Entertainment Inc.
10 >> >> > > > Signed-off-by: William Hubbs <williamh@g.o>
11 >> >> > > > ---
12 >> >> > > > eclass/go-module.eclass | 76
13 >> >+++++++++++++++++++++++++++++++++++++++++
14 >> >> > > > 1 file changed, 76 insertions(+)
15 >> >> > > > create mode 100644 eclass/go-module.eclass
16 >> >> > > >
17 >> >> > > > diff --git a/eclass/go-module.eclass
18 >b/eclass/go-module.eclass
19 >> >> > > > new file mode 100644
20 >> >> > > > index 00000000000..7009fcd3beb
21 >> >> > > > --- /dev/null
22 >> >> > > > +++ b/eclass/go-module.eclass
23 >> >> > > > @@ -0,0 +1,76 @@
24 >> >> > > > +# Copyright 1999-2015 Gentoo Foundation
25 >> >> > >
26 >> >> > > You need to replace your calendar. And copyright holder.
27 >> >> >
28 >> >> > Sure, I thought I ffixed that.
29 >> >> >
30 >> >> > > > +# Distributed under the terms of the GNU General Public
31 >> >License v2
32 >> >> > > > +
33 >> >> > > > +# @ECLASS: go-module.eclass
34 >> >> > >
35 >> >> > > Any reason to change naming from golang-* to go-* now?
36 >> >> >
37 >> >> > Well, "lang" is sort of redundant, and there will be only one
38 >> >eclass, so
39 >> >> > I thought I would make things a bit more simple.
40 >> >> >
41 >> >> > > > +# @MAINTAINER:
42 >> >> > > > +# William Hubbs <williamh@g.o>
43 >> >> > > > +# @SUPPORTED_EAPIS: 7
44 >> >> > > > +# @BLURB: basic eclass for building software written in the
45 >go
46 >> >> > > > +# programming language that uses go modules.
47 >> >> > > > +# @DESCRIPTION:
48 >> >> > > > +# This eclass provides a convenience src_prepare() phase
49 >and
50 >> >some basic
51 >> >> > > > +# settings needed for all software written in the go
52 >> >programming
53 >> >> > > > +# language that uses go modules.
54 >> >> > > > +#
55 >> >> > > > +# You will know the software you are packaging uses modules
56 >> >because
57 >> >> > > > +# it will have files named go.sum and go.mod in its
58 >top-level
59 >> >source
60 >> >> > > > +# directory. If it does not have these files, use the
61 >golang-*
62 >> >eclasses.
63 >> >> > > > +#
64 >> >> > > > +# If the software you are packaging uses modules, the next
65 >> >question is
66 >> >> > > > +# whether it has a directory named "vendor" at the
67 >top-level
68 >> >of the source tree.
69 >> >> > > > +#
70 >> >> > > > +# If it doesn't, you need to create a tarball of what would
71 >be
72 >> >in the
73 >> >> > > > +# vendor directory and mirror it locally. This is done with
74 >> >the
75 >> >> > > > +# following commands if upstream is using a git repository:
76 >> >> > > > +#
77 >> >> > > > +# @CODE:
78 >> >> > > > +#
79 >> >> > > > +# $ cd /my/clone/of/upstream
80 >> >> > > > +# $ git checkout <release>
81 >> >> > > > +# $ go mod vendor
82 >> >> > > > +# $ tar cvf project-version-vendor.tar.gz vendor
83 >> >> > > > +#
84 >> >> > > > +# @CODE:
85 >> >> > > > +#
86 >> >> > > > +# Other than this, all you need to do is inherit this
87 >eclass
88 >> >then
89 >> >> > > > +# make sure the exported src_prepare function is run.
90 >> >> > > > +
91 >> >> > > > +case ${EAPI:-0} in
92 >> >> > > > + 7) ;;
93 >> >> > > > + *) die "${ECLASS} API in EAPI ${EAPI} not yet
94 >established."
95 >> >> > > > +esac
96 >> >> > > > +
97 >> >> > > > +if [[ -z ${_GO_MODULE} ]]; then
98 >> >> > > > +
99 >> >> > > > +_GO_MODULE=1
100 >> >> > > > +
101 >> >> > > > +BDEPEND=">=dev-lang/go-1.12"
102 >> >> > > > +
103 >> >> > > > +# Do not download dependencies from the internet
104 >> >> > > > +# make build output verbose by default
105 >> >> > > > +export GOFLAGS="-mod=vendor -v -x"
106 >> >> > > > +
107 >> >> > > > +# Do not complain about CFLAGS etc since go projects do not
108 >> >use them.
109 >> >> > > > +QA_FLAGS_IGNORED='.*'
110 >> >> > > > +
111 >> >> > > > +# Upstream does not support stripping go packages
112 >> >> > > > +RESTRICT="strip"
113 >> >> > > > +
114 >> >> > > > +EXPORT_FUNCTIONS src_prepare
115 >> >> > >
116 >> >> > > Don't you need to inherit some other eclass to make it build?
117 >> >> >
118 >> >> > The primary reason for all of the golang-* eclasses was the
119 >GOPATH
120 >> >> > variable, which is not relevant when you are using modules.
121 >> >> >
122 >> >> > I can look at adding a src_compile to this eclass, but I haven't
123 >> >thought
124 >> >> > about what it would contain yet.
125 >> >> >
126 >> >> > > > +
127 >> >> > > > +# @FUNCTION: go-module_src_prepare
128 >> >> > > > +# @DESCRIPTION:
129 >> >> > > > +# Run a default src_prepare then move our provided vendor
130 >> >directory to
131 >> >> > > > +# the appropriate spot if upstream doesn't provide a vendor
132 >> >directory.
133 >> >> > > > +go-module_src_prepare() {
134 >> >> > > > + default
135 >> >> > > > + # Use the upstream provided vendor directory if it exists.
136 >> >> > > > + [[ -d vendor ]] && return
137 >> >> > > > + # If we are not providing a mirror of a vendor directory
138 >we
139 >> >created
140 >> >> > > > + # manually, return since there may be nothing to vendor.
141 >> >> > > > + [[ ! -d ../vendor ]] && return
142 >> >> > > > + # At this point, we know we are providing a vendor mirror.
143 >> >> > > > + mv ../vendor . || die "Unable to move ../vendor directory"
144 >> >> > >
145 >> >> > > Wouldn't it be much simpler to create appropriate directory
146 >> >structure
147 >> >> > > in the tarball? Then you wouldn't need a new eclass at all.
148 >> >> >
149 >> >> > You would definitely need an eclass (see the settings and
150 >> >dependencies).
151 >> >> >
152 >> >> > Take a look at the differences in the spire and hub ebuilds in
153 >this
154 >> >> > series. I'm not sure what you mean by adding the directory
155 >> >structure to
156 >> >> > the tarball? I guess you could add something to the vendor
157 >tarball
158 >> >when
159 >> >> > you create it.
160 >> >>
161 >> >> I mean packing it as 'spire-1.2.3/vendor' or whatever the package
162 >> >> directory is, so that it extracts correctly instead of making a
163 >> >tarball
164 >> >> that needs to be moved afterwards.
165 >> >
166 >> >That would clobber the upstream provided vendor directory and that's
167 >> >what I want to avoid with the first test in src_prepare.
168 >>
169 >> If upstream already includes vendored modules, why would you create
170 >your own tarball in the first place?
171 >
172 >You are right, and currently I quietly ignore your vendor tarball if
173 >upstream
174 >vendors the dependencies also. I could change this to generate a
175 >warning
176 >or die and force you to fix the ebuild, but that would not be possible
177 >if I follow your suggestion because I would not be able to tell whether
178 >the vendored dependencies came from us or upstream.
179
180 Why would anyone create a vendor tarball if things work without it? That makes no sense. Also adding unused archives to SRC_URI is a QA violation.
181
182 >
183 >Also, another concern about your suggestion is the --transform switch
184 >that would have to be added to the tar command people use to create
185 >the
186 >vendor tarball, something like:
187 >
188 >tar -acvf package-version-vendor.tar.gz
189 >--transform='s#^vendor#package-version-vendor#' vendor
190 >
191 >You suggested that a maintainer could create a new tarball and build on
192 >top of it. I guess you mean don't use upstream's tarball if they don't
193 >vendor and create my own tarball and add the vendor directory to it.
194 >I'm
195 >against that option because I don't feel that we should manually
196 >tinker
197 >with upstream tarballs. That opens a pretty big can of worms imo.
198
199 No. I suggested that rather than adding another git clone and checking out a tag (which sooner or later would mean someone forgetting and using master instead), you could unpack the same archive you're going to use in the ebuild.
200 >
201 >William
202
203
204 --
205 Best regards,
206 Michał Górny

Replies