update-alternatives.bbclass: Stabilize iteration order

The use of a dictionary for link_rename causes problems for higher-order
alternatives, i.e. when an alternative link points to another
alternative link, since these links must be processed in the order in
which they were originally added for symlink correction to work.

Switch from a dict to a list of tuples to ensure processing happens in
the original order.

(From OE-Core rev: 326220267ffc43ec1f507ad0cc47ac59caafd5b7)

Signed-off-by: Clemens Lang <clemens.lang@bmw-carit.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Clemens Lang
2019-01-03 16:55:29 +01:00
committed by Richard Purdie
parent 69431c3982
commit caf55cf9b4

View File

@@ -148,7 +148,7 @@ def apply_update_alternative_renames(d):
pkgdest = d.getVar('PKGD')
for pkg in (d.getVar('PACKAGES') or "").split():
# If the src == dest, we know we need to rename the dest by appending ${BPN}
link_rename = {}
link_rename = []
for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split():
alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name)
if not alt_link:
@@ -174,7 +174,7 @@ def apply_update_alternative_renames(d):
elif os.path.lexists(src):
if os.path.islink(src):
# Delay rename of links
link_rename[alt_target] = alt_target_rename
link_rename.append((alt_target, alt_target_rename))
else:
bb.note('%s: Rename %s -> %s' % (pn, alt_target, alt_target_rename))
os.rename(src, dest)
@@ -185,22 +185,21 @@ def apply_update_alternative_renames(d):
# Process delayed link names
# Do these after other renames so we can correct broken links
for alt_target in link_rename:
for (alt_target, alt_target_rename) in link_rename:
src = '%s/%s' % (pkgdest, alt_target)
dest = '%s/%s' % (pkgdest, link_rename[alt_target])
link = os.readlink(src)
dest = '%s/%s' % (pkgdest, alt_target_rename)
link_target = oe.path.realpath(src, pkgdest, True)
if os.path.lexists(link_target):
# Ok, the link_target exists, we can rename
bb.note('%s: Rename (link) %s -> %s' % (pn, alt_target, link_rename[alt_target]))
bb.note('%s: Rename (link) %s -> %s' % (pn, alt_target, alt_target_rename))
os.rename(src, dest)
else:
# Try to resolve the broken link to link.${BPN}
link_maybe = '%s.%s' % (os.readlink(src), pn)
if os.path.lexists(os.path.join(os.path.dirname(src), link_maybe)):
# Ok, the renamed link target exists.. create a new link, and remove the original
bb.note('%s: Creating new link %s -> %s' % (pn, link_rename[alt_target], link_maybe))
bb.note('%s: Creating new link %s -> %s' % (pn, alt_target_rename, link_maybe))
os.symlink(link_maybe, dest)
os.unlink(src)
else: