diff mbox series

[v3,3/3] lib/bb/tests/setup.py: add tests for oe-fragments-one-of

Message ID 20260122-bitbake-setup-choose-builtin-v3-3-c55291acc1a7@bootlin.com
State Not Applicable
Headers show
Series bitbake-setup: add descriptions for fragment choices | expand

Commit Message

Antonin Godard Jan. 22, 2026, 3:02 p.m. UTC
There were no tests of oe-fragments-one-of so add a new configuration
for it, and test both formats for the options (with or without a
description).

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 lib/bb/tests/setup.py | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

Comments

Alexander Kanavin Jan. 22, 2026, 5:54 p.m. UTC | #1
On Thu, 22 Jan 2026 at 16:02, Antonin Godard <antonin.godard@bootlin.com> wrote:
> +            },
> +            {
> +                "name": "gizmo-fragments-one-of",
> +                "description": "Gizmo configuration using oe-fragments-one-of, both formats",
> +                "oe-template": "test-configuration-gizmo",
> +                "oe-fragments-one-of": {
> +                    "fragment-desc": {
> +                        "description": "Test fragments (with description)",
> +                        "options" : [
> +                            { "name": "fragment-desc-1", "description": "fragment 1 desc" }
> +                        ]
> +                    },
> +                    "fragment-nodesc": {
> +                        "description": "Test fragments (no description)",
> +                        "options" : [
> +                            "fragment-nodesc-1"
> +                        ]
> +                    }
> +                }

To avoid multiplying test configs further (and making the tests
slower), perhaps this can be added to gizmo-notemplate, and that
renamed to gizmo-notemplate-fragments-one-of ?

> -                                                                 'gadget-notemplate','gizmo-notemplate')},
> +                                                                 'gadget-notemplate',
> +                                                                 'gizmo-notemplate',
> +                                                                 'gizmo-fragments-one-of fragment-desc-1 fragment-nodesc-1')},

As there's only one choice in each, bitbake-setup should pick that
without asking, or having to specify them on command line. Let's test
that too, and drop the fragment names from here.

Alex
Antonin Godard Jan. 23, 2026, 8:34 a.m. UTC | #2
Hi,

On Thu Jan 22, 2026 at 6:54 PM CET, Alexander Kanavin via lists.yoctoproject.org wrote:
> On Thu, 22 Jan 2026 at 16:02, Antonin Godard <antonin.godard@bootlin.com> wrote:
>> +            },
>> +            {
>> +                "name": "gizmo-fragments-one-of",
>> +                "description": "Gizmo configuration using oe-fragments-one-of, both formats",
>> +                "oe-template": "test-configuration-gizmo",
>> +                "oe-fragments-one-of": {
>> +                    "fragment-desc": {
>> +                        "description": "Test fragments (with description)",
>> +                        "options" : [
>> +                            { "name": "fragment-desc-1", "description": "fragment 1 desc" }
>> +                        ]
>> +                    },
>> +                    "fragment-nodesc": {
>> +                        "description": "Test fragments (no description)",
>> +                        "options" : [
>> +                            "fragment-nodesc-1"
>> +                        ]
>> +                    }
>> +                }
>
> To avoid multiplying test configs further (and making the tests
> slower), perhaps this can be added to gizmo-notemplate, and that
> renamed to gizmo-notemplate-fragments-one-of ?

Sure

>> -                                                                 'gadget-notemplate','gizmo-notemplate')},
>> +                                                                 'gadget-notemplate',
>> +                                                                 'gizmo-notemplate',
>> +                                                                 'gizmo-fragments-one-of fragment-desc-1 fragment-nodesc-1')},
>
> As there's only one choice in each, bitbake-setup should pick that
> without asking, or having to specify them on command line. Let's test
> that too, and drop the fragment names from here.

I tried that with the following modified configuration:

{
    "name": "gizmo-notemplate-fragments-one-of",
    "description": "Gizmo notemplate configuration",
    "bb-layers": ["layerC","layerD/meta-layer"],
    "oe-fragments": ["test-fragment-2"],
    "oe-fragments-one-of": {
        "fragment-desc": {
            "description": "Test fragments (with description)",
            "options" : [
                { "name": "fragment-desc-1", "description": "fragment 1 desc" }
            ]
        },
        "fragment-nodesc": {
            "description": "Test fragments (no description)",
            "options" : [
                "fragment-nodesc-1"
            ]
        }
    }
},

But I'm hitting:

bb.process.ExecutionError: Execution of '/bitbake/bin/bitbake-setup --global-settings /tmp/bitbake-fetch-q1wqa8zi/global-config init --non-interactive test-config-1 gizmo-notemplate-fragments-one-of' failed with exit code 1:
Traceback (most recent call last):
  File "/bitbake/bin/bitbake-setup", line 1320, in <module>
    main()
  File "/bitbake/bin/bitbake-setup", line 1310, in main
    init_config(top_dir, all_settings, args)
  File "/bitbake/bin/bitbake-setup", line 767, in init_config
    upstream_config = obtain_config(top_dir, settings["default"]["registry"], args, source_overrides, d)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/bitbake/bin/bitbake-setup", line 586, in obtain_config
    upstream_config['bitbake-config']['oe-fragment-choices'] = choose_fragments(upstream_config['bitbake-config'].get('oe-fragments-one-of',{}), config_parameters[1:], args.non_interactive, args.skip_selection)
                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/bitbake/bin/bitbake-setup", line 534, in choose_fragments
    raise Exception(f"Unable to choose from options in non-interactive mode: {[o['name'] for o in options]}")
