diff mbox series

[14/16] recipetool: Fix temporary fetch recipe location after layer.conf changes

Message ID 20261130152704.3471590-14-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:27 p.m. UTC
_get_temp_recipe_dir() looked for BBFILES entries ending in .bb, but
BBFILES is now <layerdir>/recipes* globs, so recipetool create (and
devtool add/upgrade) failed to find anywhere to put the temporary fetch
recipe.

Use a new recipes-recipetool directory in a writeable layer from
BBFILES, still preferring the workspace.

Drop the BBFILES reference from the newappend warning.

AI-Generated: Uses Claude Opus 5.5
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 scripts/lib/recipetool/newappend.py |  2 +-
 scripts/lib/scriptutils.py          | 24 ++++++++++++++----------
 2 files changed, 15 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/scripts/lib/recipetool/newappend.py b/scripts/lib/recipetool/newappend.py
index 08e2474dc42..3d8d22b2be1 100644
--- a/scripts/lib/recipetool/newappend.py
+++ b/scripts/lib/recipetool/newappend.py
@@ -48,7 +48,7 @@  def newappend(args):
         return 1
 
     if not path_ok:
-        logger.warning('Unable to determine correct subdirectory path for bbappend file - check that what %s adds to BBFILES also matches .bbappend files. Using %s for now, but until you fix this the bbappend will not be applied.', os.path.join(args.destlayer, 'conf', 'layer.conf'), os.path.dirname(append_path))
+        logger.warning('Unable to determine correct subdirectory path for bbappend file. Using %s for now, but it may not be applied.', os.path.dirname(append_path))
 
     layerdirs = [os.path.abspath(layerdir) for layerdir in rd.getVar('BBLAYERS').split()]
     if not os.path.abspath(args.destlayer) in layerdirs:
diff --git a/scripts/lib/scriptutils.py b/scripts/lib/scriptutils.py
index 860415789b1..dc3ef98f175 100644
--- a/scripts/lib/scriptutils.py
+++ b/scripts/lib/scriptutils.py
@@ -114,16 +114,20 @@  def _get_temp_recipe_dir(d):
     # This is a little bit hacky but we need to find a place where we can put
     # the recipe so that bitbake can find it. We're going to delete it at the
     # end so it doesn't really matter where we put it.
-    bbfiles = d.getVar('BBFILES').split()
+    # BBFILES has a <layerdir>/recipes* entry for each layer, we place in a
+    # recipes-recipetool directory under one, prefering workspace if present.
+    layerdata = d.getVar('layerdata', False) or {}
+    workspace = layerdata.get('workspace')
+    if workspace and os.access(workspace.path, os.W_OK):
+        # Prefer the workspace
+        return os.path.join(workspace.path, 'recipes-recipetool')
+    layerdirs = [os.path.dirname(pth) for pth in d.getVar('BBFILES').split()
+                 if os.path.basename(pth) == 'recipes*']
     fetchrecipedir = None
-    for pth in bbfiles:
-        if pth.endswith('.bb'):
-            pthdir = os.path.dirname(pth)
-            if os.access(os.path.dirname(os.path.dirname(pthdir)), os.W_OK):
-                fetchrecipedir = pthdir.replace('*', 'recipetool')
-                if pthdir.endswith('workspace/recipes/*'):
-                    # Prefer the workspace
-                    break
+    for layer in layerdirs:
+        layer = os.path.realpath(layer)
+        if os.access(layer, os.W_OK):
+            fetchrecipedir = os.path.join(layer, 'recipes-recipetool')
     return fetchrecipedir
 
 class FetchUrlFailure(Exception):
@@ -155,7 +159,7 @@  def fetch_url(tinfoil, srcuri, srcrev, destdir, logger, preserve_tmp=False, mirr
 
         fetchrecipedir = _get_temp_recipe_dir(tinfoil.config_data)
         if not fetchrecipedir:
-            logger.error('Searched BBFILES but unable to find a writeable place to put temporary recipe')
+            logger.error('Unable to find a writeable layer containing recipes to put the temporary recipe in')
             sys.exit(1)
         fetchrecipe = None
         bb.utils.mkdirhier(fetchrecipedir)