diff mbox series

[meta,V2,01/12] Evaluate functions inside sw-description

Message ID 20220406081837.2222008-2-sbabic@denx.de
State Accepted
Headers show
Series Support to call functions inside sw-description | expand

Commit Message

Stefano Babic April 6, 2022, 8:18 a.m. UTC
Instead to add new rules to parse sw-description to generate data,
create a generic method to let the class to call a function. It is then
enough to create a list / libraries of these function instead to find
new ways to extend sw-description's syntax.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 classes/swupdate-common.bbclass | 34 +++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
index 53aa48e..556ab8d 100644
--- a/classes/swupdate-common.bbclass
+++ b/classes/swupdate-common.bbclass
@@ -38,7 +38,7 @@  def swupdate_getdepends(d):
 
     return depstr
 
-def swupdate_get_sha256(s, filename):
+def swupdate_get_sha256(d, s, filename):
     import hashlib
 
     m = hashlib.sha256()
@@ -84,7 +84,7 @@  def swupdate_write_sha256(s):
           m = re.match(r"^(?P<before_placeholder>.+)(sha256|version).+[=:].*(?P<quote>[\'\"])@(?P<filename>.*)(?P=quote)", line)
           if m:
               filename = m.group('filename')
-              hash = swupdate_get_sha256(s, filename)
+              hash = swupdate_get_sha256(None, s, filename)
               write_lines.append(line.replace("@%s" % (filename), hash))
           else:
               write_lines.append(line)
@@ -93,6 +93,34 @@  def swupdate_write_sha256(s):
         for line in write_lines:
             f.write(line)
 
+def swupdate_create_func_line(s, function, parms):
+    parmlist = parms.split(',')
+    cmd = "'" + s + "'"
+    for parm in parmlist:
+        if len(cmd):
+           cmd = cmd + ','
+        cmd = cmd + "'" + parm + "'"
+    cmd = function + '(' + cmd + ')'
+    return cmd
+
+def swupdate_exec_functions(d, s, write_lines):
+    import re
+    for index, line in enumerate(write_lines):
+        m = re.match(r"^(?P<before_placeholder>.+)\$(?P<bitbake_function_name>\w+)\((?P<parms>.+)\)(?P<after_placeholder>.+)$", line)
+        if m:
+            bb.warn("Found function")
+            fun = m.group('bitbake_function_name') + "(d, \"" + s + "\", \"" + m.group('parms') + "\")"
+            ret = eval(fun)
+            bb.warn("Fun : %s" % fun)
+            bb.warn ("%s return %s " % (m.group('bitbake_function_name'), ret))
+            cmd = swupdate_create_func_line(s, m.group('bitbake_function_name'), m.group('parms') )
+            bb.warn ("Returned command %s" % cmd)
+            line = m.group('before_placeholder') + ret + m.group('after_placeholder') + "\n"
+            #ret = eval(cmd)
+            bb.warn ("==> Returned command %s : %s" % (cmd, ret))
+            write_lines[index] = line
+
+
 def swupdate_expand_bitbake_variables(d, s):
     write_lines = []
 
@@ -125,6 +153,8 @@  def swupdate_expand_bitbake_variables(d, s):
 
             write_lines.append(line)
 
+    swupdate_exec_functions(d, s, write_lines)
+
     with open(os.path.join(s, "sw-description"), 'w+') as f:
         for line in write_lines:
             f.write(line)