浏览代码

Extend Allow expansion of variables in sw-description

Variables are just matched one for each line in sw-description. The
patch extend the behavior and searches recursively in each line for all
matches of the substituion pattern @@variable@@.

This adds supports for variable's flags, too. The following match is
also resolved:

	@@variable[name-of-flag]@@

This is useful to evaluate SWUpdate's flags as the image extension.

Signed-off-by: Stefano Babic <sbabic@denx.de>
Stefano Babic 6 年之前
父节点
当前提交
4ab05dff6a
共有 1 个文件被更改,包括 25 次插入9 次删除
  1. 25 9
      classes/swupdate-common.bbclass

+ 25 - 9
classes/swupdate-common.bbclass

@@ -35,15 +35,31 @@ def swupdate_expand_bitbake_variables(d, s):
     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 is None:
-                   bitbake_variable_value = ""
-                   bb.warn("BitBake variable %s not set" % (m.group('bitbake_variable_name')))
-                write_lines.append(m.group('before_placeholder') + bitbake_variable_value + m.group('after_placeholder') + "\n");
-            else:
-                write_lines.append(line)
+            found = False
+            while True:
+                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 is None:
+                       bitbake_variable_value = ""
+                       bb.warn("BitBake variable %s not set" % (m.group('bitbake_variable_name')))
+                    line = m.group('before_placeholder') + bitbake_variable_value + m.group('after_placeholder')
+                    found = True
+                    continue
+                else:
+                    m = re.match(r"^(?P<before_placeholder>.+)@@(?P<bitbake_variable_name>.+)\[(?P<flag_var_name>.+)\]@@(?P<after_placeholder>.+)$", line)
+                    if m:
+                       bitbake_variable_value = (d.getVarFlag(m.group('bitbake_variable_name'), m.group('flag_var_name'), True) or "")
+                       if bitbake_variable_value is None:
+                          bitbake_variable_value = ""
+                       line = m.group('before_placeholder') + bitbake_variable_value + m.group('after_placeholder')
+                       continue
+
+                    if found:
+                       line = line + "\n"
+                    break
+
+            write_lines.append(line)
 
     with open(os.path.join(s, "sw-description"), 'w+') as f:
         for line in write_lines: