diff options
author | Sven Schwermer <sven.schwermer@disruptive-technologies.com> | 2024-04-11 12:10:29 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-04-23 13:40:24 +0100 |
commit | e4c3483ecf496b7637d1e9fd3b0eb9ace94a09d2 (patch) | |
tree | 60a70522da14217629ff00f725c84db7edc72822 | |
parent | 0d6a71d49217eb2f036374eef2285a9046b69dc4 (diff) | |
download | poky-e4c3483ecf496b7637d1e9fd3b0eb9ace94a09d2.tar.gz |
recipetool: Handle unclean response in go resolver
It appears that some go modules repond with a 404 error when trying to
resolve them dynamically. The response body may still contain the
go-import meta tag. An example for such behaviour is gonum.org/v1/gonum.
(From OE-Core rev: 8f2e14ab6562a9a68819a960c66a258ea9dbe246)
Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | scripts/lib/recipetool/create_go.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py index c560831442..0fb7115e26 100644 --- a/scripts/lib/recipetool/create_go.py +++ b/scripts/lib/recipetool/create_go.py | |||
@@ -16,7 +16,7 @@ from html.parser import HTMLParser | |||
16 | from recipetool.create import RecipeHandler, handle_license_vars | 16 | from recipetool.create import RecipeHandler, handle_license_vars |
17 | from recipetool.create import guess_license, tidy_licenses, fixup_license | 17 | from recipetool.create import guess_license, tidy_licenses, fixup_license |
18 | from recipetool.create import determine_from_url | 18 | from recipetool.create import determine_from_url |
19 | from urllib.error import URLError | 19 | from urllib.error import URLError, HTTPError |
20 | 20 | ||
21 | import bb.utils | 21 | import bb.utils |
22 | import json | 22 | import json |
@@ -251,15 +251,18 @@ class GoRecipeHandler(RecipeHandler): | |||
251 | req = urllib.request.Request(url) | 251 | req = urllib.request.Request(url) |
252 | 252 | ||
253 | try: | 253 | try: |
254 | resp = urllib.request.urlopen(req) | 254 | body = urllib.request.urlopen(req).read() |
255 | 255 | except HTTPError as http_err: | |
256 | logger.warning( | ||
257 | "Unclean status when fetching page from [%s]: %s", url, str(http_err)) | ||
258 | body = http_err.fp.read() | ||
256 | except URLError as url_err: | 259 | except URLError as url_err: |
257 | logger.warning( | 260 | logger.warning( |
258 | "Failed to fetch page from [%s]: %s", url, str(url_err)) | 261 | "Failed to fetch page from [%s]: %s", url, str(url_err)) |
259 | return None | 262 | return None |
260 | 263 | ||
261 | parser = GoImportHTMLParser() | 264 | parser = GoImportHTMLParser() |
262 | parser.feed(resp.read().decode('utf-8')) | 265 | parser.feed(body.decode('utf-8')) |
263 | parser.close() | 266 | parser.close() |
264 | 267 | ||
265 | return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None) | 268 | return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None) |