update-alternative.bbclass: add batch alternatives support
With new batch ability, we can use below simple 2 lines for multiple alternatives updates: ALTERNATIVE_LINKS = "${bindir}/cmd1 {sbindir}/cmd2 ..." ALTERNATIVE_PRIORITY = "100" Then for each command "/path/cmd" listed in ALTERNATIVE_LINKS, below is done automatically: ${D}/path/cmd is renamed to ${D}/path/cmd.{PN} a new alternative named 'cmd' is created which: links /path/cmd to /path/cmd.{PN} with priority specified in ALTERNATIVE_PRIORITY This way the recipe with multiple alternatives could be simplified a lot. There are still some cases where above assumptions may break, but I expect more recipes should benefit from this simple enhancement Fix [BUGID #257] Signed-off-by: Kevin Tian <kevin.tian@intel.com>
This commit is contained in:
parent
5f289ac80f
commit
22cbcd964f
|
@ -1,3 +1,41 @@
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# There're two basic modes supported: 'single update' and 'batch update'
|
||||||
|
#
|
||||||
|
# 'single update' is used for a single alternative command, and you're
|
||||||
|
# expected to provide at least below keywords:
|
||||||
|
#
|
||||||
|
# ALTERNATIVE_NAME - the name that the alternative is registered
|
||||||
|
# ALTERNATIVE_PATH - the path of installed alternative
|
||||||
|
#
|
||||||
|
# ALTENATIVE_PRIORITY and ALTERNATIVE_LINK are optional which have defautls
|
||||||
|
# in this class.
|
||||||
|
#
|
||||||
|
# 'batch update' is used if you have multiple alternatives to be updated.
|
||||||
|
# Unlike 'single update', 'batch update' in most times only require two
|
||||||
|
# parameter:
|
||||||
|
#
|
||||||
|
# ALTERNATIVE_LINKS - a list of symbol links for which you'd like to
|
||||||
|
# create alternatives, with space as delimiter, e.g:
|
||||||
|
#
|
||||||
|
# ALTERNATIVE_LINKS = "${bindir}/cmd1 ${sbindir}/cmd2 ..."
|
||||||
|
#
|
||||||
|
# ALTNERATIVE_PRIORITY - optional, applies to all
|
||||||
|
#
|
||||||
|
# To simplify the design, this class has the assumption that for a name
|
||||||
|
# listed in ALTERNATIVE_LINKS, say /path/cmd:
|
||||||
|
#
|
||||||
|
# the name of the alternative would be: cmd
|
||||||
|
# the path of installed alternative would be: /path/cmd.${PN}
|
||||||
|
# ${D}/path/cmd will be renamed to ${D}/path/cmd.{PN} automatically
|
||||||
|
# priority will be the same from ALTERNATIVE_PRIORITY
|
||||||
|
#
|
||||||
|
# If above assumption breaks your requirement, then you still need to use
|
||||||
|
# your own update-alternatives command directly.
|
||||||
|
|
||||||
# defaults
|
# defaults
|
||||||
ALTERNATIVE_PRIORITY = "10"
|
ALTERNATIVE_PRIORITY = "10"
|
||||||
ALTERNATIVE_LINK = "${bindir}/${ALTERNATIVE_NAME}"
|
ALTERNATIVE_LINK = "${bindir}/${ALTERNATIVE_NAME}"
|
||||||
|
@ -10,7 +48,42 @@ update_alternatives_postrm() {
|
||||||
update-alternatives --remove ${ALTERNATIVE_NAME} ${ALTERNATIVE_PATH}
|
update-alternatives --remove ${ALTERNATIVE_NAME} ${ALTERNATIVE_PATH}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# for batch alternatives, we use a simple approach to require only one parameter
|
||||||
|
# with the rest info deduced implicitly
|
||||||
|
update_alternatives_batch_postinst() {
|
||||||
|
for link in ${ALTERNATIVE_LINKS}
|
||||||
|
do
|
||||||
|
name=`basename ${link}`
|
||||||
|
path=${link}.${PN}
|
||||||
|
update-alternatives --install ${link} ${name} ${path} ${ALTERNATIVE_PRIORITY}
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
update_alternatives_batch_postrm() {
|
||||||
|
for link in ${ALTERNATIVE_LINKS}
|
||||||
|
do
|
||||||
|
name=`basename ${link}`
|
||||||
|
path=${link}.${PN}
|
||||||
|
update-alternatives --remove ${name} $path
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
update_alternatives_batch_doinstall() {
|
||||||
|
if [ "${PN}" = "${BPN}" ] ; then
|
||||||
|
for link in ${ALTERNATIVE_LINKS}
|
||||||
|
do
|
||||||
|
mv ${D}${link} ${D}${link}.${PN}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
def update_alternatives_after_parse(d):
|
def update_alternatives_after_parse(d):
|
||||||
|
if bb.data.getVar('ALTERNATIVE_LINKS', d) != None:
|
||||||
|
doinstall = bb.data.getVar('do_install', d, 1)
|
||||||
|
doinstall += bb.data.getVar('update_alternatives_batch_doinstall', d, 1)
|
||||||
|
bb.data.setVar('do_install', doinstall, d)
|
||||||
|
return
|
||||||
|
|
||||||
if bb.data.getVar('ALTERNATIVE_NAME', d) == None:
|
if bb.data.getVar('ALTERNATIVE_NAME', d) == None:
|
||||||
raise bb.build.FuncFailed, "%s inherits update-alternatives but doesn't set ALTERNATIVE_NAME" % bb.data.getVar('FILE', d)
|
raise bb.build.FuncFailed, "%s inherits update-alternatives but doesn't set ALTERNATIVE_NAME" % bb.data.getVar('FILE', d)
|
||||||
if bb.data.getVar('ALTERNATIVE_PATH', d) == None:
|
if bb.data.getVar('ALTERNATIVE_PATH', d) == None:
|
||||||
|
@ -26,11 +99,17 @@ python populate_packages_prepend () {
|
||||||
postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1)
|
postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) or bb.data.getVar('pkg_postinst', d, 1)
|
||||||
if not postinst:
|
if not postinst:
|
||||||
postinst = '#!/bin/sh\n'
|
postinst = '#!/bin/sh\n'
|
||||||
postinst += bb.data.getVar('update_alternatives_postinst', d, 1)
|
if bb.data.getVar('ALTERNATIVE_LINKS', d) != None:
|
||||||
|
postinst += bb.data.getVar('update_alternatives_batch_postinst', d, 1)
|
||||||
|
else:
|
||||||
|
postinst += bb.data.getVar('update_alternatives_postinst', d, 1)
|
||||||
bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
|
bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
|
||||||
postrm = bb.data.getVar('pkg_postrm_%s' % pkg, d, 1) or bb.data.getVar('pkg_postrm', d, 1)
|
postrm = bb.data.getVar('pkg_postrm_%s' % pkg, d, 1) or bb.data.getVar('pkg_postrm', d, 1)
|
||||||
if not postrm:
|
if not postrm:
|
||||||
postrm = '#!/bin/sh\n'
|
postrm = '#!/bin/sh\n'
|
||||||
postrm += bb.data.getVar('update_alternatives_postrm', d, 1)
|
if bb.data.getVar('ALTERNATIVE_LINKS', d) != None:
|
||||||
|
postrm += bb.data.getVar('update_alternatives_batch_postrm', d, 1)
|
||||||
|
else:
|
||||||
|
postrm += bb.data.getVar('update_alternatives_postrm', d, 1)
|
||||||
bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d)
|
bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue