Gentoo Archives: gentoo-dev

From: Zac Medico <zmedico@g.o>
To: Zac Medico <zmedico@g.o>, William Hubbs <williamh@g.o>, gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: [PATCH] go-module.eclass: add functions for use in custom src_unpack phase
Date: Wed, 19 May 2021 20:57:45
Message-Id: 3b860916-18d1-cc5d-90c9-0bef307be0da@gentoo.org
In Reply to: [gentoo-dev] Re: [PATCH] go-module.eclass: add functions for use in custom src_unpack phase by Zac Medico
1 On 5/19/21 1:45 PM, Zac Medico wrote:
2 >> +# @FUNCTION: go-module_setup_proxy
3 >> +# @DESCRIPTION:
4 >> +# If your ebuild redefines src_unpack and uses EGO_SUM you need to call
5 >> +# this function in src_unpack.
6 >> +# It sets up the go module proxy in the appropriate location and exports
7 >> +# the GOPROXY environment variable so that go calls will be able to
8 >> +# locate the proxy directory.
9 >> +go-module_setup_proxy() {
10 >> + # shellcheck disable=SC2120
11 >> + debug-print-function "${FUNCNAME}" "$@"
12 >> +
13 >> + if [[ ! ${_GO_MODULE_SET_GLOBALS_CALLED} ]]; then
14 >> + die "go-module_set_globals must be called in global scope"
15 >> + fi
16 >> +
17 >> + local goproxy_dir="${T}/go-proxy"
18 >> + mkdir -p "${goproxy_dir}" || die
19 >> +
20 >> + # For each Golang module distfile, look up where it's supposed to go and
21 >> + # symlink it into place.
22 >> + local f
23 >> + local goproxy_mod_dir
24 >> + for f in ${A}; do
25 >> + goproxy_mod_path="${_GOMODULE_GOSUM_REVERSE_MAP["${f}"]}"
26 >> + if [[ -n "${goproxy_mod_path}" ]]; then
27 >> + debug-print-function "Populating go proxy for ${goproxy_mod_path}"
28 >> + # Build symlink hierarchy
29 >> + goproxy_mod_dir=$( dirname "${goproxy_dir}"/"${goproxy_mod_path}" )
30 >> + mkdir -p "${goproxy_mod_dir}" || die
31 >> + ln -sf "${DISTDIR}"/"${f}" "${goproxy_dir}/${goproxy_mod_path}" ||
32 >> + die "Failed to ln"
33 >> + local v=${goproxy_mod_path}
34 >> + v="${v%.mod}"
35 >> + v="${v%.zip}"
36 >> + v="${v//*\/}"
37 >> + _go-module_gosum_synthesize_files "${goproxy_mod_dir}" "${v}"
38 >> + fi
39 >> + done
40 >> + export GOPROXY="file://${goproxy_dir}"
41 >> +
42 >> + # Validate the gosum now
43 >> + _go-module_src_unpack_verify_gosum
44 >> +}
45 >> +
46 >> # @FUNCTION: go-module_src_unpack
47 >> # @DESCRIPTION:
48 >> # If EGO_SUM is set, unpack the base tarball(s) and set up the
49 >>
50 >
51 > The go-module_setup_proxy function solves bug 790851 nicely, since
52 > sys-cluster/k3s ebuilds can call that instead of go-module_src_unpack.
53
54 I do have one criticism of the go-module_setup_proxy, which is that it
55 relies on the side-effect of the GOPROXY export for its operation. We
56 can instead echo the GOPROXY value to stdout and force the caller to
57 export it themselves, and provide a convenience wrapper function which
58 works based on side-effects.
59 --
60 Thanks,
61 Zac

Attachments

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

Replies