Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add a PV → KV conversion function
Date: Mon, 17 Oct 2022 12:27:00
Message-Id: d4026905f65c41132bbd05003eb5b7ab5727a41a.camel@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH 1/3] dist-kernel-utils.eclass: Add a PV → KV conversion function by Oskari Pirhonen
1 On Mon, 2022-10-17 at 01:19 -0500, Oskari Pirhonen wrote:
2 > On Sun, Oct 16, 2022 at 06:49:17 +0200, Michał Górny wrote:
3 > > Signed-off-by: Michał Górny <mgorny@g.o>
4 > > ---
5 > > eclass/dist-kernel-utils.eclass | 16 ++++++++++++++++
6 > > eclass/tests/dist-kernel-utils.sh | 28 ++++++++++++++++++++++++++++
7 > > 2 files changed, 44 insertions(+)
8 > > create mode 100755 eclass/tests/dist-kernel-utils.sh
9 > >
10 > > diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
11 > > index 8c1b56f41506..439bdc87695d 100644
12 > > --- a/eclass/dist-kernel-utils.eclass
13 > > +++ b/eclass/dist-kernel-utils.eclass
14 > > @@ -155,5 +155,21 @@ dist-kernel_reinstall_initramfs() {
15 > > "${kernel_dir}/System.map"
16 > > }
17 > >
18 > > +# @FUNCTION: dist-kernel_PV_to_KV
19 > > +# @USAGE: <pv>
20 > > +# @DESCRIPTION:
21 > > +# Convert a Gentoo-style ebuild version to kernel "x.y.z[-rcN]" version.
22 > > +dist-kernel_PV_to_KV() {
23 > > + debug-print-function ${FUNCNAME} "${@}"
24 > > +
25 > > + [[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments"
26 > > + local pv=${1}
27 > > +
28 > > + local kv=${pv%%_*}
29 > > + [[ -z $(ver_cut 3- "${kv}") ]] && kv+=".0"
30 > > + [[ ${pv} == *_* ]] && kv+=-${pv#*_}
31 > > + echo "${kv}"
32 > > +}
33 > > +
34 > > _DIST_KERNEL_UTILS=1
35 > > fi
36 > > diff --git a/eclass/tests/dist-kernel-utils.sh b/eclass/tests/dist-kernel-utils.sh
37 > > new file mode 100755
38 > > index 000000000000..82be706dc498
39 > > --- /dev/null
40 > > +++ b/eclass/tests/dist-kernel-utils.sh
41 > > @@ -0,0 +1,28 @@
42 > > +#!/usr/bin/env bash
43 > > +# Copyright 2022 Gentoo Authors
44 > > +# Distributed under the terms of the GNU General Public License v2
45 > > +
46 > > +EAPI=8
47 > > +
48 > > +source tests-common.sh || exit
49 > > +
50 > > +inherit dist-kernel-utils
51 > > +# TODO: hack because tests-common don't implement ver_cut
52 > > +EAPI=6 inherit eapi7-ver
53 > > +
54 > > +test_KV_to_PV() {
55 > > + local kv=${1}
56 > > + local exp_PV=${2}
57 > > +
58 > > + tbegin "dist-kernel_PV_to_KV ${kv} -> ${exp_PV}"
59 > > + local val=$(dist-kernel_PV_to_KV "${kv}")
60 > > + [[ ${val} == ${exp_PV} ]]
61 > > + tend $?
62 > > +}
63 >
64 > Your test function is called `test_KV_to_PV` but the function you're
65 > testing is `dist-kernel_PV_to_KV`. Is this correct, or am I just looking
66 > at it wrong? The rest of the comments are under the assumption that the
67 > `KV`/`kv` and `PV` are meant to be flipped in the test function.
68
69 Good catch! I'll fix that.
70
71 >
72 > > +
73 > > +test_KV_to_PV 6.0_rc1 6.0.0-rc1
74 >
75 > Shouldn't this become just 6.0-rc1? That's the name of the branch in
76 > torvalds/linux.git (as well as what's in the name of the tarball and
77 > what was reported on https://kernel.org ).
78
79 The directory in /lib/modules is actually named 6.0.0-rc1*.
80
81 >
82 > > +test_KV_to_PV 6.0 6.0.0
83 >
84 > Similar to above.
85 >
86 > > +test_KV_to_PV 6.0.1_rc1 6.0.1-rc1
87 >
88 > Is there any point in converting x.y.z_rcN? To my knowledge, such a
89 > version will never exist.
90 >
91
92 I think I've seen tags like this in one of the stable repos but maybe
93 they don't actually happen. In either case, I think it's a good test
94 that the function doesn't do something unexpected like accidentally lose
95 the suffix.
96
97 --
98 Best regards,
99 Michał Górny