[PATCH] bitbake-setup: preserve build config when init script is missing
Giancarlo Cicellyn Comneno <[email protected]>
| Newsgroups | org.openembedded.lists.bitbake-devel |
|---|---|
| Message-ID | <[email protected]> |
setup_bitbake_build() moves an existing build/conf aside before checking whether oe-init-build-env is available. If the script disappears between setup and update, the update currently returns without restoring the previous configuration, leaving a freshly generated build/conf in place and reporting success. Check for oe-init-build-env before modifying build/conf and fail explicitly when it is unavailable. Add a regression test verifying that the update fails and preserves the user's local.conf. Tests: LC_ALL=C LANG=C ./bin/bitbake-selftest bb.tests.setup AI-Generated: Uses OpenAI ChatGPT Signed-off-by: Giancarlo Cicellyn Comneno <[email protected]> --- bin/bitbake-setup | 8 +++--- lib/bb/tests/setup.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/bin/bitbake-setup b/bin/bitbake-setup index 34260139c..d214ad568 100755 --- a/bin/bitbake-setup +++ b/bin/bitbake-setup @@ -354,6 +354,10 @@ def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir, update_bb_c if template and not os.path.exists(oesetupbuild): raise Exception("Cannot complete setting up a bitbake build directory from OpenEmbedded template '{}' as oe-setup-build was not found in any layers; please use oe-init-build-env manually.".format(template)) + oeinitbuildenvdir = os.path.join(layerdir, 'oe-init-build-env-dir') + if not template and not os.path.exists(os.path.join(oeinitbuildenvdir, "oe-init-build-env")): + raise Exception("Could not find oe-init-build-env in any of the layers; please use another mechanism to initialize the bitbake environment") + bitbake_confdir = os.path.join(bitbake_builddir, 'conf') backup_bitbake_confdir = add_unique_timestamp_to_path(os.path.join(bitbake_builddir, 'conf-backup')) upstream_bitbake_confdir = add_unique_timestamp_to_path(os.path.join(bitbake_builddir, 'conf-upstream')) @@ -368,10 +372,6 @@ def setup_bitbake_build(bitbake_config, layerdir, setupdir, thisdir, update_bb_c if template: bb.process.run([oesetupbuild, "setup", "-c", template, "-b", bitbake_builddir, "--no-shell"]) else: - oeinitbuildenvdir = os.path.join(layerdir, 'oe-init-build-env-dir') - if not os.path.exists(os.path.join(oeinitbuildenvdir, "oe-init-build-env")): - logger.error("Could not find oe-init-build-env in any of the layers; please use another mechanism to initialize the bitbake environment") - return _make_init_build_env(bitbake_builddir, os.path.realpath(oeinitbuildenvdir)) _prepend_passthrough_to_init_build_env(bitbake_builddir) diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py index 53a07ee3a..ab18abd0a 100644 --- a/lib/bb/tests/setup.py +++ b/lib/bb/tests/setup.py @@ -578,6 +578,63 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) out = self.runbbsetup(["init", "--non-interactive", "-L", "test-repo", self.testrepopath, "--setup-dir-name", custom_setup_dir, "test-config-1", "gadget"]) _check_local_sources(custom_setup_dir) + def test_update_preserves_build_conf_when_init_build_env_missing(self): + if 'BBPATH' in os.environ: + del os.environ['BBPATH'] + os.chdir(self.tempdir) + + self.runbbsetup([ + "settings", "set", "default", "registry", + "'git://{};protocol=file;branch=master;rev=master'".format( + self.registrypath + ), + ]) + self.add_file_to_testrepo('test-file', 'initial\n') + self.add_json_config_to_registry( + 'test-config-1.conf.json', 'master', 'master' + ) + + self.runbbsetup([ + "init", + "--non-interactive", + "test-config-1", + "gadget-notemplate", + ]) + + setuppath = self.get_setup_path( + 'test-config-1', 'gadget-notemplate' + ) + local_conf = os.path.join( + setuppath, 'build', 'conf', 'local.conf' + ) + + user_content = 'USER_SETTING = "preserve-me"\n' + with open(local_conf, 'w') as f: + f.write(user_content) + + os.remove(os.path.join(self.testrepopath, 'oe-init-build-env')) + self.git(['add', '-u'], cwd=self.testrepopath) + self.git( + ['commit', '-m', 'Remove oe-init-build-env'], + cwd=self.testrepopath, + ) + + os.environ['BBPATH'] = os.path.join(setuppath, 'build') + try: + with self.assertRaisesRegex( + bb.process.ExecutionError, + "Could not find oe-init-build-env", + ): + self.runbbsetup([ + "update", + "--update-bb-conf=yes", + ]) + finally: + del os.environ['BBPATH'] + + with open(local_conf) as f: + self.assertEqual(f.read(), user_content) + def test_vscode(self): if 'BBPATH' in os.environ: del os.environ['BBPATH'] -- 2.43.0