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