Gentoo Archives: gentoo-dev

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 1/3] eclass/go-module: add support for building based on go.sum
Date: Mon, 17 Feb 2020 05:48:53
Message-Id: robbat2-20200216T214238-018091598Z@orbis-terrarum.net
In Reply to: Re: [gentoo-dev] [PATCH 1/3] eclass/go-module: add support for building based on go.sum by "Michał Górny"
1 Stay tuned for v2 with major improvements based on talking to upstream.
2 - Dropped an entire distfile per golang module (down to 1-2 files per
3 module in go.sum)
4 - Better Go 1.13 support (some semantics changed slightly from 1.12)
5 - Easier way to track & include licenses of all the modules
6
7 On Thu, Feb 13, 2020 at 05:57:57PM +0100, Michał Górny wrote:
8 > > +# EGO_SUM=(
9 > > +# "github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ="
10 > > +# "github.com/BurntSushi/toml v0.3.1/go.mod h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ="
11 > Is it expected that the two entries would have the same hash?
12 In this case, they SHOULD have been different, but it does happen in
13 reality for the /go.mod entries, here's an example:
14 github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
15 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
16 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
17 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
18
19 1.2.1->1.2.2 there was no change in the dependencies, so the file didn't change.
20
21 > > -EXPORT_FUNCTIONS src_unpack pkg_postinst
22 > > +EXPORT_FUNCTIONS src_unpack src_prepare pkg_postinst
23 > Exporting a new phase looks potentially dangerous. Are you sure no
24 > ebuilds are broken by this?
25 I'm not sure, so I've rolled it into src_unpack for now.
26 >
27 > > +
28 > > +# @ECLASS-VARIABLE: EGO_SUM
29 > > +# @DESCRIPTION:
30 > > +# This variable duplicates the go.sum content from inside the target package.
31 > > +# Entries of the form <version>/go.mod should be excluded.
32 > ...but you've included one of them in the example on top of the eclass.
33 There was an ongoing discussion with upstream, where I was trying to
34 trim down the number of distfiles involved. Sadly generating the .mod
35 files turns out to have some non-trivial corner cases
36
37 I did manage to drop the .info files at least, so it's 1-2 distfiles per
38 dependency now.
39
40 >
41 > > +#
42 > > +# <module> <version> <hash>
43 >
44 > Now I'm confused. Unless my eyes betray me, PATCH 2 has entries without
45 > hash.
46 >
47 > Also, the description fails to mention that you're supposed to quote
48 > each line.
49 Improved in documentation, and covered why the hash is optional right
50 now.
51
52 > > +# The format is described upstream here:
53 > > +# https://tip.golang.org/cmd/go/#hdr-Module_authentication_using_go_sum
54 ...
55 > I think it would be valuable to include an example here as well.
56 Done.
57 > > +# proxy generally verifies modules via the Hash1 code.
58 > > +#
59 > > +# Note: Users in China may find some mirrors in the list blocked, and may wish
60 > > +# to an explicit entry to /etc/portage/mirrors pointing mirror://goproxy/ to
61 > > +# https://goproxy.cn/, or change this variable.
62 > > +# See https://arslan.io/2019/08/02/why-you-should-use-a-go-module-proxy/ for further details
63 > > +: "${GOMODULE_GOPROXY_BASEURI:=mirror://goproxy/}"
64 > 'Changing this variable' sounds like violating metadata immutability
65 > rule and running in trouble with the caches.
66 Covered who & why this should be set, esp wrt to immutability.
67
68 > > +
69 > > +# @FUNCTION: go-module_set_globals
70 > > +# @DESCRIPTION:
71 > > +# Convert the information in EGO_SUM for other usage in the ebuild.
72 > > +# - Populates EGO_SUM_SRC_URI that can be added to SRC_URI
73 > > +# - Exports _EGO_SUM_MAPPING which provides reverse mapping from distfile back
74 > > +# to the relative part of SRC_URI, as needed for GOPROXY=file:///...
75 > > +go-module_set_globals() {
76 > > + local line error_in_gosum errorlines errormsg exts
77 > > + local newline=$'\n'
78 > > + error_in_gosum=0
79 > > + errorlines=( )
80 > > + for line in "${EGO_SUM[@]}"; do
81 > > + local module version modfile version_modfile hash1 x
82 > > + read -r module version_modfile hash1 x <<< "${line}"
83 > > + # Validate input
84 > > + if [[ -n $hash1 ]] && [[ ${hash1:0:3} != "h1:" ]] ; then
85 >
86 > Please use ${foo} everywhere consistently, and put && inside [[ ]].
87 > Also, I dare say wildcard match is more readable than hardcoding string
88 > length, i.e.:
89 >
90 > [[ -n ${hash1} && ${hash1} != h1:* ]]
91 ...
92
93 > > + # Split 'v0.3.0/go.mod' into 'v0.3.0' and '/go.mod'
94 > > + version=${version_modfile%%/*}
95 > > + modfile=${version_modfile#*/}
96 > > + [[ "$modfile" == "${version_modfile}" ]] && modfile=
97 > Check the initial string, not the result of arbitrary manipulations
98 > on it. This would wrongly evaluate true for 'v0.3.0/v0.3.0'.
99 Reworked this
100
101 > > +go-module_src_unpack() {
102 > > + if [[ "${#EGO_VENDOR[@]}" -gt 0 ]]; then
103 > > + _go-module_src_unpack_vendor
104 > > + elif [[ "${#EGO_SUM[@]}" -gt 0 ]]; then
105 > > + _go-module_src_unpack_gosum
106 > Does that mean those two are mutually exclusive?
107 Yes.
108
109 > > +# @FUNCTION: go-module_src_prepare
110 ...
111 > Wouldn't it be better to append this to src_unpack? Overriding
112 > src_prepare is generally problematic, and as I've said above, you're
113 > already risking by adding a new export.
114 Moved it.
115
116 > > +# @ECLASS-VARIABLE: GOMODULE_GOSUM_PATH
117 > > +# @DESCRIPTION:
118 > > +# Path to root go.sum of package. If your ebuild modifies S after inheriting
119 > > +# the eclass, you may need to update this variable.
120 > > +: "${GO_MODULE_GOSUM_PATH:=${S}/go.sum}"
121 > Wouldn't it be cleaner to have the path relative to ${S} by default?
122 Variable is no longer needed.
123
124 > > +# @FUNCTION: _go-module_src_unpack_gosum
125 ...
126 > > + declare -A _EGO_SUM_MAPPING_ASSOC
127 > Why not make it local?
128
129 Done.
130
131 > > + # go.sum entries ending in /go.mod aren't strictly needed at this phase
132 ...
133 > Why not create and restore a copy? Or does go-get make other changes?
134 The minimize is dropped entirely per upstream discussions.
135
136 --
137 Robin Hugh Johnson
138 Gentoo Linux: Dev, Infra Lead, Foundation Treasurer
139 E-Mail : robbat2@g.o
140 GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
141 GnuPG FP : 7D0B3CEB E9B85B1F 825BCECF EE05E6F6 A48F6136

Attachments

File name MIME type
signature.asc application/pgp-signature