diff mbox series

[1/2] bitbake: parse: add support for flagged fragment variables

Message ID 20241211134615.2685951-1-alex.kanavin@gmail.com
State Accepted, archived
Commit ed9a3ca9426500511feb77f41a146953dbfe9af7
Headers show
Series [1/2] bitbake: parse: add support for flagged fragment variables | expand

Commit Message

Alexander Kanavin Dec. 11, 2024, 1:46 p.m. UTC
From: Alexander Kanavin <alex@linutronix.de>

It was suggested that using flags in fragment content to
mark fragment-specific metadata (such as descriptions and
dependencies) is prone to quiet regressions when fragments
are renamed or moved, and it clutters the fragment content.

With this change allowed fragment metadata variables must
be explicitly listed in a variable that is given to addfragment
directive, and parser will add the flag containing the fragment name
to them.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 lib/bb/parse/ast.py                  | 11 +++++++++--
 lib/bb/parse/parse_py/ConfHandler.py |  2 +-
 2 files changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/parse/ast.py b/lib/bb/parse/ast.py
index 7abefab2c2e..03370180e35 100644
--- a/lib/bb/parse/ast.py
+++ b/lib/bb/parse/ast.py
@@ -327,10 +327,11 @@  class InheritDeferredNode(AstNode):
         data.setVar('__BBDEFINHERITS', inherits)
 
 class AddFragmentsNode(AstNode):
-    def __init__(self, filename, lineno, fragments_path_prefix, fragments_variable):
+    def __init__(self, filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable):
         AstNode.__init__(self, filename, lineno)
         self.fragments_path_prefix = fragments_path_prefix
         self.fragments_variable = fragments_variable
+        self.flagged_variables_list_variable = flagged_variables_list_variable
 
     def eval(self, data):
         # No need to use mark_dependency since we would only match a fragment
@@ -345,6 +346,7 @@  class AddFragmentsNode(AstNode):
 
         fragments = data.getVar(self.fragments_variable)
         layers = data.getVar('BBLAYERS')
+        flagged_variables = data.getVar(self.flagged_variables_list_variable).split()
 
         if not fragments:
             return
@@ -354,6 +356,10 @@  class AddFragmentsNode(AstNode):
             fragment_path = find_fragment(layers, layerid, full_fragment_name)
             if fragment_path:
                 bb.parse.ConfHandler.include(self.filename, fragment_path, self.lineno, data, "include fragment")
+                for flagged_var in flagged_variables:
+                    val = data.getVar(flagged_var)
+                    data.setVarFlag(flagged_var, f, val)
+                    data.setVar(flagged_var, None)
             else:
                 bb.error("Could not find fragment {} in enabled layers: {}".format(f, layers))
 
@@ -404,7 +410,8 @@  def handleInheritDeferred(statements, filename, lineno, m):
 def handleAddFragments(statements, filename, lineno, m):
     fragments_path_prefix = m.group(1)
     fragments_variable = m.group(2)
-    statements.append(AddFragmentsNode(filename, lineno, fragments_path_prefix, fragments_variable))
+    flagged_variables_list_variable = m.group(3)
+    statements.append(AddFragmentsNode(filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable))
 
 def runAnonFuncs(d):
     code = []
diff --git a/lib/bb/parse/parse_py/ConfHandler.py b/lib/bb/parse/parse_py/ConfHandler.py
index 35321dacfe1..d0711eda042 100644
--- a/lib/bb/parse/parse_py/ConfHandler.py
+++ b/lib/bb/parse/parse_py/ConfHandler.py
@@ -47,7 +47,7 @@  __export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
 __unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
 __unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\]$" )
 __addpylib_regexp__      = re.compile(r"addpylib\s+(.+)\s+(.+)" )
-__addfragments_regexp__  = re.compile(r"addfragments\s+(.+)\s+(.+)" )
+__addfragments_regexp__  = re.compile(r"addfragments\s+(.+)\s+(.+)\s+(.+)" )
 
 def init(data):
     return