Skip to contentSkip to conversation

lib/bb/cooker.py: fix reset in case of different featureset

PATCH New [email protected] 1 participant 3 messages Nov 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/3 lib/bb/cooker.py: fix reset in case of different featureset

From: Chen Qi <[email protected]>

The cooker needs to re-parse data in case of different featureset. This needs to happen not only when some feature is added, but also when some feature is removed.

---
 lib/bb/cooker.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
lib/bb/cooker.py +9 -1
index 03f262ac1..1c06737ad 100644
@@ -90,6 +90,11 @@ class CookerFeatures(object):
             return
         self._features.add(f)
 
+    def delFeature(self, f):
+        if f not in self._features:
+            return
+        self._features.remove(f)
+
     def __contains__(self, f):
         return f in self._features
 
@@ -237,7 +242,10 @@ class BBCooker:
         original_featureset = list(self.featureset)
         for feature in features:
             self.featureset.setFeature(feature)
-        bb.debug(1, "Features set %s (was %s)" % (original_featureset, list(self.featureset)))
+        for orig_feature in original_featureset:
+            if orig_feature not in features:
+                self.featureset.delFeature(orig_feature)
+        bb.debug(1, "Features set %s (was %s)" % (list(self.featureset), original_featureset))
         if (original_featureset != list(self.featureset)) and self.state != State.ERROR and hasattr(self, "data"):
             self.reset()
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 2/3 bitbake: add SKIP_FRAGMENTS CookerFeature

From: Chen Qi <[email protected]>

This patch add a new CookerFeature, SKIP_FRAGMENTS, which when enabled will skip fragments parsing.

This feature is mainly used by bitbake-config-build. It's a tool to manage fragements. So we want to skip fragment parsing to avoid unnecessary errors.

