Переглянути джерело

class: rework autoversion to be more generic

Drop special parsing with @SWU_VERSION, not required anymore, because it
is possible to call a function by setting the name inside
sw-description. Simplify the workflow and the search pattern. Drop
limitation that a package should be part of SWU, and look up for any
variable belonging to any package. Drop the association between filename
and package name, because it is in most cases wrong and it is replaced
by the explicit name of the package in sw-description.

Old syntax:

	version = "@SWU_AUTO_VERSION"; // package name = filename
		or
	version = "@SWU_AUTO_VERSION:<package name>"
		or
	version = "@SWU_AUTO_VERSION:<package name>@<variable>"

New syntax:

	<any attribute> = "$swupdate_auto_versions(<package name>)";
		or
	<any attribute> = "$swupdate_auto_versions(<package name>@<variable>)";

Signed-off-by: Stefano Babic <sbabic@denx.de>
CC: Thomas Haemmerle <thomas.haemmerle@leica-geosystems.com>
Stefano Babic 3 роки тому
батько
коміт
8f237442e7
2 змінених файлів з 35 додано та 66 видалено
  1. 0 66
      classes/swupdate-common.bbclass
  2. 35 0
      classes/swupdate-lib.bbclass

+ 0 - 66
classes/swupdate-common.bbclass

@@ -153,78 +153,12 @@ def swupdate_find_bitbake_variables(d):
         pass
     return ' '.join(set(vardeps))
 
-def swupdate_expand_auto_versions(d, s):
-    import re
-    import oe.packagedata
-    AUTO_VERSION_TAG = "@SWU_AUTO_VERSION"
-    AUTOVERSION_REGEXP = "version\s*=\s*\"%s" % AUTO_VERSION_TAG
-
-    with open(os.path.join(s, "sw-description"), 'r') as f:
-        data = f.read()
-
-    def get_package_name(group, file_list):
-        package = None
-
-        m = re.search(r"%s:(?P<package>.+?(?=[\"@]))" % (AUTOVERSION_REGEXP), group)
-        if m:
-            package = m.group('package')
-            return (package, True)
-
-        for filename in file_list:
-            if filename in group:
-                package = filename
-
-        if not package:
-            bb.fatal("Failed to find file in group %s" % (group))
-
-        return (package, False)
-
-    def get_packagedata_key(group):
-        m = re.search(r"%s.+?(?<=@)(?P<key>.+?(?=\"))" % (AUTOVERSION_REGEXP), group)
-        if m:
-            return (m.group('key'), True)
-        return ("PV", False)
-
-    regexp = re.compile(r"\{[^\{]*%s.[^\}]*\}" % (AUTOVERSION_REGEXP))
-    while True:
-        m = regexp.search(data)
-        if not m:
-            break
-
-        group = data[m.start():m.end()]
-
-        (package, pkg_name_defined) = get_package_name(group, (d.getVar('SWUPDATE_IMAGES', True) or "").split())
-
-        pkg_info = os.path.join(d.getVar('PKGDATA_DIR'), 'runtime-reverse', package)
-        pkgdata = oe.packagedata.read_pkgdatafile(pkg_info)
-
-        (key, key_defined) = get_packagedata_key(group)
-
-        if not key in pkgdata.keys():
-            bb.warn("\"%s\" not set for package %s - using \"1.0\"" % (key, package))
-            version = "1.0"
-        else:
-            version = pkgdata[key].split('+')[0]
-
-        replace_str = AUTO_VERSION_TAG
-        if pkg_name_defined:
-            replace_str = replace_str + ":" + package
-        if key_defined:
-            replace_str = replace_str + "@" + key
-
-        group = group.replace(replace_str, version)
-        data = data[:m.start()] + group + data[m.end():]
-
-    with open(os.path.join(s, "sw-description"), 'w+') as f:
-        f.write(data)
-
 def prepare_sw_description(d):
     import shutil
     import subprocess
 
     s = d.getVar('S', True)
     swupdate_expand_bitbake_variables(d, s)
-    swupdate_expand_auto_versions(d, s)
 
     swupdate_write_sha256(s)
 

+ 35 - 0
classes/swupdate-lib.bbclass

@@ -75,3 +75,38 @@ def swupdate_sign_file(d, s, filename):
 
     return hash
 
+def swupdate_auto_versions(d, s, parms):
+    import re
+    import oe.packagedata
+
+    def get_package_name(group):
+        package = None
+
+        pkgvar = group.split('@')
+        package = pkgvar[0]
+        if len(pkgvar) > 1:
+            varname = pkgvar[1]
+        else:
+            varname = 'PV'
+
+        return (package, varname)
+
+    if parms is None:
+        return "undefined"
+
+    group = parms
+
+    (package, key) = get_package_name(group)
+
+    bb.debug(2, "Package %s defined %s" %(package, key))
+
+    pkg_info = os.path.join(d.getVar('PKGDATA_DIR'), 'runtime-reverse', package)
+    pkgdata = oe.packagedata.read_pkgdatafile(pkg_info)
+
+    if not key in pkgdata.keys():
+        bb.warn("\"%s\" not set for package %s - using \"1.0\"" % (key, package))
+        version = "1.0"
+    else:
+        version = pkgdata[key].split('+')[0]
+
+    return version