<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 24, 2016 at 7:26 AM, Christopher Larson <span dir="ltr">&lt;<a href="mailto:kergoth@gmail.com" target="_blank">kergoth@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="adM"><div class="h5"><br><div class="gmail_quote">On Tue, May 24, 2016 at 2:13 AM, Richard Purdie <span dir="ltr">&lt;<a href="mailto:richard.purdie@linuxfoundation.org" target="_blank">richard.purdie@linuxfoundation.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Mon, 2016-05-23 at 13:34 -0700, Christopher Larson wrote:<br>
&gt; From: Christopher Larson &lt;<a href="mailto:chris_larson@mentor.com" target="_blank">chris_larson@mentor.com</a>&gt;<br>
&gt;<br>
&gt; These files are treated as the contents of a bitbake variable, so<br>
&gt; usual<br>
&gt; bitbake variable references are supported. I considered using another<br>
&gt; templating mechanism, for example the one used by yocto-layer, but<br>
&gt; then we&#39;d<br>
&gt; end up largely mapping metadata variables to template fields anyway,<br>
&gt; which is<br>
&gt; a pointless indirection. Let bitbake expand the variables directly<br>
&gt; instead.<br>
&gt;<br>
&gt; This feature lets us, for example, reference ${APPEND} in --append,<br>
&gt; and avoid<br>
&gt; hardcoding the serial console tty in the wks file, and let the user&#39;s<br>
&gt; changes<br>
&gt; to APPEND affect wic the way they do the other image construction<br>
&gt; mechanisms.<br>
&gt;<br>
&gt; The template is read in and set in a variable at parse time, so<br>
&gt; changes to the<br>
&gt; variables referenced by the template will result in rebuilding the<br>
&gt; image.<br>
&gt;<br>
&gt; Signed-off-by: Christopher Larson &lt;<a href="mailto:chris_larson@mentor.com" target="_blank">chris_larson@mentor.com</a>&gt;<br>
&gt; ---<br>
&gt;  meta/classes/image_types.bbclass | 35<br>
&gt; +++++++++++++++++++++++++++++++++++<br>
&gt;  1 file changed, 35 insertions(+)<br>
&gt;<br>
&gt; diff --git a/meta/classes/image_types.bbclass<br>
&gt; b/meta/classes/image_types.bbclass<br>
&gt; index dc681ae..caf8757 100644<br>
&gt; --- a/meta/classes/image_types.bbclass<br>
&gt; +++ b/meta/classes/image_types.bbclass<br>
&gt; @@ -206,6 +206,16 @@ IMAGE_CMD_wic () {<br>
&gt;  }<br>
&gt;  IMAGE_CMD_wic[vardepsexclude] = &quot;WKS_FULL_PATH WKS_FILES&quot;<br>
&gt;<br>
&gt; +python process_wks_template () {<br>
&gt; +    &quot;&quot;&quot;Write out expanded template contents to WKS_FULL_PATH.&quot;&quot;&quot;<br>
&gt; +    template_body = d.getVar(&#39;_WKS_TEMPLATE&#39;, True)<br>
&gt; +    if template_body:<br>
&gt; +        wks_file = d.getVar(&#39;WKS_FULL_PATH&#39;, True)<br>
&gt; +        with open(wks_file, &#39;w&#39;) as f:<br>
&gt; +            f.write(template_body)<br>
&gt; +}<br>
&gt; +do_image_wic[prefuncs] += &#39;process_wks_template&#39;<br>
&gt; +<br>
&gt;  # Rebuild when the wks file or vars in WICVARS change<br>
&gt;  USING_WIC = &quot;${@bb.utils.contains_any(&#39;IMAGE_FSTYPES&#39;, &#39;wic &#39; + &#39;<br>
&gt; &#39;.join(&#39;wic.%s&#39; % c for c in &#39;${COMPRESSIONTYPES}&#39;.split()), &#39;1&#39;, &#39;&#39;,<br>
&gt; d)}&quot;<br>
&gt;  WKS_FILE_CHECKSUM = &quot;${@&#39;${WKS_FULL_PATH}:%s&#39; %<br>
&gt; os.path.exists(&#39;${WKS_FULL_PATH}&#39;) if &#39;${USING_WIC}&#39; else &#39;&#39;}&quot;<br>
&gt; @@ -302,3 +312,28 @@ IMAGE_TYPES_MASKED ?= &quot;&quot;<br>
&gt;  # The WICVARS variable is used to define list of bitbake variables<br>
&gt; used in wic code<br>
&gt;  # variables from this list is written to &lt;image&gt;.env file<br>
&gt;  WICVARS ?= &quot;BBLAYERS DEPLOY_DIR_IMAGE HDDDIR IMAGE_BASENAME<br>
&gt; IMAGE_BOOT_FILES IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES<br>
&gt; INITRD ISODIR MACHINE_ARCH ROOTFS_SIZE STAGING_DATADIR<br>
&gt; STAGING_DIR_NATIVE STAGING_LIBDIR TARGET_SYS&quot;<br>
&gt; +<br>
&gt; +python () {<br>
&gt; +    &quot;&quot;&quot;Read in and set up wks file template for wic.&quot;&quot;&quot;<br>
&gt; +    if d.getVar(&#39;USING_WIC&#39;, True):<br>
&gt; +        wks_file_u = d.getVar(&#39;WKS_FULL_PATH&#39;, False)<br>
&gt; +        wks_file = d.expand(wks_file_u)<br>
&gt; +        base, ext = os.path.splitext(wks_file)<br>
&gt; +        if ext == &#39;.in&#39; and os.path.exists(wks_file):<br>
&gt; +            wks_out_file = os.path.join(d.getVar(&#39;WORKDIR&#39;, True),<br>
&gt; os.path.basename(base))<br>
&gt; +            d.setVar(&#39;WKS_FULL_PATH&#39;, wks_out_file)<br>
&gt; +            d.setVar(&#39;WKS_TEMPLATE_PATH&#39;, wks_file_u)<br>
&gt; +            d.setVar(&#39;WKS_FILE_CHECKSUM&#39;,<br>
&gt; &#39;${WKS_TEMPLATE_PATH}:True&#39;)<br>
&gt; +<br>
&gt; +            try:<br>
&gt; +                with open(wks_file, &#39;r&#39;) as f:<br>
&gt; +                    body = f.read()<br>
&gt; +            except (IOError, OSError) as exc:<br>
&gt; +                pass<br>
<br>
</div></div>I&#39;m a little nervous about determinism here. Shouldn&#39;t it either find<br>
the referenced file or error?</blockquote></div><br></div></div>That&#39;s a fair point, I think I was concerned about parse time errors, since they tend to blow up into a lot of unpleasantness for the user, since parse time errors in classes can cause errors for multiple recipes. If no file is read in at parse time, there&#39;ll be no contents to write out, and we could then error when trying to build the image with wic, as no wks file will exist.<br><br clear="all"><div>Of course, the file being missing will change checksums for the image tasks, but I think that&#39;s reasonable.</div><div><br></div><div>Thoughts?</div></blockquote></div><br>I&#39;ll do a bit more testing on the behaviors and get back to you on that later. Thanks.<br>-- <br><div class="gmail_signature"><div dir="ltr">Christopher Larson<br>kergoth at gmail dot com<br>Founder - BitBake, OpenEmbedded, OpenZaurus<br>Maintainer - Tslib<br>Senior Software Engineer, Mentor Graphics</div></div>
</div></div>