Commit 81986274 authored by Thomas Haemmerle's avatar Thomas Haemmerle Committed by Stefano Babic
Browse files

Introduce functionality for automatically fetching package versions

Versions of the packages included in update file needs to be entered
manually in sw-description file or provided in as a bitbake variable.

This patch searches for a group in sw-description file containing the
tag `version = "@SWU_AUTO_VERSION"`.
If found, the version of the corresponding package is fetched from it's
package-data-file (`PV`) and the tag is replaced with the version.
Possible trailing strings in `PV` starting with `+` (e.g.
"+gitAUTOINC+...") are dropped to keep semantic versions.

Since the filenames not always belong to the package name (deployed
with another name or the file is a container for the real package)
support providing the correct package name by appending the tag with
Signed-off-by: default avatarThomas Haemmerle <>
parent 1a3c1fc4
......@@ -25,6 +25,18 @@ Image hashing
During creation of the update file, occurrences of @IMAGE (where IMAGE is an
image filename) are replaced with the sha256 hash of the image.
BitBake auto versions
By setting the version tag in the update file to `@SWU_AUTO_VERSION` it is
automatically replaced with `PV` from BitBake's package-data-file for the package
matching the name of the provided filename tag.
Since the filename can differ from package name (deployed with another name or
the file is a container for the real package) you can append the correct package
name to the tag:
SWU image signing
......@@ -88,10 +88,64 @@ def swupdate_expand_bitbake_variables(d, s):
for line in write_lines:
def swupdate_expand_auto_versions(d, s, list_for_cpio):
import re
import oe.packagedata
with open(os.path.join(s, "sw-description"), 'r') as f:
data =
def get_package_name(group, file_list):
m ="%s:(?P<package>.+?(?=\"))" % (AUTOVERSION_REGEXP), group)
if m:
package ='package')
return (package, True)
for filename in file_list:
if filename in group:
package = filename
if not package:
bb.fatal("Failed to find %s in group with \"%s\"" % (filename, AUTO_VERSION_TAG))
return (package, False)
regexp = re.compile(r"\{[^\{]*%s.[^\}]*\}" % (AUTOVERSION_REGEXP))
while True:
m =
if not m:
group = data[m.start():m.end()]
(package, pkg_name_defined) = get_package_name(group, list_for_cpio)
pkg_info = os.path.join(d.getVar('PKGDATA_DIR'), 'runtime-reverse', package)
pkgdata = oe.packagedata.read_pkgdatafile(pkg_info)
if not "PV" in pkgdata.keys():
bb.warn("\"PV\" not set for package %s - using \"1.0\"" % (package))
version = "1.0"
version = pkgdata['PV'].split('+')[0]
replace_str = AUTO_VERSION_TAG
if pkg_name_defined:
replace_str = replace_str + ":" + package
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:
def prepare_sw_description(d, s, list_for_cpio):
import shutil
swupdate_expand_bitbake_variables(d, s)
swupdate_expand_auto_versions(d, s, list_for_cpio)
for file in list_for_cpio:
if file != 'sw-description' and swupdate_is_hash_needed(s, file):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment