Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: William Hubbs <williamh@g.o>
Subject: Re: [gentoo-dev] [PATCH] go-module.eclass: deprecate EGO_SUM and call ego instead of go
Date: Sat, 26 Feb 2022 07:26:11
Message-Id: eeb0785fc956146911c22b3ab5ba49f3aec2b66d.camel@gentoo.org
In Reply to: [gentoo-dev] [PATCH] go-module.eclass: deprecate EGO_SUM and call ego instead of go by William Hubbs
1 On Fri, 2022-02-25 at 20:50 -0600, William Hubbs wrote:
2 > EGO_SUM can be thousands of lines long in ebuilds, and it leads to
3 > creating Manifest files that are thousands of lines long.
4 > It has been determined that vendor tarballs are a better solution if
5 > upstream doesn't vendor their dependencies.
6 >
7 > Also, call the ego helper function instead of calling go directly.
8 >
9 > Signed-off-by: William Hubbs <williamh@g.o>
10 > ---
11 > eclass/go-module.eclass | 140 ++++++++++------------------------------
12 > 1 file changed, 34 insertions(+), 106 deletions(-)
13 >
14 > diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass
15 > index 66fe52c9ad7..7f0d766f444 100644
16 > --- a/eclass/go-module.eclass
17 > +++ b/eclass/go-module.eclass
18 > @@ -25,8 +25,18 @@
19 > #
20 > # If the software has a directory named vendor in its
21 > # top level directory, the only thing you need to do is inherit the
22 > -# eclass. Otherwise, you need to also populate
23 > -# EGO_SUM and call go-module_set_globals as discussed below.
24 > +# eclass. If it doesn't, you need to also create a vendor tarball and
25 > +# host it somewhere, for example in your dev space.
26 > +#
27 > +# Here are the commands to create a vendor tarball.
28 > +#
29 > +# @CODE
30 > +#
31 > +# $ cd /path/to/project
32 > +# $ go mod vendor
33 > +# $ tar -acf project-1.0.tar.xz vendor
34
35 Why not 'cd ..' first and create a tarball that doesn't require custom
36 src_unpack()? Also, shouldn't the name be 'project-1.0-vendor.tar'?
37 Also, you're mising -J.
38
39 > +#
40 > +# @CODE
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 > @@ -40,15 +50,9 @@
45 > #
46 > # inherit go-module
47 > #
48 > -# EGO_SUM=(
49 > -# "github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod"
50 > -# "github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59"
51 > -# )
52 > -#
53 > -# go-module_set_globals
54 > -#
55 > -# SRC_URI="https://github.com/example/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz
56 > -# ${EGO_SUM_SRC_URI}"
57 > +# SRC_URI="https://github.com/example/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
58 > +# Do not add the next line if you don't have a vendor tarball
59 > +# SRC_URI+="${P}-vendor.tar.gz"
60 > #
61 > # @CODE
62 >
63 > @@ -100,72 +104,6 @@ QA_FLAGS_IGNORED='.*'
64 > # Go packages should not be stripped with strip(1).
65 > RESTRICT+=" strip"
66 >
67 > -# @ECLASS-VARIABLE: EGO_SUM
68 > -# @DESCRIPTION:
69 > -# This array is based on the contents of the go.sum file from the top
70 > -# level directory of the software you are packaging. Each entry must be
71 > -# quoted and contain the first two fields of a line from go.sum.
72 > -#
73 > -# You can use some combination of sed/awk/cut to extract the
74 > -# contents of EGO_SUM or use the dev-go/get-ego-vendor tool.
75 > -#
76 > -# One manual way to do this is the following:
77 > -#
78 > -# @CODE
79 > -#
80 > -# cat go.sum | cut -d" " -f1,2 | awk '{print "\t\"" $0 "\""}'
81 > -#
82 > -# @CODE
83 > -#
84 > -# The format of go.sum is described upstream here:
85 > -# https://go.dev/ref/mod#go-sum-files
86 > -#
87 > -# For inclusion in EGO_SUM, the h1: value and other future extensions SHOULD be
88 > -# omitted at this time. The EGO_SUM parser will accept them for ease of ebuild
89 > -# creation.
90 > -#
91 > -# h1:<hash> is the Hash1 structure used by upstream Go
92 > -# The Hash1 is MORE stable than Gentoo distfile hashing, and upstream warns
93 > -# that it's conceptually possible for the Hash1 value to remain stable while
94 > -# the upstream zipfiles change. Here are examples that do NOT change the h1:
95 > -# hash, but do change a regular checksum over all bytes of the file:
96 > -# - Differing mtimes within zipfile
97 > -# - Differing filename ordering with the zipfile
98 > -# - Differing zipfile compression parameters
99 > -# - Differing zipfile extra fields
100 > -#
101 > -# For Gentoo usage, the authors of this eclass feel that the h1: hash should
102 > -# NOT be included in the EGO_SUM at this time in order to reduce size of the
103 > -# ebuilds. This position will be reconsidered in future when a Go module
104 > -# distfile collision comes to light, where the Hash1 value of two distfiles is
105 > -# the same, but checksums over the file as a byte stream consider the files to
106 > -# be different.
107 > -#
108 > -# This decision does NOT weaken Go module security, as Go will verify the
109 > -# go.sum copy of the Hash1 values during building of the package.
110 > -
111 > -# @ECLASS-VARIABLE: _GOMODULE_GOPROXY_BASEURI
112 > -# @DESCRIPTION:
113 > -# Golang module proxy service to fetch module files from. Note that the module
114 > -# proxy generally verifies modules via the Hash1 code.
115 > -#
116 > -# Users in China may find some mirrors in the default list blocked, and should
117 > -# explicitly set an entry in /etc/portage/mirrors for goproxy to
118 > -# https://goproxy.cn/ or another mirror that is not blocked in China.
119 > -# See https://arslan.io/2019/08/02/why-you-should-use-a-go-module-proxy/ for
120 > -# further details
121 > -#
122 > -# This variable is NOT intended for user-level configuration of mirrors, but
123 > -# rather to cover go modules that might exist only on specific Goproxy
124 > -# servers for non-technical reasons.
125 > -#
126 > -# This variable should NOT be present in user-level configuration e.g.
127 > -# /etc/portage/make.conf, as it will violate metadata immutability!
128 > -#
129 > -# I am considering removing this and just hard coding mirror://goproxy
130 > -# below, so please do not rely on it.
131 > -: "${_GOMODULE_GOPROXY_BASEURI:=mirror://goproxy/}"
132 > -
133 > # @ECLASS-VARIABLE: _GOMODULE_GOSUM_REVERSE_MAP
134 > # @DESCRIPTION:
135 > # Mapping back from Gentoo distfile name to upstream distfile path.
136 > @@ -181,7 +119,7 @@ declare -A -g _GOMODULE_GOSUM_REVERSE_MAP
137 > # ebuild will be considered optional. No dependencies will be added and
138 > # no phase functions will be exported.
139 > #
140 > -# If you enable GO_OPTIONAL, you have to set BDEPEND on >=dev-lang/go-1.12
141 > +# If you enable GO_OPTIONAL, you have to set BDEPEND on >=dev-lang/go-1.16
142 > # for your package and call go-module_src_unpack manually.
143 >
144 > # @FUNCTION: ego
145 > @@ -199,11 +137,7 @@ ego() {
146 >
147 > # @FUNCTION: go-module_set_globals
148 > # @DESCRIPTION:
149 > -# Convert the information in EGO_SUM for other usage in the ebuild.
150 > -# - Populates EGO_SUM_SRC_URI that can be added to SRC_URI
151 > -# - Exports _GOMODULE_GOSUM_REVERSE_MAP which provides reverse mapping from
152 > -# distfile back to the relative part of SRC_URI, as needed for
153 > -# GOPROXY=file:///...
154 > +# This function is deprecated.
155 > go-module_set_globals() {
156 > local line exts
157 > # for tracking go.sum errors
158 > @@ -256,7 +190,7 @@ go-module_set_globals() {
159 > # Relative URI within a GOPROXY for a file
160 > _reluri="${_dir}/@v/${version}.${_ext}"
161 > # SRC_URI: LHS entry
162 > - _uri="${_GOMODULE_GOPROXY_BASEURI}/${_reluri}"
163 > + _uri="mirror://goproxy/${_reluri}"
164 > # _uri="mirror://goproxy/${_reluri}"
165 > # SRC_URI: RHS entry, encode any slash in the path as
166 > # %2F in the filename
167 > @@ -289,9 +223,7 @@ go-module_set_globals() {
168 >
169 > # @FUNCTION: go-module_setup_proxy
170 > # @DESCRIPTION:
171 > -# If your ebuild redefines src_unpack and uses EGO_SUM you need to call
172 > -# this function in src_unpack.
173 > -# It sets up the go module proxy in the appropriate location.
174 > +# This function is deprecated.
175 > go-module_setup_proxy() {
176 > # shellcheck disable=SC2120
177 > debug-print-function "${FUNCNAME}" "$@"
178 > @@ -331,27 +263,30 @@ go-module_setup_proxy() {
179 > # @FUNCTION: go-module_src_unpack
180 > # @DESCRIPTION:
181 > # If EGO_SUM is set, unpack the base tarball(s) and set up the
182 > -# local go proxy.
183 > +# local go proxy. Also warn that this usage is deprecated.
184 > # - Otherwise, if EGO_VENDOR is set, bail out.
185 > -# - Otherwise do a normal unpack.
186 > +# - Otherwise do a normal unpack and move the vendor directory into
187 > +# place if appropriate.
188 > go-module_src_unpack() {
189 > if [[ "${#EGO_SUM[@]}" -gt 0 ]]; then
190 > + eqawarn "This ebuild uses EGO_SUM which is deprecated"
191 > + eqawarn "Please migrate to a vendor tarball"
192 > + eqawarn "This will become a fatal error in the future"
193 > _go-module_src_unpack_gosum
194 > elif [[ "${#EGO_VENDOR[@]}" -gt 0 ]]; then
195 > eerror "${EBUILD} is using EGO_VENDOR which is no longer supported"
196 > die "Please update this ebuild"
197 > else
198 > default
199 > + [[ -d "${S}"/vendor ]] && return
200 > + [[ ! -d vendor ]] && return
201 > + mv vendor "${S}" || die
202 > fi
203 > }
204 >
205 > # @FUNCTION: _go-module_src_unpack_gosum
206 > # @DESCRIPTION:
207 > -# Populate a GOPROXY directory hierarchy with distfiles from EGO_SUM and
208 > -# unpack the base distfiles.
209 > -#
210 > -# Exports GOPROXY environment variable so that Go calls will source the
211 > -# directory correctly.
212 > +# This function is deprecated.
213 > _go-module_src_unpack_gosum() {
214 > # shellcheck disable=SC2120
215 > debug-print-function "${FUNCNAME}" "$@"
216 > @@ -392,10 +327,7 @@ _go-module_src_unpack_gosum() {
217 >
218 > # @FUNCTION: _go-module_gosum_synthesize_files
219 > # @DESCRIPTION:
220 > -# Given a path & version, populate all Goproxy metadata files which aren't
221 > -# needed to be downloaded directly.
222 > -# - .../@v/${version}.info
223 > -# - .../@v/list
224 > +# This function is deprecated.
225 > _go-module_gosum_synthesize_files() {
226 > local target=$1
227 > local version=$2
228 > @@ -419,8 +351,7 @@ _go-module_gosum_synthesize_files() {
229 >
230 > # @FUNCTION: _go-module_src_unpack_verify_gosum
231 > # @DESCRIPTION:
232 > -# Validate the Go modules declared by EGO_SUM are sufficient to cover building
233 > -# the package, without actually building it yet.
234 > +# This function is deprecated.
235 > _go-module_src_unpack_verify_gosum() {
236 > # shellcheck disable=SC2120
237 > debug-print-function "${FUNCNAME}" "$@"
238 > @@ -435,7 +366,7 @@ _go-module_src_unpack_verify_gosum() {
239 > # This will print 'downloading' messages, but it's accessing content from
240 > # the $GOPROXY file:/// URL!
241 > einfo "Tidying go.mod/go.sum"
242 > - go mod tidy >/dev/null
243 > + ego mod tidy >/dev/null
244 >
245 > # This used to call 'go get' to verify by fetching everything from the main
246 > # go.mod. However 'go get' also turns out to recursively try to fetch
247 > @@ -461,16 +392,13 @@ go-module_live_vendor() {
248 > die "${FUNCNAME} only allowed when upstream isn't vendoring"
249 >
250 > pushd "${S}" >& /dev/null || die
251 > - go mod vendor || die
252 > + ego mod vendor
253 > popd >& /dev/null || die
254 > }
255 >
256 > # @FUNCTION: _go-module_gomod_encode
257 > # @DESCRIPTION:
258 > -# Encode the name(path) of a Golang module in the format expected by Goproxy.
259 > -#
260 > -# Upper letters are replaced by their lowercase version with a '!' prefix.
261 > -#
262 > +# This function is deprecated.
263 > _go-module_gomod_encode() {
264 > ## Python:
265 > # return re.sub('([A-Z]{1})', r'!\1', s).lower()
266
267 --
268 Best regards,
269 Michał Górny

Replies