Skip to contentSkip to conversation

configfragments.py: Correct the help for enable-fragment

PATCH Superseded Peter Kjellerstedt 1 participant 3 messages Nov 21, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 configfragments.py: Correct the help for enable-fragment

The help entry for --quiet had been added to list-fragments rather than enable-fragment.

Due to the fact that --quiet is a global option, this actually adds a dummy --quiet option as it would otherwise hide the global option, but would never be set since any --quiet argument would already have been parsed when this option is parsed.

---
 meta/lib/bbconfigbuild/configfragments.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
meta/lib/bbconfigbuild/configfragments.py +3 -1
index 6fdac33a5d..f79e238297 100644
@@ -197,7 +197,9 @@ class ConfigFragmentsPlugin(LayerPlugin):
 
         parser_enable_fragment = self.add_command(sp, 'enable-fragment', self.do_enable_fragment, parserecipes=False)
         parser_enable_fragment.add_argument("--confpath", default=default_confpath, help='Configuration file which contains a list of enabled fragments (default is {}).'.format(default_confpath))
-        parser_list_fragments.add_argument('--quiet', '-q', action='store_true', help='Do not print descriptions of the newly enabled fragments')
+        # Store the quiet argument in quiet_dummy. This is because --quiet is a
+        # global option and this one is only here to add an entry for --help.
+        parser_enable_fragment.add_argument('--quiet', '-q', action='store_true', dest='quiet_dummy', help='Do not print descriptions of the newly enabled fragments')
         parser_enable_fragment.add_argument('fragmentname', help='The name of the fragment (use list-fragments to see them)', nargs='+')
 
         parser_disable_fragment = self.add_command(sp, 'disable-fragment', self.do_disable_fragment, parserecipes=False)
#1 lore raw

PATCH 2/3 configfragments.py: Make list-fragments fail early

If a fragment has not been configured correctly, make list-fragments fail with an error before it has output information about any built-in fragments.

---
 meta/lib/bbconfigbuild/configfragments.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
meta/lib/bbconfigbuild/configfragments.py +3 -1
index f79e238297..15142ec9f9 100644
@@ -75,11 +75,13 @@ class ConfigFragmentsPlugin(LayerPlugin):
                  print('{}\tSets {} = "{}"'.format(f, builtin_dict[prefix], value))
             print('')
 
+        allfragments = self.discover_fragments()
+
         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():
+        for layername, layerdata in allfragments.items():
             layerdir = layerdata['layerdir']
             fragments = layerdata['fragments']
             enabled_fragments = [f for f in fragments if f['name'] in all_enabled_fragments]
#2 lore raw

PATCH 3/3 configfragments.py: Improve reporting of errors and warnings

In reply to Peter Kjellerstedt

Use bb.fatal() and bb.warn() to report errors and warnings. This makes for a nicer experience for the user, and allows the warnings to be silenced using the --quiet option.

---
 meta/lib/bbconfigbuild/configfragments.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
meta/lib/bbconfigbuild/configfragments.py +5 -5
index 15142ec9f9..8365a15a32 100644
@@ -28,10 +28,10 @@ class ConfigFragmentsPlugin(LayerPlugin):
         summary = d.getVar('BB_CONF_FRAGMENT_SUMMARY')
         description = d.getVar('BB_CONF_FRAGMENT_DESCRIPTION')
         if not summary:
-            raise Exception('Please add a one-line summary as BB_CONF_FRAGMENT_SUMMARY = \"...\" variable at the beginning of {}'.format(path))
+            bb.fatal('Please add a one-line summary as BB_CONF_FRAGMENT_SUMMARY = "..." variable at the beginning of {}'.format(path))
 
         if not description:
-            raise Exception('Please add a description as BB_CONF_FRAGMENT_DESCRIPTION = \"...\" variable at the beginning of {}'.format(path))
+            bb.fatal('Please add a description as BB_CONF_FRAGMENT_DESCRIPTION = "..." variable at the beginning of {}'.format(path))
 
         return summary, description
 
@@ -131,7 +131,7 @@ class ConfigFragmentsPlugin(LayerPlugin):
             enabled_fragments = origvalue.split()
             for f in args.fragmentname:
                 if f in enabled_fragments:
-                    print("Fragment {} already included in {}".format(f, args.confpath))
+                    bb.warn("Fragment {} already included in {}".format(f, args.confpath))
                 else:
                     # first filter out all built-in fragments with the same prefix as the one that is being enabled
                     enabled_fragments = [fragment for fragment in enabled_fragments if not(self.builtin_fragment_exists(fragment) and self.fragment_prefix(fragment) == self.fragment_prefix(f))]
@@ -141,7 +141,7 @@ class ConfigFragmentsPlugin(LayerPlugin):
         fragments = self.discover_fragments()
         for f in args.fragmentname:
             if not self.get_fragment(f, fragments) and not self.builtin_fragment_exists(f):
-                raise Exception("Fragment {} does not exist; use 'list-fragments' to see the full list.".format(f))
+                bb.fatal("Fragment {} does not exist; use 'list-fragments' to see the full list.".format(f))
 
         self.create_conf(args.confpath)
         modified = bb.utils.edit_metadata_file(args.confpath, ["OE_FRAGMENTS"], enable_helper)
@@ -160,7 +160,7 @@ class ConfigFragmentsPlugin(LayerPlugin):
                 if f in enabled_fragments:
                     enabled_fragments.remove(f)
                 else:
-                    print("Fragment {} not currently enabled in {}".format(f, args.confpath))
+                    bb.warn("Fragment {} not currently enabled in {}".format(f, args.confpath))
             return " ".join(enabled_fragments), None, 0, True
 
         self.create_conf(args.confpath)