diff mbox series

bitbake-layers: allow adding layers as relative paths

Message ID 20250601093555.40432-1-shen_jiamin@comp.nus.edu.sg
State New
Headers show
Series bitbake-layers: allow adding layers as relative paths | expand

Commit Message

Shen Jiamin June 1, 2025, 9:35 a.m. UTC
Modify the add-layer command to accept a new --relative (-r) option
that adds specified layer directories as paths relative to TOPDIR
instead of absolute paths.

This change updates the handling of bblayers.conf to store layer
paths in the form ${TOPDIR}/relative/path, improving portability
and flexibility when managing layers.

Signed-off-by: Shen Jiamin <shen_jiamin@comp.nus.edu.sg>
---
 lib/bblayers/action.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Alexander Kanavin June 2, 2025, 7:50 a.m. UTC | #1
On Sun, 1 Jun 2025 at 11:36, Jiamin Shen via lists.openembedded.org
<shen_jiamin=comp.nus.edu.sg@lists.openembedded.org> wrote:
> Modify the add-layer command to accept a new --relative (-r) option
> that adds specified layer directories as paths relative to TOPDIR
> instead of absolute paths.
>
> This change updates the handling of bblayers.conf to store layer
> paths in the form ${TOPDIR}/relative/path, improving portability
> and flexibility when managing layers.

Unfortunately I do not agree. Making layer paths relative to TOPDIR
(which is the build directory) means build directories always have be
in the same relative location to layers, which makes it less portable
or flexible.

Rather, there is a mechanism to replace specific paths with paths
relative to ##OEROOT## when producing a build template
(bblayers.conf.sample), and vice versa when initializing a build from
a template with oe-init-build-env, oe-setup-build, or indeed,
bitbake-setup.

Alex
diff mbox series

Patch

diff --git a/lib/bblayers/action.py b/lib/bblayers/action.py
index a14f19948..bd3b6bb04 100644
--- a/lib/bblayers/action.py
+++ b/lib/bblayers/action.py
@@ -38,7 +38,8 @@  class ActionPlugin(LayerPlugin):
                 sys.stderr.write("Specified layer directory %s doesn't contain a conf/layer.conf file\n" % layerdir)
                 return 1

-        bblayers_conf = os.path.join(findTopdir(),'conf', 'bblayers.conf')
+        topdir = findTopdir()
+        bblayers_conf = os.path.join(topdir, 'conf', 'bblayers.conf')
         if not os.path.exists(bblayers_conf):
             sys.stderr.write("Unable to find bblayers.conf\n")
             return 1
@@ -48,6 +49,12 @@  class ActionPlugin(LayerPlugin):
         backup = tempdir + "/bblayers.conf.bak"
         shutil.copy2(bblayers_conf, backup)

+        if args.relative:
+            layerdirs = [
+                os.path.join("${TOPDIR}", os.path.relpath(ldir, topdir))
+                for ldir in layerdirs
+            ]
+
         try:
             notadded, _ = bb.utils.edit_bblayers_conf(bblayers_conf, layerdirs, None)
             if not (args.force or notadded):
@@ -268,6 +275,7 @@  build results (as the layer priority order has effectively changed).

     def register_commands(self, sp):
         parser_add_layer = self.add_command(sp, 'add-layer', self.do_add_layer, parserecipes=False)
+        parser_add_layer.add_argument('-r', '--relative', action='store_true', help='Add layer directories relative to TOPDIR (default is absolute paths)')
         parser_add_layer.add_argument('layerdir', nargs='+', help='Layer directory/directories to add')

         parser_remove_layer = self.add_command(sp, 'remove-layer', self.do_remove_layer, parserecipes=False)