diff mbox series

[v2,23/26] linux-kernel-base: locate virtual/kernel WORKDIR

Message ID 20260712054954.4063745-23-vince@underview.tech
State Under Review
Headers show
Series [v2,01/26] bitbake: globally define KERNEL_PACKAGE_NAME | expand

Commit Message

Vincent Davis Jr July 12, 2026, 5:49 a.m. UTC
If KERNEL_PACKAGE_NAME is not set to default
string "kernel" there's currently no way to
determine the WORKDIR of virtual/kernel.

Commit adds a way to determine virtual/kernel WORKDIR.
So, perf and make-mod-scripts builds.

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
---
 meta/classes-recipe/linux-kernel-base.bbclass | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/meta/classes-recipe/linux-kernel-base.bbclass b/meta/classes-recipe/linux-kernel-base.bbclass
index e2187a73f0..83fc075ced 100644
--- a/meta/classes-recipe/linux-kernel-base.bbclass
+++ b/meta/classes-recipe/linux-kernel-base.bbclass
@@ -54,6 +54,36 @@  def linux_module_packages(s, d):
     suffix = ""
     return " ".join(map(lambda s: "kernel-module-%s%s" % (s.lower().replace('_', '-').replace('@', '+'), suffix), s.split()))
 
+def set_kernel_staging_vars(d):
+    from pathlib import Path
+
+    kpn = d.getVar("KERNEL_PACKAGE_NAME")
+
+    # FROM: kernel.bbclass
+    # The default kernel recipe builds in a shared location defined by
+    # bitbake/distro confs: STAGING_KERNEL_DIR and STAGING_KERNEL_BUILDDIR.
+    # Set these variables to directories under ${WORKDIR} in alternate
+    # kernel recipes (I.e. where KERNEL_PACKAGE_NAME != kernel) so that they
+    # may build in parallel with the default kernel without clobbering.
+    #
+    # Due to this STAGING_KERNEL_DIR is changed from default defined in
+    # bitbake.conf. Currently there is no way to globally set a variable
+    # in a kernel recipe and no way to get the WORKDIR of the kernel
+    # recipe from within this recipe. So, folder path is determined
+    # using other pre-existing information.
+    if kpn != "kernel":
+        workdir = d.getVar("WORKDIR") + "/../../" + d.getVar("PREFERRED_PROVIDER_virtual/kernel")
+        src_path = Path(workdir)
+        # Helps acquire package version.
+        # Caller should only be using 1 version at given time.
+        for x in src_path.iterdir():
+            if x.is_dir():
+                staging_kernel_dir = os.path.join(workdir, "%s/kernel-source" % (x))
+                staging_kernel_builddir = os.path.join(workdir, "%s/kernel-build-artifacts" % (x))
+                d.setVar("STAGING_KERNEL_DIR", staging_kernel_dir)
+                d.setVar("STAGING_KERNEL_BUILDDIR", staging_kernel_builddir)
+                break
+
 export KBUILD_BUILD_VERSION = "1"
 export KBUILD_BUILD_USER ?= "oe-user"
 export KBUILD_BUILD_HOST ?= "oe-host"