Skip to contentSkip to conversation

lib/configfragments: match fragment prefixes rather than full fragment names when disabling fragments

PATCH In review Alexander Kanavin 3 participants 5 messages Nov 28, 2025 – Nov 29, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/configfragments: match fragment prefixes rather than full fragment names when disabling fragments

From: Alexander Kanavin <[email protected]>

This allows disabling classes of fragments without knowing their full names, e.g. instead of

$ bitbake-config-build disable-fragment machine/qemuarm

one can issue

$ bitbake-config-build disable-fragment machine

to match and disable everything that starts with 'machine'.

Add an --exact option to preserve exact maching (e.g. when theres some/feature and some/feature-with-foobar both enabled and only the first needs to be disabled).

---
 meta/lib/bbconfigbuild/configfragments.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
meta/lib/bbconfigbuild/configfragments.py +11 -7
index de521f0c149..f5b4dfe1ec2 100644
@@ -161,16 +161,19 @@ class ConfigFragmentsPlugin(LayerPlugin):
         def disable_helper(varname, origvalue, op, newlines):
             enabled_fragments = origvalue.split()
             for f in args.fragmentname:
-                if f in enabled_fragments:
-                    enabled_fragments.remove(f)
-                else:
-                    print("Fragment {} not currently enabled in {}".format(f, args.confpath))
+                for e in enabled_fragments[:]:
+                    if (not args.exact and e.startswith(f)) or f==e:
+                        print("Removing fragment {} from {}".format(e, args.confpath))
+                        enabled_fragments.remove(e)
             return " ".join(enabled_fragments), None, 0, True
 
         self.create_conf(args.confpath)
         modified = bb.utils.edit_metadata_file(args.confpath, ["OE_FRAGMENTS"], disable_helper)
-        if modified:
-            print("Fragment {} removed from {}.".format(", ".join(args.fragmentname), args.confpath))
+        if not modified:
+            if args.exact:
+                print("Fragment names {} matched nothing in {}.".format(", ".join(args.fragmentname), args.confpath))
+            else:
+                print("Fragment prefixes {} matched nothing in {}.".format(", ".join(args.fragmentname), args.confpath))
 
     def do_show_fragment(self, args):
         """ Show the content of a fragment """
@@ -210,7 +213,8 @@ class ConfigFragmentsPlugin(LayerPlugin):
 
         parser_disable_fragment = self.add_command(sp, 'disable-fragment', self.do_disable_fragment, parserecipes=False)
         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_disable_fragment.add_argument('--exact', action='store_true', help='Match fragment names exactly')
