diff mbox series

fetch2/gomod: Support URIs with only a hostname

Message ID 20240912210614.1042592-1-pkj@axis.com
State New
Headers show
Series fetch2/gomod: Support URIs with only a hostname | expand

Commit Message

Peter Kjellerstedt Sept. 12, 2024, 9:06 p.m. UTC
When calculating the module name for a gomod URI with only a hostname,
e.g.:

  gomod://go.opencensus.io;version=v0.24.0;sha256sum=203a767d7f8e7c1ebe5588220ad168d1e15b14ae70a636de7ca9a4a88a7e0d0c

the non-existing path would actually be treated as "/", which resulted
in a trailing slash being added to the module name preventing the unpack
method from correctly locating the go.mod file.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---
 bitbake/lib/bb/fetch2/gomod.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Christian Lindeberg Sept. 13, 2024, 8:13 p.m. UTC | #1
On Thu, Sep 12, 2024 at 11:06 PM, Peter Kjellerstedt wrote:

> 
> When calculating the module name for a gomod URI with only a hostname,
> e.g.:
> 
> gomod://go.opencensus.io;version=v0.24.0;sha256sum=203a767d7f8e7c1ebe5588220ad168d1e15b14ae70a636de7ca9a4a88a7e0d0c
> 
> 
> the non-existing path would actually be treated as "/", which resulted
> in a trailing slash being added to the module name preventing the unpack
> method from correctly locating the go.mod file.

Good catch. I hadn't come across a module path only consisting of the host part before. The crucible recipe was a good exercise.

Thanks,
Christian

> 
> 
> Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
> ---
> bitbake/lib/bb/fetch2/gomod.py | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/bitbake/lib/bb/fetch2/gomod.py
> b/bitbake/lib/bb/fetch2/gomod.py
> index 1b532d03ff..21fbe80f56 100644
> --- a/bitbake/lib/bb/fetch2/gomod.py
> +++ b/bitbake/lib/bb/fetch2/gomod.py
> @@ -103,7 +103,9 @@ class GoMod(Wget):
> if 'version' not in ud.parm:
> raise MissingParameterError('version', ud.url)
> 
> - module = ud.host + ud.path
> + module = ud.host
> + if ud.path != '/':
> + module += ud.path
> ud.parm['module'] = module
> 
> # Set URL and filename for wget download
> @@ -174,7 +176,9 @@ class GoModGit(Git):
> if 'version' not in ud.parm:
> raise MissingParameterError('version', ud.url)
> 
> - module = ud.host + ud.path
> + module = ud.host
> + if ud.path != '/':
> + module += ud.path
> ud.parm['module'] = module
> 
> # Set host, path and srcrev for git download
diff mbox series

Patch

diff --git a/bitbake/lib/bb/fetch2/gomod.py b/bitbake/lib/bb/fetch2/gomod.py
index 1b532d03ff..21fbe80f56 100644
--- a/bitbake/lib/bb/fetch2/gomod.py
+++ b/bitbake/lib/bb/fetch2/gomod.py
@@ -103,7 +103,9 @@  class GoMod(Wget):
         if 'version' not in ud.parm:
             raise MissingParameterError('version', ud.url)
 
-        module = ud.host + ud.path
+        module = ud.host
+        if ud.path != '/':
+            module += ud.path
         ud.parm['module'] = module
 
         # Set URL and filename for wget download
@@ -174,7 +176,9 @@  class GoModGit(Git):
         if 'version' not in ud.parm:
             raise MissingParameterError('version', ud.url)
 
-        module = ud.host + ud.path
+        module = ud.host
+        if ud.path != '/':
+            module += ud.path
         ud.parm['module'] = module
 
         # Set host, path and srcrev for git download