All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: Christopher Larson <kergoth@gmail.com>,
	openembedded-core@lists.openembedded.org
Cc: Christopher Larson <chris_larson@mentor.com>
Subject: Re: [PATCH 3/3] image_types.bbclass: support template .wks.in files for wic
Date: Tue, 24 May 2016 10:13:55 +0100	[thread overview]
Message-ID: <1464081235.9570.51.camel@linuxfoundation.org> (raw)
In-Reply-To: <c1371045c7b7740a468f44db12ff20a2c881902c.1463769811.git.chris_larson@mentor.com>

On Mon, 2016-05-23 at 13:34 -0700, Christopher Larson wrote:
> From: Christopher Larson <chris_larson@mentor.com>
> 
> These files are treated as the contents of a bitbake variable, so
> usual
> bitbake variable references are supported. I considered using another
> templating mechanism, for example the one used by yocto-layer, but
> then we'd
> end up largely mapping metadata variables to template fields anyway,
> which is
> a pointless indirection. Let bitbake expand the variables directly
> instead.
> 
> This feature lets us, for example, reference ${APPEND} in --append,
> and avoid
> hardcoding the serial console tty in the wks file, and let the user's
> changes
> to APPEND affect wic the way they do the other image construction
> mechanisms.
> 
> The template is read in and set in a variable at parse time, so
> changes to the
> variables referenced by the template will result in rebuilding the
> image.
> 
> Signed-off-by: Christopher Larson <chris_larson@mentor.com>
> ---
>  meta/classes/image_types.bbclass | 35
> +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/meta/classes/image_types.bbclass
> b/meta/classes/image_types.bbclass
> index dc681ae..caf8757 100644
> --- a/meta/classes/image_types.bbclass
> +++ b/meta/classes/image_types.bbclass
> @@ -206,6 +206,16 @@ IMAGE_CMD_wic () {
>  }
>  IMAGE_CMD_wic[vardepsexclude] = "WKS_FULL_PATH WKS_FILES"
>  
> +python process_wks_template () {
> +    """Write out expanded template contents to WKS_FULL_PATH."""
> +    template_body = d.getVar('_WKS_TEMPLATE', True)
> +    if template_body:
> +        wks_file = d.getVar('WKS_FULL_PATH', True)
> +        with open(wks_file, 'w') as f:
> +            f.write(template_body)
> +}
> +do_image_wic[prefuncs] += 'process_wks_template'
> +
>  # Rebuild when the wks file or vars in WICVARS change
>  USING_WIC = "${@bb.utils.contains_any('IMAGE_FSTYPES', 'wic ' + '
> '.join('wic.%s' % c for c in '${COMPRESSIONTYPES}'.split()), '1', '',
> d)}"
>  WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' %
> os.path.exists('${WKS_FULL_PATH}') if '${USING_WIC}' else ''}"
> @@ -302,3 +312,28 @@ IMAGE_TYPES_MASKED ?= ""
>  # The WICVARS variable is used to define list of bitbake variables
> used in wic code
>  # variables from this list is written to <image>.env file
>  WICVARS ?= "BBLAYERS DEPLOY_DIR_IMAGE HDDDIR IMAGE_BASENAME
> IMAGE_BOOT_FILES IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES
> INITRD ISODIR MACHINE_ARCH ROOTFS_SIZE STAGING_DATADIR
> STAGING_DIR_NATIVE STAGING_LIBDIR TARGET_SYS"
> +
> +python () {
> +    """Read in and set up wks file template for wic."""
> +    if d.getVar('USING_WIC', True):
> +        wks_file_u = d.getVar('WKS_FULL_PATH', False)
> +        wks_file = d.expand(wks_file_u)
> +        base, ext = os.path.splitext(wks_file)
> +        if ext == '.in' and os.path.exists(wks_file):
> +            wks_out_file = os.path.join(d.getVar('WORKDIR', True),
> os.path.basename(base))
> +            d.setVar('WKS_FULL_PATH', wks_out_file)
> +            d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
> +            d.setVar('WKS_FILE_CHECKSUM',
> '${WKS_TEMPLATE_PATH}:True')
> +
> +            try:
> +                with open(wks_file, 'r') as f:
> +                    body = f.read()
> +            except (IOError, OSError) as exc:
> +                pass

I'm a little nervous about determinism here. Shouldn't it either find
the referenced file or error?

Cheers,

Richard




  reply	other threads:[~2016-05-24  9:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-23 20:34 [PATCH 0/3] Support template files for wic Christopher Larson
2016-05-23 20:34 ` [PATCH 1/3] image.bbclass: append to prefuncs/postfuncs for do_image_* Christopher Larson
2016-05-23 20:34 ` [PATCH 2/3] image_types.bbclass: add intermediate var for WKS_FILE_CHECKSUM Christopher Larson
2016-05-23 20:34 ` [PATCH 3/3] image_types.bbclass: support template .wks.in files for wic Christopher Larson
2016-05-24  9:13   ` Richard Purdie [this message]
2016-05-24 14:26     ` Christopher Larson
2016-05-24 16:07       ` Christopher Larson
2016-05-24 17:45         ` Christopher Larson
2016-05-24 19:28           ` Christopher Larson

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=1464081235.9570.51.camel@linuxfoundation.org \
    --to=richard.purdie@linuxfoundation.org \
    --cc=chris_larson@mentor.com \
    --cc=kergoth@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /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.