Skip to contentSkip to conversation

bitbake-setup: update: add a --update-bb-conf option

PATCH Superseded Antonin Godard 3 participants 7 messages Nov 14, 2025 – Nov 17, 2025 1 message not in the archive

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover bitbake-setup: update: add a --update-bb-conf option

---
Antonin Godard (2):

      bitbake-setup: update: add a --update-bb-conf option
      bitbake-selftest: setup: add test for --update-bb-conf=no
 bin/bitbake-setup                                  | 28 +++++++++++----
 .../bitbake-user-manual-environment-setup.rst      |  8 +++++
 lib/bb/tests/setup.py                              | 41 ++++++++++++++++++++--
 3 files changed, 67 insertions(+), 10 deletions(-)

---
base-commit: 1949f6afed0e21758006aa8a7339ebc0f7b5b963
change-id: 20251114-bitbake-setup-conf-updates-91ae4efa86ae

#1 lore raw

PATCH 1/2 bitbake-setup: update: add a --update-bb-conf option

Add a --update-bb-conf option that can be used to choose whether to update the BitBake configuration files (local.conf, bblayers.conf, etc.) in the conf/ directory.

The argument can take up to three values:

-  ``prompt`` (default): ask the user whether to update.
-  ``yes``: update the configuration files.
-  ``no``: don't update the configuration files.
---
 bin/bitbake-setup                                  | 28 ++++++++++++++++------
 .../bitbake-user-manual-environment-setup.rst      |  8 +++++++
 lib/bb/tests/setup.py                              |  6 ++---
 3 files changed, 32 insertions(+), 10 deletions(-)
bin/bitbake-setup +21 -7
index 5a9dde5c92..3e711f5cd7 100755
@@ -291,7 +291,7 @@ def get_registry_config(registry_path, id):
                 return os.path.join(root, f)
     raise Exception("Unable to find {} in available configurations; use 'list' sub-command to see what is available".format(id))
 
-def update_build(config, confdir, setupdir, layerdir, d):
+def update_build(config, confdir, setupdir, layerdir, d, update_bb_conf="prompt"):
     layer_config = copy.deepcopy(config["data"]["sources"])
     layer_overrides = config["source-overrides"]["sources"]
     for k,v in layer_overrides.items():
@@ -300,7 +300,18 @@ def update_build(config, confdir, setupdir, layerdir, d):
     sources_fixed_revisions = checkout_layers(layer_config, layerdir, d)
     bitbake_config = config["bitbake-config"]
     thisdir = os.path.dirname(config["path"]) if config["type"] == 'local' else None
-    setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir)
+
+    if update_bb_conf == "prompt":
+        print(f'bitbake-setup can update the BitBake configuration in {setupdir}/conf')
+        print('This means updating the local.conf, bblayers.conf, and other files in this directory.')
+        print('A backup will be created for the existing files.')
+        y_or_n = input('Proceed to update? (y/N): ')
+        if y_or_n == 'y':
+            update_bb_conf = 'yes'
+
+    if update_bb_conf == "yes":
+        setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir)
+
     write_sources_fixed_revisions(confdir, sources_fixed_revisions)
 
 def int_input(allowed_values):
@@ -514,7 +525,7 @@ def init_config(top_dir, settings, args):
     bb.event.register("bb.build.TaskProgress", handle_task_progress, data=d)
 
     write_upstream_config(confdir, upstream_config)
-    update_build(upstream_config, confdir, setupdir, layerdir, d)
+    update_build(upstream_config, confdir, setupdir, layerdir, d, update_bb_conf="yes")
     commit_config(confdir)
 
     bb.event.remove("bb.build.TaskProgress", None)
@@ -556,7 +567,7 @@ def are_layers_changed(layers, layerdir, d):
 
     return changed
 
-def build_status(top_dir, settings, args, d, update=False):
+def build_status(top_dir, settings, args, d, update=False, update_bb_conf="prompt"):
     setupdir = args.setup_dir
 
     confdir = os.path.join(setupdir, "config")
@@ -576,21 +587,23 @@ def build_status(top_dir, settings, args, d, update=False):
     if config_diff:
         print('\nConfiguration in {} has changed:\n{}'.format(setupdir, config_diff))
         if update:
