Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
eclass/dist-kernel-utils.eclass | 16 ++++++++++++++++
eclass/tests/dist-kernel-utils.sh | 28 ++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
create mode 100755 eclass/tests/dist-kernel-utils.sh
diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
index 8c1b56f41506..439bdc87695d 100644
--- a/eclass/dist-kernel-utils.eclass
+++ b/eclass/dist-kernel-utils.eclass
@@ -155,5 +155,21 @@ dist-kernel_reinstall_initramfs() {
"${kernel_dir}/System.map"
}
+# @FUNCTION: dist-kernel_PV_to_KV
+# @USAGE: <pv>
+# @DESCRIPTION:
+# Convert a Gentoo-style ebuild version to kernel "x.y.z[-rcN]" version. +dist-kernel_PV_to_KV() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments"
+ local pv=${1}
+
+ local kv=${pv%%_*}
+ [[ -z $(ver_cut 3- "${kv}") ]] && kv+=".0"
+ [[ ${pv} == *_* ]] && kv+=-${pv#*_}
+ echo "${kv}"
+}
+
_DIST_KERNEL_UTILS=1
fi
diff --git a/eclass/tests/dist-kernel-utils.sh b/eclass/tests/dist-kernel-utils.sh
new file mode 100755
index 000000000000..82be706dc498
--- /dev/null
+++ b/eclass/tests/dist-kernel-utils.sh
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+source tests-common.sh || exit
+
+inherit dist-kernel-utils
+# TODO: hack because tests-common don't implement ver_cut
+EAPI=6 inherit eapi7-ver
+
+test_KV_to_PV() {
+ local kv=${1}
+ local exp_PV=${2}
+
+ tbegin "dist-kernel_PV_to_KV ${kv} -> ${exp_PV}"
+ local val=$(dist-kernel_PV_to_KV "${kv}")
+ [[ ${val} == ${exp_PV} ]]
+ tend $?
+}
+
+test_KV_to_PV 6.0_rc1 6.0.0-rc1
+test_KV_to_PV 6.0 6.0.0
+test_KV_to_PV 6.0.1_rc1 6.0.1-rc1
+test_KV_to_PV 6.0.1 6.0.1
+
+texit
--
2.38.0
On Sun, Oct 16, 2022 at 06:49:17 +0200, Michał Górny wrote:
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
eclass/dist-kernel-utils.eclass | 16 ++++++++++++++++
eclass/tests/dist-kernel-utils.sh | 28 ++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
create mode 100755 eclass/tests/dist-kernel-utils.sh
diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
index 8c1b56f41506..439bdc87695d 100644
--- a/eclass/dist-kernel-utils.eclass
+++ b/eclass/dist-kernel-utils.eclass
@@ -155,5 +155,21 @@ dist-kernel_reinstall_initramfs() {
"${kernel_dir}/System.map"
}
+# @FUNCTION: dist-kernel_PV_to_KV
+# @USAGE: <pv>
+# @DESCRIPTION:
+# Convert a Gentoo-style ebuild version to kernel "x.y.z[-rcN]" version. +dist-kernel_PV_to_KV() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments"
+ local pv=${1}
+
+ local kv=${pv%%_*}
+ [[ -z $(ver_cut 3- "${kv}") ]] && kv+=".0"
+ [[ ${pv} == *_* ]] && kv+=-${pv#*_}
+ echo "${kv}"
+}
+
_DIST_KERNEL_UTILS=1
fi
diff --git a/eclass/tests/dist-kernel-utils.sh b/eclass/tests/dist-kernel-utils.sh
new file mode 100755
index 000000000000..82be706dc498
--- /dev/null
+++ b/eclass/tests/dist-kernel-utils.sh
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+source tests-common.sh || exit
+
+inherit dist-kernel-utils
+# TODO: hack because tests-common don't implement ver_cut
+EAPI=6 inherit eapi7-ver
+
+test_KV_to_PV() {
+ local kv=${1}
+ local exp_PV=${2}
+
+ tbegin "dist-kernel_PV_to_KV ${kv} -> ${exp_PV}"
+ local val=$(dist-kernel_PV_to_KV "${kv}")
+ [[ ${val} == ${exp_PV} ]]
+ tend $?
+}
Your test function is called `test_KV_to_PV` but the function you're
testing is `dist-kernel_PV_to_KV`. Is this correct, or am I just looking
at it wrong? The rest of the comments are under the assumption that the `KV`/`kv` and `PV` are meant to be flipped in the test function.
+
+test_KV_to_PV 6.0_rc1 6.0.0-rc1
Shouldn't this become just 6.0-rc1? That's the name of the branch in torvalds/linux.git (as well as what's in the name of the tarball and
what was reported on https://kernel.org ).
+test_KV_to_PV 6.0 6.0.0
Similar to above.
+test_KV_to_PV 6.0.1_rc1 6.0.1-rc1
Is there any point in converting x.y.z_rcN? To my knowledge, such a
version will never exist.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 18:40:12 |
Calls: | 9,487 |
Calls today: | 6 |
Files: | 13,617 |
Messages: | 6,121,092 |