diff mbox series

[v2,1/2] bin/bitbake-setup: add descriptions for fragment choices

Message ID 20260120-bitbake-setup-choose-builtin-v2-1-ade604ff2351@bootlin.com
State New
Headers show
Series bitbake-setup: add descriptions for fragment choices | expand

Commit Message

Antonin Godard Jan. 20, 2026, 8:57 a.m. UTC
Make it possible to give fragments descriptions as it can help users
determine which fragments to pick during bitbake-setup init.

It is still possible to provide a list (with no descriptions) for
backwards-compatibility.

Update the documentation accordingly.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 bin/bitbake-setup                                  | 21 ++++++++++++-----
 .../bitbake-user-manual-environment-setup.rst      | 26 ++++++++++++++++++++--
 setup-schema/bitbake-setup.schema.json             | 21 ++++++++++++++++-
 3 files changed, 60 insertions(+), 8 deletions(-)

Comments

Alexander Kanavin Jan. 20, 2026, 12:29 p.m. UTC | #1
On Tue, 20 Jan 2026 at 09:57, Antonin Godard via
lists.openembedded.org
<antonin.godard=bootlin.com@lists.openembedded.org> wrote:
> -        choice = [o for o in v["options"] if o in parameters]
> +
> +        # options can be a list of strings or a list of dicts
> +        options = v["options"]
> +        descriptions = []
> +        if len(options) > 0 and isinstance(v["options"][0], dict):
> +            descriptions = [o["description"] for o in options]
> +            options = [o["name"] for o in options]

I think descriptions should not be a separate variable, just use list
comprehension to build up a full structure with empty descriptions:

if len(options) > 0 and isinstance(v["options"][0], str):
    options = [{'name':o, 'description':"" for o in v["options"]]
else:
    options = v["options"]

That requires tweaking the rest of the code that accesses options, but
I think the result will be cleaner, e.g. adjust:

> +        choice = [o for o in options if o in parameters]

to
choice = [o['name'] for o in options if o['name'] in parameters]

Alex
Alexander Kanavin Jan. 20, 2026, 12:37 p.m. UTC | #2
On Tue, 20 Jan 2026 at 09:57, Antonin Godard via
lists.openembedded.org
<antonin.godard=bootlin.com@lists.openembedded.org> wrote:
>  bin/bitbake-setup                                  | 21 ++++++++++++-----
>  .../bitbake-user-manual-environment-setup.rst      | 26 ++++++++++++++++++++--
>  setup-schema/bitbake-setup.schema.json             | 21 ++++++++++++++++-

Oh, one more thing: adjust lib/bb/tests/setup.py to use the new
format. Even better if you can tweak it to use both old and new in
test configs. And it needs to pass of course :D

Alex
diff mbox series

Patch

diff --git a/bin/bitbake-setup b/bin/bitbake-setup
index abe7614c832..8f28a1ef4d4 100755
--- a/bin/bitbake-setup
+++ b/bin/bitbake-setup
@@ -494,20 +494,31 @@  def choose_fragments(possibilities, parameters, non_interactive, skip_selection)
         if skip_selection and k in skip_selection:
             logger.info("Skipping a selection of {}, as requested on command line. The resulting bitbake configuration may require further manual adjustments.".format(k))
             continue
-        choice = [o for o in v["options"] if o in parameters]
+
+        # options can be a list of strings or a list of dicts
+        options = v["options"]
+        descriptions = []
+        if len(options) > 0 and isinstance(v["options"][0], dict):
+            descriptions = [o["description"] for o in options]
+            options = [o["name"] for o in options]
+
+        choice = [o for o in options if o in parameters]
         if len(choice) > 1:
-            raise Exception("Options specified on command line do not allow a single selection from possibilities {}, please remove one or more from {}".format(v["options"], parameters))
+            raise Exception("Options specified on command line do not allow a single selection from possibilities {}, please remove one or more from {}".format(options, parameters))
         if len(choice) == 1:
             choices[k] = choice[0]
             continue
 
         if non_interactive:
-            raise Exception("Unable to choose from options in non-interactive mode: {}".format(v["options"]))
+            raise Exception("Unable to choose from options in non-interactive mode: {}".format(options))
 
         logger.plain("\n" + v["description"] + ":")
-        options_enumerated = list(enumerate(v["options"], 1))
+        options_enumerated = list(enumerate(options, 1))
         for n,o in options_enumerated:
-            logger.plain("{}. {}".format(n, o))
+            opt_str = f"{n}. {o}"
+            if descriptions:
+                opt_str += f"\t{descriptions[n - 1]}"
+            logger.plain(opt_str)
         option_n = int_input([i[0] for i in options_enumerated],
                              "\nPlease select one of the above options by its number: ") - 1
         choices[k] = options_enumerated[option_n][1]
diff --git a/doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst b/doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst
index 57e799980c4..0376d77143d 100644
--- a/doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst
+++ b/doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst
@@ -759,11 +759,21 @@  They contain the following sections:
                 "oe-fragments-one-of": {
                     "machine": {
                         "description": "Target machines",
-                        "options" : ["machine/qemux86-64", "machine/qemuarm64", "machine/qemuriscv64", "machine/genericarm64", "machine/genericx86-64"]
+                        "options" : [
+                            { "name": "machine/qemux86-64", "description": "Machine configuration for running an x86-64 system on QEMU" },
+                            { "name": "machine/qemuarm64", "description": "Machine configuration for running an ARMv8 system on QEMU" },
+                            { "name": "machine/qemuriscv64", "description": "Machine configuration for running an RISC-V system on QEMU" },
+                            { "name": "machine/genericarm64", "description": "Machine configuration for Arm64 SystemReady IR/ES platforms" },
+                            { "name": "machine/genericx86-64", "description": "Machine configuration for generic x86_64 (64-bit) PCs and servers" }
+                        ]
                     },
                     "distro": {
                         "description": "Distribution configuration variants",
-                        "options" : ["distro/poky", "distro/poky-altcfg", "distro/poky-tiny"]
+                        "options" : [
+                            { "name": "distro/poky", "description": "Distro configuration for Poky (Yocto Project Reference Distro)" },
+                            { "name": "distro/poky-altcfg", "description": "Distro configuration for Poky (systemd init manager)" },
+                            { "name": "distro/poky-tiny", "description": "Distro configuration for Poky (optimized for size)" }
+                        ]
                     }
                 },
                 "configurations": [
@@ -852,6 +862,18 @@  They contain the following sections:
    -  ``oe-fragments-one-of`` (*optional*, OpenEmbedded specific): the OpenEmbedded
       fragments to select as part of the build.
 
+      This can one of two formats:
+
+      -  A list of dictionaries with ``name`` and a ``description``,
+         corresponding to respectively the fragments names and fragment
+         descriptions (like in the example above).
+
+      -  A list of fragment names. For example:
+
+         .. code-block:: json
+
+            "options" : ["machine/qemux86-64", "machine/qemuarm64", "machine/qemuriscv64", "machine/genericarm64", "machine/genericx86-64"]
+
       This will trigger choices to make during the
       :ref:`ref-bbsetup-command-init` command execution.
 
diff --git a/setup-schema/bitbake-setup.schema.json b/setup-schema/bitbake-setup.schema.json
index e51fef3b97c..be8772db1b2 100644
--- a/setup-schema/bitbake-setup.schema.json
+++ b/setup-schema/bitbake-setup.schema.json
@@ -64,7 +64,26 @@ 
                                 "type": "array",
                                 "description": "List of BitBake configuration fragments to enable",
                                 "items": {
-                                    "type": "string"
+                                    "oneOf": [
+                                        {
+                                            "type": "string",
+                                            "description": "Configuration fragment name"
+                                        },
+                                        {
+                                            "type": "object",
+                                            "description": "Dictionary of BitBake configuration fragments to enable (with description)",
+                                            "properties": {
+                                                "name": {
+                                                    "type": "string",
+                                                    "description": "Configuration fragment name"
+                                                },
+                                                "description": {
+                                                    "type": "string",
+                                                    "description": "Human-readable description of the fragment"
+                                                }
+                                            }
+                                        }
+                                    ]
                                 }
                             },
                             "oe-fragments-one-of": {