Fixes [YOCTO #16060]

---
 bin/bitbake-layers   |  7 ++++++-
 lib/bb/cooker.py     | 13 ++++++++++++-
 lib/bb/cookerdata.py |  4 ++++
 lib/bb/parse/ast.py  |  3 +++
 4 files changed, 25 insertions(+), 2 deletions(-)
bin/bitbake-layers +6 -1
index 341ecbcd9..7d929567a 100755
@@ -23,6 +23,7 @@ topdir = os.path.dirname(bindir)
 sys.path[0:0] = [os.path.join(topdir, 'lib')]
 
 import bb.tinfoil
+import bb.cooker
 import bb.msg
 
 logger = bb.msg.logger_create(toolname, sys.stdout)
@@ -64,7 +65,11 @@ def main():
         if global_args.force > 1:
             bbpaths = []
         else:
-            tinfoil.prepare(True)
+            if toolname == "bitbake-config-build":
+                extra_features = [bb.cooker.CookerFeatures.SKIP_FRAGMENTS]
+            else:
+                extra_features = None
+            tinfoil.prepare(True, extra_features=extra_features)
             bbpaths = tinfoil.config_data.getVar('BBPATH').split(':')
 
         for path in ([topdir] + bbpaths):
lib/bb/cooker.py +12 -1
index 1c06737ad..b896c233e 100644
@@ -79,7 +79,7 @@ class SkippedPackage:
 
 
 class CookerFeatures(object):
-    _feature_list = [HOB_EXTRA_CACHES, BASEDATASTORE_TRACKING, SEND_SANITYEVENTS, RECIPE_SIGGEN_INFO] = list(range(4))
+    _feature_list = [HOB_EXTRA_CACHES, BASEDATASTORE_TRACKING, SEND_SANITYEVENTS, RECIPE_SIGGEN_INFO, SKIP_FRAGMENTS] = list(range(5))
 
     def __init__(self):
         self._features=set()
@@ -286,6 +286,11 @@ class BBCooker:
                 logger.critical("Unable to import extra RecipeInfo '%s' from '%s': %s" % (cache_name, module_name, exc))
                 raise bb.BBHandledException()
 
+        if CookerFeatures.SKIP_FRAGMENTS in self.featureset:
+            self.enableSkipFragments()
+        else:
+            self.disableSkipFragments()
+
         self.databuilder = bb.cookerdata.CookerDataBuilder(self.configuration, False)
         self.databuilder.parseBaseConfiguration()
         self.data = self.databuilder.data
@@ -363,6 +368,12 @@ You can also remove the BB_HASHSERVE_UPSTREAM setting, but this may result in si
         if hasattr(self, "data"):
             self.data.disableTracking()
 
+    def enableSkipFragments(self):
+        self.configuration.skip_fragments = True
+
+    def disableSkipFragments(self):
+        self.configuration.skip_fragments = False
+
     def revalidateCaches(self):
         bb.parse.clear_cache()
 
lib/bb/cookerdata.py +4 -0
index 65c153a5b..b6dca7af7 100644
@@ -137,6 +137,7 @@ class CookerConfiguration(object):
         self.build_verbose_stdout = False
         self.dry_run = False
         self.tracking = False
+        self.skip_fragments = False
         self.writeeventlog = False
         self.limited_deps = False
         self.runall = []
@@ -226,12 +227,15 @@ class CookerDataBuilder(object):
         self.prefiles = cookercfg.prefile
         self.postfiles = cookercfg.postfile
         self.tracking = cookercfg.tracking
+        self.skip_fragments = cookercfg.skip_fragments
 
         bb.utils.set_context(bb.utils.clean_context())
         bb.event.set_class_handlers(bb.event.clean_class_handlers())
         self.basedata = bb.data.init()
         if self.tracking:
             self.basedata.enableTracking()
+        if self.skip_fragments:
+            self.basedata.setVar("_BB_SKIP_FRAGMENTS", "1")
 
         # Keep a datastore of the initial environment variables and their
         # values from when BitBake was launched to enable child processes
lib/bb/parse/ast.py +3 -0
index e6ff1ff76..bf9bd4f55 100644
@@ -351,6 +351,9 @@ class AddFragmentsNode(AstNode):
         self.builtin_fragments_variable = builtin_fragments_variable
 
     def eval(self, data):
+        if data.getVar('_BB_SKIP_FRAGMENTS') == '1':
+            return
+
         # No need to use mark_dependency since we would only match a fragment
         # from a specific layer and there can only be a single layer with a
         # given namespace.
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 3/3 lib/bb/parse/ast.py: error out for internal fragment in case of a previous value

In reply to [email protected]

From: Chen Qi <[email protected]>

When an internal fragment is enabled, and there's already a value for the corresponding variable, we should error out to avoid any confusion.

For example, when 'machine/qemux86-64' fragement is enabled, and we get some "MACHINE = xxx" in local.conf or env, we should error out and recomment users to use 'bitbake-config-build disable-fragment'.

We should be tolerating '??=' assignments. For example, DISTRO defaults to "nodistro" in oe-core layer, and when 'distro/poky" fragment is enabled, there should be no confusion.

Fixes [YOCTO #16060]

---
 lib/bb/parse/ast.py | 6 ++++++
 1 file changed, 6 insertions(+)
lib/bb/parse/ast.py +6 -0
index bf9bd4f55..00e3615e6 100644
@@ -367,6 +367,12 @@ class AddFragmentsNode(AstNode):
         def check_and_set_builtin_fragment(fragment, data, builtin_fragments):
             prefix, value = fragment.split('/', 1)
             if prefix in builtin_fragments.keys():
+                if data.getVar(builtin_fragments[prefix], noweakdefault=True) != None:
+                    bb.fatal(
+                        ("A builtin fragment '%s' is used while %s has already got an assignment.\n"
+                         "Please either disable the fragment or remove the value assignment.\n"
+                         "To disable the fragment, use 'bitbake-config-build disable-fragment %s'."
+                         ) % (fragment, builtin_fragments[prefix], fragment))
                 fragment_history = data.varhistory.variable(self.fragments_variable)
                 loginfo={}
                 for fh in fragment_history[::-1]:
Signature · 1 line
2.34.1