diff mbox series

[v2] bitbake-layers: Support add-layer to prepend

Message ID 20240509102424.1073669-1-hieu2.nguyen@lge.com
State New
Headers show
Series [v2] bitbake-layers: Support add-layer to prepend | expand

Commit Message

Hieu Van Nguyen May 9, 2024, 10:24 a.m. UTC
As you know, layer order in BBLAYERS can affect in parsing recipes process,
in some cases, users want to add a layer on the top of BBLAYERS variable

So, add "--prepend" option for bitbake-layers to support add-layer to prepend

Signed-off-by: Hieu Van Nguyen <hieu2.nguyen@lge.com>
---
 lib/bb/utils.py        | 8 ++++++--
 lib/bblayers/action.py | 3 ++-
 2 files changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index ebee65d3d..f1634da0a 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -1414,7 +1414,7 @@  def edit_metadata_file(meta_file, variables, varfunc):
     return updated
 
 
-def edit_bblayers_conf(bblayers_conf, add, remove, edit_cb=None):
+def edit_bblayers_conf(bblayers_conf, add, remove, edit_cb=None, prepend=None):
     """Edit bblayers.conf, adding and/or removing layers
     Parameters:
         bblayers_conf: path to bblayers.conf file to edit
@@ -1424,6 +1424,7 @@  def edit_bblayers_conf(bblayers_conf, add, remove, edit_cb=None):
             empty list to remove nothing
         edit_cb: optional callback function that will be called after
             processing adds/removes once per existing entry.
+        prepend: optional support add-layer to prepend
     Returns a tuple:
         notadded: list of layers specified to be added but weren't
             (because they were already in the list)
@@ -1484,7 +1485,10 @@  def edit_bblayers_conf(bblayers_conf, add, remove, edit_cb=None):
             for addlayer in addlayers:
                 if addlayer not in bblayers:
                     updated = True
-                    bblayers.append(addlayer)
+                    if prepend:
+                        bblayers.insert(0,addlayer)
+                    else:
+                        bblayers.append(addlayer)
             del addlayers[:]
 
         if edit_cb:
diff --git a/lib/bblayers/action.py b/lib/bblayers/action.py
index a14f19948..8ef89fc09 100644
--- a/lib/bblayers/action.py
+++ b/lib/bblayers/action.py
@@ -49,7 +49,7 @@  class ActionPlugin(LayerPlugin):
         shutil.copy2(bblayers_conf, backup)
 
         try:
-            notadded, _ = bb.utils.edit_bblayers_conf(bblayers_conf, layerdirs, None)
+            notadded, _ = bb.utils.edit_bblayers_conf(bblayers_conf, layerdirs, None, None, args.prepend)
             if not (args.force or notadded):
                 self.tinfoil.modified_files()
                 try:
@@ -269,6 +269,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('layerdir', nargs='+', help='Layer directory/directories to add')
+        parser_add_layer.add_argument('--prepend', action='store_true', help='Prepend layer directory/directories')
 
         parser_remove_layer = self.add_command(sp, 'remove-layer', self.do_remove_layer, parserecipes=False)
         parser_remove_layer.add_argument('layerdir', nargs='+', help='Layer directory/directories to remove (wildcards allowed, enclose in quotes to avoid shell expansion)')