+            update_build(new_upstream_config, confdir, setupdir, layerdir, d,
+                         update_bb_conf=update_bb_conf)
             commit_config(confdir)
-            update_build(new_upstream_config, confdir, setupdir, layerdir, d)
         else:
             bb.process.run('git -C {} restore config-upstream.json'.format(confdir))
         return
 
     if are_layers_changed(current_upstream_config["data"]["sources"], layerdir, d):
         if update:
-            update_build(current_upstream_config, confdir, setupdir, layerdir, d)
+            update_build(current_upstream_config, confdir, setupdir, layerdir, d,
+                         update_bb_conf=update_bb_conf)
         return
 
     print("\nConfiguration in {} has not changed.".format(setupdir))
 
 def build_update(top_dir, settings, args, d):
-    build_status(top_dir, settings, args, d, update=True)
+    build_status(top_dir, settings, args, d, update=True, update_bb_conf=args.update_bb_conf)
 
 def do_fetch(fetcher, dir):
     # git fetcher simply dumps git output to stdout; in bitbake context that is redirected to temp/log.do_fetch
@@ -844,6 +857,7 @@ def main():
 
     parser_update = subparsers.add_parser('update', help='Update a setup to be in sync with configuration')
     add_setup_dir_arg(parser_update)
+    parser_update.add_argument('--update-bb-conf', choices=['prompt', 'yes', 'no'], default='prompt', help='Update bitbake configuration files (bblayers.conf, local.conf) (default: prompt)')
     parser_update.set_defaults(func=build_update)
 
     parser_install_buildtools = subparsers.add_parser('install-buildtools', help='Install buildtools which can help fulfil missing or incorrect dependencies on the host machine')
doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst +8 -0
index 3193952972..dd8d08877f 100644
@@ -401,6 +401,14 @@ status of the :term:`Setup` before updating it.
 
 In addition, the command can take the following arguments:
 
+-  ``--update-bb-conf``: whether to update the :term:`BitBake Build`
+   configuration (``local.conf``, ``bblayers.conf``, etc.). This argument can
+   take up to three values:
+
+   -  ``prompt`` (default): ask the user whether to update.
+   -  ``yes``: update the configuration files.
+   -  ``no``: don't update the configuration files.
+
 -  ``--setup-dir``: path to the :term:`Setup` to update. Not required if the
    command is invoked from an initialized BitBake environment that contains
    :term:`BBPATH`.
lib/bb/tests/setup.py +3 -3
index 46834f361e..58049c8c7a 100644
@@ -310,7 +310,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                 os.environ['BBPATH'] = os.path.join(setuppath, 'build')
                 out = self.runbbsetup("status")
                 self.assertIn("Configuration in {} has not changed".format(setuppath), out[0])
-                out = self.runbbsetup("update")
+                out = self.runbbsetup("update --update-bb-conf='yes'")
                 self.assertIn("Configuration in {} has not changed".format(setuppath), out[0])
 
         # install buildtools
@@ -331,7 +331,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
             os.environ['BBPATH'] = os.path.join(setuppath, 'build')
             out = self.runbbsetup("status")
             self.assertIn("Layer repository file://{} checked out into {}/layers/test-repo updated revision master from".format(self.testrepopath, setuppath), out[0])
-            out = self.runbbsetup("update")
+            out = self.runbbsetup("update --update-bb-conf='yes'")
             if c in ('gadget', 'gizmo'):
                 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0])
                 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0])
@@ -355,7 +355,7 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
             out = self.runbbsetup("status")
             self.assertIn("Configuration in {} has changed:".format(setuppath), out[0])
             self.assertIn('-                    "rev": "master"\n+                    "rev": "another-branch"', out[0])
-            out = self.runbbsetup("update")
+            out = self.runbbsetup("update --update-bb-conf='yes'")
             if c in ('gadget', 'gizmo'):
                 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0])
                 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0])
Signature · 1 line
2.51.0
#2 lore raw

bin/bitbake-setup def update_build(config, confdir, setupdir, layerdir, d): · line 313

