public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: Mark Asselstine <mark.asselstine@windriver.com>
To: Stefan Herbrechtsmeier
	<stefan.herbrechtsmeier-oss@weidmueller.com>,
	openembedded-core@lists.openembedded.org
Cc: Lukas Funke <lukas.funke@weidmueller.com>,
	Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Subject: Re: [OE-core] [PATCH 3/5] poky-meta: add go vendor class for offline builds
Date: Wed, 11 May 2022 16:42:12 -0400	[thread overview]
Message-ID: <6f487ea7-1ecf-1055-17a9-e8eae4f2d96e@windriver.com> (raw)
In-Reply-To: <20220506065917.1375-3-stefan.herbrechtsmeier-oss@weidmueller.com>



On 2022-05-06 02:59, Stefan Herbrechtsmeier wrote:
> From: Lukas Funke <lukas.funke@weidmueller.com>
> 
> Signed-off-by: Lukas Funke <lukas.funke@weidmueller.com>
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> ---
> 
>   meta/classes/go-vendor.bbclass | 68 ++++++++++++++++++++++++++++++++++
>   1 file changed, 68 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..a1a740a1fc
> --- /dev/null
> +++ b/meta/classes/go-vendor.bbclass
> @@ -0,0 +1,68 @@
> +# Copyright 2022 (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
> +# 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
> +#
> +

Several instances of trailing whitespace in the file header.

> +inherit go-mod
> +
> +def go_src_uri(repo, path=None, subdir=None, vcs='git', destsuffix_prefix = 'git/src/import/vendor.fetch'):
> +    module_path = repo if not path else path
> +    src_uri = "{}://{};name={};destsuffix={}/{}".format(vcs, repo, \
> +                                    module_path.replace('/', '.'), \
> +                                    destsuffix_prefix, module_path)
> +
> +    src_uri += ";subdir={}".format(subdir) if subdir else ""
> +    src_uri += ";nobranch=1;protocol=https" if vcs == "git" else ""
> +
> +    return src_uri
> +
> +def go_generate_vendor_manifest(d):
> +
> +    vendor_dir = os.path.join(os.path.basename(d.getVar('S')),
> +                                        'src', d.getVar('GO_IMPORT'), "vendor")
> +    dst = os.path.join(vendor_dir, "modules.txt")
> +
> +    go_modules = d.getVarFlags("GO_MODULE_PATH")
> +    with open(dst, "w") as manifest:
> +        for go_module in go_modules:
> +            module_path = d.getVarFlag("GO_MODULE_PATH", go_module)
> +            module_version = d.getVarFlag("GO_MODULE_VERSION", go_module)
> +            if module_path and module_version:
> +                manifest.write("# %s %s\n" % (module_path, module_version))
> +                manifest.write("## explicit\n")
> +                exclude = set(['vendor'])
> +                for subdir, dirs, files in os.walk(os.path.join(vendor_dir, module_path), topdown=True):
> +                    dirs[:] = [d for d in dirs if d not in exclude]
> +                    for file in files:

I am not sure what other folks think but I tend not to like to see 
python builtins reused as variable names. Too easy to screw up and 
messes with sytax highlighting in editors.

MarkA

> +                        if file.endswith(".go"):
> +                            manifest.write(subdir[len(vendor_dir)+1:] + "\n")
> +                            break
> +
> +python go_do_unpack:append() {
> +    src_uri = (d.getVar('SRC_URI') or "").split()
> +    if len(src_uri) == 0:
> +        return
> +
> +    try:
> +        fetcher = bb.fetch2.Fetch(src_uri, d)
> +        src_folder = os.path.join(os.path.basename(d.getVar('S')),
> +                                        'src', d.getVar('GO_IMPORT'))
> +        vendor_src = os.path.join(src_folder, "vendor")
> +        vendor_dst = os.path.join(d.getVar('S'), "src", "import", "vendor.fetch")
> +
> +        os.symlink(os.path.relpath(vendor_dst, src_folder), vendor_src)
> +        go_generate_vendor_manifest(d)
> +
> +    except bb.fetch2.BBFetchException as e:
> +        raise bb.build.FuncFailed(e)
> +}
> 
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#165324): https://lists.openembedded.org/g/openembedded-core/message/165324
> Mute This Topic: https://lists.openembedded.org/mt/90928683/3616946
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [mark.asselstine@windriver.com]
> -=-=-=-=-=-=-=-=-=-=-=-
> 


  reply	other threads:[~2022-05-11 20:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06  6:59 [PATCH 1/5] recipetool-create: add ensure_native_cmd function Stefan Herbrechtsmeier
2022-05-06  6:59 ` [PATCH 2/5] create_npm: reuse ensure_native_cmd from create.py Stefan Herbrechtsmeier
2022-05-06  6:59 ` [PATCH 3/5] poky-meta: add go vendor class for offline builds Stefan Herbrechtsmeier
2022-05-11 20:42   ` Mark Asselstine [this message]
2022-05-06  6:59 ` [PATCH 4/5] recipetool: add go recipe generator Stefan Herbrechtsmeier
2022-05-06  7:15   ` [OE-core] " Alexander Kanavin
2022-05-11 20:37     ` Mark Asselstine
2022-05-06  6:59 ` [PATCH 5/5] oe-selftest: add go recipe create selftest Stefan Herbrechtsmeier
2022-05-06  7:16   ` [OE-core] " Alexander Kanavin
2022-05-11 20:08     ` Mark Asselstine
2022-05-06  7:09 ` [OE-core] [PATCH 1/5] recipetool-create: add ensure_native_cmd function Alexander Kanavin
2022-05-11 19:45   ` Mark Asselstine
2022-05-11 19:47     ` Mark Asselstine
2022-05-09 21:46 ` Luca Ceresoli
2022-05-11  6:54   ` Stefan Herbrechtsmeier

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=6f487ea7-1ecf-1055-17a9-e8eae4f2d96e@windriver.com \
    --to=mark.asselstine@windriver.com \
    --cc=lukas.funke@weidmueller.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=stefan.herbrechtsmeier-oss@weidmueller.com \
    --cc=stefan.herbrechtsmeier@weidmueller.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox