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