1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-01 13:09:50 +00:00

bitbake: fetch2: Add gomodgit fetcher

Add a go module fetcher for downloading module dependencies to the
module cache directly from a git repository. The fetcher can be used
with the go-mod class in OE-Core.

A module dependency can be specified with:

  SRC_URI += "gomodgit://golang.org/x/net;version=v0.9.0;srcrev=..."

(Bitbake rev: 29ff38ccf0d5389a5bee81e252a78548361a9d7c)

Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Christian Lindeberg
2024-09-06 11:27:39 +02:00
committed by Richard Purdie
parent dd7631426c
commit 87c29b5a94
3 changed files with 228 additions and 2 deletions
+89
View File
@@ -3455,3 +3455,92 @@ class GoModTest(FetcherTest):
downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
class GoModGitTest(FetcherTest):
@skipIfNoNetwork()
def test_gomodgit_url_repo(self):
urls = ['gomodgit://golang.org/x/net;version=v0.9.0;'
'repo=go.googlesource.com/net;'
'srcrev=694cff8668bac64e0864b552bffc280cd27f21b1']
fetcher = bb.fetch2.Fetch(urls, self.d)
ud = fetcher.ud[urls[0]]
self.assertEqual(ud.host, 'go.googlesource.com')
self.assertEqual(ud.path, '/net')
self.assertEqual(ud.names, ['golang.org/x/net@v0.9.0'])
self.assertEqual(self.d.getVar('SRCREV_golang.org/x/net@v0.9.0'), '694cff8668bac64e0864b552bffc280cd27f21b1')
fetcher.download()
self.assertTrue(os.path.exists(ud.localpath))
fetcher.unpack(self.unpackdir)
vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
self.assertTrue(os.path.exists(os.path.join(vcsdir, 'ed42bd05533fd84ae290a5d33ebd3695a0a2b06131beebd5450825bee8603aca')))
downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'golang.org/x/net/@v/v0.9.0.zip')))
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'golang.org/x/net/@v/v0.9.0.mod')))
@skipIfNoNetwork()
def test_gomodgit_url_subdir(self):
urls = ['gomodgit://github.com/Azure/azure-sdk-for-go/sdk/storage/azblob;version=v1.0.0;'
'repo=github.com/Azure/azure-sdk-for-go;subdir=sdk/storage/azblob;'
'srcrev=ec928e0ed34db682b3f783d3739d1c538142e0c3']
fetcher = bb.fetch2.Fetch(urls, self.d)
ud = fetcher.ud[urls[0]]
self.assertEqual(ud.host, 'github.com')
self.assertEqual(ud.path, '/Azure/azure-sdk-for-go')
self.assertEqual(ud.parm['subpath'], 'sdk/storage/azblob')
self.assertEqual(ud.names, ['github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0'])
self.assertEqual(self.d.getVar('SRCREV_github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0'), 'ec928e0ed34db682b3f783d3739d1c538142e0c3')
fetcher.download()
self.assertTrue(os.path.exists(ud.localpath))
fetcher.unpack(self.unpackdir)
vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
self.assertTrue(os.path.exists(os.path.join(vcsdir, 'd31d6145676ed3066ce573a8198f326dea5be45a43b3d8f41ce7787fd71d66b3')))
downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.zip')))
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'github.com/!azure/azure-sdk-for-go/sdk/storage/azblob/@v/v1.0.0.mod')))
@skipIfNoNetwork()
def test_gomodgit_url_srcrev_var(self):
urls = ['gomodgit://gopkg.in/ini.v1;version=v1.67.0']
self.d.setVar('SRCREV_gopkg.in/ini.v1@v1.67.0', 'b2f570e5b5b844226bbefe6fb521d891f529a951')
fetcher = bb.fetch2.Fetch(urls, self.d)
ud = fetcher.ud[urls[0]]
self.assertEqual(ud.host, 'gopkg.in')
self.assertEqual(ud.path, '/ini.v1')
self.assertEqual(ud.names, ['gopkg.in/ini.v1@v1.67.0'])
self.assertEqual(ud.parm['srcrev'], 'b2f570e5b5b844226bbefe6fb521d891f529a951')
fetcher.download()
fetcher.unpack(self.unpackdir)
vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
self.assertTrue(os.path.exists(os.path.join(vcsdir, 'b7879a4be9ba8598851b8278b14c4f71a8316be64913298d1639cce6bde59bc3')))
downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))
@skipIfNoNetwork()
def test_gomodgit_url_no_go_mod_in_module(self):
urls = ['gomodgit://gopkg.in/ini.v1;version=v1.67.0;'
'srcrev=b2f570e5b5b844226bbefe6fb521d891f529a951']
fetcher = bb.fetch2.Fetch(urls, self.d)
ud = fetcher.ud[urls[0]]
self.assertEqual(ud.host, 'gopkg.in')
self.assertEqual(ud.path, '/ini.v1')
self.assertEqual(ud.names, ['gopkg.in/ini.v1@v1.67.0'])
self.assertEqual(self.d.getVar('SRCREV_gopkg.in/ini.v1@v1.67.0'), 'b2f570e5b5b844226bbefe6fb521d891f529a951')
fetcher.download()
fetcher.unpack(self.unpackdir)
vcsdir = os.path.join(self.unpackdir, 'pkg/mod/cache/vcs')
self.assertTrue(os.path.exists(os.path.join(vcsdir, 'b7879a4be9ba8598851b8278b14c4f71a8316be64913298d1639cce6bde59bc3')))
downloaddir = os.path.join(self.unpackdir, 'pkg/mod/cache/download')
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.zip')))
self.assertTrue(os.path.exists(os.path.join(downloaddir, 'gopkg.in/ini.v1/@v/v1.67.0.mod')))