1 |
Golang does not support the 'socks5h://' schema for http[s]_proxy |
2 |
env variable: https://github.com/golang/go/blob/9123221ccf3c80c741ead5b6f2e960573b1676b9/src/vendor/golang.org/x/net/http/httpproxy/proxy.go#L152-L159, |
3 |
while libcurl supports it: https://github.com/curl/curl/blob/ae98b85020094fb04eee7e7b4ec4eb1a38a98b98/docs/libcurl/opts/CURLOPT_PROXY.3#L48-L59. |
4 |
So, if a 'https_proxy=socks5h://127.0.0.1:1080' env has been set in the |
5 |
make.conf to make curl (assuming curl is the current download command) to |
6 |
download all packages through the proxy, go-module_live_vendor will |
7 |
fail. |
8 |
|
9 |
The only difference between these two schemas is, 'socks5h' will solve |
10 |
the hostname via the proxy while 'socks5' will not. I think it's ok to |
11 |
fallback 'socks5h' to 'socks5' for `go vendor` command and warn user, |
12 |
until golang supports it. |
13 |
|
14 |
related to issue: https://github.com/golang/go/issues/24135 |
15 |
Closes: https://github.com/gentoo/gentoo/pull/28887 |
16 |
Signed-off-by: Ryan Qian <i@×××××××.net> |
17 |
|
18 |
diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass |
19 |
index 10ed475c5b11e..d1b5798b6f40f 100644 |
20 |
--- a/eclass/go-module.eclass |
21 |
+++ b/eclass/go-module.eclass |
22 |
@@ -14,7 +14,7 @@ |
23 |
# written in the go programming language that uses modules. |
24 |
# If the software you are packaging has a file named go.mod in its top level |
25 |
# directory, it uses modules. |
26 |
-# |
27 |
+# |
28 |
# Modules have been the preferred method of tracking dependencies in software |
29 |
# written in Go since version 1.16, |
30 |
# so if the software isn't using modules, it should be updated. |
31 |
@@ -119,13 +119,13 @@ RESTRICT+=" strip" |
32 |
# |
33 |
# You can use some combination of sed/awk/cut to extract the |
34 |
# contents of EGO_SUM or use the dev-go/get-ego-vendor tool. |
35 |
-# |
36 |
+# |
37 |
# One manual way to do this is the following: |
38 |
# |
39 |
# @CODE |
40 |
# |
41 |
# cat go.sum | cut -d" " -f1,2 | awk '{print "\t\"" $0 "\""}' |
42 |
-# |
43 |
+# |
44 |
# @CODE |
45 |
# |
46 |
# The format of go.sum is described upstream here: |
47 |
@@ -485,6 +485,27 @@ go-module_live_vendor() { |
48 |
[[ -d "${S}"/vendor ]] && |
49 |
die "${FUNCNAME} only allowed when upstream isn't vendoring" |
50 |
|
51 |
+ local hp |
52 |
+ local -a hps |
53 |
+ if [[ -n $HTTP_PROXY ]]; then |
54 |
+ hps+=( HTTP_PROXY ) |
55 |
+ elif [[ -n $http_proxy ]]; then |
56 |
+ hps+=( http_proxy ) |
57 |
+ fi |
58 |
+ if [[ -n $HTTPS_PROXY ]]; then |
59 |
+ hps+=( HTTPS_PROXY ) |
60 |
+ elif [[ -n $https_proxy ]]; then |
61 |
+ hps+=( https_proxy ) |
62 |
+ fi |
63 |
+ for hp in "${hps[@]}"; do |
64 |
+ if [[ -n ${!hp} ]] && [[ ${!hp} =~ ^socks5h:// ]]; then |
65 |
+ set -- export ${hp}="socks5${!hp#socks5h}" |
66 |
+ ewarn "golang does not support the 'socks5h://' schema for '${hp}', fallback to the 'socks5://' schema" |
67 |
+ einfo "${@}" |
68 |
+ "${@}" |
69 |
+ fi |
70 |
+ done |
71 |
+ |
72 |
pushd "${S}" >& /dev/null || die |
73 |
ego mod vendor |
74 |
popd >& /dev/null || die |
75 |
|
76 |
|
77 |
On 2022年12月31日星期六 CST 下午3:25:15 Ryan Qian wrote: |
78 |
> Golang does not support the 'socks5h://' schema for http[s]_proxy |
79 |
> env variable: https://github.com/golang/go/blob/ |
80 |
> 9123221ccf3c80c741ead5b6f2e960573b1676b9/src/vendor/golang.org/x/net/http/ |
81 |
> httpproxy/proxy.go#L152-L159, |
82 |
> while libcurl supports it: https://github.com/curl/curl/blob/ |
83 |
> ae98b85020094fb04eee7e7b4ec4eb1a38a98b98/docs/libcurl/opts/CURLOPT_PROXY. |
84 |
> 3#L48-L59. |
85 |
> So, if a 'https_proxy=socks5h://127.0.0.1:1080' env has been set in the |
86 |
> make.conf to make curl (assuming curl is the current download command) to |
87 |
> download all packages through the proxy, go-module_live_vendor will |
88 |
> fail. |
89 |
> |
90 |
> The only difference between these two schemas is, 'socks5h' will solve |
91 |
> the hostname via the proxy while 'socks5' will not. I think it's ok to |
92 |
> fallback 'socks5h' to 'socks5' for `go vendor` command and warn user, |
93 |
> until golang supports it. |
94 |
> |
95 |
> related to issue: golang/go#24135 |
96 |
> Closes: https://github.com/gentoo/gentoo/pull/28887 |
97 |
> Signed-off-by: Ryan Qian <i@×××××××.net> |
98 |
> |
99 |
> diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass |
100 |
> index 10ed475c5b11e..d1b5798b6f40f 100644 |
101 |
> --- a/eclass/go-module.eclass |
102 |
> +++ b/eclass/go-module.eclass |
103 |
> @@ -14,7 +14,7 @@ |
104 |
> # written in the go programming language that uses modules. |
105 |
> # If the software you are packaging has a file named go.mod in its top level |
106 |
> # directory, it uses modules. |
107 |
> -# |
108 |
> +# |
109 |
> # Modules have been the preferred method of tracking dependencies in software |
110 |
> # written in Go since version 1.16, |
111 |
> # so if the software isn't using modules, it should be updated. |
112 |
> @@ -119,13 +119,13 @@ RESTRICT+=" strip" |
113 |
> # |
114 |
> # You can use some combination of sed/awk/cut to extract the |
115 |
> # contents of EGO_SUM or use the dev-go/get-ego-vendor tool. |
116 |
> -# |
117 |
> +# |
118 |
> # One manual way to do this is the following: |
119 |
> # |
120 |
> # @CODE |
121 |
> # |
122 |
> # cat go.sum | cut -d" " -f1,2 | awk '{print "\t\"" $0 "\""}' |
123 |
> -# |
124 |
> +# |
125 |
> # @CODE |
126 |
> # |
127 |
> # The format of go.sum is described upstream here: |
128 |
> @@ -485,6 +485,27 @@ go-module_live_vendor() { |
129 |
> [[ -d "${S}"/vendor ]] && |
130 |
> die "${FUNCNAME} only allowed when upstream isn't |
131 |
> vendoring" |
132 |
> |
133 |
> + local hp |
134 |
> + local -a hps |
135 |
> + if [[ -n $HTTP_PROXY ]]; then |
136 |
> + hps+=( HTTP_PROXY ) |
137 |
> + elif [[ -n $http_proxy ]]; then |
138 |
> + hps+=( http_proxy ) |
139 |
> + fi |
140 |
> + if [[ -n $HTTPS_PROXY ]]; then |
141 |
> + hps+=( HTTPS_PROXY ) |
142 |
> + elif [[ -n $https_proxy ]]; then |
143 |
> + hps+=( https_proxy ) |
144 |
> + fi |
145 |
> + for hp in "${hps[@]}"; do |
146 |
> + if [[ -n ${!hp} ]] && [[ ${!hp} =~ ^socks5h:// ]]; then |
147 |
> + set -- export ${hp}="socks5${!hp#socks5h}" |
148 |
> + ewarn "golang does not support the |
149 |
> 'socks5h://' schema for '${hp}', fallback to the 'socks5://' schema" |
150 |
> + einfo "${@}" |
151 |
> + "${@}" |
152 |
> + fi |
153 |
> + done |
154 |
> + |
155 |
> pushd "${S}" >& /dev/null || die |
156 |
> ego mod vendor |
157 |
> popd >& /dev/null || die |