Part of https://github.com/gentoo/gentoo/pull/37327

From 021915604b90ee45332dc373f401e52afa832370 Mon Sep 17 00:00:00 2001
From: James Calligeros <jcalligero...@gmail.com>
Date: Sat, 29 Jun 2024 01:55:12 +0000
Subject: [PATCH] kernel-build.eclass: sanity check the prepared kernel's
 release string

Previously, this was only checked by kernel-install_pkg_preinst(). This
means that the entire kernel would have to be built and stripped before
we knew if we had built the correct kernel or not.

Duplicate this check in kernel-build_src_configure() so that we don't waste
time and energy building an incorrectly-versioned kernel.

Signed-off-by: James Calligeros <jcalligero...@gmail.com>
---
 eclass/kernel-build.eclass | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 7d4b98ac027d9..408837c4c57a7 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -239,6 +239,19 @@ kernel-build_src_configure() {
                local relfile=${WORKDIR}/build/include/config/kernel.release
                KV_FULL=$(<"${relfile}") || die
        fi
+
+       # Make sure we are about to build the correct kernel
+       if [[ ${PV} != *9999 ]]; then
+               local expected_ver=$(dist-kernel_PV_to_KV "${PV}")
+
+               if [[ ${KV_FULL} != ${expected_ver}* ]]; then
+                       eerror "Kernel version does not match PV!"
+                       eerror "Source version: ${KV_FULL}"
+                       eerror "Expected (PV*): ${expected_ver}*"
+                       eerror "Please ensure you are applying the correct 
patchset."
+                       die "Kernel version mismatch: got ${KV_FULL}, expected 
${expected_ver}*"
+               fi
+       fi
 }

 # @FUNCTION: kernel-build_src_compile


Reply via email to