Skip to contentSkip to conversation

bitbake-setup init improvements

PATCH Superseded Antonin Godard 3 participants 8 messages Nov 14, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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 stops the init with Ctrl+C

---
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 in init

 bin/bitbake-setup | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

---
base-commit: 363e0d34b1cd03d27d1674f9c08da819dfe32dfa
change-id: 20251114-bitbake-setup-abort-8a5333c049ea

#1 lore raw

PATCH 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.

---
 bin/bitbake-setup | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bin/bitbake-setup +1 -1
index 5bbe3c0fce..6410504d4f 100755
@@ -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
#2 lore raw

Re: [bitbake-devel] [PATCH 1/3] bitbake-setup: fix top_dir creation in create_siteconf

bin/bitbake-setup def create_siteconf(top_dir, non_interactive, settings): · line 680

Quoted 2 lines · Antonin Godard via lists.openembedded.org
bin/bitbake-setup +1 -1
-        os.makedirs(os.path.dirname(top_dir), exist_ok=True)
+        os.makedirs(top_dir, exist_ok=True)

Wait. What and where creates the top directory then, if writing the site.conf still succeeds without this change?

Alex

#3 lore raw

Re: [bitbake-devel] [PATCH 1/3] bitbake-setup: fix top_dir creation in create_siteconf

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

bin/bitbake-setup def create_siteconf(top_dir, non_interactive, settings): · line 680

Quoted 2 lines · Antonin Godard via lists.openembedded.org
bin/bitbake-setup +1 -1
-        os.makedirs(os.path.dirname(top_dir), exist_ok=True)
+        os.makedirs(top_dir, exist_ok=True)

Wait. What and where creates the top directory then, if writing the site.conf still succeeds without this change?

I think the directory was being created by accident in init_bb_cache()

Quoted 11 lines

Alex

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

#4 lore raw

PATCH 2/3 bitbake-setup: create top-dir later in init

In reply to Antonin Godard

Calling 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 | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
bin/bitbake-setup +8 -2
index 6410504d4f..3dc46cbbfa 100755
@@ -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,6 +900,10 @@ 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)))
 
+        if args.func == init_config:
+            init_config(top_dir, all_settings, args)
+            return
+
         d = init_bb_cache(top_dir, all_settings, args)
         args.func(top_dir, all_settings, args, d)
         save_bb_cache()
Signature · 1 line
2.51.0
#5 lore raw

Re: [bitbake-devel] [PATCH 2/3] bitbake-setup: create top-dir later in init

bin/bitbake-setup def main(): · line 909

Quoted 9 lines · Antonin Godard via lists.openembedded.org

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)))

bin/bitbake-setup +4 -0
+        if args.func == init_config:
+            init_config(top_dir, all_settings, args)
+            return
+
         d = init_bb_cache(top_dir, all_settings, args)
         args.func(top_dir, all_settings, args, d)
         save_bb_cache()

save_bb_cache() isn't called anymore with this change, so needs to be an if..else block rather, with save_bb_cache() coming just after?

Not sure if that function still does useful things, it's been there since the earliest prototypes so I no longer remember what it does and why.

Alex

#6 lore raw

PATCH 3/3 bitbake-setup: handle ctrl+c in init

In reply to Antonin Godard

Instead of printing the stack trace, print "Shutting down..." when the user presses Ctrl+C during the init. Mention that the top-directory's setups might be incomplete if the topdir was already created.

---
 bin/bitbake-setup | 10 ++++++++++
 1 file changed, 10 insertions(+)
bin/bitbake-setup +10 -0
index 3dc46cbbfa..151cb79cac 100755
@@ -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")
 
@@ -452,7 +454,15 @@ def obtain_config(top_dir, settings, args, source_overrides, d):
     upstream_config['skip-selection'] = args.skip_selection
     return upstream_config
 
+def init_sigint_handler(sig, frame, top_dir):
+    print(f'\nShutting down...')
+    if isinstance(top_dir, str) and os.path.exists(top_dir):
+        print(f'{top_dir} may contain an incomplete setup!')
+    exit()
+
 def init_config(top_dir, settings, args):
+    _handler = functools.partial(init_sigint_handler, top_dir=top_dir)
+    signal.signal(signal.SIGINT, _handler)
     create_siteconf(top_dir, args.non_interactive, settings)
 
     d = init_bb_cache(top_dir, settings, args)
Signature · 1 line
2.51.0
#7 lore raw

Re: [bitbake-devel] [PATCH 3/3] bitbake-setup: handle ctrl+c in init

Since other functions may also become interactive (e.g. update prompting the user if files in build/conf/ should be replaced), shouldn't this be installed as a generic handler in main()?

Alex

Quoted 52 lines · Antonin Godard via lists.openembedded.org

Instead of printing the stack trace, print "Shutting down..." when the user presses Ctrl+C during the init. Mention that the top-directory's setups might be incomplete if the topdir was already created.

---
 bin/bitbake-setup | 10 ++++++++++
 1 file changed, 10 insertions(+)
bin/bitbake-setup +10 -1
index 3dc46cbbfa..151cb79cac 100755
@@ -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")
 
@@ -452,7 +454,15 @@ def obtain_config(top_dir, settings, args, source_overrides, d):
     upstream_config['skip-selection'] = args.skip_selection
     return upstream_config
 
+def init_sigint_handler(sig, frame, top_dir):
+    print(f'\nShutting down...')
+    if isinstance(top_dir, str) and os.path.exists(top_dir):
+        print(f'{top_dir} may contain an incomplete setup!')
+    exit()
+
 def init_config(top_dir, settings, args):
+    _handler = functools.partial(init_sigint_handler, top_dir=top_dir)
+    signal.signal(signal.SIGINT, _handler)
     create_siteconf(top_dir, args.non_interactive, settings)
 
     d = init_bb_cache(top_dir, settings, args)
 
--

2.51.0

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