Skip to contentSkip to conversation

bitbake.conf: enable built-in fragments for MACHINE and DISTRO

PATCH New Alexander Kanavin 1 participant 2 messages Jun 18, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bitbake.conf: enable built-in fragments for MACHINE and DISTRO

From: Alexander Kanavin <[email protected]>

Please see the patch for bitbake for rationale. With this setting in place, it's possible to set

OE_FRAGMENTS += "distro/poky machine/qemuarm"

and bitbake will interpret that as

DISTRO = "poky"
MACHINE = "qemuarm"

---
 meta/conf/bitbake.conf | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/conf/bitbake.conf +2 -1
index 54d6bebc39f..77399abce0a 100644
@@ -821,7 +821,8 @@ include conf/local.conf
 
 OE_FRAGMENTS_PREFIX ?= "conf/fragments"
 OE_FRAGMENTS_METADATA_VARS ?= "BB_CONF_FRAGMENT_SUMMARY BB_CONF_FRAGMENT_DESCRIPTION"
-addfragments ${OE_FRAGMENTS_PREFIX} OE_FRAGMENTS OE_FRAGMENTS_METADATA_VARS
+OE_FRAGMENTS_BUILTIN ?= "machine:MACHINE distro:DISTRO"
+addfragments ${OE_FRAGMENTS_PREFIX} OE_FRAGMENTS OE_FRAGMENTS_METADATA_VARS OE_FRAGMENTS_BUILTIN
 
 require ${@"conf/multiconfig/${BB_CURRENT_MC}.conf" if "${BB_CURRENT_MC}" != "" else ""}
 include conf/machine/${MACHINE}.conf
Signature · 1 line
2.39.5
#1 lore raw

PATCH 2/2 lib/bbconfigbuild/configfragments: add support for listing and enabling built-in fragments

From: Alexander Kanavin <[email protected]>

Sample output:

$ bitbake-config-build enable-fragment machine/qemuarm
Fragment machine/qemuarm added to /srv/storage/alex/yocto/build-64-alt/conf/auto.conf.
$ bitbake-config-build list-fragments
Available built-in fragments:
machine/...	Sets MACHINE = ...
distro/...	Sets DISTRO = ...

Enabled built-in fragments:
machine/qemuarm Sets MACHINE = "qemuarm"

... (standard on-disk fragments output follows)

---
 meta/lib/bbconfigbuild/configfragments.py | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
meta/lib/bbconfigbuild/configfragments.py +21 -1
index c1dddc3e4cb..61c33ac3161 100644
@@ -62,7 +62,22 @@ class ConfigFragmentsPlugin(LayerPlugin):
             else:
                 print('Name: {}\nPath: {}\nEnabled: {}\nSummary: {}\nDescription:\n{}\n'.format(f['name'], f['path'], 'yes' if is_enabled else 'no', f['summary'],''.join(f['description'])))
 
+        def print_builtin_fragments(builtin, enabled):
+            print('Available built-in fragments:')
+            builtin_dict = {i[0]:i[1] for i in [f.split(':') for f in builtin]}
+            for prefix,var in builtin_dict.items():
+                print('{}/...\tSets {} = ...'.format(prefix, var))
+            print('')
+            enabled_builtin_fragments = [f for f in enabled if self.builtin_fragment_exists(f)]
+            print('Enabled built-in fragments:')
+            for f in enabled_builtin_fragments:
+                 prefix, value = f.split('/', 1)
+                 print('{}\tSets {} = "{}"'.format(f, builtin_dict[prefix], value))
+            print('')
+
         all_enabled_fragments = (self.tinfoil.config_data.getVar('OE_FRAGMENTS') or "").split()
+        all_builtin_fragments = (self.tinfoil.config_data.getVar('OE_FRAGMENTS_BUILTIN') or "").split()
+        print_builtin_fragments(all_builtin_fragments, all_enabled_fragments)
 
         for layername, layerdata in self.discover_fragments().items():
             layerdir = layerdata['layerdir']
@@ -89,6 +104,11 @@ class ConfigFragmentsPlugin(LayerPlugin):
                   return True
         return False
 
+    def builtin_fragment_exists(self, fragmentname):
+        fragment_prefix = fragmentname.split("/",1)[0]
+        fragment_prefix_defs = set([f.split(':')[0] for f in self.tinfoil.config_data.getVar('OE_FRAGMENTS_BUILTIN').split()])
+        return fragment_prefix in fragment_prefix_defs
+
     def create_conf(self, confpath):
         if not os.path.exists(confpath):
             with open(confpath, 'w') as f:
@@ -112,7 +132,7 @@ class ConfigFragmentsPlugin(LayerPlugin):
             return " ".join(enabled_fragments), None, 0, True
 
         for f in args.fragmentname:
-            if not self.fragment_exists(f):
+            if not self.fragment_exists(f) and not self.builtin_fragment_exists(f):
                 raise Exception("Fragment {} does not exist; use 'list-fragments' to see the full list.".format(f))
 
         self.create_conf(args.confpath)
Signature · 1 line
2.39.5