summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorChristian Lindeberg <christian.lindeberg@axis.com>2025-03-20 11:19:49 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-03-27 11:19:33 +0000
commitc00ad319d49537e3277fcf70196eec534a958959 (patch)
treebf91d678e8bb193df929aefc4af6593e0fca69e8 /bitbake
parentecff1d6a2dcfcd243d15039f08727889e7889158 (diff)
downloadpoky-c00ad319d49537e3277fcf70196eec534a958959.tar.gz
bitbake: fetch2/gomod: Fix mirroring problem
Build the 'downloadfilename' parameter by replacing path separators in the module path like the git fetcher builds the mirror tar ball name. Copy the downloaded file in the fetcher's unpack method like the crate fetcher instead of calling the base fetcher's unpack method. (Bitbake rev: 7762cea087597019460d66b04268757bd46befdf) Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/fetch2/gomod.py35
-rw-r--r--bitbake/lib/bb/tests/fetch.py9
2 files changed, 31 insertions, 13 deletions
diff --git a/bitbake/lib/bb/fetch2/gomod.py b/bitbake/lib/bb/fetch2/gomod.py
index 03f649bc2f..53c1d8d115 100644
--- a/bitbake/lib/bb/fetch2/gomod.py
+++ b/bitbake/lib/bb/fetch2/gomod.py
@@ -107,23 +107,23 @@ class GoMod(Wget):
107 if ud.path != '/': 107 if ud.path != '/':
108 module += ud.path 108 module += ud.path
109 ud.parm['module'] = module 109 ud.parm['module'] = module
110 version = ud.parm['version']
110 111
111 # Set URL and filename for wget download 112 # Set URL and filename for wget download
112 path = escape(module + '/@v/' + ud.parm['version'])
113 if ud.parm.get('mod', '0') == '1': 113 if ud.parm.get('mod', '0') == '1':
114 path += '.mod' 114 ext = '.mod'
115 else: 115 else:
116 path += '.zip' 116 ext = '.zip'
117 ud.parm['unpack'] = '0' 117 path = escape(f"{module}/@v/{version}{ext}")
118 ud.url = bb.fetch2.encodeurl( 118 ud.url = bb.fetch2.encodeurl(
119 ('https', proxy, '/' + path, None, None, None)) 119 ('https', proxy, '/' + path, None, None, None))
120 ud.parm['downloadfilename'] = path 120 ud.parm['downloadfilename'] = f"{module.replace('/', '.')}@{version}{ext}"
121 121
122 ud.parm['name'] = f"{module}@{ud.parm['version']}" 122 # Set name for checksum verification
123 ud.parm['name'] = f"{module}@{version}"
123 124
124 # Set subdir for unpack 125 # Set path for unpack
125 ud.parm['subdir'] = os.path.join(moddir, 'cache/download', 126 ud.parm['unpackpath'] = os.path.join(moddir, 'cache/download', path)
126 os.path.dirname(path))
127 127
128 super().urldata_init(ud, d) 128 super().urldata_init(ud, d)
129 129
@@ -131,13 +131,22 @@ class GoMod(Wget):
131 """Unpack the module in the module cache.""" 131 """Unpack the module in the module cache."""
132 132
133 # Unpack the module zip file or go.mod file 133 # Unpack the module zip file or go.mod file
134 super().unpack(ud, rootdir, d) 134 unpackpath = os.path.join(rootdir, ud.parm['unpackpath'])
135 unpackdir = os.path.dirname(unpackpath)
136 bb.utils.mkdirhier(unpackdir)
137 ud.unpack_tracer.unpack("file-copy", unpackdir)
138 cmd = f"cp {ud.localpath} {unpackpath}"
139 path = d.getVar('PATH')
140 if path:
141 cmd = f"PATH={path} {cmd}"
142 name = os.path.basename(unpackpath)
143 bb.note(f"Unpacking {name} to {unpackdir}/")
144 subprocess.check_call(cmd, shell=True, preexec_fn=subprocess_setup)
135 145
136 if ud.localpath.endswith('.zip'): 146 if name.endswith('.zip'):
137 # Unpack the go.mod file from the zip file 147 # Unpack the go.mod file from the zip file
138 module = ud.parm['module'] 148 module = ud.parm['module']
139 unpackdir = os.path.join(rootdir, ud.parm['subdir']) 149 name = name.rsplit('.', 1)[0] + '.mod'
140 name = os.path.basename(ud.localpath).rsplit('.', 1)[0] + '.mod'
141 bb.note(f"Unpacking {name} to {unpackdir}/") 150 bb.note(f"Unpacking {name} to {unpackdir}/")
142 with zipfile.ZipFile(ud.localpath) as zf: 151 with zipfile.ZipFile(ud.localpath) as zf:
143 with open(os.path.join(unpackdir, name), mode='wb') as mf: 152 with open(os.path.join(unpackdir, name), mode='wb') as mf:
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 486c10cd08..f2f140ff24 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -3378,6 +3378,8 @@ class GoModTest(FetcherTest):
3378 fetcher = bb.fetch2.Fetch(urls, self.d) 3378 fetcher = bb.fetch2.Fetch(urls, self.d)
3379 ud = fetcher.ud[urls[0]] 3379 ud = fetcher.ud[urls[0]]
3380 self.assertEqual(ud.url, 'https://proxy.golang.org/github.com/%21azure/azure-sdk-for-go/sdk/storage/azblob/%40v/v1.0.0.zip') 3380 self.assertEqual(ud.url, 'https://proxy.golang.org/github.com/%21azure/azure-sdk-for-go/sdk/storage/azblob/%40v/v1.0.0.zip')
3381 self.assertEqual(ud.parm['downloadfilename'], 'github.com.Azure.azure-sdk-for-go.sdk.storage.azblob@v1.0.0.zip')
3382 self.assertEqual(ud.parm['name'], 'github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0')
3381 3383
3382 fetcher.download() 3384 fetcher.download()
3383 fetcher.unpack(self.unpackdir) 3385 fetcher.unpack(self.unpackdir)
@@ -3395,6 +3397,8 @@ class GoModTest(FetcherTest):
3395 fetcher = bb.fetch2.Fetch(urls, self.d) 3397 fetcher = bb.fetch2.Fetch(urls, self.d)
3396 ud = fetcher.ud[urls[0]] 3398 ud = fetcher.ud[urls[0]]
3397 self.assertEqual(ud.url, 'https://proxy.golang.org/github.com/%21azure/azure-sdk-for-go/sdk/storage/azblob/%40v/v1.0.0.mod') 3399 self.assertEqual(ud.url, 'https://proxy.golang.org/github.com/%21azure/azure-sdk-for-go/sdk/storage/azblob/%40v/v1.0.0.mod')
3400 self.assertEqual(ud.parm['downloadfilename'], 'github.com.Azure.azure-sdk-for-go.sdk.storage.azblob@v1.0.0.mod')
3401 self.assertEqual(ud.parm['name'], 'github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0')
3398 3402
3399 fetcher.download() 3403 fetcher.download()
3400 fetcher.unpack(self.unpackdir) 3404 fetcher.unpack(self.unpackdir)
@@ -3409,6 +3413,7 @@ class GoModTest(FetcherTest):
3409 fetcher = bb.fetch2.Fetch(urls, self.d) 3413 fetcher = bb.fetch2.Fetch(urls, self.d)
3410 ud = fetcher.ud[urls[0]] 3414 ud = fetcher.ud[urls[0]]
3411 self.assertEqual(ud.url, 'https://proxy.golang.org/gopkg.in/ini.v1/%40v/v1.67.0.zip') 3415 self.assertEqual(ud.url, 'https://proxy.golang.org/gopkg.in/ini.v1/%40v/v1.67.0.zip')
3416 self.assertEqual(ud.parm['downloadfilename'], 'gopkg.in.ini.v1@v1.67.0.zip')
3412 self.assertEqual(ud.parm['name'], 'gopkg.in/ini.v1@v1.67.0') 3417 self.assertEqual(ud.parm['name'], 'gopkg.in/ini.v1@v1.67.0')
3413 3418
3414 fetcher.download() 3419 fetcher.download()
@@ -3427,6 +3432,8 @@ class GoModTest(FetcherTest):
3427 fetcher = bb.fetch2.Fetch(urls, self.d) 3432 fetcher = bb.fetch2.Fetch(urls, self.d)
3428 ud = fetcher.ud[urls[0]] 3433 ud = fetcher.ud[urls[0]]
3429 self.assertEqual(ud.url, 'https://proxy.golang.org/gopkg.in/ini.v1/%40v/v1.67.0.zip') 3434 self.assertEqual(ud.url, 'https://proxy.golang.org/gopkg.in/ini.v1/%40v/v1.67.0.zip')
3435 self.assertEqual(ud.parm['downloadfilename'], 'gopkg.in.ini.v1@v1.67.0.zip')
3436 self.assertEqual(ud.parm['name'], 'gopkg.in/ini.v1@v1.67.0')
3430 3437
3431 fetcher.download() 3438 fetcher.download()
3432 fetcher.unpack(self.unpackdir) 3439 fetcher.unpack(self.unpackdir)
@@ -3444,6 +3451,8 @@ class GoModTest(FetcherTest):
3444 fetcher = bb.fetch2.Fetch(urls, self.d) 3451 fetcher = bb.fetch2.Fetch(urls, self.d)
3445 ud = fetcher.ud[urls[0]] 3452 ud = fetcher.ud[urls[0]]
3446 self.assertEqual(ud.url, 'https://proxy.golang.org/go.opencensus.io/%40v/v0.24.0.zip') 3453 self.assertEqual(ud.url, 'https://proxy.golang.org/go.opencensus.io/%40v/v0.24.0.zip')
3454 self.assertEqual(ud.parm['downloadfilename'], 'go.opencensus.io@v0.24.0.zip')
3455 self.assertEqual(ud.parm['name'], 'go.opencensus.io@v0.24.0')
3447 3456
3448 fetcher.download() 3457 fetcher.download()
3449 fetcher.unpack(self.unpackdir) 3458 fetcher.unpack(self.unpackdir)