summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-06-03 13:31:43 +0200
committerDylan Baker <dylan@pnwbakers.com>2025-08-01 07:55:49 -0700
commit752c36040a44eb89c880dbfe85ddd7d92bc8f70b (patch)
treea38606ddf9328bb9da68971c590f5d5d89f6ffec
parent04d20432175d62ed0d1cf671facad0f66a7cb3e5 (diff)
downloadmeson-752c36040a44eb89c880dbfe85ddd7d92bc8f70b.tar.gz
cargo: use _raw_to_dataclass for Manifest
Prepare to add type checking. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--mesonbuild/cargo/manifest.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/mesonbuild/cargo/manifest.py b/mesonbuild/cargo/manifest.py
index 8d5284920..9f5b44d39 100644
--- a/mesonbuild/cargo/manifest.py
+++ b/mesonbuild/cargo/manifest.py
@@ -367,21 +367,20 @@ class Manifest:
if pkg.autolib and 'lib' not in raw and \
os.path.exists(os.path.join(path, 'src/lib.rs')):
raw['lib'] = {}
- return cls(
- package=pkg,
- dependencies={k: Dependency.from_raw(k, v) for k, v in raw.get('dependencies', {}).items()},
- dev_dependencies={k: Dependency.from_raw(k, v) for k, v in raw.get('dev-dependencies', {}).items()},
- build_dependencies={k: Dependency.from_raw(k, v) for k, v in raw.get('build-dependencies', {}).items()},
- lib=Library.from_raw(raw['lib'], raw['package']['name']) if 'lib' in raw else None,
- bin=[Binary.from_raw(b) for b in raw.get('bin', {})],
- test=[Test.from_raw(b) for b in raw.get('test', {})],
- bench=[Benchmark.from_raw(b) for b in raw.get('bench', {})],
- example=[Example.from_raw(b) for b in raw.get('example', {})],
- features=raw.get('features', {}),
- target={k: {k2: Dependency.from_raw(k2, v2) for k2, v2 in v.get('dependencies', {}).items()}
- for k, v in raw.get('target', {}).items()},
- path=path,
- )
+ fixed = _raw_to_dataclass(raw, cls, f'Cargo.toml package {raw["package"]["name"]}',
+ package=lambda x: pkg,
+ dependencies=lambda x: {k: Dependency.from_raw(k, v) for k, v in x.items()},
+ dev_dependencies=lambda x: {k: Dependency.from_raw(k, v) for k, v in x.items()},
+ build_dependencies=lambda x: {k: Dependency.from_raw(k, v) for k, v in x.items()},
+ lib=lambda x: Library.from_raw(x, raw['package']['name']),
+ bin=lambda x: [Binary.from_raw(b) for b in x],
+ test=lambda x: [Test.from_raw(b) for b in x],
+ bench=lambda x: [Benchmark.from_raw(b) for b in x],
+ example=lambda x: [Example.from_raw(b) for b in x],
+ target=lambda x: {k: {k2: Dependency.from_raw(k2, v2) for k2, v2 in v.get('dependencies', {}).items()}
+ for k, v in x.items()})
+ fixed.path = path
+ return fixed
@dataclasses.dataclass