2010-09-25 06:54:44 +00:00
# This class is used to help the alternatives system which is useful when
# multiple sources provide same command. You can use update-alternatives
# command directly in your recipe, but in most cases this class simplifies
# that job.
#
2012-05-15 16:06:22 +00:00
# To use this class a number of variables should be defined:
#
# List all of the alternatives needed by a package:
# ALTERNATIVE_<pkg> = "name1 name2 name3 ..."
#
# i.e. ALTERNATIVE_busybox = "sh sed test bracket"
#
# The pathname of the link
# ALTERNATIVE_LINK_NAME[name] = "target"
#
# This is the name of the binary once it's been installed onto the runtime.
# This name is global to all split packages in this recipe, and should match
# other recipes with the same functionality.
# i.e. ALTERNATIVE_LINK_NAME[bracket] = "/usr/bin/["
#
# NOTE: If ALTERNATIVE_LINK_NAME is not defined, it defaults to ${bindir}/name
#
# The default link to create for all targets
# ALTERNATIVE_TARGET = "target"
#
# This is useful in a multicall binary case
# i.e. ALTERNATIVE_TARGET = "/bin/busybox"
#
# A non-default link to create for a target
# ALTERNATIVE_TARGET[name] = "target"
#
# This is the name of the binary as it's been install by do_install
# i.e. ALTERNATIVE_TARGET[sh] = "/bin/bash"
#
# A package specific link for a target
# ALTERNATIVE_TARGET_<pkg>[name] = "target"
#
# This is useful when a recipe provides multiple alternatives for the
# same item.
#
# NOTE: If ALTERNATIVE_TARGET is not defined, it will inherit the value
# from ALTERNATIVE_LINK_NAME.
#
# NOTE: If the ALTERNATIVE_LINK_NAME and ALTERNATIVE_TARGET are the same,
2012-05-15 23:24:58 +00:00
# ALTERNATIVE_TARGET will have '.{BPN}' appended to it. If the file
2012-05-15 16:06:22 +00:00
# referenced has not been renamed, it will also be renamed. (This avoids
# the need to rename alternative files in the do_install step, but still
# supports it if necessary for some reason.)
#
# The default priority for any alternatives
# ALTERNATIVE_PRIORITY = "priority"
#
# i.e. default is ALTERNATIVE_PRIORITY = "10"
#
# The non-default priority for a specific target
# ALTERNATIVE_PRIORITY[name] = "priority"
#
# The package priority for a specific target
# ALTERNATIVE_PRIORITY_<pkg>[name] = "priority"
2010-09-25 06:54:44 +00:00
2005-08-31 10:45:47 +00:00
ALTERNATIVE_PRIORITY = "10"
2010-09-25 06:54:44 +00:00
2012-05-15 16:06:22 +00:00
# We need special processing for vardeps because it can not work on
2015-11-05 15:48:18 +00:00
# modified flag values. So we aggregate the flags into a new variable
2012-05-15 16:06:22 +00:00
# and include that vairable in the set.
UPDALTVARS = "ALTERNATIVE ALTERNATIVE_LINK_NAME ALTERNATIVE_TARGET ALTERNATIVE_PRIORITY"
2017-01-19 08:47:13 +00:00
PACKAGE_WRITE_DEPS += "virtual/update-alternatives-native"
2012-05-15 16:06:22 +00:00
def gen_updatealternativesvardeps(d):
2016-12-14 21:13:04 +00:00
pkgs = (d.getVar("PACKAGES") or "").split()
vars = (d.getVar("UPDALTVARS") or "").split()
2012-08-20 16:52:21 +00:00
# First compute them for non_pkg versions
for v in vars:
2016-05-09 13:12:16 +00:00
for flag in sorted((d.getVarFlags(v) or {}).keys()):
2012-05-15 16:06:22 +00:00
if flag == "doc" or flag == "vardeps" or flag == "vardepsexp":
2012-08-20 16:52:21 +00:00
continue
d.appendVar('%s_VARDEPS' % (v), ' %s:%s' % (flag, d.getVarFlag(v, flag, False)))
for p in pkgs:
for v in vars:
2016-05-09 13:12:16 +00:00
for flag in sorted((d.getVarFlags("%s_%s" % (v,p)) or {}).keys()):
2012-08-20 16:52:21 +00:00
if flag == "doc" or flag == "vardeps" or flag == "vardepsexp":
continue
d.appendVar('%s_VARDEPS_%s' % (v,p), ' %s:%s' % (flag, d.getVarFlag('%s_%s' % (v,p), flag, False)))
2006-11-20 09:16:34 +00:00
2013-01-18 23:13:38 +00:00
def ua_extend_depends(d):
2016-12-14 21:13:04 +00:00
if not 'virtual/update-alternatives' in d.getVar('PROVIDES'):
2013-04-15 11:07:03 +00:00
d.appendVar('DEPENDS', ' virtual/${MLPREFIX}update-alternatives')
2013-01-18 23:13:38 +00:00
2005-08-31 10:45:47 +00:00
python __anonymous() {
2013-01-18 23:13:38 +00:00
# Update Alternatives only works on target packages...
2014-01-17 10:25:18 +00:00
if bb.data.inherits_class('native', d) or \
2013-01-18 23:13:38 +00:00
bb.data.inherits_class('cross', d) or bb.data.inherits_class('crosssdk', d) or \
bb.data.inherits_class('cross-canadian', d):
return
2017-02-21 13:17:28 +00:00
# Disable when targeting mingw32 (no target support)
if d.getVar("TARGET_OS") == "mingw32":
return
2012-05-15 16:06:22 +00:00
# compute special vardeps
gen_updatealternativesvardeps(d)
2013-01-18 23:13:38 +00:00
# extend the depends to include virtual/update-alternatives
ua_extend_depends(d)
2012-05-15 16:06:22 +00:00
}
def gen_updatealternativesvars(d):
2012-08-20 16:52:21 +00:00
ret = []
2016-12-14 21:13:04 +00:00
pkgs = (d.getVar("PACKAGES") or "").split()
vars = (d.getVar("UPDALTVARS") or "").split()
2012-08-20 16:52:21 +00:00
for v in vars:
ret.append(v + "_VARDEPS")
for p in pkgs:
for v in vars:
ret.append(v + "_" + p)
ret.append(v + "_VARDEPS_" + p)
return " ".join(ret)
2012-05-15 16:06:22 +00:00
# Now the new stuff, we use a custom function to generate the right values
populate_packages[vardeps] += "${UPDALTVARS} ${@gen_updatealternativesvars(d)}"
# We need to do the rename after the image creation step, but before
# the split and strip steps.. packagecopy seems to be the earliest reasonable
# place.
python perform_packagecopy_append () {
2012-07-11 17:33:43 +00:00
# Check for deprecated usage...
2016-12-14 21:13:04 +00:00
pn = d.getVar('BPN')
if d.getVar('ALTERNATIVE_LINKS') != None:
2013-05-21 07:35:31 +00:00
bb.fatal('%s: Use of ALTERNATIVE_LINKS/ALTERNATIVE_PATH/ALTERNATIVE_NAME is no longer supported, please convert to the updated syntax, see update-alternatives.bbclass for more info.' % pn)
2012-07-11 17:33:43 +00:00
# Do actual update alternatives processing
2016-12-14 21:13:04 +00:00
pkgdest = d.getVar('PKGD')
for pkg in (d.getVar('PACKAGES') or "").split():
2012-07-11 17:33:43 +00:00
# If the src == dest, we know we need to rename the dest by appending ${BPN}
link_rename = {}
2016-12-14 21:13:04 +00:00
for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split():
2016-12-14 21:13:06 +00:00
alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name)
2012-07-11 17:33:43 +00:00
if not alt_link:
2016-12-14 21:13:04 +00:00
alt_link = "%s/%s" % (d.getVar('bindir'), alt_name)
2012-07-11 17:33:43 +00:00
d.setVarFlag('ALTERNATIVE_LINK_NAME', alt_name, alt_link)
2016-12-14 21:13:06 +00:00
alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_TARGET', alt_name)
2016-12-14 21:13:04 +00:00
alt_target = alt_target or d.getVar('ALTERNATIVE_TARGET_%s' % pkg) or d.getVar('ALTERNATIVE_TARGET') or alt_link
2012-07-11 17:33:43 +00:00
# Sometimes alt_target is specified as relative to the link name.
alt_target = os.path.join(os.path.dirname(alt_link), alt_target)
# If the link and target are the same name, we need to rename the target.
if alt_link == alt_target:
src = '%s/%s' % (pkgdest, alt_target)
alt_target_rename = '%s.%s' % (alt_target, pn)
dest = '%s/%s' % (pkgdest, alt_target_rename)
if os.path.lexists(dest):
bb.note('%s: Already renamed: %s' % (pn, alt_target_rename))
elif os.path.lexists(src):
if os.path.islink(src):
# Delay rename of links
link_rename[alt_target] = alt_target_rename
else:
bb.note('%s: Rename %s -> %s' % (pn, alt_target, alt_target_rename))
os.rename(src, dest)
else:
bb.warn("%s: alternative target (%s or %s) does not exist, skipping..." % (pn, alt_target, alt_target_rename))
continue
d.setVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name, alt_target_rename)
# Process delayed link names
# Do these after other renames so we can correct broken links
for alt_target in link_rename:
src = '%s/%s' % (pkgdest, alt_target)
dest = '%s/%s' % (pkgdest, link_rename[alt_target])
link = os.readlink(src)
2013-02-10 12:41:48 +00:00
link_target = oe.path.realpath(src, pkgdest, True)
2012-07-11 17:33:43 +00:00
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]))
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))
os.symlink(link_maybe, dest)
os.unlink(src)
else:
bb.warn('%s: Unable to resolve dangling symlink: %s' % (pn, alt_target))
2005-08-31 10:45:47 +00:00
}
2013-02-03 17:31:30 +00:00
PACKAGESPLITFUNCS_prepend = "populate_packages_updatealternatives "
python populate_packages_updatealternatives () {
2016-12-14 21:13:04 +00:00
pn = d.getVar('BPN')
2012-07-11 17:33:43 +00:00
# Do actual update alternatives processing
2016-12-14 21:13:04 +00:00
pkgdest = d.getVar('PKGD')
for pkg in (d.getVar('PACKAGES') or "").split():
2012-07-11 17:33:43 +00:00
# Create post install/removal scripts
2016-12-20 09:47:45 +00:00
alt_setup_links = "# Begin section update-alternatives\n"
alt_remove_links = "# Begin section update-alternatives\n"
2016-12-14 21:13:04 +00:00
for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split():
2016-12-14 21:13:06 +00:00
alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name)
alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_TARGET', alt_name)
2016-12-14 21:13:04 +00:00
alt_target = alt_target or d.getVar('ALTERNATIVE_TARGET_%s' % pkg) or d.getVar('ALTERNATIVE_TARGET') or alt_link
2012-07-11 17:33:43 +00:00
# Sometimes alt_target is specified as relative to the link name.
alt_target = os.path.join(os.path.dirname(alt_link), alt_target)
2016-12-14 21:13:06 +00:00
alt_priority = d.getVarFlag('ALTERNATIVE_PRIORITY_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_PRIORITY', alt_name)
2016-12-14 21:13:04 +00:00
alt_priority = alt_priority or d.getVar('ALTERNATIVE_PRIORITY_%s' % pkg) or d.getVar('ALTERNATIVE_PRIORITY')
2012-07-11 17:33:43 +00:00
# This shouldn't trigger, as it should have been resolved earlier!
if alt_link == alt_target:
bb.note('alt_link == alt_target: %s == %s -- correcting, this should not happen!' % (alt_link, alt_target))
alt_target = '%s.%s' % (alt_target, pn)
if not os.path.lexists('%s/%s' % (pkgdest, alt_target)):
bb.warn('%s: NOT adding alternative provide %s: %s does not exist' % (pn, alt_link, alt_target))
continue
# Default to generate shell script.. eventually we may want to change this...
2012-12-29 05:19:23 +00:00
alt_target = os.path.normpath(alt_target)
2012-07-11 17:33:43 +00:00
2016-12-20 09:47:45 +00:00
alt_setup_links += 'update-alternatives --install %s %s %s %s\n' % (alt_link, alt_name, alt_target, alt_priority)
alt_remove_links += 'update-alternatives --remove %s %s\n' % (alt_name, alt_target)
2012-07-11 17:33:43 +00:00
2016-12-20 09:47:45 +00:00
alt_setup_links += "# End section update-alternatives\n"
alt_remove_links += "# End section update-alternatives\n"
if len(alt_setup_links.splitlines()) > 2:
2012-12-06 20:51:13 +00:00
# RDEPENDS setup
2016-12-14 21:13:04 +00:00
provider = d.getVar('VIRTUAL-RUNTIME_update-alternatives')
2012-12-06 20:51:13 +00:00
if provider:
#bb.note('adding runtime requirement for update-alternatives for %s' % pkg)
2015-06-18 14:14:16 +00:00
d.appendVar('RDEPENDS_%s' % pkg, ' ' + d.getVar('MLPREFIX', False) + provider)
2012-12-06 20:51:13 +00:00
2015-03-23 19:10:51 +00:00
bb.note('adding update-alternatives calls to postinst/prerm for %s' % pkg)
2012-07-11 17:33:43 +00:00
bb.note('%s' % alt_setup_links)
2016-12-14 21:13:04 +00:00
postinst = d.getVar('pkg_postinst_%s' % pkg) or '#!/bin/sh\n'
2016-12-20 09:47:45 +00:00
postinst = postinst.splitlines(True)
try:
index = postinst.index('# Begin section update-rc.d\n')
postinst.insert(index, alt_setup_links)
except ValueError:
postinst.append(alt_setup_links)
postinst = ''.join(postinst)
2012-07-11 17:33:43 +00:00
d.setVar('pkg_postinst_%s' % pkg, postinst)
bb.note('%s' % alt_remove_links)
2016-12-14 21:13:04 +00:00
prerm = d.getVar('pkg_prerm_%s' % pkg) or '#!/bin/sh\n'
2016-12-20 09:47:45 +00:00
prerm = prerm.splitlines(True)
try:
index = prerm.index('# End section update-rc.d\n')
prerm.insert(index + 1, alt_remove_links)
except ValueError:
prerm.append(alt_remove_links)
prerm = ''.join(prerm)
2015-03-23 19:10:51 +00:00
d.setVar('pkg_prerm_%s' % pkg, prerm)
2005-08-31 10:45:47 +00:00
}
2012-05-15 16:06:22 +00:00
python package_do_filedeps_append () {
2016-12-14 21:13:04 +00:00
pn = d.getVar('BPN')
pkgdest = d.getVar('PKGDEST')
2012-07-11 17:33:43 +00:00
for pkg in packages.split():
2016-12-14 21:13:04 +00:00
for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split():
2016-12-14 21:13:06 +00:00
alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name)
alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_TARGET', alt_name)
2016-12-14 21:13:04 +00:00
alt_target = alt_target or d.getVar('ALTERNATIVE_TARGET_%s' % pkg) or d.getVar('ALTERNATIVE_TARGET') or alt_link
2012-07-11 17:33:43 +00:00
if alt_link == alt_target:
2016-01-21 20:37:58 +00:00
bb.warn('%s: alt_link == alt_target: %s == %s' % (pn, alt_link, alt_target))
2012-07-11 17:33:43 +00:00
alt_target = '%s.%s' % (alt_target, pn)
if not os.path.lexists('%s/%s/%s' % (pkgdest, pkg, alt_target)):
continue
# Add file provide
2013-02-01 13:50:38 +00:00
trans_target = oe.package.file_translate(alt_target)
2012-07-11 17:33:43 +00:00
d.appendVar('FILERPROVIDES_%s_%s' % (trans_target, pkg), " " + alt_link)
2016-12-14 21:13:04 +00:00
if not trans_target in (d.getVar('FILERPROVIDESFLIST_%s' % pkg) or ""):
2012-07-11 17:33:43 +00:00
d.appendVar('FILERPROVIDESFLIST_%s' % pkg, " " + trans_target)
2012-05-15 16:06:22 +00:00
}