Exception: Unable to choose from options in non-interactive mode: ['fragment-desc-1']

So just after:

        # options can be a list of strings or a list of dicts
        options = v["options"]
        if len(options) > 0 and isinstance(v["options"][0], str):
            options = [{"name": o, "description": ""} for o in v["options"]]

I added:

        if len(options) == 1:
            choices[k] = options[0]["name"]
            continue

which seems to accomplish what you had in mind.

However this makes the setup dir name "non-predictable" and I hit the following
next error:

Traceback (most recent call last):
  File "/bitbake/lib/bb/tests/setup.py", line 357, in test_setup
    self.check_setupdir_files(setuppath, test_file_content)
  File "/bitbake/lib/bb/tests/setup.py", line 224, in check_setupdir_files
    with open(os.path.join(setuppath, 'config', "config-upstream.json")) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/bitbake-fetch-9d85c0us/bitbake-builds/test-config-1-gizmo-notemplate-fragments-one-of/config/config-upstream.json'

which is due to the setup directory name containing the fragment choices (even
if none were passed on the command-line).

$ ls -l /tmp/bitbake-fetch-atck07q2/bitbake-builds
...
drwxr-xr-x    - builder 23 Jan 08:22 test-config-1-gizmo-notemplate-fragments-one-of-fragment-desc-1-fragment-nodesc-1

So I added:

                "setup-dir-name": "gizmo-notemplate-fragments-one-of",

To make sure we get a fixed name for this configuration. Sounds good to you?

Antonin
Alexander Kanavin Jan. 23, 2026, 11:09 a.m. UTC | #3
On Fri, 23 Jan 2026 at 09:34, Antonin Godard <antonin.godard@bootlin.com> wrote:
> >> -                                                                 'gadget-notemplate','gizmo-notemplate')},
> >> +                                                                 'gadget-notemplate',
> >> +                                                                 'gizmo-notemplate',
> >> +                                                                 'gizmo-fragments-one-of fragment-desc-1 fragment-nodesc-1')},
> >
> > As there's only one choice in each, bitbake-setup should pick that
> > without asking, or having to specify them on command line. Let's test
> > that too, and drop the fragment names from here.

After reading your response, I retract this suggestion. The reason
bitbake-setup is not automatically picking up a single choice is
because such configuration doesn't make sense: if someone makes
oe-fragments-one-of with a single choice, they should just add that
choice to oe-fragments.

That said, we still need to test oe-fragments-one-of, so can you place
two choices to each (old syntax, new syntax), and supply the
selections on command line, as you've already done? The non-active
fragment can be entirely bogus and non-existing.

Alex
diff mbox series

Patch

diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py
index 834d098547c..eaada3ce1e7 100644
--- a/lib/bb/tests/setup.py
+++ b/lib/bb/tests/setup.py
@@ -146,6 +146,25 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                 "bb-layers": ["layerC","layerD/meta-layer"],
                 "bb-layers-file-relative": ["layerE/meta-layer"],
                 "oe-fragments": ["test-fragment-2"]
+            },
+            {
+                "name": "gizmo-fragments-one-of",
+                "description": "Gizmo configuration using oe-fragments-one-of, both formats",
+                "oe-template": "test-configuration-gizmo",
+                "oe-fragments-one-of": {
+                    "fragment-desc": {
+                        "description": "Test fragments (with description)",
+                        "options" : [
+                            { "name": "fragment-desc-1", "description": "fragment 1 desc" }
+                        ]
+                    },
+                    "fragment-nodesc": {
+                        "description": "Test fragments (no description)",
+                        "options" : [
+                            "fragment-nodesc-1"
+                        ]
+                    }
+                }
             }
         ]
     },
@@ -258,7 +277,7 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
     def get_setup_path(self, cf, c):
         if c == 'gizmo':
             return os.path.join(self.tempdir, 'bitbake-builds', 'this-is-a-custom-gizmo-build')
-        return os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, c))
+        return os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, "-".join(c.split())))
 
     def test_setup(self):
         # unset BBPATH to ensure tests run in isolation from the existing bitbake environment
@@ -328,7 +347,9 @@  print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                                                  'buildconfigs':('gadget','gizmo',
                                                                  'gizmo-env-passthrough',
                                                                  'gizmo-no-fragment',
-                                                                 'gadget-notemplate','gizmo-notemplate')},
+                                                                 'gadget-notemplate',
+                                                                 'gizmo-notemplate',
+                                                                 'gizmo-fragments-one-of fragment-desc-1 fragment-nodesc-1')},
                                'test-config-2': {'cmdline': os.path.join(self.registrypath,'config-2/test-config-2.conf.json'),
                                                  'buildconfigs': ('gadget','gizmo',
                                                                   'gizmo-env-passthrough',