All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bitbake-setup: replace {THISDIR} token with an explicit keyword
@ 2025-11-06 11:47 Alexander Kanavin
  2025-11-06 12:11 ` [bitbake-devel] " Antonin Godard
  0 siblings, 1 reply; 14+ messages in thread
From: Alexander Kanavin @ 2025-11-06 11:47 UTC (permalink / raw)
  To: bitbake-devel; +Cc: Alexander Kanavin

From: Alexander Kanavin <alex@linutronix.de>

{THISDIR} is a special value token that can be used in the list of enabled
layers to specify the layer location relative to the confguration file:
https://git.openembedded.org/bitbake/commit/?id=b3153be29de8b8570b0c184369bd41f4c646cf92

This replaces the token with an explicit separate keyword for such layers:
so that special processing to determine the final value can be avoided, and
the feature can be formalized in the json schema:

instead of
   "bb-layers": [
        "{THISDIR}/meta-my-project"
    ]

this allows
   "bb-layers-relative-to-this-file": [
        "meta-my-project"

Going forward I think we should strive to avoid any further special value tokens.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 bin/bitbake-setup     | 28 ++++++++++++++++------------
 lib/bb/tests/setup.py | 20 ++++++++++----------
 2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index 47de4654e..7e227d82d 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -129,21 +129,24 @@ def checkout_layers(layers, layerdir, d):
     return layers_fixed_revisions
 
 def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir):
-    def _setup_build_conf(layers, build_conf_dir):
+    def _setup_build_conf(layers, relative_layers, build_conf_dir):
         os.makedirs(build_conf_dir)
         layers_s = []
+
         for l in layers:
-            if l.startswith("{THISDIR}/"):
-                if thisdir:
-                    l = l.format(THISDIR=thisdir)
-                else:
-                    raise Exception("Configuration is using {THISDIR} to specify " \
-                    "a layer path relative to itself. This can be done only " \
-                    "when the configuration is specified by its path on local " \
-                    "disk, not when it's in a registry or is fetched over http.")
-            if not os.path.isabs(l):
-                l = os.path.join(layerdir, l)
+            l = os.path.join(layerdir, l)
+            layers_s.append("  {} \\".format(l))
+
+        for l in relative_layers:
+            if thisdir:
+                l = os.path.join(thisdir, l)
+            else:
+                raise Exception("Configuration is using {THISDIR} to specify " \
+                "a layer path relative to itself. This can be done only " \
+                "when the configuration is specified by its path on local " \
+                "disk, not when it's in a registry or is fetched over http.")
             layers_s.append("  {} \\".format(l))
+
         layers_s = "\n".join(layers_s)
         bblayers_conf = """BBLAYERS ?= " \\
 {}
@@ -220,7 +223,8 @@ def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir):
         os.rename(bitbake_confdir, backup_bitbake_confdir)
 
     if layers:
-        _setup_build_conf(layers, bitbake_confdir)
+        relative_layers = bitbake_config.get("bb-layers-relative-to-this-file") or []
+        _setup_build_conf(layers, relative_layers, bitbake_confdir)
 
     if template:
         bb.process.run("{} setup -c {} -b {} --no-shell".format(oesetupbuild, template, bitbake_builddir))
diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py
index 767a6298d..83b1794a3 100644
--- a/lib/bb/tests/setup.py
+++ b/lib/bb/tests/setup.py
@@ -148,9 +148,10 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                 "oe-fragments": ["test-fragment-2"]
             },
             {
-                "name": "gizmo-notemplate-with-thisdir",
-                "description": "Gizmo notemplate configuration using THISDIR",
-                "bb-layers": ["layerC","layerD/meta-layer","{THISDIR}/layerE/meta-layer"],
+                "name": "gizmo-notemplate-with-relative-layers",
+                "description": "Gizmo notemplate configuration using relative layers",
+                "bb-layers": ["layerC","layerD/meta-layer"],
+                "bb-layers-relative-to-this-file": ["layerE/meta-layer"],
                 "oe-fragments": ["test-fragment-2"]
             }
         ]
@@ -204,14 +205,13 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
             with open(os.path.join(bb_conf_path, 'bblayers.conf')) as f:
                 bblayers = f.read()
                 for l in bitbake_config["bb-layers"]:
-                    if l.startswith('{THISDIR}/'):
-                        thisdir_layer = os.path.join(
+                    self.assertIn(os.path.join(setuppath, "layers", l), bblayers)
+                for l in bitbake_config.get("bb-layers-relative-to-this-file") or []:
+                    relative_layer = os.path.join(
                             os.path.dirname(config_upstream["path"]),
-                            l.removeprefix("{THISDIR}/"),
+                            l,
                         )
-                        self.assertIn(thisdir_layer, bblayers)
-                    else:
-                        self.assertIn(os.path.join(setuppath, "layers", l), bblayers)
+                    self.assertIn(relative_layer, bblayers)
 
         if 'oe-fragment' in bitbake_config.keys():
             for f in bitbake_config["oe-fragments"]:
@@ -298,7 +298,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                                                                   'gizmo-env-passthrough',
                                                                   'gizmo-no-fragment',
                                                                   'gadget-notemplate','gizmo-notemplate',
-                                                                  'gizmo-notemplate-with-thisdir')}
+                                                                  'gizmo-notemplate-with-relative-layers')}
                                }
         for cf, v in test_configurations.items():
             for c in v['buildconfigs']:
-- 
2.39.5



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-11-07 13:19 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-06 11:47 [PATCH] bitbake-setup: replace {THISDIR} token with an explicit keyword Alexander Kanavin
2025-11-06 12:11 ` [bitbake-devel] " Antonin Godard
2025-11-06 12:28   ` Alexander Kanavin
2025-11-06 15:15     ` Richard Purdie
2025-11-06 15:26       ` Robert P. J. Day
2025-11-06 17:09         ` Alexander Kanavin
2025-11-07  0:59       ` Peter Kjellerstedt
2025-11-07  3:32         ` Alexander Kanavin
2025-11-07  9:55           ` Richard Purdie
2025-11-07 10:14             ` Alexander Kanavin
2025-11-07 10:17               ` Richard Purdie
2025-11-07 10:20                 ` Alexander Kanavin
2025-11-07 13:18                   ` Richard Purdie
     [not found]         ` <18759C05E6F46C57.499307@lists.openembedded.org>
2025-11-07  8:07           ` Alexander Kanavin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.