Quoted 10 lines · Antonin Godard via lists.yoctoproject.org
bin/bitbake-setup +10 -0
+    if update_bb_conf == "prompt":
+        print(f'bitbake-setup can update the BitBake configuration in {setupdir}/conf')
+        print('This means updating the local.conf, bblayers.conf, and other files in this directory.')
+        print('A backup will be created for the existing files.')
+        y_or_n = input('Proceed to update? (y/N): ')
+        if y_or_n == 'y':
+            update_bb_conf = 'yes'
+
+    if update_bb_conf == "yes":
+        setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir)

I don't think this is the proper way to implement the feature. Even if the user answers no, they should still get the new updated config that they can inspect and integrate into their existing one, so rather than ask the question here, it should be asked *inside* setup_bitbake_build(), and only if that function determines that a config already exists. Then, depending on the answer, it either renames the old config, and writes a new one (current behavior), or leaves the current one as it is, and writes the new config into a newly made separate directory. Then there's existing code to compare and diff the directories, so if they turn out identical, the redundant copy is deleted.

Alex

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

#4 lore raw
Quoted 11 lines · Alexander Kanavin via lists.openembedded.org

I don't think this is the proper way to implement the feature. Even if the user answers no, they should still get the new updated config that they can inspect and integrate into their existing one, so rather than ask the question here, it should be asked *inside* setup_bitbake_build(), and only if that function determines that a config already exists. Then, depending on the answer, it either renames the old config, and writes a new one (current behavior), or leaves the current one as it is, and writes the new config into a newly made separate directory. Then there's existing code to compare and diff the directories, so if they turn out identical, the redundant copy is deleted.

Come to think of it, we could do even better:
- write the new config into a temporary directory
- check if a config exists, move into place if it doesn't
- check if a new config is same as existing one, remove the unneeded new copy if so
- if it is not the same, then print the diff, and ask the user if they would like the new config to replace the old one (if the answer is not already given on the command line)
- with either 'yes' or 'no' both old and new configs should be preserved for further inspection

Alex

#5 lore raw

PATCH 2/2 bitbake-selftest: setup: add test for --update-bb-conf=no

In reply to Antonin Godard

We want to check that with --update-bb-conf set to 'no' our BitBake configuration remains unchanged. For this create a list of checksums of the files in conf/ and compare before/after bitbake-setup update --update-bb-conf=no.

---
 lib/bb/tests/setup.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
lib/bb/tests/setup.py +35 -0
index 58049c8c7a..b4258f0492 100644
@@ -6,6 +6,8 @@
 
 from bb.tests.fetch import FetcherTest
 import json
+import hashlib
+import glob
 
 class BitbakeSetupTest(FetcherTest):
     def setUp(self):
@@ -360,3 +362,36 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0])
                 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0])
             self.check_setupdir_files(setuppath, test_file_content)
+
+        # do the same as the previous test, but now without updating the bitbake configuration (--update-bb-conf=no)
+        # and check that files have not been modified
+
+        def _conf_chksum(confdir: str) -> list:
+            sums = []
+            for f in glob.glob(f'{confdir}/*'):
+                if not os.path.islink(f):
+                    with open(f, 'rb') as fd:
+                        sum = os.path.basename(f) + '_' + hashlib.file_digest(fd, "sha256").hexdigest()
+                        sums.append(sum)
+            return sums
+
+        prev_test_file_content = test_file_content
+        test_file_content = 'modified-in-branch-no-bb-conf-update\n'
+        branch = "another-branch-no-bb-conf-update"
+        self.git('checkout -b {}'.format(branch), cwd=self.testrepopath)
+        self.add_file_to_testrepo('test-file', test_file_content)
+        json_1 = self.add_json_config_to_registry('test-config-1.conf.json', branch, branch)
+        for c in ('gadget', 'gizmo',
+                  'gizmo-env-passthrough',
+                  'gizmo-no-fragment',
+                  'gadget-notemplate', 'gizmo-notemplate'):
+            setuppath = os.path.join(self.tempdir, 'bitbake-builds', 'test-config-1-{}'.format(c))
+            os.environ['BBPATH'] = os.path.join(setuppath, 'build')
+            # write something in local.conf and bblayers.conf
+            for f in ["local.conf", "bblayers.conf"]:
+                with open(f"{setuppath}/build/conf/{f}", "w") as fd:
+                    fd.write("deadbeef")
+            sums_before = _conf_chksum(f"{setuppath}/build/conf")
+            out = self.runbbsetup("update --update-bb-conf='no'")
+            sums_after = _conf_chksum(f"{setuppath}/build/conf")
+            self.assertEqual(sums_before, sums_after)
Signature · 1 line
2.51.0
#6 lore raw

