Gentoo Archives: gentoo-dev

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