diff mbox series

[2/2] bitbake.conf/base: Add recipe hosttools warning to the start of builds

Message ID 20261127175054.2271255-2-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/2] bitbake/base: Implement RECIPE_HOSTTOOLS | expand

Commit Message

Richard Purdie Nov. 27, 2026, 5:50 p.m. UTC
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/classes-global/base.bbclass | 27 +++++++++++++++++++++++++++
 meta/conf/bitbake.conf           |  1 +
 2 files changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/meta/classes-global/base.bbclass b/meta/classes-global/base.bbclass
index 3163db55195..98ef8d8b636 100644
--- a/meta/classes-global/base.bbclass
+++ b/meta/classes-global/base.bbclass
@@ -298,6 +298,33 @@  python base_task_eventhandler() {
             setup_hosttools_dir(toolsdir, 'RECIPE_HOSTTOOLS', d)
 }
 
+addhandler base_recipetools_eventhandler
+base_recipetools_eventhandler[eventmask] = "bb.runqueue.RecipeCheckEvent"
+python base_recipetools_eventhandler() {
+    recipedata = e.recipedata
+    needed = set()
+    for recipe in recipedata:
+        tools = recipedata[recipe]["RECIPE_HOSTTOOLS"].split()
+        for tool in tools:
+            needed.add(tool)
+
+    origbbenv = d.getVar("BB_ORIGENV", False)
+    path = origbbenv.getVar("PATH")
+    # Need to ignore our own scripts directories to avoid circular links
+    for p in path.split(":"):
+        if p.endswith("/scripts"):
+            path = path.replace(p, "/ignoreme")
+    notfound = set()
+    for tool in needed:
+        # Prefer gnu-prefixed binaries, if available
+        srctool = (bb.utils.which(path, "gnu" + tool, executable=True) or
+                   bb.utils.which(path, tool, executable=True))
+        if not srctool:
+            notfound.add(tool)
+    if notfound:
+        bb.fatal("Tool(s) '%s' are needed by recipes due to be built but are not available on this system. Please add them first." % (" ".join(notfound)))
+}
+
 addhandler base_eventhandler
 base_eventhandler[eventmask] = "bb.event.ConfigParsed bb.event.MultiConfigParsed bb.event.BuildStarted bb.event.RecipePreFinalise bb.event.RecipeParsed bb.event.RecipePreDeferredInherits"
 python base_eventhandler() {
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 31b3f6243b6..39dac165d2f 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -522,6 +522,7 @@  export PATH
 # Build utility info.
 ##################################################################
 
+BB_CACHE_EXTRAVARS += "RECIPE_HOSTTOOLS"
 # Directory with symlinks to host tools used by build
 HOSTTOOLS_DIR = "${TMPDIR}/hosttools"
 RECIPE_HOSTTOOLS_DIR = "${WORKDIR}/recipe-hosttools"