From b7a457c7bcb379054e921a273efd234a4b47b485 Mon Sep 17 00:00:00 2001 From: Mike Gilbert Date: Mon, 13 Sep 2021 10:46:57 -0400 Subject: [PATCH] linux-info.eclass: rework get_running_version This function may fail if the version cannot be parsed from a Makefile found by following the /lib/modules/${KV_FULL}/{source,build} symlinks. Instead of failing, we should just split KV_FULL as a fallback. Also, simplify the existance checks for the kernel Makefile; if we can't find the kernel source directory, there is really no point in checking for the kernel build directory. The latter will probably contain a Makefile with no version information. Bug: https://bugs.gentoo.org/811726 Signed-off-by: Mike Gilbert --- eclass/linux-info.eclass | 47 +++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/eclass/linux-info.eclass b/eclass/linux-info.eclass index 4e08949a385..8f9d0366ca7 100644 --- a/eclass/linux-info.eclass +++ b/eclass/linux-info.eclass @@ -629,34 +629,27 @@ get_running_version() { die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" fi - KV_FULL=$(uname -r) - - if [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source) - KBUILD_OUTPUT=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build) - unset KV_FULL - get_version - return $? - elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile ]]; then - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source) - unset KV_FULL - get_version - return $? - elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build) - unset KV_FULL - get_version - return $? - else - # This handles a variety of weird kernel versions. Make sure to update - # tests/linux-info_get_running_version.sh if you want to change this. - local kv_full=${KV_FULL//[-+_]*} - KV_MAJOR=$(ver_cut 1 ${kv_full}) - KV_MINOR=$(ver_cut 2 ${kv_full}) - KV_PATCH=$(ver_cut 3 ${kv_full}) - KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}" - : ${KV_PATCH:=0} + local kv=$(uname -r) + + if [[ -f ${ROOT%/}/lib/modules/${kv}/source/Makefile ]]; then + KERNEL_DIR=$(readlink -f "${ROOT%/}/lib/modules/${kv}/source") + if [[ -f ${ROOT%/}/lib/modules/${kv}/build/Makefile ]]; then + KBUILD_OUTPUT=$(readlink -f "${ROOT%/}/lib/modules/${kv}/build") + fi + get_version && return 0 fi + + KV_FULL=$kv + + # This handles a variety of weird kernel versions. Make sure to update + # tests/linux-info_get_running_version.sh if you want to change this. + local kv_full=${KV_FULL//[-+_]*} + KV_MAJOR=$(ver_cut 1 ${kv_full}) + KV_MINOR=$(ver_cut 2 ${kv_full}) + KV_PATCH=$(ver_cut 3 ${kv_full}) + KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}" + : ${KV_PATCH:=0} + return 0 } -- 2.33.0