public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: claudius.heine.ext@siemens.com
To: isar-users@googlegroups.com
Cc: Claudius Heine <ch@denx.de>
Subject: [PATCH] wic-img: switch over to use the template.bbclass mechanism
Date: Wed, 13 Mar 2019 14:05:57 +0100	[thread overview]
Message-ID: <20190313130557.22878-1-claudius.heine.ext@siemens.com> (raw)

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


             reply	other threads:[~2019-03-13 13:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-13 13:05 claudius.heine.ext [this message]
2019-03-13 13:16 ` Henning Schild
2019-03-13 13:18   ` Claudius Heine
2019-03-25 16:35 ` Maxim Yu. Osipov

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=20190313130557.22878-1-claudius.heine.ext@siemens.com \
    --to=claudius.heine.ext@siemens.com \
    --cc=ch@denx.de \
    --cc=isar-users@googlegroups.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