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