summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kanavin <alex@linutronix.de>2025-06-18 11:20:53 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-06-20 12:03:37 +0100
commit941ac7d2562ddc39ffcb85ebcc64621b132cf1d3 (patch)
tree0b453490be1b70396001cd5a0fded97845ca6318
parentbe8123d8dfd502f88fe2f6646e746db140753d6e (diff)
downloadpoky-941ac7d2562ddc39ffcb85ebcc64621b132cf1d3.tar.gz
bitbake: parse/ast: add support for 'built-in' fragments
When reviewing proposed fragments to add settings for DISTRO and MACHINE, RP noted that such fragments only add clutter and overhead, and there's no need to maintain them as separate files. Rather when bitbake sees 'fragmentvar/fragmentvalue' it can expand that into FRAGMENTVAR = "fragmentvalue". To achieve that, 'addfragments' directive is extended with a parameter that sets the name of the variable that holds definitions of such built-in fragments, for example like this: "machine:MACHINE distro:DISTRO" Then each enabled fragment name is matched against these definitions and the respective variable is set, e.g. 'machine/qemuarm' would match 'machine:MACHINE' and result in MACHINE set to 'qemuarm'. This happens before any fragment files are looked up on disk, and no such lookup happens if there was a match, which should prevent possible misuse of the feature. So the builtin fragment definition is also an allowlist for them. Please also see the patches for oe-core that show an application of the feature. (Bitbake rev: 3b9d7bea915dc7f10e845854f1dae325743f9456) Signed-off-by: Alexander Kanavin <alex@linutronix.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst19
-rw-r--r--bitbake/lib/bb/parse/ast.py16
-rw-r--r--bitbake/lib/bb/parse/parse_py/ConfHandler.py2
3 files changed, 32 insertions, 5 deletions
diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
index a27b7758d9..f60a9d8312 100644
--- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
+++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
@@ -998,9 +998,9 @@ This directive allows fine-tuning local configurations with configuration
998snippets contained in layers in a structured, controlled way. Typically it would 998snippets contained in layers in a structured, controlled way. Typically it would
999go into ``bitbake.conf``, for example:: 999go into ``bitbake.conf``, for example::
1000 1000
1001 addfragments conf/fragments OE_FRAGMENTS OE_FRAGMENTS_METADATA_VARS 1001 addfragments conf/fragments OE_FRAGMENTS OE_FRAGMENTS_METADATA_VARS OE_BUILTIN_FRAGMENTS
1002 1002
1003``addfragments`` takes three parameters: 1003``addfragments`` takes four parameters:
1004 1004
1005- path prefix for fragment files inside the layer file tree that bitbake 1005- path prefix for fragment files inside the layer file tree that bitbake
1006 uses to construct full paths to the fragment files 1006 uses to construct full paths to the fragment files
@@ -1011,6 +1011,8 @@ go into ``bitbake.conf``, for example::
1011- name of variable that contains a list of variable names containing 1011- name of variable that contains a list of variable names containing
1012 fragment-specific metadata (such as descriptions) 1012 fragment-specific metadata (such as descriptions)
1013 1013
1014- name of variable that contains definitions for built-in fragments
1015
1014This allows listing enabled configuration fragments in ``OE_FRAGMENTS`` 1016This allows listing enabled configuration fragments in ``OE_FRAGMENTS``
1015variable like this:: 1017variable like this::
1016 1018
@@ -1035,6 +1037,19 @@ The implementation will add a flag containing the fragment name to each of those
1035when parsing fragments, so that the variables are namespaced by fragment name, and do not override 1037when parsing fragments, so that the variables are namespaced by fragment name, and do not override
1036each other when several fragments are enabled. 1038each other when several fragments are enabled.
1037 1039
1040The variable containing a built-in fragment definitions could look like this::
1041
1042 OE_BUILTIN_FRAGMENTS = "someprefix:SOMEVARIABLE anotherprefix:ANOTHERVARIABLE"
1043
1044and then if 'someprefix/somevalue' is added to the variable that holds the list
1045of enabled fragments:
1046
1047 OE_FRAGMENTS = "... someprefix/somevalue"
1048
1049bitbake will treat that as direct value assignment in its configuration::
1050
1051 SOMEVARIABLE = "somevalue"
1052
1038Functions 1053Functions
1039========= 1054=========
1040 1055
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index ea1096f2de..49a0788038 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -343,11 +343,12 @@ class InheritDeferredNode(AstNode):
343 bb.parse.BBHandler.inherit_defer(*self.inherit, data) 343 bb.parse.BBHandler.inherit_defer(*self.inherit, data)
344 344
345class AddFragmentsNode(AstNode): 345class AddFragmentsNode(AstNode):
346 def __init__(self, filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable): 346 def __init__(self, filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable, builtin_fragments_variable):
347 AstNode.__init__(self, filename, lineno) 347 AstNode.__init__(self, filename, lineno)
348 self.fragments_path_prefix = fragments_path_prefix 348 self.fragments_path_prefix = fragments_path_prefix
349 self.fragments_variable = fragments_variable 349 self.fragments_variable = fragments_variable
350 self.flagged_variables_list_variable = flagged_variables_list_variable 350 self.flagged_variables_list_variable = flagged_variables_list_variable
351 self.builtin_fragments_variable = builtin_fragments_variable
351 352
352 def eval(self, data): 353 def eval(self, data):
353 # No need to use mark_dependency since we would only match a fragment 354 # No need to use mark_dependency since we would only match a fragment
@@ -360,13 +361,23 @@ class AddFragmentsNode(AstNode):
360 return candidate_fragment_path 361 return candidate_fragment_path
361 return None 362 return None
362 363
364 def check_and_set_builtin_fragment(fragment, data, builtin_fragments):
365 prefix, value = fragment.split('/', 1)
366 if prefix in builtin_fragments.keys():
367 data.setVar(builtin_fragments[prefix], value)
368 return True
369 return False
370
363 fragments = data.getVar(self.fragments_variable) 371 fragments = data.getVar(self.fragments_variable)
364 layers = data.getVar('BBLAYERS') 372 layers = data.getVar('BBLAYERS')
365 flagged_variables = data.getVar(self.flagged_variables_list_variable).split() 373 flagged_variables = data.getVar(self.flagged_variables_list_variable).split()
374 builtin_fragments = {f[0]:f[1] for f in [f.split(':') for f in data.getVar(self.builtin_fragments_variable).split()] }
366 375
367 if not fragments: 376 if not fragments:
368 return 377 return
369 for f in fragments.split(): 378 for f in fragments.split():
379 if check_and_set_builtin_fragment(f, data, builtin_fragments):
380 continue
370 layerid, fragment_name = f.split('/', 1) 381 layerid, fragment_name = f.split('/', 1)
371 full_fragment_name = data.expand("{}/{}.conf".format(self.fragments_path_prefix, fragment_name)) 382 full_fragment_name = data.expand("{}/{}.conf".format(self.fragments_path_prefix, fragment_name))
372 fragment_path = find_fragment(layers, layerid, full_fragment_name) 383 fragment_path = find_fragment(layers, layerid, full_fragment_name)
@@ -430,7 +441,8 @@ def handleAddFragments(statements, filename, lineno, m):
430 fragments_path_prefix = m.group(1) 441 fragments_path_prefix = m.group(1)
431 fragments_variable = m.group(2) 442 fragments_variable = m.group(2)
432 flagged_variables_list_variable = m.group(3) 443 flagged_variables_list_variable = m.group(3)
433 statements.append(AddFragmentsNode(filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable)) 444 builtin_fragments_variable = m.group(4)
445 statements.append(AddFragmentsNode(filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable, builtin_fragments_variable))
434 446
435def runAnonFuncs(d): 447def runAnonFuncs(d):
436 code = [] 448 code = []
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
index 675838d845..9ddbae123d 100644
--- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
@@ -48,7 +48,7 @@ __export_regexp__ = re.compile( r"export\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
48__unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" ) 48__unset_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)$" )
49__unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\]$" ) 49__unset_flag_regexp__ = re.compile( r"unset\s+([a-zA-Z0-9\-_+.${}/~]+)\[([a-zA-Z0-9\-_+.][a-zA-Z0-9\-_+.@]+)\]$" )
50__addpylib_regexp__ = re.compile(r"addpylib\s+(.+)\s+(.+)" ) 50__addpylib_regexp__ = re.compile(r"addpylib\s+(.+)\s+(.+)" )
51__addfragments_regexp__ = re.compile(r"addfragments\s+(.+)\s+(.+)\s+(.+)" ) 51__addfragments_regexp__ = re.compile(r"addfragments\s+(.+)\s+(.+)\s+(.+)\s+(.+)" )
52 52
53def init(data): 53def init(data):
54 return 54 return