Message ID | 20240411101030.2846823-2-sven@svenschwermer.de |
---|---|
State | New |
Headers | show |
Series | [1/2] recipetool: Handle unclean response in go resolver | expand |
On Thu, 2024-04-11 at 12:10 +0200, Sven via lists.openembedded.org wrote: > From: Sven Schwermer <sven.schwermer@disruptive-technologies.com> > > When dynamically resolving go modules, the HTML page may contain several > go-import meta tags. We must handle all and pick the correct one based > on the module name. An example for such a behaviour is > gonum.org/v1/gonum: > > <meta name="go-import" content="gonum.org/v1/exp git https://github.com/gonum/exp"> > <meta name="go-import" content="gonum.org/v1/gonum git https://github.com/gonum/gonum"> > <meta name="go-import" content="gonum.org/v1/hdf5 git https://github.com/gonum/hdf5"> > <meta name="go-import" content="gonum.org/v1/netlib git https://github.com/gonum/netlib"> > <meta name="go-import" content="gonum.org/v1/plot git https://github.com/gonum/plot"> > <meta name="go-import" content="gonum.org/v1/tools git https://github.com/gonum/tools"> > > Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com> > --- > scripts/lib/recipetool/create_go.py | 23 +++++++++-------------- > 1 file changed, 9 insertions(+), 14 deletions(-) > > diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py > index 0fb7115e26..a85a2f2786 100644 > --- a/scripts/lib/recipetool/create_go.py > +++ b/scripts/lib/recipetool/create_go.py > @@ -225,7 +225,7 @@ class GoRecipeHandler(RecipeHandler): > > def __init__(self): > super().__init__() > - self.__srv = [] > + self.__srv = {} > > def handle_starttag(self, tag, attrs): > if tag == 'meta' and list( > @@ -233,19 +233,14 @@ class GoRecipeHandler(RecipeHandler): > content = list( > filter(lambda a: (a[0] == 'content'), attrs)) > if content: > - self.__srv = content[0][1].split() > + srv = content[0][1].split() > + self.__srv[srv[0]] = srv > > - @property > - def import_prefix(self): > - return self.__srv[0] if len(self.__srv) else None > - > - @property > - def vcs(self): > - return self.__srv[1] if len(self.__srv) else None > - > - @property > - def repourl(self): > - return self.__srv[2] if len(self.__srv) else None > + def go_import(self, modulepath): > + if modulepath in self.__srv: > + srv = self.__srv[modulepath] > + return GoImport(srv[0], srv[1], srv[2], None) > + return None > > url = url.geturl() + "?go-get=1" > req = urllib.request.Request(url) > @@ -265,7 +260,7 @@ class GoRecipeHandler(RecipeHandler): > parser.feed(body.decode('utf-8')) > parser.close() > > - return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None) > + return parser.go_import(modulepath) > > def __resolve_from_golang_proxy(self, modulepath, version): > """ Should we be extending "oe-selftest -r recipetool" with tests for something? Cheers, Richard
Hi, On 4/11/24 2:17 PM, Richard Purdie wrote: > > Should we be extending "oe-selftest -r recipetool" with tests for something? > Good question, I would have to look into the self-testing framework. I don't have experience with that yet. Would you consider adding a test a requirement to get this merged? Sven
diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py index 0fb7115e26..a85a2f2786 100644 --- a/scripts/lib/recipetool/create_go.py +++ b/scripts/lib/recipetool/create_go.py @@ -225,7 +225,7 @@ class GoRecipeHandler(RecipeHandler): def __init__(self): super().__init__() - self.__srv = [] + self.__srv = {} def handle_starttag(self, tag, attrs): if tag == 'meta' and list( @@ -233,19 +233,14 @@ class GoRecipeHandler(RecipeHandler): content = list( filter(lambda a: (a[0] == 'content'), attrs)) if content: - self.__srv = content[0][1].split() + srv = content[0][1].split() + self.__srv[srv[0]] = srv - @property - def import_prefix(self): - return self.__srv[0] if len(self.__srv) else None - - @property - def vcs(self): - return self.__srv[1] if len(self.__srv) else None - - @property - def repourl(self): - return self.__srv[2] if len(self.__srv) else None + def go_import(self, modulepath): + if modulepath in self.__srv: + srv = self.__srv[modulepath] + return GoImport(srv[0], srv[1], srv[2], None) + return None url = url.geturl() + "?go-get=1" req = urllib.request.Request(url) @@ -265,7 +260,7 @@ class GoRecipeHandler(RecipeHandler): parser.feed(body.decode('utf-8')) parser.close() - return GoImport(parser.import_prefix, parser.vcs, parser.repourl, None) + return parser.go_import(modulepath) def __resolve_from_golang_proxy(self, modulepath, version): """