1 |
Golang does not support the 'socks5h://' schema for http[s]_proxy |
2 |
env variable: https://github.com/golang/go/blob/ |
3 |
9123221ccf3c80c741ead5b6f2e960573b1676b9/src/vendor/golang.org/x/net/http/ |
4 |
httpproxy/proxy.go#L152-L159, |
5 |
while libcurl supports it: https://github.com/curl/curl/blob/ |
6 |
ae98b85020094fb04eee7e7b4ec4eb1a38a98b98/docs/libcurl/opts/CURLOPT_PROXY. |
7 |
3#L48-L59. |
8 |
So, if a 'https_proxy=socks5h://127.0.0.1:1080' env has been set in the |
9 |
make.conf to make curl (assuming curl is the current download command) to |
10 |
download all packages through the proxy, go-module_live_vendor will |
11 |
fail. |
12 |
|
13 |
The only difference between these two schemas is, 'socks5h' will solve |
14 |
the hostname via the proxy while 'socks5' will not. I think it's ok to |
15 |
fallback 'socks5h' to 'socks5' for `go vendor` command and warn user, |
16 |
until golang supports it. |
17 |
|
18 |
related to issue: golang/go#24135 |
19 |
Closes: https://github.com/gentoo/gentoo/pull/28887 |
20 |
Signed-off-by: Ryan Qian <i@×××××××.net> |
21 |
|
22 |
diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass |
23 |
index 10ed475c5b11e..d1b5798b6f40f 100644 |
24 |
--- a/eclass/go-module.eclass |
25 |
+++ b/eclass/go-module.eclass |
26 |
@@ -14,7 +14,7 @@ |
27 |
# written in the go programming language that uses modules. |
28 |
# If the software you are packaging has a file named go.mod in its top level |
29 |
# directory, it uses modules. |
30 |
-# |
31 |
+# |
32 |
# Modules have been the preferred method of tracking dependencies in software |
33 |
# written in Go since version 1.16, |
34 |
# so if the software isn't using modules, it should be updated. |
35 |
@@ -119,13 +119,13 @@ RESTRICT+=" strip" |
36 |
# |
37 |
# You can use some combination of sed/awk/cut to extract the |
38 |
# contents of EGO_SUM or use the dev-go/get-ego-vendor tool. |
39 |
-# |
40 |
+# |
41 |
# One manual way to do this is the following: |
42 |
# |
43 |
# @CODE |
44 |
# |
45 |
# cat go.sum | cut -d" " -f1,2 | awk '{print "\t\"" $0 "\""}' |
46 |
-# |
47 |
+# |
48 |
# @CODE |
49 |
# |
50 |
# The format of go.sum is described upstream here: |
51 |
@@ -485,6 +485,27 @@ go-module_live_vendor() { |
52 |
[[ -d "${S}"/vendor ]] && |
53 |
die "${FUNCNAME} only allowed when upstream isn't |
54 |
vendoring" |
55 |
|
56 |
+ local hp |
57 |
+ local -a hps |
58 |
+ if [[ -n $HTTP_PROXY ]]; then |
59 |
+ hps+=( HTTP_PROXY ) |
60 |
+ elif [[ -n $http_proxy ]]; then |
61 |
+ hps+=( http_proxy ) |
62 |
+ fi |
63 |
+ if [[ -n $HTTPS_PROXY ]]; then |
64 |
+ hps+=( HTTPS_PROXY ) |
65 |
+ elif [[ -n $https_proxy ]]; then |
66 |
+ hps+=( https_proxy ) |
67 |
+ fi |
68 |
+ for hp in "${hps[@]}"; do |
69 |
+ if [[ -n ${!hp} ]] && [[ ${!hp} =~ ^socks5h:// ]]; then |
70 |
+ set -- export ${hp}="socks5${!hp#socks5h}" |
71 |
+ ewarn "golang does not support the |
72 |
'socks5h://' schema for '${hp}', fallback to the 'socks5://' schema" |
73 |
+ einfo "${@}" |
74 |
+ "${@}" |
75 |
+ fi |
76 |
+ done |
77 |
+ |
78 |
pushd "${S}" >& /dev/null || die |
79 |
ego mod vendor |
80 |
popd >& /dev/null || die |