bitbake-setup init improvements
v2 cover bitbake-setup init improvements
Improve the init user experience by:
- Creating the top directory only when we need it (and avoid leaving empty directories behind)
- Print a message when a user sends Ctrl+C
---
Changes in v2:
- In the first patch mention that the top dir was created by chance.
- Add if..else so save_bb_cache() is still called after init.
- Make the sigint handler global, print message based on called
function.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Antonin Godard (3):
bitbake-setup: fix top_dir creation in create_siteconf
bitbake-setup: create top-dir later in init
bitbake-setup: handle ctrl+c
bin/bitbake-setup | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)
---
base-commit: fff23f8ce8f60aba6b89512a734623067661816e
change-id: 20251114-bitbake-setup-abort-8a5333c049ea
PATCH v2 1/3 bitbake-setup: fix top_dir creation in create_siteconf
The intent of the create_siteconf() is to create the site.conf file common to all setups. For this it needs the top directory to be created. Create the top directory instead of its parent.
Previously, this directory was created by chance by init_bb_cache().
--- bin/bitbake-setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
@@ -677,7 +677,7 @@ def create_siteconf(top_dir, non_interactive, settings): if y_or_n != 'y': exit() - os.makedirs(os.path.dirname(top_dir), exist_ok=True) + os.makedirs(top_dir, exist_ok=True) with open(siteconfpath, 'w') as siteconffile: siteconffile.write( textwrap.dedent(
Signature · 1 line
2.51.0
PATCH v2 2/3 bitbake-setup: create top-dir later in init
In reply to Antonin GodardCalling init_bb_cache() before init_config() creates the top-directory already, before the user has accepted to proceed after the first few messages:
Bitbake-setup is using <topdir> as top directory ("bitbake-setup settings --help" shows how to change it).
A common site.conf file will be created, please edit or replace before running builds
<topdir>/site.conf
Proceed? (y/N):
Saying N here would leave an empty top directory which is unexpected.
Move the init_bb_cache() call later in init_config().
--- bin/bitbake-setup | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
bin/bitbake-setup +10 -4
@@ -452,14 +452,16 @@ def obtain_config(top_dir, settings, args, source_overrides, d): upstream_config['skip-selection'] = args.skip_selection return upstream_config -def init_config(top_dir, settings, args, d): +def init_config(top_dir, settings, args): + create_siteconf(top_dir, args.non_interactive, settings) + + d = init_bb_cache(top_dir, settings, args) stdout = sys.stdout def handle_task_progress(event, d): rate = event.rate if event.rate else '' progress = event.progress if event.progress > 0 else 0 print("{}% {} ".format(progress, rate), file=stdout, end='\r') - create_siteconf(top_dir, args.non_interactive, settings) source_overrides = json.load(open(args.source_overrides)) if args.source_overrides else {'sources':{}} upstream_config = obtain_config(top_dir, 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'])))
@@ -898,8 +900,12 @@ def main(): print('Bitbake-setup is using {} as top directory ("bitbake-setup settings --help" shows how to change it).\n'.format(top_dir, global_settings_path(args))) - d = init_bb_cache(top_dir, all_settings, args) - args.func(top_dir, all_settings, args, d) + if args.func == init_config: + init_config(top_dir, all_settings, args) + else: + d = init_bb_cache(top_dir, all_settings, args) + args.func(top_dir, all_settings, args, d) + save_bb_cache() else: from argparse import Namespace
Signature · 1 line
2.51.0
PATCH v2 3/3 bitbake-setup: handle ctrl+c
In reply to Antonin GodardInstead of printing the stack trace, print "Shutting down..." when the user presses Ctrl+C during command executions. Mention that the top-directory's setups might be incomplete if the topdir was already created at this point.
--- bin/bitbake-setup | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
bin/bitbake-setup +17 -0
@@ -17,6 +17,8 @@ import glob import subprocess import copy import textwrap +import signal +import functools default_registry = os.path.normpath(os.path.dirname(__file__) + "/../default-registry")
@@ -783,6 +785,15 @@ def merge_settings(builtin_settings, global_settings, topdir_settings, cmdline_s return all_settings +def sigint_handler(sig, frame, func, top_dir): + print(f'\nShutting down...') + if isinstance(top_dir, str) and os.path.exists(top_dir): + if func in [init_config, build_update]: + print(f'{top_dir} may contain an incomplete setup!') + elif func == install_buildtools: + print(f'{top_dir} may contain an incomplete buildtools installation!') + exit() + def main(): def add_setup_dir_arg(parser): setup_dir = get_setup_dir_via_bbpath()
@@ -888,6 +899,12 @@ def main(): global_settings = load_settings(global_settings_path(args)) top_dir = get_top_dir(args, merge_settings(builtin_settings, global_settings, {}, args.cmdline_settings)) + # register handler now to pass top_dir + _handler = functools.partial(sigint_handler, + func=args.func, + top_dir=os.path.abspath(top_dir)) + signal.signal(signal.SIGINT, _handler) + # This cannot be set with the rest of the builtin settings as top_dir needs to be determined first builtin_settings['default']['dl-dir'] = os.path.join(top_dir, '.bitbake-setup-downloads')
Signature · 1 line
2.51.0
Thanks, v2 lgtm.
Alex
Quoted 37 lines · Antonin Godard via lists.openembedded.org
Improve the init user experience by:
- Creating the top directory only when we need it (and avoid leaving empty directories behind)
- Print a message when a user sends Ctrl+CSigned-off-by Antonin Godard <[email protected]>---
Changes in v2:
- In the first patch mention that the top dir was created by chance.
- Add if..else sosave_bb_cache()is still called after init.
- Make the sigint handler global, print message based on called
function.
- Link to v1: https://lore.kernel.org/r/[email protected]---
Antonin Godard (3):
bitbake-setup: fixtop_dircreation increate_siteconf
bitbake-setup: create top-dir later in init
bitbake-setup: handle ctrl+cbin/bitbake-setup | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)---
base-commit:fff23f8ce8f60aba6b89512a734623067661816e
change-id: 20251114-bitbake-setup-abort-8a5333c049ea-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#18415): https://lists.openembedded.org/g/bitbake-devel/message/18415
Mute This Topic: https://lists.openembedded.org/mt/116334413/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-