| Message ID | 20251114-bitbake-setup-conf-updates-v1-2-990583d8251b@bootlin.com |
|---|---|
| State | Not Applicable |
| Headers | show |
| Series | bitbake-setup: update: add a --update-bb-conf option | expand |
On Fri Nov 14, 2025 at 5:44 PM CET, Antonin Godard via lists.yoctoproject.org wrote: > 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. > > Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> > --- > lib/bb/tests/setup.py | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py > index 58049c8c7a..b4258f0492 100644 > --- a/lib/bb/tests/setup.py > +++ b/lib/bb/tests/setup.py > @@ -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() 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
On Mon, 17 Nov 2025 at 13:08, Mathieu Dubois-Briand via lists.yoctoproject.org <mathieu.dubois-briand=bootlin.com@lists.yoctoproject.org> wrote: > 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? I think it should be a simple change to read the file content, and feed that into hashlib. Alex
diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py index 58049c8c7a..b4258f0492 100644 --- a/lib/bb/tests/setup.py +++ b/lib/bb/tests/setup.py @@ -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)
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. Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> --- lib/bb/tests/setup.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)