update-alternatives.bbclass: Add function to get renamed binaries
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/3 update-alternatives.bbclass: Add function to get renamed binaries
This adds a function to get the new name for renamed binaries by the update-alternatives class. The function uses the build metadata because some update-alternatives binaries/scripts lack the feature to provide this information.
This also adds the function _ua_alt_target for code reuse.
[YOCTO #13238]
--- meta/classes/update-alternatives.bbclass | 43 +++++++++++++++++++++--- 1 file changed, 38 insertions(+), 5 deletions(-)
meta/classes/update-alternatives.bbclass +38 -5
@@ -216,6 +216,43 @@ python apply_update_alternative_renames () { update_files(alt_target, alt_target_rename, pkg, d) } +def update_alternatives_get_alt_target(d, link): + """ + Returns the renamed binary modified by update-alternatives class. + + Unfortunately not all update-alternative binaries/scripts implement a way + to provide a list of binaries for a link, so we need to use the build + metadata to get the information. + + NOTE: This function needs to run after apply_update_alternative_renames + """ + for pkg in (d.getVar('PACKAGES') or "").split(): + for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split(): + alt_link = d.getVarFlag('ALTERNATIVE_LINK_NAME', alt_name) + + # Just care for the link being asked for + if link != alt_link: + continue + + alt_target = _ua_alt_target(d, alt_name, alt_link, pkg) + if alt_target != alt_link: + return alt_target + else: + return None + + return None + +def _ua_alt_target(d, alt_name, alt_link, pkg): + alt_target = d.getVarFlag('ALTERNATIVE_TARGET_%s' % pkg, alt_name) or \ + d.getVarFlag('ALTERNATIVE_TARGET', alt_name) or \ + d.getVar('ALTERNATIVE_TARGET_%s' % pkg) or \ + d.getVar('ALTERNATIVE_TARGET') or \ + alt_link + + # Sometimes alt_target is specified as relative to the link name. + alt_target = os.path.join(os.path.dirname(alt_link), alt_target) + return alt_target + PACKAGESPLITFUNCS_prepend = "populate_packages_updatealternatives " python populate_packages_updatealternatives () {
@@ -232,11 +269,7 @@ python populate_packages_updatealternatives () { alt_remove_links = "" for alt_name in (d.getVar('ALTERNATIVE_%s' % pkg) or "").split(): 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) - alt_target = alt_target or d.getVar('ALTERNATIVE_TARGET_%s' % pkg) or d.getVar('ALTERNATIVE_TARGET') or alt_link - # Sometimes alt_target is specified as relative to the link name. - alt_target = os.path.join(os.path.dirname(alt_link), alt_target) - + alt_target = _ua_alt_target(d, alt_name, alt_link, pkg) alt_priority = d.getVarFlag('ALTERNATIVE_PRIORITY_%s' % pkg, alt_name) or d.getVarFlag('ALTERNATIVE_PRIORITY', alt_name) alt_priority = alt_priority or d.getVar('ALTERNATIVE_PRIORITY_%s' % pkg) or d.getVar('ALTERNATIVE_PRIORITY')
Signature · 1 line
2.19.2
PATCH 2/3 ptest.bbclass: Add feature to populate a binary directory
In reply to a message not in the archiveThis adds a functionality to populate a binary directory with symlinks within the PTEST_PATH directory to the binaries build by the package. This is helpful for binaries that are renamed by update-alternatives.
This will take all the package binaries' that are in bindir, sbindir base_bindir, and base_sbindir and create symlinks in PTEST_BINDIR_PATH. To enable this feature just add PTEST_BINDIR = "1" to the recipe.
[YOCTO #13238]
--- meta/classes/ptest.bbclass | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
meta/classes/ptest.bbclass +52 -0
@@ -63,6 +63,58 @@ do_install_ptest_base() { fi done done + + if [ "${PTEST_BINDIR}" == "1" ]; then + install_ptest_bindir + fi +} + +PTEST_BINDIR_PATH="${D}${PTEST_PATH}/bin" + +install_ptest_bindir() { + # Create ${PTEST_PATH}/bin to create symlinks to the package's binaries + # this way the path can be added to PATH and execute the binaries easier + # from ptest-runner. + bbdebug 1 "Generating PTEST's bin directory" + binary_paths="${bindir} ${sbindir} ${base_bindir} ${base_sbindir}" + mkdir -p ${PTEST_BINDIR_PATH} + + for path in ${binary_paths}; do + for src in ${D}${path}/*; do + binary=`basename ${src}` + ln -s ${path}/${binary} ${PTEST_BINDIR_PATH}/${binary} + done + done +} + +# This function needs to run after apply_update_alternative_renames because the +# aforementioned function will update the ALTERNATIVE_LINK_NAME flag. Append is +# used here to make this function to run as late as possible. +PACKAGE_PREPROCESS_FUNCS_append = "${@bb.utils.contains("PTEST_BINDIR", "1", " ptest_update_alternatives", "", d)}" + +python ptest_update_alternatives() { + """ + This function will fix the symlinks in the PTEST_BINDIR that + were broken by the renaming of update-alternatives + """ + + if not bb.data.inherits_class('update-alternatives', d) \ + or not update_alternatives_enabled(d): + return + + bb.note("Updating PTEST symlinks after the renaming of update-alternatives") + + ptest_pkgd_bindir = os.path.join(d.getVar("PKGD"), + d.getVar("PTEST_PATH")[1:], + "bin") + links_dict = { os.path.join(ptest_pkgd_bindir, link): + os.readlink(os.path.join(ptest_pkgd_bindir, link)) + for link in os.listdir(ptest_pkgd_bindir) } + for filename, link in links_dict.items(): + alt_link = update_alternatives_get_alt_target(d, link) + if alt_link: + os.unlink(filename) + os.symlink(alt_link, filename) } do_configure_ptest_base[dirs] = "${B}"
Signature · 1 line
2.19.2
PATCH 3/3 util-linux: Use PTEST binary directory
In reply to a message not in the archiveSome binaries generated by util-linux will be replaced by core-utils in the final image by update-alternatives, so use a dedicated directory with symlinks to avoid using a binary generated by another package.
This will solve the issue with the ptest runner timing out when running the kill ptests for util-linux.
[YOCTO #13238]
--- meta/recipes-core/util-linux/util-linux.inc | 5 +++-- meta/recipes-core/util-linux/util-linux/run-ptest | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)
meta/recipes-core/util-linux/util-linux.inc +3 -2
@@ -284,6 +284,7 @@ ALTERNATIVE_LINK_NAME[wall.1] = "${mandir}/man1/wall.1" BBCLASSEXTEND = "native nativesdk" +PTEST_BINDIR = "1" do_compile_ptest() { oe_runmake buildtest-TESTS }
@@ -312,8 +313,8 @@ do_install_ptest() { '/^\tif[[:space:]]\[[[:space:]]![[:space:]]-x[[:space:]]"$1"/s|$1|`which $1 2>/dev/null`|g' \ ${D}${PTEST_PATH}/tests/functions.sh - # "kill -L" behaves differently than "/bin/kill -L" so we need an additional fix + # Running "kill" without the the complete path would use the shell's built-in kill sed -i -e \ - '/^TS_CMD_KILL/ s|kill|/bin/kill|g' \ + '/^TS_CMD_KILL/ s|kill|${PTEST_PATH}/bin/kill|g' \ ${D}${PTEST_PATH}/tests/commands.sh }
meta/recipes-core/util-linux/util-linux/run-ptest +4 -0
@@ -1,5 +1,9 @@ #!/bin/sh +current_path=$(readlink -f $0) +export bindir=$(dirname $current_path) +export PATH=$bindir/bin:$PATH + cd tests || exit 1 comps=$(find ts/ -type f -perm -111 -regex ".*/[^\.~]*" | sort)
Signature · 1 line
2.19.2