Skip to contentSkip to conversation

bitbake-setup: Tweak user inputs

PATCH In review Ryan Eatmon 3 participants 11 messages Sep 12, 2025 – Sep 16, 2025 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 bitbake-setup: Tweak user inputs

Create a common function to get the user input when choosing an item from a list. Add support for not returning from the function until the user has selected a number.

When choosing items from the option list, if there is only one item, then auto select it. This is similar to code when picking the configuration.

---
 bin/bitbake-setup | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
bin/bitbake-setup +18 -6
index dc2de30a8..36103f1e8 100755
@@ -252,6 +252,14 @@ def flatten_bitbake_configs(configs):
                 flattened_configs.append(merge_configs(c, sub_c))
     return flattened_configs
 
+def get_user_input(prompt):
+    choice_s = ''
+    while choice_s.isdigit() == False:
+        print("\n{}:".format(prompt))
+        choice_s = input()
+    choice_n = int(choice_s)
+    return choice_n
+
 def choose_bitbake_config(configs, parameters, non_interactive):
     flattened_configs = flatten_bitbake_configs(configs)
     configs_dict = {i["name"]:i for i in flattened_configs}
@@ -274,8 +282,7 @@ def choose_bitbake_config(configs, parameters, non_interactive):
     print("\nAvailable bitbake configurations:")
     for n, config_data in enumerated_configs:
         print("{}. {}\t{}".format(n, config_data["name"], config_data["description"]))
-    print("\nPlease select one of the above bitbake configurations by its number:")
-    config_n = int(input())
+    config_n = get_user_input('Please select one of the above bitbake configurations by its number')
     return flattened_configs[config_n]
 
 def choose_config(configs, non_interactive):
@@ -298,8 +305,7 @@ def choose_config(configs, non_interactive):
            print("{}. {}\t{} (supported until {})".format(n, config_name, config_desc, expiry_date))
         else:
            print("{}. {}\t{}".format(n, config_name, config_desc))
-    print("\nPlease select one of the above configurations by its number:")
-    config_n = int(input())
+    config_n = get_user_input('Please select one of the above configurations by its number')
     return config_list[config_n][1]
 
 def choose_fragments(possibilities, parameters, non_interactive):
@@ -317,10 +323,16 @@ def choose_fragments(possibilities, parameters, non_interactive):
 
         print("\n" + v["description"] + ":")
         options_enumerated = list(enumerate(v["options"]))
+
+        if len(options_enumerated) == 1:
+            only_config = options_enumerated[0]
+            print("\nSelecting the only available option {}".format(only_config))
+            choices[k] = options_enumerated[only_config[0]][1]
+            continue
+
         for n,o in options_enumerated:
             print("{}. {}".format(n, o))
-        print("\nPlease select one of the above options by its number:")
-        option_n = int(input())
+        option_n = get_user_input('Please select one of the above options by its number')
         choices[k] = options_enumerated[option_n][1]
     return choices
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/3 bitbake-setup: Fix extracting config name

When extracting the config name from from the filename, just splitting on . does not allow for . in the config name. For example:

coresdk-11.01.08-config.json -> coresdk-11

when it should be:

coresdk-11.01.08-config.json -> coresdk-11.01.08-config

os.path.splitext() already does this logic correctly, so use that instead.

---
 bin/bitbake-setup | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
index 36103f1e8..342251bd5 100755
@@ -50,7 +50,7 @@ def save_bb_cache():
     bb.fetch2.fetcher_parse_done()
 
 def get_config_name(config):
-    return os.path.basename(config).split('.')[0]
+    return os.path.splitext(os.path.basename(config))[0]
 
 def write_config(config, config_dir):
     with open(os.path.join(config_dir, "config-upstream.json"),'w') as s:
Signature · 1 line
2.17.1
#2 lore raw

Re: [bitbake-devel] [bitbake][PATCH 2/3] bitbake-setup: Fix extracting config name

Quoted 4 lines · Ryan Eatmon via lists.openembedded.org

When extracting the config name from from the filename, just splitting on . does not allow for . in the config name. For example:

Quoted 8 lines

coresdk-11.01.08-config.json -> coresdk-11

when it should be:

coresdk-11.01.08-config.json -> coresdk-11.01.08-config

os.path.splitext() already does this logic correctly, so use that instead.

The files are explicitly expected to end with .conf.json. Otherwise the tool could potentially pick up unrelated json files in registries. There's probably a missing check for that condition somewhere?

Alex

#3 lore raw

Re: [bitbake-devel] [bitbake][PATCH 2/3] bitbake-setup: Fix extracting config name

Quoted 10 lines · Alexander Kanavin
Quoted 8 lines · Ryan Eatmon via lists.openembedded.org

When extracting the config name from from the filename, just splitting on . does not allow for . in the config name. For example:

coresdk-11.01.08-config.json -> coresdk-11

when it should be:

Quoted 8 lines
Quoted 4 lines

coresdk-11.01.08-config.json -> coresdk-11.01.08-config

os.path.splitext() already does this logic correctly, so use that instead.

