diff mbox series

[v2,04/18] oeqa/selftest: verify Cargo config serialization

Message ID 20261109-devtool-ide-sdk-cargo-v2-4-d56134000561@savoirfairelinux.com
State New
Headers show
Series devtool: ide-sdk: add support for Rust recipes | expand

Commit Message

Enguerrand de Ribaucourt Nov. 9, 2026, 1:44 p.m. UTC
Parse the config exported by devtool and round-trip the TOML writer's
supported tables and values.

AI-Generated: Uses GitHub Copilot
Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>

---
Changes in v2:
- Commit added to verify the generated Cargo config.
---
 meta/lib/oeqa/selftest/cases/devtool.py | 63 +++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py
index 265f2147a4..cab49b4c02 100644
--- a/meta/lib/oeqa/selftest/cases/devtool.py
+++ b/meta/lib/oeqa/selftest/cases/devtool.py
@@ -5242,3 +5242,66 @@  class DevtoolIdeSdkMiscTests(DevtoolIdeSdkTests):
         with open(modified_config_file) as modified_config:
             modified_config_new = modified_config.read()
         self.assertEqual(modified_config_str, modified_config_new)
+
+
+class DevtoolIdeSdkCargoConfigTests(DevtoolIdeSdkTests):
+
+    def test_cargo_toml_serialization(self):
+        import importlib
+        import sys
+
+        from bb._vendor import tomli
+
+        config = {
+            'paths': ['/work/crate', '/work/quoted "crate"\\dir'],
+            'source': {'bitbake': {'directory': '/downloads/cargo'}},
+            'patch': {
+                'https://example.com/repo': {
+                    'example': {'path': '/work/patched-crate'}
+                }
+            },
+            'env': {
+                'CC': {'value': '/tool/cc --flag="quoted"\\path', 'force': True}
+            },
+            'target': {
+                'x86_64-poky-linux': {
+                    'linker': '/tool/ld',
+                    'rustflags': ['--sysroot', '/sysroot path'],
+                }
+            },
+            'term': {'progress': {'when': 'always', 'width': 80}},
+        }
+
+        scripts_lib = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib')
+        sys.path.insert(0, scripts_lib)
+        oeqa_devtool = sys.modules.pop('devtool')
+        try:
+            ide_sdk = importlib.import_module('devtool.ide_sdk')
+            self.assertEqual(tomli.loads(ide_sdk._toml_dumps(config)), config)
+        finally:
+            for name in tuple(sys.modules):
+                if name == 'devtool' or name.startswith('devtool.'):
+                    del sys.modules[name]
+            sys.modules['devtool'] = oeqa_devtool
+            sys.path.remove(scripts_lib)
+
+    def test_cargo_config_is_generated_and_valid(self):
+        from bb._vendor import tomli
+
+        recipe_name = 'cargo-example'
+        self._check_workspace()
+        self._write_bb_config()
+        self._devtool_ide_sdk_recipe(recipe_name, 'Cargo.toml', None)
+        runCmd('devtool ide-sdk %s oe-selftest-image --ide=code' % recipe_name,
+               output_log=self._cmd_logger)
+
+        cargo_config = os.path.join(
+            self.workspacedir, 'ide-sdk', recipe_name, 'cargo-config.toml')
+        self.assertExists(cargo_config, 'Cargo config was not generated')
+        with open(cargo_config) as cargo_config_file:
+            config = tomli.loads(cargo_config_file.read())
+        rust_target = get_bb_var('RUST_HOST_SYS', recipe_name)
+        self.assertEqual(config['build']['target'], rust_target)
+        self.assertEqual(
+            config['target'][rust_target]['linker'],
+            get_bb_var('CARGO_RUST_TARGET_CCLD', recipe_name))