Prechádzať zdrojové kódy

Allow expansion of BitBake variables in sw-description files

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
Reto Schneider 7 rokov pred
rodič
commit
9cc6781093
2 zmenil súbory, kde vykonal 29 pridanie a 0 odobranie
  1. 7 0
      README
  2. 22 0
      classes/swupdate-common.bbclass

+ 7 - 0
README

@@ -12,6 +12,13 @@ This layer depends on:
 URI: git://github.com/openembedded/meta-openembedded.git
 subdirectory: meta-oe
 
+BitBake variable expansion
+--------------------------
+
+To insert the values of BitBake variables into the update file, pre- and postfix
+the names with "@@". For example, to automatically set the version tag, use the
+line `version = "@@DISTRO_VERSION@@";` in your sw-description file.
+
 Image hashing
 -------------
 

+ 22 - 0
classes/swupdate-common.bbclass

@@ -29,8 +29,30 @@ def swupdate_write_sha256(s, filename, hash):
         for line in write_lines:
             f.write(line)
 
+def swupdate_expand_bitbake_variables(d, s):
+    write_lines = []
+
+    with open(os.path.join(s, "sw-description"), 'r') as f:
+        import re
+        for line in f:
+            m = re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>\w+)@@(?P<after_placeholder>.+)$", line)
+            if m:
+                bitbake_variable_value = d.getVar(m.group('bitbake_variable_name'), True)
+                if bitbake_variable_value:
+                    write_lines.append(m.group('before_placeholder') + bitbake_variable_value + m.group('after_placeholder') + "\n");
+                else:
+                    bb.fatal("BitBake variable %s not set" % (m.group('bitbake_variable_name')))
+            else:
+                write_lines.append(line)
+
+    with open(os.path.join(s, "sw-description"), 'w+') as f:
+        for line in write_lines:
+            f.write(line)
+
 def prepare_sw_description(d, s, list_for_cpio):
 
+    swupdate_expand_bitbake_variables(d, s)
+
     for file in list_for_cpio:
         if file != 'sw-description' and swupdate_is_hash_needed(s, file):
             hash = swupdate_get_sha256(s, file)