1 |
Signed-off-by: Michał Górny <mgorny@g.o> |
2 |
--- |
3 |
eclass/dist-kernel-utils.eclass | 16 ++++++++++++++++ |
4 |
eclass/tests/dist-kernel-utils.sh | 28 ++++++++++++++++++++++++++++ |
5 |
2 files changed, 44 insertions(+) |
6 |
create mode 100755 eclass/tests/dist-kernel-utils.sh |
7 |
|
8 |
diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass |
9 |
index 8c1b56f41506..439bdc87695d 100644 |
10 |
--- a/eclass/dist-kernel-utils.eclass |
11 |
+++ b/eclass/dist-kernel-utils.eclass |
12 |
@@ -155,5 +155,21 @@ dist-kernel_reinstall_initramfs() { |
13 |
"${kernel_dir}/System.map" |
14 |
} |
15 |
|
16 |
+# @FUNCTION: dist-kernel_PV_to_KV |
17 |
+# @USAGE: <pv> |
18 |
+# @DESCRIPTION: |
19 |
+# Convert a Gentoo-style ebuild version to kernel "x.y.z[-rcN]" version. |
20 |
+dist-kernel_PV_to_KV() { |
21 |
+ debug-print-function ${FUNCNAME} "${@}" |
22 |
+ |
23 |
+ [[ ${#} -ne 1 ]] && die "${FUNCNAME}: invalid arguments" |
24 |
+ local pv=${1} |
25 |
+ |
26 |
+ local kv=${pv%%_*} |
27 |
+ [[ -z $(ver_cut 3- "${kv}") ]] && kv+=".0" |
28 |
+ [[ ${pv} == *_* ]] && kv+=-${pv#*_} |
29 |
+ echo "${kv}" |
30 |
+} |
31 |
+ |
32 |
_DIST_KERNEL_UTILS=1 |
33 |
fi |
34 |
diff --git a/eclass/tests/dist-kernel-utils.sh b/eclass/tests/dist-kernel-utils.sh |
35 |
new file mode 100755 |
36 |
index 000000000000..82be706dc498 |
37 |
--- /dev/null |
38 |
+++ b/eclass/tests/dist-kernel-utils.sh |
39 |
@@ -0,0 +1,28 @@ |
40 |
+#!/usr/bin/env bash |
41 |
+# Copyright 2022 Gentoo Authors |
42 |
+# Distributed under the terms of the GNU General Public License v2 |
43 |
+ |
44 |
+EAPI=8 |
45 |
+ |
46 |
+source tests-common.sh || exit |
47 |
+ |
48 |
+inherit dist-kernel-utils |
49 |
+# TODO: hack because tests-common don't implement ver_cut |
50 |
+EAPI=6 inherit eapi7-ver |
51 |
+ |
52 |
+test_KV_to_PV() { |
53 |
+ local kv=${1} |
54 |
+ local exp_PV=${2} |
55 |
+ |
56 |
+ tbegin "dist-kernel_PV_to_KV ${kv} -> ${exp_PV}" |
57 |
+ local val=$(dist-kernel_PV_to_KV "${kv}") |
58 |
+ [[ ${val} == ${exp_PV} ]] |
59 |
+ tend $? |
60 |
+} |
61 |
+ |
62 |
+test_KV_to_PV 6.0_rc1 6.0.0-rc1 |
63 |
+test_KV_to_PV 6.0 6.0.0 |
64 |
+test_KV_to_PV 6.0.1_rc1 6.0.1-rc1 |
65 |
+test_KV_to_PV 6.0.1 6.0.1 |
66 |
+ |
67 |
+texit |
68 |
-- |
69 |
2.38.0 |