Gentoo Archives: gentoo-dev

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

Replies