From patchwork Fri Dec 4 23:03:58 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Giancarlo Cicellyn Comneno X-Patchwork-Id: 107485 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.4480.1796425448698702467 for ; Fri, 04 Dec 2026 15:04:09 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20260707 header.b=iRqLR4nu; spf=pass (domain: gmail.com, ip: 209.85.128.54, mailfrom: giancarlo.cicellyn@gmail.com) Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4a1fbd52ab6so10375365e9.0 for ; Fri, 04 Dec 2026 15:04:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796425447; x=1797030247; darn=lists.openembedded.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xD5v5CVNPhpRyXE61PrvPQjbHwN4RBPJo3NrRhpinPY=; b=iRqLR4nurkPLco/M4bP+WK6Ceo9PuCLAg8pUKbGgJ9C4PyQG00XQN1JnMzICXHe9Pw euW0cfvwFxH3DKvqknlnz8zwd5P8Mj/zZ5v/N4DTyHkluUCXB45E2zOCAiVSy/8ucicf 7uUIecE4/A5tAVTAfgWbWazanghHV2SIa5dkYUL3/IwQnRjoLEuNFtYZUFQNl+nnDdGP 373cr+b4U4058ualXFVU/B4ihwYt5x+04TT0nYKB2HH3Hu4Ms91o4jYubGbkhl/UkLcs SrgUutO8CXhMmPswTLQMRRVGqeb3XgKAYnHeer7Xge0FrhIQISRqfIuEpQqz17/4rjso Wv4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796425447; x=1797030247; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=xD5v5CVNPhpRyXE61PrvPQjbHwN4RBPJo3NrRhpinPY=; b=O1T5jdLK24cTZu9X/IotNtFVP+drdYsyuenpeE8R/iS7O+v+6x83WFIq5fYqPEwF5C 2BHj8pUWWCrF63MKMnDFz97URAw3aFg8WceI934/Fu38GG5RjufN3XGvs5+Q/QsoQSh6 Yd/QG3uVt7NtewyHFsIkVle2DlpU49lOhPxfqbroqHzuOa+nqsqy1hNT/CjEoLCxYVh8 d2DUFCPK2QTN8gnsp95KNgGVSQWuvF7bjyLIoio8HmGIst0RUK8DttyaS/mz+HZTWl4C g63ZbjaZkWa9ct/ejJa2WTmnLEYMNDO8lYdF+yDIxw44Q4lF6XobqjMaeEBdLt5HXAj/ hvMQ== X-Gm-Message-State: APuU4Z/FSB5akj1rR3NZxBUkqYOywWoeDuzYIOK6ejQIF8Fc/mPAkDIl PRCddo4frMMei64C2xReqED+VgqC1dTRQqOL5EfHANq4RbZJAw+v4vvCCaViiEFw X-Gm-Gg: AZFdTZd8qa3HsaXArVNDgBHEdj3+jRCuMYStSgH/pMMNWFPLzQC12DtbwmDR+djhAQx bS7IFjZmTmzVnP2Y0cf7sCgPmJUnV8AlpDebK6gUwUpqsCy4W28hBZDajE4yHv2w1xgek/eV4s4 y4oinPgiQj2wTPCOvf+4v5v/lcYyLCXfPmK5NFBY8EsmNdO48gXcURzf6jNvsSA+BADL6q1FxAU TmqH+PvXBS5hk5c5VnB5TMFCCLRTpvXcNC/7vEb2G9tBaZvmGutfHiMehyx/aWk+dHhGwmllM2W oGte3AThiSRduo5JIPUMaPB39NG0cVaFl9WO04He2UV0wuts79CZZ1mPA1nb3pXXX/uZHJ8peIR gN01/t9T9JB8/tKjMhoxbeLbllEtIqbumXS9/hx/ytRQIkTMnR+EHIN/AmSUM0iLS1Z0HEXtae9 H0kkifAPRloD9m00XtfNQvGclQ4BPEOi0Xev20d3BzywUcm8UUvkY4511nlv9/u3QTlkc/WswXQ DNN3XfCLhFfmQONWwaHbX4Q/vcVVKTxPcwI3euimWzcvqLPlOQwz1Hms/euN3wFLgweQtc3W61q BhPql0AdPQsqPfUqv8gtD7MTKRFOJ1HJ9vGcLX/LtzgR7pgQCC5NMw61EySFsFwRibFbvARZ/2C rO2s9V1dbzUcXwhsAqG9UYB61DTeuXd8kIuvoVZvRrJ8dwHocZKwnPcvMxMWAvGiS6PZS6j31Bl FxJ56Ioe37qwF1v4huvNQCI0fMRDLz1SBsbuzLcgQ2Ncn+c5lOn3gVHkpoIKlGsqdO5Lir0w== X-Received: by 2002:a05:600c:34d2:b0:4a1:fae5:f2e2 with SMTP id 5b1f17b1804b1-4bbeb6ef054mr68963945e9.4.1796425447017; Fri, 04 Dec 2026 15:04:07 -0800 (PST) Return-Path: Received: from no-one-server (93-45-68-55.ip101.fastwebnet.it. [93.45.68.55]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbf1703f80sm12208645e9.1.2026.12.04.15.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 15:04:06 -0800 (PST) From: Giancarlo Cicellyn Comneno To: bitbake-devel@lists.openembedded.org Cc: Giancarlo Cicellyn Comneno Subject: [PATCH] bitbake-setup: support exporting configuration templates as JSON Date: Sat, 5 Dec 2026 00:03:58 +0100 Message-ID: <20261204230358.533865-1-giancarlo.cicellyn@gmail.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Fri, 04 Dec 2026 23:04:17 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/bitbake-devel/message/20531 The list command can export registry metadata as JSON, but does not provide the contents of an individual configuration template. External tools therefore cannot inspect its configuration and fragment choices without initializing a setup or duplicating registry fetching logic. Add a --config option to list, requiring --write-json, to export the complete selected template using the existing registry acquisition and lookup functions. Respect the existing expiration filter and ensure temporary registry directories are removed on failure as well as on success. Preserve the existing list output and leave the init workflow unchanged. Add offline tests covering template export, expiration filtering, error handling, cleanup and compatibility with existing list output. Validation: LC_ALL=C BB_SKIP_NETTESTS=yes bin/bitbake-selftest bb.tests.setup 19 tests run, 11 passed, 8 skipped. AI-Generated: Uses OpenAI Codex (gpt-6.1-sol) AI-Generated: Uses OpenAI ChatGPT (GPT-6.2) Signed-off-by: Giancarlo Cicellyn Comneno --- bin/bitbake-setup | 32 ++++- .../bitbake-user-manual-environment-setup.rst | 4 + lib/bb/tests/setup.py | 136 ++++++++++++++++++ 3 files changed, 167 insertions(+), 5 deletions(-) diff --git a/bin/bitbake-setup b/bin/bitbake-setup index 6b02558cc..99d67ad88 100755 --- a/bin/bitbake-setup +++ b/bin/bitbake-setup @@ -1030,11 +1030,29 @@ def list_registry(registry_path, with_expired): def list_configs(settings, args): import tempfile top_dir = tempfile.mkdtemp(prefix="bitbake-setup-list-") - settings['default']['dl-dir'] = os.path.join(top_dir, '.bitbake-setup-downloads') - d = init_bb_cache(top_dir, settings, args) - registry_path = update_registry(settings["default"]["registry"], cache_dir(top_dir), d) - json_data = list_registry(registry_path, args.with_expired) - shutil.rmtree(top_dir) + try: + settings['default']['dl-dir'] = os.path.join(top_dir, '.bitbake-setup-downloads') + d = init_bb_cache(top_dir, settings, args) + registry_path = update_registry(settings["default"]["registry"], cache_dir(top_dir), d) + json_data = list_registry(registry_path, args.with_expired) + # AI-Generated: Uses OpenAI Codex (gpt-6.1-sol). Export the template without selecting build options. + if args.config is not None: + if args.config not in json_data: + logger.error("Unable to find {} in available configurations; use 'list' sub-command to see what is available".format(args.config)) + sys.exit(1) + with open(get_registry_config(registry_path, args.config)) as f: + template = json.load(f) + except json.JSONDecodeError as e: + logger.error("Failed to parse configuration: %s" % e) + sys.exit(1) + finally: + shutil.rmtree(top_dir) + + if args.config is not None: + with open(args.write_json, 'w') as f: + json.dump(template, f, sort_keys=True, indent=4) + logger.plain("Configuration {} written into {}".format(args.config, args.write_json)) + return logger.plain("Available configurations:") for config_name, config_data in sorted(json_data.items()): @@ -1347,6 +1365,7 @@ def main(): parser_list = subparsers.add_parser('list', help='List available configurations') parser_list.add_argument('--with-expired', action='store_true', help='List also configurations that are no longer supported due to reaching their end-of-life dates.') parser_list.add_argument('--write-json', action='store', help='Write available configurations into a json file so they can be programmatically processed.') + parser_list.add_argument('--config', metavar='TEMPLATE_ID', help='Export a complete Configuration Template instead of the registry listing (requires --write-json).') parser_list.set_defaults(func=list_configs) parser_init = subparsers.add_parser('init', help='Select a configuration and initialize a setup from it') @@ -1406,6 +1425,9 @@ def main(): args = parser.parse_args() + if getattr(args, 'func', None) == list_configs and args.config is not None and not args.write_json: + parser_list.error('--config requires --write-json') + if args.debug: logger.setLevel(logging.DEBUG) elif args.quiet: diff --git a/doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst b/doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst index e15c9ed0d..d1c1543dc 100644 --- a/doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst +++ b/doc/bitbake-user-manual/bitbake-user-manual-environment-setup.rst @@ -410,6 +410,10 @@ In addition, the command can take the following arguments: - ``--write-json``: write the configurations into a JSON file so they can be programmatically processed. +- ``--config TEMPLATE_ID``: with ``--write-json OUTPUT``, export the complete + selected Configuration Template as JSON without initializing a setup. + Expired templates require ``--with-expired``. + .. _ref-bbsetup-command-status: ``bitbake-setup status`` diff --git a/lib/bb/tests/setup.py b/lib/bb/tests/setup.py index 53a07ee3a..7636f1d53 100644 --- a/lib/bb/tests/setup.py +++ b/lib/bb/tests/setup.py @@ -17,6 +17,7 @@ import subprocess import sys import tempfile import unittest +from unittest import mock import venv import zipfile from bb.tests.support.httpserver import HTTPService @@ -319,6 +320,141 @@ print("BBPATH is {{}}".format(os.environ["BBPATH"])) return os.path.join(self.tempdir, 'bitbake-builds', 'this-is-a-custom-gizmo-build') return os.path.join(self.tempdir, 'bitbake-builds', '{}-{}'.format(cf, "-".join(c.split()))) + # AI-Generated: Uses OpenAI Codex (gpt-6.1-sol). Offline template export coverage. + def run_list_fixture(self, args, registry=None): + # Isolate all temporary cache directories and forbid network access. + tmpdir = os.path.join(self.tempdir, 'list-tmp') + os.makedirs(tmpdir, exist_ok=True) + with mock.patch.dict(os.environ, {'TMPDIR': tmpdir, 'BBPATH': ''}): + try: + return self.runbbsetup([ + '--no-network', '--setting', 'default', 'registry', registry or self.tempdir, + 'list'] + args) + finally: + self.assertEqual(os.listdir(tmpdir), []) + self.assertFalse(os.path.exists(os.path.join(self.tempdir, 'bitbake-builds'))) + self.assertFalse(os.path.exists(os.path.join(self.tempdir, '.bitbake-setup-cache'))) + for root, dirs, files in os.walk(self.tempdir): + self.assertNotIn('site.conf', files) + self.assertNotIn('layers', dirs) + self.assertNotIn('.vscode', dirs) + self.assertFalse(any(f.endswith('.code-workspace') for f in files)) + + def write_list_fixture(self, data): + registry = os.path.join(self.tempdir, 'configurations', 'nested') + os.makedirs(registry, exist_ok=True) + path = os.path.join(registry, 'test-template.conf.json') + with open(path, 'w') as f: + json.dump(data, f) + return path + + def test_list_export_template(self): + output = os.path.join(self.tempdir, 'template.json') + for count in (1, 2): + with self.subTest(configurations=count): + template = { + 'description': 'Complete template', 'version': '1.0', + 'sources': {'unused': {'git-remote': {'remotes': { + 'origin': {'uri': 'file://' + os.path.join(self.tempdir, 'unused-layer')}}, + 'branch': 'main', 'rev': 'HEAD'}}}, + 'bitbake-setup': {'configurations': [ + {'name': 'config-{}'.format(i), 'oe-template': 'unused', + 'oe-fragments-one-of': {'choice': {'options': ['a', 'b']}}} + for i in range(count)]}, + 'extension': {'nested': [None, True, False, 42, 1.5, 'café', + {'empty': [], 'object': {}}]}, + } + self.write_list_fixture(template) + self.run_list_fixture(['--config', 'test-template', '--write-json', output]) + with open(output) as f: + self.assertEqual(json.load(f), template) + + def test_list_export_unknown(self): + self.write_list_fixture({'description': 'Available template'}) + output = os.path.join(self.tempdir, 'template.json') + for existing in (False, True): + with self.subTest(existing=existing): + if existing: + with open(output, 'w') as f: + f.write('keep existing output') + with self.assertRaises(bb.process.ExecutionError) as error: + self.run_list_fixture(['--config', 'missing', '--write-json', output]) + self.assertIn('Unable to find missing', str(error.exception)) + if existing: + with open(output) as f: + self.assertEqual(f.read(), 'keep existing output') + else: + self.assertFalse(os.path.exists(output)) + + def test_list_export_expired(self): + template = {'description': 'Expired template', 'expires': '2000-01-01', + 'bitbake-setup': {'configurations': [{'name': 'expired'}]}} + self.write_list_fixture(template) + output = os.path.join(self.tempdir, 'template.json') + with self.assertRaises(bb.process.ExecutionError) as error: + self.run_list_fixture(['--config', 'test-template', '--write-json', output]) + self.assertIn('Unable to find test-template', str(error.exception)) + self.assertFalse(os.path.exists(output)) + self.run_list_fixture(['--config', 'test-template', '--with-expired', '--write-json', output]) + with open(output) as f: + self.assertEqual(json.load(f), template) + + def test_list_export_invalid_arguments(self): + with self.assertRaises(bb.process.ExecutionError) as error: + self.run_list_fixture(['--config', 'test-template']) + self.assertEqual(error.exception.exitcode, 2) + self.assertIn('--config requires --write-json', str(error.exception)) + + def test_list_export_invalid_json(self): + path = self.write_list_fixture({'description': 'Broken template'}) + with open(path, 'w') as f: + f.write('{invalid json') + output = os.path.join(self.tempdir, 'template.json') + for existing in (False, True): + with self.subTest(existing=existing): + if existing: + with open(output, 'w') as f: + f.write('keep existing output') + with self.assertRaises(bb.process.ExecutionError) as error: + self.run_list_fixture(['--config', 'test-template', '--write-json', output]) + self.assertIn('Failed to parse configuration', str(error.exception)) + if existing: + with open(output) as f: + self.assertEqual(f.read(), 'keep existing output') + else: + self.assertFalse(os.path.exists(output)) + + def test_list_export_registry_failure(self): + output = os.path.join(self.tempdir, 'template.json') + registry = 'git://{};protocol=file;branch=master;rev=master'.format( + os.path.join(self.tempdir, 'missing-registry')) + with self.assertRaises(bb.process.ExecutionError): + self.run_list_fixture(['--config', 'test-template', '--write-json', output], + registry=registry) + self.assertFalse(os.path.exists(output)) + + def test_list_registry_json_compatibility(self): + self.write_list_fixture({'description': 'Available template', 'extra': {'a': [1, 2]}}) + registry = os.path.join(self.tempdir, 'configurations') + with open(os.path.join(registry, 'old.conf.json'), 'w') as f: + json.dump({'description': 'Old template', 'expires': '2000-01-01'}, f) + output = os.path.join(self.tempdir, 'registry.json') + for expired in (False, True): + with self.subTest(with_expired=expired): + flags = ['--with-expired'] if expired else [] + plain = self.run_list_fixture(flags)[0] + written = self.run_list_fixture(flags + ['--write-json', output])[0] + self.assertEqual(written, plain + 'Available configurations written into {}\n'.format(output)) + self.assertIn('test-template\tAvailable template', plain) + expected = {'test-template': {'description': 'Available template'}} + if expired: + expected['old'] = {'description': 'Old template', 'expires': '2000-01-01'} + self.assertIn('old\tOld template (supported until 2000-01-01)', plain) + else: + self.assertNotIn('old\t', plain) + with open(output) as f: + self.assertEqual(json.load(f), expected) + def test_setup(self): # unset BBPATH to ensure tests run in isolation from the existing bitbake environment if 'BBPATH' in os.environ: