Skip to content

Commit 752c360

Browse files
bonzinidcbaker
authored andcommitted
cargo: use _raw_to_dataclass for Manifest
Prepare to add type checking. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 04d2043 commit 752c360

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

mesonbuild/cargo/manifest.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -367,21 +367,20 @@ def from_raw(cls, raw: raw.Manifest, path: str = '') -> Self:
367367
if pkg.autolib and 'lib' not in raw and \
368368
os.path.exists(os.path.join(path, 'src/lib.rs')):
369369
raw['lib'] = {}
370-
return cls(
371-
package=pkg,
372-
dependencies={k: Dependency.from_raw(k, v) for k, v in raw.get('dependencies', {}).items()},
373-
dev_dependencies={k: Dependency.from_raw(k, v) for k, v in raw.get('dev-dependencies', {}).items()},
374-
build_dependencies={k: Dependency.from_raw(k, v) for k, v in raw.get('build-dependencies', {}).items()},
375-
lib=Library.from_raw(raw['lib'], raw['package']['name']) if 'lib' in raw else None,
376-
bin=[Binary.from_raw(b) for b in raw.get('bin', {})],
377-
test=[Test.from_raw(b) for b in raw.get('test', {})],
378-
bench=[Benchmark.from_raw(b) for b in raw.get('bench', {})],
379-
example=[Example.from_raw(b) for b in raw.get('example', {})],
380-
features=raw.get('features', {}),
381-
target={k: {k2: Dependency.from_raw(k2, v2) for k2, v2 in v.get('dependencies', {}).items()}
382-
for k, v in raw.get('target', {}).items()},
383-
path=path,
384-
)
370+
fixed = _raw_to_dataclass(raw, cls, f'Cargo.toml package {raw["package"]["name"]}',
371+
package=lambda x: pkg,
372+
dependencies=lambda x: {k: Dependency.from_raw(k, v) for k, v in x.items()},
373+
dev_dependencies=lambda x: {k: Dependency.from_raw(k, v) for k, v in x.items()},
374+
build_dependencies=lambda x: {k: Dependency.from_raw(k, v) for k, v in x.items()},
375+
lib=lambda x: Library.from_raw(x, raw['package']['name']),
376+
bin=lambda x: [Binary.from_raw(b) for b in x],
377+
test=lambda x: [Test.from_raw(b) for b in x],
378+
bench=lambda x: [Benchmark.from_raw(b) for b in x],
379+
example=lambda x: [Example.from_raw(b) for b in x],
380+
target=lambda x: {k: {k2: Dependency.from_raw(k2, v2) for k2, v2 in v.get('dependencies', {}).items()}
381+
for k, v in x.items()})
382+
fixed.path = path
383+
return fixed
385384

386385

387386
@dataclasses.dataclass

0 commit comments

Comments
 (0)