public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] wic-img: switch over to use the template.bbclass mechanism
@ 2019-03-13 13:05 claudius.heine.ext
  2019-03-13 13:16 ` Henning Schild
  2019-03-25 16:35 ` Maxim Yu. Osipov
  0 siblings, 2 replies; 4+ messages in thread
From: claudius.heine.ext @ 2019-03-13 13:05 UTC (permalink / raw)
  To: isar-users; +Cc: Claudius Heine

From: Claudius Heine <ch@denx.de>

We don't need to have two template mechanism implemented in Isar. This
patch switches the very specific one in wic-img to use the generic one
from template.bbclass.

Signed-off-by: Claudius Heine <ch@denx.de>
---
 meta/classes/wic-img.bbclass | 40 +++++++++++++-----------------------
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass
index 5a451a0..09d9f2e 100644
--- a/meta/classes/wic-img.bbclass
+++ b/meta/classes/wic-img.bbclass
@@ -6,29 +6,14 @@
 
 WKS_FILE_CHECKSUM = "${@'${WKS_FULL_PATH}:%s' % os.path.exists('${WKS_FULL_PATH}')}"
 
-python do_write_wks_template () {
-    """Write out expanded template contents to WKS_FULL_PATH."""
-    import re
-
-    template_body = d.getVar('_WKS_TEMPLATE')
-
-    # Remove any remnant variable references left behind by the expansion
-    # due to undefined variables
-    expand_var_regexp = re.compile(r"\${[^{}@\n\t :]+}")
-    while True:
-        new_body = re.sub(expand_var_regexp, '', template_body)
-        if new_body == template_body:
-            break
-        else:
-            template_body = new_body
-
-    wks_file = d.getVar('WKS_FULL_PATH')
-    with open(wks_file, 'w') as f:
-        f.write(template_body)
+do_copy_wks_template[file-checksums] += "${WKS_FILE_CHECKSUM}"
+do_copy_wks_template () {
+    cp -f '${WKS_TEMPLATE_PATH}' '${WORKDIR}/${WKS_TEMPLATE_FILE}'
 }
 
 python () {
     import itertools
+    import re
 
     wks_full_path = None
 
@@ -70,22 +55,25 @@ python () {
         d.setVar('WKS_TEMPLATE_PATH', wks_file_u)
         d.setVar('WKS_FILE_CHECKSUM', '${WKS_TEMPLATE_PATH}:True')
 
+        wks_template_file = os.path.basename(base) + '.tmpl'
+        d.setVar('WKS_TEMPLATE_FILE', wks_template_file)
+        d.appendVar('TEMPLATE_FILES', " {}".format(wks_template_file))
+
         # We need to re-parse each time the file changes, and bitbake
         # needs to be told about that explicitly.
         bb.parse.mark_dependency(d, wks_file)
 
+        expand_var_regexp = re.compile(r"\${(?P<name>[^{}@\n\t :]+)}")
+
         try:
             with open(wks_file, 'r') as f:
-                body = f.read()
+                d.appendVar("TEMPLATE_VARS", " {}".format(
+                    " ".join(expand_var_regexp.findall(f.read()))))
         except (IOError, OSError) as exc:
             pass
         else:
-            # Previously, I used expandWithRefs to get the dependency list
-            # and add it to WICVARS, but there's no point re-parsing the
-            # file in process_wks_template as well, so just put it in
-            # a variable and let the metadata deal with the deps.
-            d.setVar('_WKS_TEMPLATE', body)
-            bb.build.addtask('do_write_wks_template', 'do_wic_image', None, d)
+            bb.build.addtask('do_copy_wks_template', 'do_transform_template do_wic_image', None, d)
+            bb.build.addtask('do_transform_template', 'do_wic_image', None, d)
 }
 
 inherit buildchroot
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-25 16:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-13 13:05 [PATCH] wic-img: switch over to use the template.bbclass mechanism claudius.heine.ext
2019-03-13 13:16 ` Henning Schild
2019-03-13 13:18   ` Claudius Heine
2019-03-25 16:35 ` Maxim Yu. Osipov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox