<div dir="ltr">Why didn&#39;t you make this image_types_wic.bbclass and use IMAGE_CLASSES to load it?</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 27, 2017 at 12:19 PM, Ed Bartosh <span dir="ltr">&lt;<a href="mailto:ed.bartosh@linux.intel.com" target="_blank">ed.bartosh@linux.intel.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There is a lot of wic code in image.bbclass and image_types.bbclass<br>
Having all code separated in one file should make it more readable<br>
and easier to maintain.<br>
<br>
Signed-off-by: Ed Bartosh &lt;<a href="mailto:ed.bartosh@linux.intel.com">ed.bartosh@linux.intel.com</a>&gt;<br>
---<br>
 meta/classes/image-wic.bbclass   | 120 ++++++++++++++++++++++++++++++<wbr>+++++++++<br>
 meta/classes/image.bbclass       |  25 +-------<br>
 meta/classes/image_types.<wbr>bbclass |  95 ------------------------------<wbr>-<br>
 3 files changed, 122 insertions(+), 118 deletions(-)<br>
 create mode 100644 meta/classes/image-wic.bbclass<br>
<br>
diff --git a/meta/classes/image-wic.<wbr>bbclass b/meta/classes/image-wic.<wbr>bbclass<br>
new file mode 100644<br>
index 0000000..2acfd65<br>
--- /dev/null<br>
+++ b/meta/classes/image-wic.<wbr>bbclass<br>
@@ -0,0 +1,120 @@<br>
+# The WICVARS variable is used to define list of bitbake variables used in wic code<br>
+# variables from this list is written to &lt;image&gt;.env file<br>
+WICVARS ?= &quot;\<br>
+           BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD HDDDIR IMAGE_BASENAME IMAGE_BOOT_FILES \<br>
+           IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD ISODIR MACHINE_ARCH RECIPE_SYSROOT_NATIVE \<br>
+           ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS&quot;<br>
+<br>
+WKS_FILE ??= &quot;${IMAGE_BASENAME}.${MACHINE}.<wbr>wks&quot;<br>
+WKS_FILES ?= &quot;${WKS_FILE} ${IMAGE_BASENAME}.wks&quot;<br>
+WKS_SEARCH_PATH ?= &quot;${THISDIR}:${@&#39;:&#39;.join(&#39;%s/<wbr>wic&#39; % p for p in &#39;${BBPATH}&#39;.split(&#39;:&#39;))}:${@&#39;:<wbr>&#39;.join(&#39;%s/scripts/lib/wic/<wbr>canned-wks&#39; % l for l in &#39;${BBPATH}:${COREBASE}&#39;.split(<wbr>&#39;:&#39;))}&quot;<br>
+WKS_FULL_PATH = &quot;${@wks_search(&#39;${WKS_FILES}&#39;.<wbr>split(), &#39;${WKS_SEARCH_PATH}&#39;) or &#39;&#39;}&quot;<br>
+<br>
+def wks_search(files, search_path):<br>
+    for f in files:<br>
+        if os.path.isabs(f):<br>
+            if os.path.exists(f):<br>
+                return f<br>
+        else:<br>
+            searched = bb.utils.which(search_path, f)<br>
+            if searched:<br>
+                return searched<br>
+<br>
+WIC_CREATE_EXTRA_ARGS ?= &quot;&quot;<br>
+<br>
+IMAGE_CMD_wic () {<br>
+       out=&quot;${IMGDEPLOYDIR}/${IMAGE_<wbr>NAME}&quot;<br>
+       wks=&quot;${WKS_FULL_PATH}&quot;<br>
+       if [ -z &quot;$wks&quot; ]; then<br>
+               bbfatal &quot;No kickstart files from WKS_FILES were found: ${WKS_FILES}. Please set WKS_FILE or WKS_FILES appropriately.&quot;<br>
+       fi<br>
+<br>
+       BUILDDIR=&quot;${TOPDIR}&quot; wic create &quot;$wks&quot; --vars &quot;${STAGING_DIR}/${MACHINE}/<wbr>imgdata/&quot; -e &quot;${IMAGE_BASENAME}&quot; -o &quot;$out/&quot; ${WIC_CREATE_EXTRA_ARGS}<br>
+       mv &quot;$out/$(basename &quot;${wks%.wks}&quot;)&quot;*.direct &quot;$out${IMAGE_NAME_SUFFIX}.wic&quot;<br>
+       rm -rf &quot;$out/&quot;<br>
+}<br>
+IMAGE_CMD_wic[vardepsexclude] = &quot;WKS_FULL_PATH WKS_FILES&quot;<br>
+<br>
+# Rebuild when the wks file or vars in WICVARS change<br>
+USING_WIC = &quot;${@bb.utils.contains_any(&#39;<wbr>IMAGE_FSTYPES&#39;, &#39;wic &#39; + &#39; &#39;.join(&#39;wic.%s&#39; % c for c in &#39;${CONVERSIONTYPES}&#39;.split()), &#39;1&#39;, &#39;&#39;, d)}&quot;<br>
+WKS_FILE_CHECKSUM = &quot;${@&#39;${WKS_FULL_PATH}:%s&#39; % os.path.exists(&#39;${WKS_FULL_<wbr>PATH}&#39;) if &#39;${USING_WIC}&#39; else &#39;&#39;}&quot;<br>
+do_image_wic[file-checksums] += &quot;${WKS_FILE_CHECKSUM}&quot;<br>
+do_image_wic[depends] += &quot;wic-tools:do_build&quot;<br>
+<br>
+python () {<br>
+    if d.getVar(&#39;USING_WIC&#39;) and &#39;do_bootimg&#39; in d:<br>
+        bb.build.addtask(&#39;do_image_<wbr>wic&#39;, &#39;&#39;, &#39;do_bootimg&#39;, d)<br>
+}<br>
+<br>
+python do_write_wks_template () {<br>
+    &quot;&quot;&quot;Write out expanded template contents to WKS_FULL_PATH.&quot;&quot;&quot;<br>
+    import re<br>
+<br>
+    template_body = d.getVar(&#39;_WKS_TEMPLATE&#39;)<br>
+<br>
+    # Remove any remnant variable references left behind by the expansion<br>
+    # due to undefined variables<br>
+    expand_var_regexp = re.compile(r&quot;\${[^{}@\n\t :]+}&quot;)<br>
+    while True:<br>
+        new_body = re.sub(expand_var_regexp, &#39;&#39;, template_body)<br>
+        if new_body == template_body:<br>
+            break<br>
+        else:<br>
+            template_body = new_body<br>
+<br>
+    wks_file = d.getVar(&#39;WKS_FULL_PATH&#39;)<br>
+    with open(wks_file, &#39;w&#39;) as f:<br>
+        f.write(template_body)<br>
+}<br>
+<br>
+python () {<br>
+    if d.getVar(&#39;USING_WIC&#39;):<br>
+        wks_file_u = d.getVar(&#39;WKS_FULL_PATH&#39;, False)<br>
+        wks_file = d.expand(wks_file_u)<br>
+        base, ext = os.path.splitext(wks_file)<br>
+        if ext == &#39;.in&#39; and os.path.exists(wks_file):<br>
+            wks_out_file = os.path.join(d.getVar(&#39;<wbr>WORKDIR&#39;), os.path.basename(base))<br>
+            d.setVar(&#39;WKS_FULL_PATH&#39;, wks_out_file)<br>
+            d.setVar(&#39;WKS_TEMPLATE_PATH&#39;, wks_file_u)<br>
+            d.setVar(&#39;WKS_FILE_CHECKSUM&#39;, &#39;${WKS_TEMPLATE_PATH}:True&#39;)<br>
+<br>
+            # We need to re-parse each time the file changes, and bitbake<br>
+            # needs to be told about that explicitly.<br>
+            bb.parse.mark_dependency(d, wks_file)<br>
+<br>
+            try:<br>
+                with open(wks_file, &#39;r&#39;) as f:<br>
+                    body = f.read()<br>
+            except (IOError, OSError) as exc:<br>
+                pass<br>
+            else:<br>
+                # Previously, I used expandWithRefs to get the dependency list<br>
+                # and add it to WICVARS, but there&#39;s no point re-parsing the<br>
+                # file in process_wks_template as well, so just put it in<br>
+                # a variable and let the metadata deal with the deps.<br>
+                d.setVar(&#39;_WKS_TEMPLATE&#39;, body)<br>
+                bb.build.addtask(&#39;do_write_<wbr>wks_template&#39;, &#39;do_image_wic&#39;, None, d)<br>
+}<br>
+<br>
+#<br>
+# Write environment variables used by wic<br>
+# to tmp/sysroots/&lt;machine&gt;/<wbr>imgdata/&lt;image&gt;.env<br>
+#<br>
+python do_rootfs_wicenv () {<br>
+    wicvars = d.getVar(&#39;WICVARS&#39;)<br>
+    if not wicvars:<br>
+        return<br>
+<br>
+    stdir = d.getVar(&#39;STAGING_DIR&#39;)<br>
+    outdir = os.path.join(stdir, d.getVar(&#39;MACHINE&#39;), &#39;imgdata&#39;)<br>
+    bb.utils.mkdirhier(outdir)<br>
+    basename = d.getVar(&#39;IMAGE_BASENAME&#39;)<br>
+    with open(os.path.join(outdir, basename) + &#39;.env&#39;, &#39;w&#39;) as envf:<br>
+        for var in wicvars.split():<br>
+            value = d.getVar(var)<br>
+            if value:<br>
+                envf.write(&#39;%s=&quot;%s&quot;\n&#39; % (var, value.strip()))<br>
+}<br>
+addtask do_rootfs_wicenv after do_image before do_image_wic<br>
+do_rootfs_wicenv[vardeps] += &quot;${WICVARS}&quot;<br>
+do_rootfs_wicenv[prefuncs] = &#39;set_image_size&#39;<br>
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass<br>
index 13fd996..1a549e9 100644<br>
--- a/meta/classes/image.bbclass<br>
+++ b/meta/classes/image.bbclass<br>
@@ -192,6 +192,8 @@ python () {<br>
 IMAGE_CLASSES += &quot;image_types&quot;<br>
 inherit ${IMAGE_CLASSES}<br>
<br>
+inherit image-wic<br>
+<br>
 IMAGE_POSTPROCESS_COMMAND ?= &quot;&quot;<br>
<br>
 # some default locales<br>
@@ -332,29 +334,6 @@ fakeroot python do_image_qa () {<br>
 }<br>
 addtask do_image_qa after do_image_complete before do_build<br>
<br>
-#<br>
-# Write environment variables used by wic<br>
-# to tmp/sysroots/&lt;machine&gt;/<wbr>imgdata/&lt;image&gt;.env<br>
-#<br>
-python do_rootfs_wicenv () {<br>
-    wicvars = d.getVar(&#39;WICVARS&#39;)<br>
-    if not wicvars:<br>
-        return<br>
-<br>
-    stdir = d.getVar(&#39;STAGING_DIR&#39;)<br>
-    outdir = os.path.join(stdir, d.getVar(&#39;MACHINE&#39;), &#39;imgdata&#39;)<br>
-    bb.utils.mkdirhier(outdir)<br>
-    basename = d.getVar(&#39;IMAGE_BASENAME&#39;)<br>
-    with open(os.path.join(outdir, basename) + &#39;.env&#39;, &#39;w&#39;) as envf:<br>
-        for var in wicvars.split():<br>
-            value = d.getVar(var)<br>
-            if value:<br>
-                envf.write(&#39;%s=&quot;%s&quot;\n&#39; % (var, value.strip()))<br>
-}<br>
-addtask do_rootfs_wicenv after do_image before do_image_wic<br>
-do_rootfs_wicenv[vardeps] += &quot;${WICVARS}&quot;<br>
-do_rootfs_wicenv[prefuncs] = &#39;set_image_size&#39;<br>
-<br>
 def setup_debugfs_variables(d):<br>
     d.appendVar(&#39;IMAGE_ROOTFS&#39;, &#39;-dbg&#39;)<br>
     d.appendVar(&#39;IMAGE_LINK_NAME&#39;, &#39;-dbg&#39;)<br>
diff --git a/meta/classes/image_types.<wbr>bbclass b/meta/classes/image_types.<wbr>bbclass<br>
index ad95dc6..e2ecf93 100644<br>
--- a/meta/classes/image_types.<wbr>bbclass<br>
+++ b/meta/classes/image_types.<wbr>bbclass<br>
@@ -192,97 +192,6 @@ IMAGE_CMD_ubi () {<br>
<br>
 IMAGE_CMD_ubifs = &quot;mkfs.ubifs -r ${IMAGE_ROOTFS} -o ${IMGDEPLOYDIR}/${IMAGE_NAME}$<wbr>{IMAGE_NAME_SUFFIX}.ubifs ${MKUBIFS_ARGS}&quot;<br>
<br>
-WKS_FILE ??= &quot;${IMAGE_BASENAME}.${MACHINE}.<wbr>wks&quot;<br>
-WKS_FILES ?= &quot;${WKS_FILE} ${IMAGE_BASENAME}.wks&quot;<br>
-WKS_SEARCH_PATH ?= &quot;${THISDIR}:${@&#39;:&#39;.join(&#39;%s/<wbr>wic&#39; % p for p in &#39;${BBPATH}&#39;.split(&#39;:&#39;))}:${@&#39;:<wbr>&#39;.join(&#39;%s/scripts/lib/wic/<wbr>canned-wks&#39; % l for l in &#39;${BBPATH}:${COREBASE}&#39;.split(<wbr>&#39;:&#39;))}&quot;<br>
-WKS_FULL_PATH = &quot;${@wks_search(&#39;${WKS_FILES}&#39;.<wbr>split(), &#39;${WKS_SEARCH_PATH}&#39;) or &#39;&#39;}&quot;<br>
-<br>
-def wks_search(files, search_path):<br>
-    for f in files:<br>
-        if os.path.isabs(f):<br>
-            if os.path.exists(f):<br>
-                return f<br>
-        else:<br>
-            searched = bb.utils.which(search_path, f)<br>
-            if searched:<br>
-                return searched<br>
-<br>
-WIC_CREATE_EXTRA_ARGS ?= &quot;&quot;<br>
-<br>
-IMAGE_CMD_wic () {<br>
-       out=&quot;${IMGDEPLOYDIR}/${IMAGE_<wbr>NAME}&quot;<br>
-       wks=&quot;${WKS_FULL_PATH}&quot;<br>
-       if [ -z &quot;$wks&quot; ]; then<br>
-               bbfatal &quot;No kickstart files from WKS_FILES were found: ${WKS_FILES}. Please set WKS_FILE or WKS_FILES appropriately.&quot;<br>
-       fi<br>
-<br>
-       BUILDDIR=&quot;${TOPDIR}&quot; wic create &quot;$wks&quot; --vars &quot;${STAGING_DIR}/${MACHINE}/<wbr>imgdata/&quot; -e &quot;${IMAGE_BASENAME}&quot; -o &quot;$out/&quot; ${WIC_CREATE_EXTRA_ARGS}<br>
-       mv &quot;$out/$(basename &quot;${wks%.wks}&quot;)&quot;*.direct &quot;$out${IMAGE_NAME_SUFFIX}.wic&quot;<br>
-       rm -rf &quot;$out/&quot;<br>
-}<br>
-IMAGE_CMD_wic[vardepsexclude] = &quot;WKS_FULL_PATH WKS_FILES&quot;<br>
-<br>
-# Rebuild when the wks file or vars in WICVARS change<br>
-USING_WIC = &quot;${@bb.utils.contains_any(&#39;<wbr>IMAGE_FSTYPES&#39;, &#39;wic &#39; + &#39; &#39;.join(&#39;wic.%s&#39; % c for c in &#39;${CONVERSIONTYPES}&#39;.split()), &#39;1&#39;, &#39;&#39;, d)}&quot;<br>
-WKS_FILE_CHECKSUM = &quot;${@&#39;${WKS_FULL_PATH}:%s&#39; % os.path.exists(&#39;${WKS_FULL_<wbr>PATH}&#39;) if &#39;${USING_WIC}&#39; else &#39;&#39;}&quot;<br>
-do_image_wic[file-checksums] += &quot;${WKS_FILE_CHECKSUM}&quot;<br>
-do_image_wic[depends] += &quot;wic-tools:do_build&quot;<br>
-<br>
-python () {<br>
-    if d.getVar(&#39;USING_WIC&#39;) and &#39;do_bootimg&#39; in d:<br>
-        bb.build.addtask(&#39;do_image_<wbr>wic&#39;, &#39;&#39;, &#39;do_bootimg&#39;, d)<br>
-}<br>
-<br>
-python do_write_wks_template () {<br>
-    &quot;&quot;&quot;Write out expanded template contents to WKS_FULL_PATH.&quot;&quot;&quot;<br>
-    import re<br>
-<br>
-    template_body = d.getVar(&#39;_WKS_TEMPLATE&#39;)<br>
-<br>
-    # Remove any remnant variable references left behind by the expansion<br>
-    # due to undefined variables<br>
-    expand_var_regexp = re.compile(r&quot;\${[^{}@\n\t :]+}&quot;)<br>
-    while True:<br>
-        new_body = re.sub(expand_var_regexp, &#39;&#39;, template_body)<br>
-        if new_body == template_body:<br>
-            break<br>
-        else:<br>
-            template_body = new_body<br>
-<br>
-    wks_file = d.getVar(&#39;WKS_FULL_PATH&#39;)<br>
-    with open(wks_file, &#39;w&#39;) as f:<br>
-        f.write(template_body)<br>
-}<br>
-<br>
-python () {<br>
-    if d.getVar(&#39;USING_WIC&#39;):<br>
-        wks_file_u = d.getVar(&#39;WKS_FULL_PATH&#39;, False)<br>
-        wks_file = d.expand(wks_file_u)<br>
-        base, ext = os.path.splitext(wks_file)<br>
-        if ext == &#39;.in&#39; and os.path.exists(wks_file):<br>
-            wks_out_file = os.path.join(d.getVar(&#39;<wbr>WORKDIR&#39;), os.path.basename(base))<br>
-            d.setVar(&#39;WKS_FULL_PATH&#39;, wks_out_file)<br>
-            d.setVar(&#39;WKS_TEMPLATE_PATH&#39;, wks_file_u)<br>
-            d.setVar(&#39;WKS_FILE_CHECKSUM&#39;, &#39;${WKS_TEMPLATE_PATH}:True&#39;)<br>
-<br>
-            # We need to re-parse each time the file changes, and bitbake<br>
-            # needs to be told about that explicitly.<br>
-            bb.parse.mark_dependency(d, wks_file)<br>
-<br>
-            try:<br>
-                with open(wks_file, &#39;r&#39;) as f:<br>
-                    body = f.read()<br>
-            except (IOError, OSError) as exc:<br>
-                pass<br>
-            else:<br>
-                # Previously, I used expandWithRefs to get the dependency list<br>
-                # and add it to WICVARS, but there&#39;s no point re-parsing the<br>
-                # file in process_wks_template as well, so just put it in<br>
-                # a variable and let the metadata deal with the deps.<br>
-                d.setVar(&#39;_WKS_TEMPLATE&#39;, body)<br>
-                bb.build.addtask(&#39;do_write_<wbr>wks_template&#39;, &#39;do_image_wic&#39;, None, d)<br>
-}<br>
-<br>
 EXTRA_IMAGECMD = &quot;&quot;<br>
<br>
 inherit siteinfo<br>
@@ -380,7 +289,3 @@ IMAGE_EXTENSION_live = &quot;hddimg iso&quot;<br>
 # The IMAGE_TYPES_MASKED variable will be used to mask out from the IMAGE_FSTYPES,<br>
 # images that will not be built at do_rootfs time: vmdk, vdi, qcow2, hdddirect, hddimg, iso, etc.<br>
 IMAGE_TYPES_MASKED ?= &quot;&quot;<br>
-<br>
-# The WICVARS variable is used to define list of bitbake variables used in wic code<br>
-# variables from this list is written to &lt;image&gt;.env file<br>
-WICVARS ?= &quot;BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD HDDDIR IMAGE_BASENAME IMAGE_BOOT_FILES IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD ISODIR MACHINE_ARCH RECIPE_SYSROOT_NATIVE ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS&quot;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.1.4<br>
<br>
--<br>
______________________________<wbr>_________________<br>
Openembedded-core mailing list<br>
<a href="mailto:Openembedded-core@lists.openembedded.org">Openembedded-core@lists.<wbr>openembedded.org</a><br>
<a href="http://lists.openembedded.org/mailman/listinfo/openembedded-core" rel="noreferrer" target="_blank">http://lists.openembedded.org/<wbr>mailman/listinfo/openembedded-<wbr>core</a><br>
</font></span></blockquote></div><br></div>