diff mbox series

[RFC] parse: add bitbake version check via bitbake_min_version keyword

Message ID 20251022113146.3207795-1-alex.kanavin@gmail.com
State New
Headers show
Series [RFC] parse: add bitbake version check via bitbake_min_version keyword | expand

Commit Message

Alexander Kanavin Oct. 22, 2025, 11:31 a.m. UTC
From: Alexander Kanavin <alex@linutronix.de>

Layers (e.g. openembedded-core) can specify in conf/layer.conf:

bitbake_min_version 2.15.2

and if bitbake has a lesser version it will stop itself, as early
as possible, to avoid hitting cryptic compatibility issues later on,
with this error:

bb.parse.ParseError: ParseError at /home/alex/bitbake-builds/poky-master-poky-distro_poky-machine_qemux86-64/layers/openembedded-core/meta/conf/layer.conf:1: Bitbake version 2.15.3 is required and version 2.15.2 is used

Note that sanity.bbclass in oe-core has a similar check, but as
this thread [1] highlighted, compatibility issues can stop bitbake
sooner and the check is never reached, leaving the user with
confusing errors.

[1] https://lists.openembedded.org/g/openembedded-core/topic/115724008

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

Patch

diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index cfead466e1c..20c6f51a837 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -412,6 +412,14 @@  class AddFragmentsNode(AstNode):
             else:
                 bb.error("Could not find fragment {} in enabled layers: {}".format(f, layers))
 
+class BbMinVersionNode(AstNode):
+    def __init__(self, filename, lineno, bb_min_version):
+        AstNode.__init__(self, filename, lineno)
+        self.bb_min_version = bb_min_version
+
+    def eval(self, data):
+        bb.parse.ConfHandler.check_bb_version(self.filename, self.lineno, self.bb_min_version)
+
 def handleInclude(statements, filename, lineno, m, force):
     statements.append(IncludeNode(filename, lineno, m.group(1), force))
 
@@ -466,6 +474,10 @@  def handleAddFragments(statements, filename, lineno, m):
     builtin_fragments_variable = m.group(4)
     statements.append(AddFragmentsNode(filename, lineno, fragments_path_prefix, fragments_variable, flagged_variables_list_variable, builtin_fragments_variable))
 
+def handleBbMinVersion(statements, filename, lineno, m):
+    bb_min_version = m.group(1)
+    statements.append(BbMinVersionNode(filename, lineno, bb_min_version))
+
 def runAnonFuncs(d):
     code = []
     for funcname in d.getVar("__BBANONFUNCS", False) or []:
diff --git a/bitbake/lib/bb/parse/parse_py/ConfHandler.py b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
index 9ddbae123dc..eff7f67129d 100644
--- a/bitbake/lib/bb/parse/parse_py/ConfHandler.py
+++ b/bitbake/lib/bb/parse/parse_py/ConfHandler.py
@@ -49,6 +49,7 @@  __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+(.+)\s+(.+)\s+(.+)" )
+__bitbake_min_version_regexp__ = re.compile(r"bitbake_min_version\s+(.+)" )
 
 def init(data):
     return
@@ -102,6 +103,10 @@  def include_single_file(parentfn, fn, lineno, data, error_out):
             else:
                 raise ParseError("Error parsing %s: %s" % (fn, exc.strerror), parentfn, lineno)
 
+def check_bb_version(fn, lineno, min_version):
+    if bb.utils.vercmp_string_op(bb.__version__, min_version, "<"):
+        raise ParseError('Bitbake version %s is required and version %s is used\n' % (min_version, bb.__version__), fn, lineno)
+
 # We have an issue where a UI might want to enforce particular settings such as
 # an empty DISTRO variable. If configuration files do something like assigning
 # a weak default, it turns out to be very difficult to filter out these changes,
@@ -213,6 +218,11 @@  def feeder(lineno, s, fn, statements, baseconfig=False, conffile=True):
         ast.handleAddFragments(statements, fn, lineno, m)
         return
 
+    m = __bitbake_min_version_regexp__.match(s)
+    if m:
+        ast.handleBbMinVersion(statements, fn, lineno, m)
+        return
+
     raise ParseError("unparsed line: '%s'" % s, fn, lineno);
 
 # Add us to the handlers list