parse static method
Reads memory and deviceProfiles.<id>.{memory, ram, platform} out of
a project's dartvel: section.
Implementation
static DVMemoryConfig parse(Object? dartvelSection) {
final List<String> problems = <String>[];
final Map<Object?, Object?> dv = dartvelSection is Map
? dartvelSection
: const <Object?, Object?>{};
final Object? memory = dv['memory'];
if (memory != null && memory is! Map) {
problems.add('memory must be a map');
}
final Map<Object?, Object?> section = memory is Map
? memory
: const <Object?, Object?>{};
final _Layer global = _layer(section, 'memory', problems);
final Map<String, _Layer> targets = <String, _Layer>{};
final Object? declared = section['targets'];
if (declared is Map) {
declared.forEach((Object? key, Object? body) {
final String name = '$key';
if (!targetKeys.containsKey(name)) {
problems.add(
'memory.targets.$name is not a Dartvel target '
'(one of ${targetKeys.keys.join(', ')})',
);
return;
}
targets[name] = body is Map
? _layer(body, 'memory.targets.$name', problems)
: _Layer.empty;
});
} else if (declared != null) {
problems.add('memory.targets must be a map');
}
final Map<String, _Layer> profiles = <String, _Layer>{};
final Map<String, DVSize> ram = <String, DVSize>{};
final Map<String, String> platforms = <String, String>{};
final Object? deviceProfiles = dv['deviceProfiles'];
if (deviceProfiles is Map) {
deviceProfiles.forEach((Object? id, Object? body) {
if (body is! Map) return;
final String name = '$id';
final Object? m = body['memory'];
if (m is Map) {
profiles[name] = _layer(m, 'deviceProfiles.$name.memory', problems);
}
final Object? r = body['ram'];
if (r != null) {
final DVSize? size = DVSize.tryRead(r);
if (size == null) {
problems.add('deviceProfiles.$name.ram: "$r" is not a size');
} else {
ram[name] = size;
}
}
final Object? platform = body['platform'];
if (platform is String) platforms[name] = platform;
});
}
return DVMemoryConfig._(
global: global,
targets: targets,
profiles: profiles,
ram: ram,
platforms: platforms,
problems: List<String>.unmodifiable(problems),
);
}