+        parser_disable_fragment.add_argument('fragmentname', help='The name of the fragment, or a name prefix to match', 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')
Signature · 1 line
2.39.5
#1 lore raw
Quoted 9 lines · Alexander Kanavin via lists.openembedded.org

From: Alexander Kanavin <[email protected]>

This allows disabling classes of fragments without knowing their full names, e.g. instead of

$ bitbake-config-build disable-fragment machine/qemuarm

one can issue

Quoted 7 lines
$ bitbake-config-build disable-fragment machine

to match and disable everything that starts with 'machine'.

Add an --exact option to preserve exact maching (e.g. when theres some/feature and some/feature-with-foobar both enabled and only the first needs to be disabled).

Why not add a --wildcard option instead, and keep the default behavior backwards compatible?

Quoted 54 lines
---
 meta/lib/bbconfigbuild/configfragments.py | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
meta/lib/bbconfigbuild/configfragments.py +11 -8
index de521f0c149..f5b4dfe1ec2 100644
@@ -161,16 +161,19 @@ class ConfigFragmentsPlugin(LayerPlugin):
         def disable_helper(varname, origvalue, op, newlines):
             enabled_fragments = origvalue.split()
             for f in args.fragmentname:
-                if f in enabled_fragments:
-                    enabled_fragments.remove(f)
-                else:
-                    print("Fragment {} not currently enabled in {}".format(f, args.confpath))
+                for e in enabled_fragments[:]:
+                    if (not args.exact and e.startswith(f)) or f==e:
+                        print("Removing fragment {} from {}".format(e, args.confpath))
+                        enabled_fragments.remove(e)
             return " ".join(enabled_fragments), None, 0, True
 
         self.create_conf(args.confpath)
         modified = bb.utils.edit_metadata_file(args.confpath, ["OE_FRAGMENTS"], disable_helper)
-        if modified:
-            print("Fragment {} removed from {}.".format(", ".join(args.fragmentname), args.confpath))
+        if not modified:
+            if args.exact:
+                print("Fragment names {} matched nothing in {}.".format(", ".join(args.fragmentname), args.confpath))
+            else:
+                print("Fragment prefixes {} matched nothing in {}.".format(", ".join(args.fragmentname), args.confpath))
 
     def do_show_fragment(self, args):
         """ Show the content of a fragment """
@@ -210,7 +213,8 @@ class ConfigFragmentsPlugin(LayerPlugin):
 
         parser_disable_fragment = self.add_command(sp, 'disable-fragment', self.do_disable_fragment, parserecipes=False)
         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_disable_fragment.add_argument('--exact', action='store_true', help='Match fragment names exactly')
+        parser_disable_fragment.add_argument('fragmentname', help='The name of the fragment, or a name prefix to match', 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')
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#226921): https://lists.openembedded.org/g/openembedded-core/message/226921
Mute This Topic: https://lists.openembedded.org/mt/116517046/6084445
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw
Quoted 9 lines · Gyorgy Sarvari
Quoted 9 lines

This allows disabling classes of fragments without knowing their full names, e.g. instead of

$ bitbake-config-build disable-fragment machine/qemuarm

one can issue

$ bitbake-config-build disable-fragment machine
Quoted 8 lines
Quoted 5 lines

to match and disable everything that starts with 'machine'.

Add an --exact option to preserve exact maching (e.g. when theres some/feature and some/feature-with-foobar both enabled and only the first needs to be disabled).

Why not add a --wildcard option instead, and keep the default behavior backwards compatible?

I considered this, but I tohught most people would prefer prefix matching to be the default, it's just more convenient. Fragments are still very new, and situations where --exact is necessary are rare.

This will be discussed in patch review. If preserving behaviour is the outcome, I wouldn't add an option (that no one would know about), it would be a separate command: disable-by-prefix.

Alex

#3 lore raw
Quoted 19 lines · Alexander Kanavin via lists.openembedded.org
Quoted 9 lines · Gyorgy Sarvari
Quoted 9 lines

This allows disabling classes of fragments without knowing their full names, e.g. instead of

$ bitbake-config-build disable-fragment machine/qemuarm

one can issue

$ bitbake-config-build disable-fragment machine
Quoted 8 lines
Quoted 5 lines

to match and disable everything that starts with 'machine'.

Add an --exact option to preserve exact maching (e.g. when theres some/feature and some/feature-with-foobar both enabled and only the first needs to be disabled).

Why not add a --wildcard option instead, and keep the default behavior backwards compatible?

Quoted 7 lines

I considered this, but I tohught most people would prefer prefix matching to be the default, it's just more convenient. Fragments are still very new, and situations where --exact is necessary are rare.

This will be discussed in patch review. If preserving behaviour is the outcome, I wouldn't add an option (that no one would know about), it would be a separate command: disable-by-prefix.

Perhaps the compromise is to support:

bitbake-config-build disable-fragment machine/

i.e. the prefix matching only triggers if the / is at the end?

That is perhaps relatively explicit/intuitive enough?

Cheers,

Richard

#4 lore raw
Quoted 8 lines · Richard Purdie
Quoted 7 lines

I considered this, but I tohught most people would prefer prefix matching to be the default, it's just more convenient. Fragments are still very new, and situations where --exact is necessary are rare.

This will be discussed in patch review. If preserving behaviour is the outcome, I wouldn't add an option (that no one would know about), it would be a separate command: disable-by-prefix.

Quoted 7 lines

Perhaps the compromise is to support:

bitbake-config-build disable-fragment machine/

i.e. the prefix matching only triggers if the / is at the end?

That is perhaps relatively explicit/intuitive enough?

Yep, I'll send a v2.

Alex