diff mbox series

[RFC,05/08] kernel-devsrc: optionally version the package

Message ID 20261106173235.4155305-6-bruce.ashfield@gmail.com
State New
Headers show
Series enhance kernel -devsrc output options | expand

Commit Message

Bruce Ashfield Nov. 6, 2026, 5:32 p.m. UTC
From: Bruce Ashfield <bruce.ashfield@gmail.com>

kernel-devsrc is one package name for every kernel version, so the trees
of two kernel versions can't be installed side by side (an upgrade
replaces the old one).

The tree itself is already versioned (/lib/modules/<version>/build), only
the /usr/src/kernel link is shared. So add KERNELDEV_VERSIONED_PACKAGE.
When it is "1", the tree is packaged as kernel-devsrc-<version>, and
kernel-devsrc keeps only the link and depends on the version it points
at, the way the kernel's kernel-image and kernel-modules packages depend
on their versioned packages.

The link stays a packaged file, so installing or upgrading kernel-devsrc
moves it with no postinst or postrm, and nothing has to run at rootfs
time. The debug info always records /usr/src/kernel, so the link pointing
at the current kernel is what debuggers expect; an older version installed
directly is reached through its own /lib/modules/<version>/source.
Anything that looks for kernel-devsrc by name (OEHasPackage in the
kernelmodule and stap runtime tests, IMAGE_INSTALL, the SDK) still finds
it.

The 'build' RDEPENDS go on the versioned package too, so a tree installed
on its own still has what it needs to build modules.

Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
---
 meta/recipes-kernel/linux/kernel-devsrc.bb | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/meta/recipes-kernel/linux/kernel-devsrc.bb b/meta/recipes-kernel/linux/kernel-devsrc.bb
index 46337bd79b..c2021002d4 100644
--- a/meta/recipes-kernel/linux/kernel-devsrc.bb
+++ b/meta/recipes-kernel/linux/kernel-devsrc.bb
@@ -59,6 +59,14 @@  KERNELDEV_SOURCE_SPINE ?= "block certs crypto fs include init io_uring ipc kerne
 
 KERNEL_BUILD_ROOT = "${nonarch_base_libdir}/modules/"
 
+# Set to "1" to package the tree as kernel-devsrc-<kernel version>, so the
+# trees of two kernel versions can be installed side by side. kernel-devsrc
+# then only holds the /usr/src/kernel link and depends on the version it
+# points at, like the kernel's own kernel-image/kernel-modules packages.
+# Installing or upgrading kernel-devsrc moves the link to that version, and
+# anything that looks for kernel-devsrc by name still finds it.
+KERNELDEV_VERSIONED_PACKAGE ?= ""
+
 # The 'build' level: what is needed to build out of tree modules against the
 # kernel ('make scripts prepare' on target), and what kernel-devsrc has
 # always contained.
@@ -566,6 +574,15 @@  do_install[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
 
 FILES:${PN} = "${KERNEL_BUILD_ROOT} ${KERNEL_SRC_PATH} /usr/src/kernel-source-*.tar.bz2"
 
+# The versioned tree (KERNELDEV_VERSIONED_PACKAGE). It is ahead of ${PN} in
+# PACKAGES, so it takes everything but the /usr/src/kernel link.
+PACKAGES =+ "${@'${PN}-tree' if d.getVar('KERNELDEV_VERSIONED_PACKAGE') == '1' else ''}"
+PKG:${PN}-tree = "${PN}-${@legitimize_package_name(d.getVar('KERNEL_VERSION') or '')}"
+FILES:${PN}-tree = "${KERNEL_BUILD_ROOT} /usr/src/kernel-source-*.tar.bz2"
+RDEPENDS:${PN}-tree = "${@bb.utils.contains('PACKAGECONFIG', 'build', '${KERNELDEV_BUILD_RDEPENDS}', '', d)}"
+SKIP_FILEDEPS:${PN}-tree = "${SKIP_FILEDEPS:${PN}}"
+RDEPENDS:${PN} += "${@'${PN}-tree (= ${EXTENDPKGV})' if d.getVar('KERNELDEV_VERSIONED_PACKAGE') == '1' else ''}"
+
 # Added to RDEPENDS:${PN} by the 'build' PACKAGECONFIG
 KERNELDEV_BUILD_RDEPENDS = "bc python3-core flex bison ${TCLIBC}-utils gawk"
 # 4.15+ needs these next two RDEPENDS