From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 03/25] lib/oe/kernel: Move python functions from linux-kernel-base to library code
Date: Sun, 2 Aug 2026 11:28:32 +0100 [thread overview]
Message-ID: <20260802102854.3952760-4-richard.purdie@linuxfoundation.org> (raw)
In-Reply-To: <20260802102854.3952760-1-richard.purdie@linuxfoundation.org>
This means get_kernelXXX needs to become oe.kernel.get_XXX and means we can
clear linux-kernel-base to allow it to be removed, starting to simplify the
file structure.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
meta/classes-recipe/kernel.bbclass | 4 +-
meta/classes-recipe/kernelsrc.bbclass | 4 +-
meta/classes-recipe/linux-kernel-base.bbclass | 46 -----------------
meta/lib/oe/__init__.py | 2 +-
meta/lib/oe/kernel.py | 51 +++++++++++++++++++
.../linux/linux-yocto-fitimage.bb | 2 +-
.../make-mod-scripts/make-mod-scripts_1.0.bb | 2 +-
7 files changed, 58 insertions(+), 53 deletions(-)
create mode 100644 meta/lib/oe/kernel.py
diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass
index 91248467bef..aeaec8ccbd4 100644
--- a/meta/classes-recipe/kernel.bbclass
+++ b/meta/classes-recipe/kernel.bbclass
@@ -233,7 +233,7 @@ KERNEL_DTBVENDORED ?= "0"
#
# configuration
#
-KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
+KERNEL_VERSION = "${@oe.kernel.get_version_headers('${B}')}"
# kernels are generally machine specific
PACKAGE_ARCH = "${MACHINE_ARCH}"
@@ -643,7 +643,7 @@ KERNEL_LOCALVERSION ??= ""
#
# Note: This class saves the value of localversion to a file
# so other recipes like make-mod-scripts can restore it via the
-# helper function get_kernellocalversion_file
+# helper function oe.kernel.get_localversion_file
export LOCALVERSION = "${KERNEL_LOCALVERSION}"
kernel_do_configure() {
diff --git a/meta/classes-recipe/kernelsrc.bbclass b/meta/classes-recipe/kernelsrc.bbclass
index 93361842989..b105fc15990 100644
--- a/meta/classes-recipe/kernelsrc.bbclass
+++ b/meta/classes-recipe/kernelsrc.bbclass
@@ -10,8 +10,8 @@ deltask do_unpack
do_patch[depends] += "virtual/kernel:do_shared_workdir"
do_patch[noexec] = "1"
do_package[depends] += "virtual/kernel:do_populate_sysroot"
-KERNEL_VERSION = "${@get_kernelversion_file("${STAGING_KERNEL_BUILDDIR}")}"
-LOCAL_VERSION = "${@get_kernellocalversion_file("${STAGING_KERNEL_BUILDDIR}")}"
+KERNEL_VERSION = "${@oe.kernel.get_version_file("${STAGING_KERNEL_BUILDDIR}")}"
+LOCAL_VERSION = "${@oe.kernel.get_localversion_file("${STAGING_KERNEL_BUILDDIR}")}"
inherit linux-kernel-base
diff --git a/meta/classes-recipe/linux-kernel-base.bbclass b/meta/classes-recipe/linux-kernel-base.bbclass
index 76d8b4d4513..566b2c96ba7 100644
--- a/meta/classes-recipe/linux-kernel-base.bbclass
+++ b/meta/classes-recipe/linux-kernel-base.bbclass
@@ -4,52 +4,6 @@
# SPDX-License-Identifier: MIT
#
-# parse kernel ABI version out of <linux/version.h>
-def get_kernelversion_headers(p):
- import re
-
- fn = p + '/include/linux/utsrelease.h'
- if not os.path.isfile(fn):
- # after 2.6.33-rc1
- fn = p + '/include/generated/utsrelease.h'
- if not os.path.isfile(fn):
- fn = p + '/include/linux/version.h'
-
- try:
- f = open(fn, 'r')
- except IOError:
- return None
-
- l = f.readlines()
- f.close()
- r = re.compile("#define UTS_RELEASE \"(.*)\"")
- for s in l:
- m = r.match(s)
- if m:
- return m.group(1)
- return None
-
-
-def get_kernelversion_file(p):
- fn = p + '/kernel-abiversion'
-
- try:
- with open(fn, 'r') as f:
- return f.readlines()[0].strip()
- except IOError:
- return None
-
-def get_kernellocalversion_file(p):
- fn = p + '/kernel-localversion'
-
- try:
- with open(fn, 'r') as f:
- return f.readlines()[0].strip()
- except IOError:
- return ""
-
- return ""
-
export KBUILD_BUILD_VERSION = "1"
export KBUILD_BUILD_USER ?= "oe-user"
export KBUILD_BUILD_HOST ?= "oe-host"
diff --git a/meta/lib/oe/__init__.py b/meta/lib/oe/__init__.py
index 13d887a4aad..faa9987c8ca 100644
--- a/meta/lib/oe/__init__.py
+++ b/meta/lib/oe/__init__.py
@@ -12,4 +12,4 @@ __path__ = extend_path(__path__, __name__)
BBIMPORTS = ["qa", "data", "path", "utils", "types", "package", "packagedata", \
"packagegroup", "sstatesig", "lsb", "cachedpath", "license", "qemu", \
"reproducible", "rust", "buildcfg", "go", "spdx30_tasks", "spdx_common", \
- "cve_check", "tune", "classextend", "purl"]
+ "cve_check", "tune", "classextend", "purl", "kernel"]
diff --git a/meta/lib/oe/kernel.py b/meta/lib/oe/kernel.py
new file mode 100644
index 00000000000..421debed9af
--- /dev/null
+++ b/meta/lib/oe/kernel.py
@@ -0,0 +1,51 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+import re
+
+# parse kernel ABI version out of <linux/version.h>
+def get_version_headers(p):
+ fn = p + '/include/linux/utsrelease.h'
+ if not os.path.isfile(fn):
+ # after 2.6.33-rc1
+ fn = p + '/include/generated/utsrelease.h'
+ if not os.path.isfile(fn):
+ fn = p + '/include/linux/version.h'
+
+ try:
+ f = open(fn, 'r')
+ except IOError:
+ return None
+
+ l = f.readlines()
+ f.close()
+ r = re.compile("#define UTS_RELEASE \"(.*)\"")
+ for s in l:
+ m = r.match(s)
+ if m:
+ return m.group(1)
+ return None
+
+
+def get_version_file(p):
+ fn = p + '/kernel-abiversion'
+
+ try:
+ with open(fn, 'r') as f:
+ return f.readlines()[0].strip()
+ except IOError:
+ return None
+
+def get_localversion_file(p):
+ fn = p + '/kernel-localversion'
+
+ try:
+ with open(fn, 'r') as f:
+ return f.readlines()[0].strip()
+ except IOError:
+ return ""
+
+ return ""
diff --git a/meta/recipes-kernel/linux/linux-yocto-fitimage.bb b/meta/recipes-kernel/linux/linux-yocto-fitimage.bb
index 4dcffb62094..75dbcb2af5c 100644
--- a/meta/recipes-kernel/linux/linux-yocto-fitimage.bb
+++ b/meta/recipes-kernel/linux/linux-yocto-fitimage.bb
@@ -10,4 +10,4 @@ inherit linux-kernel-base kernel-fit-image
# Set the version of this recipe to the version of the included kernel
# (without taking the long way around via PV)
-PKGV = "${@get_kernelversion_file("${STAGING_KERNEL_BUILDDIR}")}"
+PKGV = "${@oe.kernel.get_version_file("${STAGING_KERNEL_BUILDDIR}")}"
diff --git a/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb b/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
index 338a50de916..ab984f4bcfe 100644
--- a/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
+++ b/meta/recipes-kernel/make-mod-scripts/make-mod-scripts_1.0.bb
@@ -24,7 +24,7 @@ DEPENDS += "virtual/cross-cc virtual/cross-binutils"
EXTRA_OEMAKE = " HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
EXTRA_OEMAKE += " HOSTCXX="${BUILD_CXX} ${BUILD_CXXFLAGS} ${BUILD_LDFLAGS}" CROSS_COMPILE=${TARGET_PREFIX}"
-KERNEL_LOCALVERSION = "${@get_kernellocalversion_file("${STAGING_KERNEL_BUILDDIR}")}"
+KERNEL_LOCALVERSION = "${@oe.kernel.get_localversion_file("${STAGING_KERNEL_BUILDDIR}")}"
export LOCALVERSION = "${KERNEL_LOCALVERSION}"
# Build some host tools under work-shared. CC, LD, and AR are probably
next prev parent reply other threads:[~2026-08-02 10:29 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-02 10:28 [PATCH 00/25] Class file improvements Richard Purdie
2026-08-02 10:28 ` [PATCH 01/25] sstatesig: Use kernel.bbclass instead of linux-kernel-base.bbclass Richard Purdie
2026-08-02 10:28 ` [PATCH 02/25] linux-kernel-base: Delete unused function Richard Purdie
2026-08-02 10:28 ` Richard Purdie [this message]
2026-08-02 10:28 ` [PATCH 04/25] kernel-yocto: Simplify code for cleanliness and slight performance Richard Purdie
2026-08-02 10:28 ` [PATCH 05/25] kernel-arch: Move kernel and uboot arch functions to lib/oe/kernel.py Richard Purdie
2026-08-02 10:28 ` [PATCH 06/25] kernel-arch: Simplify KERNEL_ARCH variable usage Richard Purdie
2026-08-02 10:28 ` [PATCH 07/25] kernel-arch: Don't export UBOOT_ARCH Richard Purdie
2026-08-02 10:28 ` [PATCH 08/25] u-boot: Separate out from kernel-arch.bbclass Richard Purdie
2026-08-02 10:28 ` [PATCH 09/25] barebox: " Richard Purdie
2026-08-02 10:28 ` [PATCH 10/25] lib/oe/kernel: Simplify map_uboot_arch Richard Purdie
2026-08-02 10:28 ` [PATCH 11/25] image_types/kernel-uimage: Swap UBOOT_ARCH for oe.kernel.map_uboot_arch call Richard Purdie
2026-08-02 10:58 ` Patchtest results for " patchtest
2026-08-02 10:28 ` [PATCH 12/25] kernel-fit-image: " Richard Purdie
2026-08-02 10:28 ` [PATCH 13/25] linux-yocto-fitimage: Set UBOOT_ARCH Richard Purdie
2026-08-02 10:28 ` [PATCH 14/25] kernel-arch: Drop UBOOT_ARCH Richard Purdie
2026-08-02 10:28 ` [PATCH 15/25] linux-libc-headers: Drop kernel-arch and set ARCH directly Richard Purdie
2026-08-02 10:28 ` [PATCH 16/25] toolchain-scripts: Drop usage of kernel-arch Richard Purdie
2026-08-02 10:28 ` [PATCH 17/25] kernel-arch: Move ARCH usage into target classes Richard Purdie
2026-08-02 10:28 ` [PATCH 18/25] linux-yocto-fitimage: Drop obsolete dependency on linux-kernel-base Richard Purdie
2026-08-02 10:58 ` Patchtest results for " patchtest
2026-08-02 10:28 ` [PATCH 19/25] linux-kernel-base: Fold remainder into kernel-arch and drop Richard Purdie
2026-08-02 10:28 ` [PATCH 20/25] kernel-devicetree: Add missing function prefixes Richard Purdie
2026-08-02 10:28 ` [PATCH 21/25] utils: Drop explode_deps function Richard Purdie
2026-08-02 10:28 ` [PATCH 22/25] utils: Move functions from utils.bbclass to utils.py Richard Purdie
2026-08-02 10:58 ` Patchtest results for " patchtest
2026-08-02 10:28 ` [PATCH 23/25] lib/oe/lsb: Merge distro_identifier functions Richard Purdie
2026-08-02 10:28 ` [PATCH 24/25] sanity: Move code to lib/oe Richard Purdie
2026-08-02 10:58 ` Patchtest results for " patchtest
2026-08-02 10:28 ` [PATCH 25/25] sanity: Drop unreachable code Richard Purdie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260802102854.3952760-4-richard.purdie@linuxfoundation.org \
--to=richard.purdie@linuxfoundation.org \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox