diff mbox series

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

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

Commit Message

Richard Purdie Nov. 30, 2026, 3:26 p.m. UTC
Using the new bitbake event, check through RECIPE_HOSTOOLS from the recipes
that are due to be built and error if any of the needed tools are not present.

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 5aaa63ce505..f814f7fec47 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 99e76b704dc..795c220a8e5 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"