The files are explicitly expected to end with .conf.json. Otherwise the tool could potentially pick up unrelated json files in registries. There's probably a missing check for that condition somewhere?

I'll update my code then to remove the .conf.json only then and send a v2.

Quoted 1 line

Alex

Signature · 3 lines
Ryan Eatmon                [email protected]
-----------------------------------------
Texas Instruments, Inc.  -  LCPD  -  MGTS
#4 lore raw

Re: [bitbake-devel] [bitbake][PATCH 2/3] bitbake-setup: Fix extracting config name

Quoted 5 lines · Ryan Eatmon
Quoted 3 lines

The files are explicitly expected to end with .conf.json. Otherwise the tool could potentially pick up unrelated json files in registries. There's probably a missing check for that condition somewhere?

I'll update my code then to remove the .conf.json only then and send a v2.

Thanks, I've already fixed this locally. Files with . in them should work now.

def get_config_name(config):

-    return os.path.basename(config).split('.')[0]
+    suffix = '.conf.json'
+    config_file = os.path.basename(config)
+    if config_file.endswith(suffix):

+ return config_file[:-len(suffix)]
+ else:
+ raise Exception("Config file {} does not end with
{}".format(config, suffix))

Alex

#5 lore raw

PATCH 3/3 bitbake-setup: Add --build-dir-style to init

In reply to Ryan Eatmon

To allow for user control over the name of the build directory, add a new command line argument to the init function that allows you to choose from a list of options:

flat    - <config>-<opt1>-<opt2>-...-<optn>
hier    - <config>/<opt1>/<opt2>/.../<optn>
config  - <config>

options - <opt1>-<opt2>-...-<optn>

Where the <opt#> is the sequence of option choices configured in the json file.

---
 bin/bitbake-setup | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
bin/bitbake-setup +10 -1
index 342251bd5..cce9dcc70 100755
@@ -386,7 +386,15 @@ def init_config(settings, args, d):
     upstream_config = obtain_config(settings, args, source_overrides, d)
     print("\nRun 'bitbake-setup init --non-interactive {}' to select this configuration non-interactively.\n".format(" ".join(upstream_config['non-interactive-cmdline-options'])))
 
-    builddir = os.path.join(os.path.abspath(args.top_dir), "{}-{}".format(upstream_config['name']," ".join(upstream_config['non-interactive-cmdline-options'][1:]).replace(" ","-").replace("/","_")))
+    if args.build_dir_style == "hier":
+        builddir = os.path.join(os.path.abspath(args.top_dir), "{}/{}".format(upstream_config['name'],"*slash*".join(upstream_config['non-interactive-cmdline-options'][1:]).replace(" ","-").replace("/","_").replace("*slash*","/")))
+    elif args.build_dir_style == "config":
+        builddir = os.path.join(os.path.abspath(args.top_dir), "{}".format(upstream_config['name']))
+    elif args.build_dir_style == "options":
+        builddir = os.path.join(os.path.abspath(args.top_dir), "{}".format(" ".join(upstream_config['non-interactive-cmdline-options'][1:]).replace(" ","-").replace("/","_")))
+    else:
+        builddir = os.path.join(os.path.abspath(args.top_dir), "{}-{}".format(upstream_config['name']," ".join(upstream_config['non-interactive-cmdline-options'][1:]).replace(" ","-").replace("/","_")))
+
     if os.path.exists(builddir):
         print("Build already initialized in {}\nUse 'bitbake-setup status' to check if it needs to be updated or 'bitbake-setup update' to perform the update.".format(builddir))
         return
@@ -749,6 +757,7 @@ def main():
     parser_init.add_argument('config', nargs='*', help="path/URL/id to a configuration file (use 'list' command to get available ids), followed by configuration options. Bitbake-setup will ask to choose from available choices if command line doesn't completely specify them.")
     parser_init.add_argument('--non-interactive', action='store_true', help='Do not ask to interactively choose from available options; if bitbake-setup cannot make a decision it will stop with a failure.')
     parser_init.add_argument('--source-overrides', action='store', help='Override sources information (repositories/revisions) with values from a local json file.')
+    parser_init.add_argument('--build-dir-style', action='store', default='flat', choices=['flat','hier','config','options'], help='Style to use for assembling the path to the build directory.  Default is flat.')
     parser_init.set_defaults(func=init_config)
 
     parser_status = subparsers.add_parser('status', help='Check if the build needs to be synchronized with configuration')
Signature · 1 line
2.17.1
#6 lore raw

Re: [bitbake-devel] [bitbake][PATCH 3/3] bitbake-setup: Add --build-dir-style to init

Quoted 5 lines · Ryan Eatmon via lists.openembedded.org

To allow for user control over the name of the build directory, add a new command line argument to the init function that allows you to choose from a list of options:

Quoted 7 lines
flat    - <config>-<opt1>-<opt2>-...-<optn>
hier    - <config>/<opt1>/<opt2>/.../<optn>
config  - <config>

options - <opt1>-<opt2>-...-<optn>

Where the <opt#> is the sequence of option choices configured in the json file.

I'm afraid it's not quite this simple for the hier option. There are places elsewhere in code that potentially assume a flat hierarchy (e.g. site.conf linkage, finding where the top dir is etc.), so this does need at least a bit of testing via the bitbake-setup test added to bitbake-selftest.

For the 'config' and 'options' styles, I'd just replace them with explicit --build-dir-name=<name> option which will just let users specify whatever they like.

Alex

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [bitbake-devel] [bitbake][PATCH 3/3] bitbake-setup: Add --build-dir-style to init

Quoted 3 lines · Alexander Kanavin via lists.openembedded.org

For the 'config' and 'options' styles, I'd just replace them with explicit --build-dir-name=<name> option which will just let users specify whatever they like.

This was trivial to add, so I just went and did it. Will arrive in the usual weekly rollup of fixes (or I will push to github at some point after looking at some other requests I'm getting).

Alex

#9 lore raw
In reply to Ryan Eatmon
Quoted 10 lines · Ryan Eatmon via lists.openembedded.org

Create a common function to get the user input when choosing an item from a list. Add support for not returning from the function until the user has selected a number.

When choosing items from the option list, if there is only one item, then auto select it. This is similar to code when picking the configuration.

---

Hi Ryan,

Thanks for your patches.

I suspect one of them is responsible of this error we got on the autobuilder:

FAIL: test_setup (bb.tests.setup.BitbakeSetupTest.test_setup)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/srv/pokybuild/yocto-worker/oe-selftest-armhost/build/bitbake/lib/bb/tests/setup.py", line 222, in test_setup
self.assertIn("test-config-1", json_configs)
AssertionError: 'test-config-1' not found in {'test-config-1.conf': {'description': 'Test configuration'}, 'test-config-2.conf': {'description': 'Test configuration'}}

https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2252
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2324
https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/2469

Can you have a look at this, please?

Thanks,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#10 lore raw
Quoted 12 lines · Mathieu Dubois-Briand
Quoted 10 lines · Ryan Eatmon via lists.openembedded.org

Create a common function to get the user input when choosing an item from a list. Add support for not returning from the function until the user has selected a number.

When choosing items from the option list, if there is only one item, then auto select it. This is similar to code when picking the configuration.

---

Quoted 6 lines

Hi Ryan,

Thanks for your patches.

I suspect one of them is responsible of this error we got on the autobuilder:

Likely it is patch 2/3 bitbake-setup: Fix extracting config name.

It looks like the test is adding configs named:

test-config-1.conf.json
test-config-2.conf.json

And with my patch instead of the config name being the part before the first '.', now it strips just the extension '.json'.

I guess my change needs a little discussion on how we want this part of bitbake-setup to operate. What do we consider the name of a config when extracting it from the file name.

I can update the tests to match my change and submit a v2 if we want to go with my change.

Thoughts?

Quoted 16 lines

FAIL: test_setup (bb.tests.setup.BitbakeSetupTest.test_setup)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/srv/pokybuild/yocto-worker/oe-selftest-armhost/build/bitbake/lib/bb/tests/setup.py", line 222, in test_setup
self.assertIn("test-config-1", json_configs)
AssertionError: 'test-config-1' not found in {'test-config-1.conf': {'description': 'Test configuration'}, 'test-config-2.conf': {'description': 'Test configuration'}}

https://autobuilder.yoctoproject.org/valkyrie/#/builders/48/builds/2252
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2324
https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/2469

Can you have a look at this, please?

Thanks,
Mathieu

Signature · 3 lines
Ryan Eatmon                [email protected]
-----------------------------------------
Texas Instruments, Inc.  -  LCPD  -  MGTS
#11 lore raw
In reply to Ryan Eatmon

bin/bitbake-setup def flatten_bitbake_configs(configs): · line 261

Quoted 7 lines · Ryan Eatmon via lists.openembedded.org
bin/bitbake-setup +7 -0
+def get_user_input(prompt):
+    choice_s = ''
+    while choice_s.isdigit() == False:
+        print("\n{}:".format(prompt))
+        choice_s = input()
+    choice_n = int(choice_s)
+    return choice_n

Thanks, I already have an implementation that also checks that the input is in valid range, and tries to guide the user to input something sensible (not yet pushed):

def int_input(allowed_values):
n = None
while not n:
try:
n = int(input())
except ValueError:
print('Not a valid number, please try again:') continue
if n not in allowed_values:
print('Number {} not one of {}, please try
again:'.format(n, allowed_values))
n = None
return n

bin/bitbake-setup def choose_fragments(possibilities, parameters, non_interactive): · line 331

Quoted 6 lines
bin/bitbake-setup +6 -0
+
+        if len(options_enumerated) == 1:
+            only_config = options_enumerated[0]
+            print("\nSelecting the only available option {}".format(only_config))
+            choices[k] = options_enumerated[only_config[0]][1]
+            continue

This should be fixed in the configuration: move the only option to 'oe-fragments'.

Alex