diff mbox series

[v2,1/2] lib/configfragments: add a show-fragments command

Message ID 20250905-show-fragments-v2-1-c13ec8df9296@bootlin.com
State New
Headers show
Series lib/configfragments: add a show-fragments command | expand

Commit Message

Antonin Godard Sept. 5, 2025, 12:23 p.m. UTC
We can print information on fragments (name, location, description,
etc.), but not their content.

Add a show-fragment command to do that. It can be used as follows:

  $ bitbake-config-build show-fragment core/yocto/sstate-mirror-cdn

And prints:

  .../meta/conf/fragments/yocto/sstate-mirror-cdn.conf:

  BB_CONF_FRAGMENT_SUMMARY = "Use prebuilt sstate artifacts for standard Yocto build configurations."
  BB_CONF_FRAGMENT_DESCRIPTION = "The Yocto Project has prebuilt artefacts available for standard build configurations. \
  ...

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 meta/lib/bbconfigbuild/configfragments.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/bbconfigbuild/configfragments.py b/meta/lib/bbconfigbuild/configfragments.py
index 61c33ac316..fce3301bac 100644
--- a/meta/lib/bbconfigbuild/configfragments.py
+++ b/meta/lib/bbconfigbuild/configfragments.py
@@ -156,6 +156,18 @@  class ConfigFragmentsPlugin(LayerPlugin):
         if modified:
             print("Fragment {} removed from {}.".format(", ".join(args.fragmentname), args.confpath))
 
+    def do_show_fragment(self, args):
+        """ Show the content of a fragment """
+        for layername, layerdata in self.discover_fragments().items():
+            fragments = layerdata['fragments']
+            for fragment in fragments:
+                if fragment['name'] == args.fragmentname:
+                    print(f"{fragment['path']}:")
+                    print()
+                    with open(fragment['path']) as fd:
+                        print(fd.read())
+                    return
+
     def do_disable_all_fragments(self, args):
         """ Disable all fragments in the local build configuration """
         def disable_all_helper(varname, origvalue, op, newlines):
@@ -181,5 +193,8 @@  class ConfigFragmentsPlugin(LayerPlugin):
         parser_disable_fragment.add_argument("--confpath", default=default_confpath, help='Configuration file which contains a list of enabled fragments (default is {}).'.format(default_confpath))
         parser_disable_fragment.add_argument('fragmentname', help='The name of the fragment', nargs='+')
 
+        parser_show_fragment = self.add_command(sp, 'show-fragment', self.do_show_fragment, parserecipes=False)
+        parser_show_fragment.add_argument('fragmentname', help='The name of the fragment')
+
         parser_disable_all = self.add_command(sp, 'disable-all-fragments', self.do_disable_all_fragments, parserecipes=False)
         parser_disable_all.add_argument("--confpath", default=default_confpath, help='Configuration file which contains a list of enabled fragments (default is {}).'.format(default_confpath))