From: "Ulrich Ölmann" <u.oelmann@pengutronix.de>
To: Lukas Funke <lukas.funke-oss@weidmueller.com>
Cc: Bruce Ashfield <bruce.ashfield@gmail.com>,
Vyacheslav Yurkov <uvv.mail@gmail.com>,
Martin Jansa <martin.jansa@gmail.com>,
Lukas Funke <lukas.funke@weidmueller.com>,
openembedded-core@lists.openembedded.org
Subject: Re: [OE-Core][PATCH v2 1/4] classes: go-vendor: Add go-vendor class
Date: Wed, 18 Oct 2023 08:36:24 +0200 [thread overview]
Message-ID: <6rbkcwigc8.fsf@pengutronix.de> (raw)
In-Reply-To: <20231017132647.352938-2-lukas.funke-oss@weidmueller.com>
Hi Lukas,
just two small typos I stumbled over.
On Tue, Oct 17 2023 at 15:26 +0200, "Lukas Funke" <lukas.funke-oss@weidmueller.com> wrote:
> From: Lukas Funke <lukas.funke@weidmueller.com>
>
> Signed-off-by: Lukas Funke <lukas.funke@weidmueller.com>
> ---
> meta/classes/go-vendor.bbclass | 135 +++++++++++++++++++++++++++++++++
> 1 file changed, 135 insertions(+)
> create mode 100644 meta/classes/go-vendor.bbclass
>
> diff --git a/meta/classes/go-vendor.bbclass b/meta/classes/go-vendor.bbclass
> new file mode 100644
> index 0000000000..13f1b8b2be
> --- /dev/null
> +++ b/meta/classes/go-vendor.bbclass
> @@ -0,0 +1,135 @@
> +#
> +# Copyright 2023 (C) Weidmueller GmbH & Co KG
> +# Author: Lukas Funke <lukas.funke@weidmueller.com>
> +#
> +# Handle Go vendor support for offline builds
> +#
> +# When importing Go modules, Go downloads the imported module using
s/imported module/imported modules/
> +# a network (proxy) connection ahead of the compile stage. This contradicts
> +# the yocto build concept of fetching every source ahead of build-time
> +# and supporting offline builds.
> +#
> +# To support offline builds, we use Go 'vendoring': module dependencies are
> +# downloaded during the fetch-phase and unpacked into the modules 'vendor'
> +# folder. Additinally a manifest file is generated for the 'vendor' folder
s/Additinally/Additionally/
Best regards
Ulrich
> +#
> +
> +inherit go-mod
> +
> +def go_src_uri(repo, version, path=None, subdir=None, \
> + vcs='git', replaces=None, pathmajor=None):
> +
> + destsuffix = "git/src/import/vendor.fetch"
> + go_module_path = repo if not path else path
> +
> + src_uri = "{}://{}" \
> + ";name={}" \
> + "".format(vcs, repo, \
> + go_module_path.replace('/', '.'))
> +
> + src_uri += ";destsuffix={}/{}@{}".format(destsuffix, \
> + go_module_path, \
> + version)
> +
> + if vcs == "git":
> + src_uri += ";nobranch=1;protocol=https"
> + if replaces:
> + src_uri += ";go_module_replacement={}".format(replaces)
> + if subdir:
> + src_uri += ";go_subdir={}".format(subdir)
> + if pathmajor:
> + src_uri += ";go_pathmajor={}".format(pathmajor)
> +
> + return src_uri
> +
> +
> +python do_go_vendor() {
> + import shutil
> +
> + src_uri = (d.getVar('SRC_URI') or "").split()
> +
> + if len(src_uri) == 0:
> + bb.error("SRC_URI is empty")
> + return
> +
> + default_destsuffix = "git/src/import/vendor.fetch"
> + fetcher = bb.fetch2.Fetch(src_uri, d)
> + go_import = d.getVar('GO_IMPORT')
> + source_dir = d.getVar('S')
> +
> + vendor_dir = os.path.join(source_dir, *['src', go_import, 'vendor'])
> + import_dir = os.path.join(source_dir, *['src', 'import', 'vendor.fetch'])
> +
> + bb.utils.mkdirhier(vendor_dir)
> + modules = {}
> +
> + for url in fetcher.urls:
> + srcuri = fetcher.ud[url].host + fetcher.ud[url].path
> +
> + # Skip main module for which the recipe is actually created
> + if srcuri == go_import:
> + continue
> +
> + # Skip local files
> + if fetcher.ud[url].type == 'file':
> + continue
> +
> + destsuffix = fetcher.ud[url].parm.get('destsuffix')
> + # We derive the module path / version in the following manner (exmaple):
> + #
> + # destsuffix = git/src/import/vendor.fetch/github.com/foo/bar@v1.2.3
> + # p = github.com/foo/bar@v1.2.3
> + # path = github.com/foo/bar
> + # version = v1.2.3
> +
> + p = destsuffix[len(default_destsuffix)+1:]
> + path, version = p.split('@')
> +
> + subdir = fetcher.ud[url].parm.get('go_subdir')
> + subdir = "" if not subdir else subdir
> +
> + pathMajor = fetcher.ud[url].parm.get('go_pathmajor')
> + pathMajor = "" if not pathMajor else pathMajor
> +
> + base = path[:-(len(subdir)+len(pathMajor))-1]
> + r = fetcher.ud[url].parm.get('go_module_replacement')
> +
> + if not path in modules and not r:
> + modules[path] = {
> + "version": version,
> + "src": os.path.join(import_dir, *[p, subdir]),
> + "subdir": subdir,
> + "pathMajor": pathMajor,
> + }
> +
> + for module_key in sorted(modules):
> +
> + # only take the version which is explicitly listed
> + # as a dependency in the go.mod
> + module = modules[module_key]
> + src = module['src']
> +
> + # If the module is released at major version 2 or higher, the module
> + # path must end with a major version suffix like /v2.
> + # This may or may not be part of the subdirectory name
> + #
> + # https://go.dev/ref/mod#modules-overview
> + srcMajorVersion = os.path.join(src, module['pathMajor'].strip('/'))
> + if os.path.exists(srcMajorVersion):
> + src = srcMajorVersion
> + dst = os.path.join(vendor_dir, module_key)
> + if os.path.exists(dst):
> + shutil.rmtree(dst)
> +
> + bb.debug(1, "cp %s --> %s" % (src, dst))
> + shutil.copytree(src, dst, symlinks=True, \
> + ignore=shutil.ignore_patterns(".git", \
> + "vendor", \
> + "*.md", \
> + "*._test.go"))
> + # Copy vendor manifest
> + bb.debug(1, "cp %s --> %s" % (os.path.join(d.getVar('WORKDIR'), "modules.txt"), vendor_dir))
> + shutil.copy2(os.path.join(d.getVar('WORKDIR'), "modules.txt"), vendor_dir)
> +}
> +
> +addtask go_vendor before do_populate_lic after do_unpack
--
Pengutronix e.K. | Ulrich Ölmann |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2023-10-18 6:40 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 13:26 [OE-Core][PATCH v2 0/4] recipetool: Add handler to create go recipes lukas.funke-oss
2023-10-17 13:26 ` [OE-Core][PATCH v2 1/4] classes: go-vendor: Add go-vendor class lukas.funke-oss
2023-10-18 6:36 ` Ulrich Ölmann [this message]
2023-10-17 13:26 ` [OE-Core][PATCH v2 2/4] selftest: recipetool: Add test for go recipe handler lukas.funke-oss
2023-10-17 13:26 ` [OE-Core][PATCH v2 3/4] recipetool: Ignore *.go files while scanning for licenses lukas.funke-oss
2023-10-17 13:26 ` [OE-Core][PATCH v2 4/4] recipetool: Add handler to create go recipes lukas.funke-oss
2023-10-17 13:53 ` Richard Purdie
2023-10-17 14:00 ` Lukas Funke
2023-10-17 22:23 ` Richard Purdie
2023-10-22 18:34 ` [OE-Core][PATCH v2 0/4] " Vyacheslav Yurkov
2023-10-23 12:18 ` Lukas Funke
2023-10-23 17:05 ` Vyacheslav Yurkov
2023-10-24 6:19 ` Lukas Funke
2023-10-24 7:32 ` Vyacheslav Yurkov
2023-10-23 18:06 ` Vyacheslav Yurkov
2023-10-24 6:33 ` Lukas Funke
2023-10-24 7:12 ` Vyacheslav Yurkov
2023-10-24 8:27 ` Lukas Funke
2023-10-27 21:32 ` Peter Kjellerstedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6rbkcwigc8.fsf@pengutronix.de \
--to=u.oelmann@pengutronix.de \
--cc=bruce.ashfield@gmail.com \
--cc=lukas.funke-oss@weidmueller.com \
--cc=lukas.funke@weidmueller.com \
--cc=martin.jansa@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
--cc=uvv.mail@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.