Gentoo Archives: gentoo-dev

From: Mike Gilbert <floppym@g.o>
To: gentoo-dev@l.g.o
Cc: kernel@g.o, Mike Gilbert <floppym@g.o>
Subject: [gentoo-dev] [PATCH 1/2] linux-info.eclass: rework get_running_version
Date: Mon, 13 Sep 2021 16:27:49
Message-Id: 20210913162730.43943-1-floppym@gentoo.org
1 This function may fail if the version cannot be parsed from a Makefile
2 found by following the /lib/modules/${KV_FULL}/{source,build} symlinks.
3 Instead of failing, we should just split KV_FULL as a fallback.
4
5 Also, simplify the existance checks for the kernel Makefile; if we can't
6 find the kernel source directory, there is really no point in checking
7 for the kernel build directory. The latter will probably contain a
8 Makefile with no version information.
9
10 Bug: https://bugs.gentoo.org/811726
11 Signed-off-by: Mike Gilbert <floppym@g.o>
12 ---
13 eclass/linux-info.eclass | 47 +++++++++++++++++-----------------------
14 1 file changed, 20 insertions(+), 27 deletions(-)
15
16 diff --git a/eclass/linux-info.eclass b/eclass/linux-info.eclass
17 index 4e08949a385..97f7b5c06a9 100644
18 --- a/eclass/linux-info.eclass
19 +++ b/eclass/linux-info.eclass
20 @@ -629,34 +629,27 @@ get_running_version() {
21 die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
22 fi
23
24 - KV_FULL=$(uname -r)
25 -
26 - if [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
27 - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
28 - KBUILD_OUTPUT=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
29 - unset KV_FULL
30 - get_version
31 - return $?
32 - elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile ]]; then
33 - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
34 - unset KV_FULL
35 - get_version
36 - return $?
37 - elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
38 - KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
39 - unset KV_FULL
40 - get_version
41 - return $?
42 - else
43 - # This handles a variety of weird kernel versions. Make sure to update
44 - # tests/linux-info_get_running_version.sh if you want to change this.
45 - local kv_full=${KV_FULL//[-+_]*}
46 - KV_MAJOR=$(ver_cut 1 ${kv_full})
47 - KV_MINOR=$(ver_cut 2 ${kv_full})
48 - KV_PATCH=$(ver_cut 3 ${kv_full})
49 - KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}"
50 - : ${KV_PATCH:=0}
51 + local kv=$(uname -r)
52 +
53 + if [[ -f ${ROOT%/}/lib/modules/${kv}/source/Makefile ]]; then
54 + KERNEL_DIR=$(readlink -f "${ROOT%/}/lib/modules/${kv}/source")
55 + if [[ -f ${ROOT%/}/lib/modules/${kv}/build/Makefile ]]; then
56 + KBUILD_OUTPUT=$(readlink -f "${ROOT%/}/lib/modules/${kv}/build")
57 + fi
58 + get_version && return 0
59 fi
60 +
61 + KV_FULL=${kv}
62 +
63 + # This handles a variety of weird kernel versions. Make sure to update
64 + # tests/linux-info_get_running_version.sh if you want to change this.
65 + local kv_full=${KV_FULL//[-+_]*}
66 + KV_MAJOR=$(ver_cut 1 ${kv_full})
67 + KV_MINOR=$(ver_cut 2 ${kv_full})
68 + KV_PATCH=$(ver_cut 3 ${kv_full})
69 + KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}"
70 + : ${KV_PATCH:=0}
71 +
72 return 0
73 }
74
75 --
76 2.33.0

Replies