[PATCH 1/5] dist-kernel-utils.eclass: Move symlink update functions here
Michał Górny <[email protected]> Fri, 29 May 2026 12:43:49 +0200
| Newsgroups | gmane.linux.gentoo.devel |
|---|---|
| Message-ID | <[email protected]> |
Move the symlink update functions from kernel-install.eclass to dist-kernel-utils.eclass to make them reusable without the former eclass. Signed-off-by: Michał Górny <[email protected]> --- eclass/dist-kernel-utils.eclass | 70 ++++++++++++++++++++++++++++++++ eclass/kernel-install.eclass | 72 +-------------------------------- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass index a910f3973606f..a4a3a07d2e934 100644 --- a/eclass/dist-kernel-utils.eclass +++ b/eclass/dist-kernel-utils.eclass @@ -341,5 +341,75 @@ dist-kernel_compressed_module_cleanup() { ) } +# @FUNCTION: dist-kernel_can_update_src_symlink +# @USAGE: <target> +# @DESCRIPTION: +# Determine whether the symlink at <target> (full path) should be +# updated. Returns 0 if it should, 1 to leave as-is. +dist-kernel_can_update_src_symlink() { + debug-print-function ${FUNCNAME} "$@" + + [[ ${#} -eq 1 ]] || die "${FUNCNAME}: invalid arguments" + local target=${1} + + # if the symlink does not exist or is broken, update + [[ ! -e ${target} ]] && return 0 + # if the target does not seem to contain kernel sources + # (i.e. is probably a leftover directory), update + [[ ! -e ${target}/Makefile ]] && return 0 + + local symlink_target=$(readlink "${target}") + # the symlink target should start with the same basename as target + # (e.g. "linux-*") + [[ ${symlink_target} != ${target##*/}-* ]] && return 1 + + # try to establish the kernel version from symlink target + local symlink_ver=${symlink_target#${target##*/}-} + # strip KV_LOCALVERSION, we want to update the old kernels not using + # KV_LOCALVERSION suffix and the new kernels using it + symlink_ver=${symlink_ver%${KV_LOCALVERSION}} + symlink_ver=${symlink_ver/-p/_p} + # strip -p* revision + local symlink_ver_no_rev=${symlink_ver%_p[0-9]*} + local rev=${symlink_ver#${symlink_ver_no_rev}} + rev=${rev#_p} + + # if ${symlink_ver} contained anything but numbers and revision (e.g. + # an extra suffix), it's not our kernel, so leave it alone + [[ -n ${symlink_ver_no_rev//[0-9.]/} || -n ${rev//[0-9]/} ]] && return 1 + + local symlink_pkg=${CATEGORY}/${PN}-${symlink_ver} + # if the current target is either being replaced, or still + # installed (probably depclean candidate), update the symlink + has "${symlink_ver}" ${REPLACING_VERSIONS} && return 0 + has_version -r "~${symlink_pkg}" && return 0 + + # otherwise it could be another kernel package, so leave it alone + return 1 +} + +# @FUNCTION: dist-kernel_update_src_symlink +# @USAGE: <target> <version> +# @DESCRIPTION: +# Update the kernel source symlink at <target> (full path) with a link +# to <target>-<version> if it's either missing or pointing out to +# an older version of this package. +dist-kernel_update_src_symlink() { + debug-print-function ${FUNCNAME} "$@" + + [[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments" + local target=${1} + local version=${2} + + if dist-kernel_can_update_src_symlink "${target}"; then + ebegin "Updating ${target} symlink" + ln -f -n -s "${target##*/}-${version}" "${target}" + eend ${?} + else + elog "${target} points at another kernel, leaving it as-is." + elog "Please use 'eselect kernel' to update it when desired." + fi +} + _DIST_KERNEL_UTILS=1 fi diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass index dc8fd31c03ee4..ae32a2cb2388b 100644 --- a/eclass/kernel-install.eclass +++ b/eclass/kernel-install.eclass @@ -236,76 +236,6 @@ BDEPEND=" x86? ( app-emulation/qemu[qemu_softmmu_targets_i386] ) )" -# @FUNCTION: kernel-install_can_update_symlink -# @USAGE: -# @DESCRIPTION: -# Determine whether the symlink at <target> (full path) should be -# updated. Returns 0 if it should, 1 to leave as-is. -kernel-install_can_update_symlink() { - debug-print-function ${FUNCNAME} "$@" - - [[ ${#} -eq 1 ]] || die "${FUNCNAME}: invalid arguments" - local target=${1} - - # if the symlink does not exist or is broken, update - [[ ! -e ${target} ]] && return 0 - # if the target does not seem to contain kernel sources - # (i.e. is probably a leftover directory), update - [[ ! -e ${target}/Makefile ]] && return 0 - - local symlink_target=$(readlink "${target}") - # the symlink target should start with the same basename as target - # (e.g. "linux-*") - [[ ${symlink_target} != ${target##*/}-* ]] && return 1 - - # try to establish the kernel version from symlink target - local symlink_ver=${symlink_target#${target##*/}-} - # strip KV_LOCALVERSION, we want to update the old kernels not using - # KV_LOCALVERSION suffix and the new kernels using it - symlink_ver=${symlink_ver%${KV_LOCALVERSION}} - symlink_ver=${symlink_ver/-p/_p} - # strip -p* revision - local symlink_ver_no_rev=${symlink_ver%_p[0-9]*} - local rev=${symlink_ver#${symlink_ver_no_rev}} - rev=${rev#_p} - - # if ${symlink_ver} contained anything but numbers and revision (e.g. - # an extra suffix), it's not our kernel, so leave it alone - [[ -n ${symlink_ver_no_rev//[0-9.]/} || -n ${rev//[0-9]/} ]] && return 1 - - local symlink_pkg=${CATEGORY}/${PN}-${symlink_ver} - # if the current target is either being replaced, or still - # installed (probably depclean candidate), update the symlink - has "${symlink_ver}" ${REPLACING_VERSIONS} && return 0 - has_version -r "~${symlink_pkg}" && return 0 - - # otherwise it could be another kernel package, so leave it alone - return 1 -} - -# @FUNCTION: kernel-install_update_symlink -# @USAGE: <target> <version> -# @DESCRIPTION: -# Update the kernel source symlink at <target> (full path) with a link -# to <target>-<version> if it's either missing or pointing out to -# an older version of this package. -kernel-install_update_symlink() { - debug-print-function ${FUNCNAME} "$@" - - [[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments" - local target=${1} - local version=${2} - - if kernel-install_can_update_symlink "${target}"; then - ebegin "Updating ${target} symlink" - ln -f -n -s "${target##*/}-${version}" "${target}" - eend ${?} - else - elog "${target} points at another kernel, leaving it as-is." - elog "Please use 'eselect kernel' to update it when desired." - fi -} - # @FUNCTION: kernel-install_get_qemu_arch # @DESCRIPTION: # Get appropriate qemu suffix for the current ${ARCH}. @@ -776,7 +706,7 @@ kernel-install_install_all() { kernel-install_pkg_postinst() { debug-print-function ${FUNCNAME} "$@" - kernel-install_update_symlink "${EROOT}/usr/src/linux" "${KV_FULL}" + dist-kernel_update_src_symlink "${EROOT}/usr/src/linux" "${KV_FULL}" dist-kernel_compressed_module_cleanup \ "${EROOT}/lib/modules/${KV_FULL}"