1 |
On 5/19/21 12:48 PM, William Hubbs wrote: |
2 |
> If an ebuild uses EGO_SUM and needs to define a custom src_unpack phase, |
3 |
> these functions will make that easier. |
4 |
> |
5 |
> go-module_setup_proxy is used to create a local file proxy of the |
6 |
> dependencies listed in EGO_SUM and go-module_filter_proxy is used to |
7 |
> create a new ${A} with the EGO_SUM_SRC_URI values removed. |
8 |
> |
9 |
> Signed-off-by: William Hubbs <williamh@g.o> |
10 |
> --- |
11 |
> eclass/go-module.eclass | 69 +++++++++++++++++++++++++++++++++++++++++ |
12 |
> 1 file changed, 69 insertions(+) |
13 |
> |
14 |
> diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass |
15 |
> index c9a7ab12eaf..80e1f711215 100644 |
16 |
> --- a/eclass/go-module.eclass |
17 |
> +++ b/eclass/go-module.eclass |
18 |
> @@ -236,6 +236,75 @@ go-module_set_globals() { |
19 |
> _GO_MODULE_SET_GLOBALS_CALLED=1 |
20 |
> } |
21 |
> |
22 |
> +# @FUNCTION: go-module_filter_proxy |
23 |
> +# @DESCRIPTION: |
24 |
> +# If your ebuild redefines src_unpack and uses EGO_SUM, use the return |
25 |
> +# value of this function in place of ${A} in your src_unpack function. |
26 |
> +# It filters the EGO_SUM_SRC_URI values out of SRC_URI. |
27 |
> +go-module_filter_proxy() { |
28 |
> + # shellcheck disable=SC2120 |
29 |
> + debug-print-function "${FUNCNAME}" "$@" |
30 |
> + |
31 |
> + if [[ ! ${_GO_MODULE_SET_GLOBALS_CALLED} ]]; then |
32 |
> + die "go-module_set_globals must be called in global scope" |
33 |
> + fi |
34 |
> + |
35 |
> + # Skip golang modules and add the rest of the entries to a local |
36 |
> + # array. |
37 |
> + local f |
38 |
> + local -a src |
39 |
> + for f in ${A}; do |
40 |
> + if [[ -z ${_GOMODULE_GOSUM_REVERSE_MAP["${f}"]} ]]; then |
41 |
> + src+=("${f}") |
42 |
> + fi |
43 |
> + done |
44 |
> + echo "${src[@]}" |
45 |
> +} |
46 |
|
47 |
While this go-module_filter_proxy might seem like a convenient way for |
48 |
an ebuild to list distfiles which are not derived from EGO_SUM, I think |
49 |
it's not the responsibility of go-module.eclass to provide this |
50 |
information, therefore it's probably better to force the ebuild |
51 |
developer to provide their own mechanism to track those files if needed, |
52 |
rather than add a superfluous function to the eclass. |
53 |
|
54 |
> +# @FUNCTION: go-module_setup_proxy |
55 |
> +# @DESCRIPTION: |
56 |
> +# If your ebuild redefines src_unpack and uses EGO_SUM you need to call |
57 |
> +# this function in src_unpack. |
58 |
> +# It sets up the go module proxy in the appropriate location and exports |
59 |
> +# the GOPROXY environment variable so that go calls will be able to |
60 |
> +# locate the proxy directory. |
61 |
> +go-module_setup_proxy() { |
62 |
> + # shellcheck disable=SC2120 |
63 |
> + debug-print-function "${FUNCNAME}" "$@" |
64 |
> + |
65 |
> + if [[ ! ${_GO_MODULE_SET_GLOBALS_CALLED} ]]; then |
66 |
> + die "go-module_set_globals must be called in global scope" |
67 |
> + fi |
68 |
> + |
69 |
> + local goproxy_dir="${T}/go-proxy" |
70 |
> + mkdir -p "${goproxy_dir}" || die |
71 |
> + |
72 |
> + # For each Golang module distfile, look up where it's supposed to go and |
73 |
> + # symlink it into place. |
74 |
> + local f |
75 |
> + local goproxy_mod_dir |
76 |
> + for f in ${A}; do |
77 |
> + goproxy_mod_path="${_GOMODULE_GOSUM_REVERSE_MAP["${f}"]}" |
78 |
> + if [[ -n "${goproxy_mod_path}" ]]; then |
79 |
> + debug-print-function "Populating go proxy for ${goproxy_mod_path}" |
80 |
> + # Build symlink hierarchy |
81 |
> + goproxy_mod_dir=$( dirname "${goproxy_dir}"/"${goproxy_mod_path}" ) |
82 |
> + mkdir -p "${goproxy_mod_dir}" || die |
83 |
> + ln -sf "${DISTDIR}"/"${f}" "${goproxy_dir}/${goproxy_mod_path}" || |
84 |
> + die "Failed to ln" |
85 |
> + local v=${goproxy_mod_path} |
86 |
> + v="${v%.mod}" |
87 |
> + v="${v%.zip}" |
88 |
> + v="${v//*\/}" |
89 |
> + _go-module_gosum_synthesize_files "${goproxy_mod_dir}" "${v}" |
90 |
> + fi |
91 |
> + done |
92 |
> + export GOPROXY="file://${goproxy_dir}" |
93 |
> + |
94 |
> + # Validate the gosum now |
95 |
> + _go-module_src_unpack_verify_gosum |
96 |
> +} |
97 |
> + |
98 |
> # @FUNCTION: go-module_src_unpack |
99 |
> # @DESCRIPTION: |
100 |
> # If EGO_SUM is set, unpack the base tarball(s) and set up the |
101 |
> |
102 |
|
103 |
The go-module_setup_proxy function solves bug 790851 nicely, since |
104 |
sys-cluster/k3s ebuilds can call that instead of go-module_src_unpack. |
105 |
-- |
106 |
Thanks, |
107 |
Zac |