From: Richard Purdie Date: Wed, 29 Jul 2026 21:39:29 +0000 (+0100) Subject: lib/oe/kernel: Move python functions from linux-kernel-base to library code X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=945f3faa4909b226996eff62bf55fa586a5279fa;p=thirdparty%2Fopenembedded%2Fopenembedded-core.git lib/oe/kernel: Move python functions from linux-kernel-base to library code 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 --- diff --git a/meta/classes-recipe/kernel.bbclass b/meta/classes-recipe/kernel.bbclass index 91248467be..aeaec8ccbd 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 9336184298..b105fc1599 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 76d8b4d451..566b2c96ba 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 -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 13d887a4aa..faa9987c8c 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 0000000000..421debed9a --- /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 +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 4dcffb6209..75dbcb2af5 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 338a50de91..ab984f4bcf 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