Re: [docs] [PATCH 2/2] bitbake-selftest: setup: add test for --update-bb-conf=no

Quoted 27 lines · Antonin Godard via lists.yoctoproject.org

We want to check that with --update-bb-conf set to 'no' our BitBake configuration remains unchanged. For this create a list of checksums of the files in conf/ and compare before/after bitbake-setup update --update-bb-conf=no.

---
 lib/bb/tests/setup.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
lib/bb/tests/setup.py +2 -0
index 58049c8c7a..b4258f0492 100644
@@ -6,6 +6,8 @@
 
 from bb.tests.fetch import FetcherTest
 import json
+import hashlib
+import glob
 
 class BitbakeSetupTest(FetcherTest):
     def setUp(self):
@@ -360,3 +362,36 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"]))
                 self.assertIn("Existing bitbake configuration directory renamed to {}/build/conf-backup.".format(setuppath), out[0])
                 self.assertIn('-{}+{}'.format(prev_test_file_content, test_file_content), out[0])
             self.check_setupdir_files(setuppath, test_file_content)

lib/bb/tests/setup.py print("BBPATH is {{}}".format(os.environ["BBPATH"])) · line 374

Quoted 10 lines
lib/bb/tests/setup.py +10 -0
+
+        # do the same as the previous test, but now without updating the bitbake configuration (--update-bb-conf=no)
+        # and check that files have not been modified
+
+        def _conf_chksum(confdir: str) -> list:
+            sums = []
+            for f in glob.glob(f'{confdir}/*'):
+                if not os.path.islink(f):
+                    with open(f, 'rb') as fd:
+                        sum = os.path.basename(f) + '_' + hashlib.file_digest(fd, "sha256").hexdigest()

Hi Antonin,

hashlib.file_digest was added in python 3.11, so this is failing on some supported distros:

Traceback (most recent call last):
File "/srv/pokybuild/yocto-worker/oe-selftest-debian/build/layers/bitbake/lib/bb/tests/setup.py", line 393, in test_setup
sums_before = _conf_chksum(f"{setuppath}/build/conf")
File "/srv/pokybuild/yocto-worker/oe-selftest-debian/build/layers/bitbake/lib/bb/tests/setup.py", line 373, in _conf_chksum

    sum = os.path.basename(f) + '_' + hashlib.file_digest(fd, "sha256").hexdigest()

AttributeError: module 'hashlib' has no attribute 'file_digest'

https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2707

Can you find some alternative?

Thanks,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#7 lore raw

Re: [docs] [PATCH 2/2] bitbake-selftest: setup: add test for --update-bb-conf=no

Quoted 7 lines · Mathieu Dubois-Briand via lists.yoctoproject.org

hashlib.file_digest was added in python 3.11, so this is failing on some supported distros:

Traceback (most recent call last):
File "/srv/pokybuild/yocto-worker/oe-selftest-debian/build/layers/bitbake/lib/bb/tests/setup.py", line 393, in test_setup
sums_before = _conf_chksum(f"{setuppath}/build/conf")
File "/srv/pokybuild/yocto-worker/oe-selftest-debian/build/layers/bitbake/lib/bb/tests/setup.py", line 373, in _conf_chksum

Quoted 6 lines
    sum = os.path.basename(f) + '_' + hashlib.file_digest(fd, "sha256").hexdigest()

AttributeError: module 'hashlib' has no attribute 'file_digest'

https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/2707

Can you find some alternative?

I think it should be a simple change to read the file content, and feed that into hashlib.

Alex