fix: parse linux distro metadata
This commit is contained in:
@@ -233,24 +233,37 @@ Future<_LinuxDistro> _detectLinuxDistro() async {
|
|||||||
return _LinuxDistro.other;
|
return _LinuxDistro.other;
|
||||||
}
|
}
|
||||||
|
|
||||||
final lower = content.toLowerCase();
|
final fields = _parseOsRelease(content);
|
||||||
if (lower.contains('id=fedora') ||
|
final id = fields['id'] ?? '';
|
||||||
lower.contains('id_like="fedora"') ||
|
final idLike = (fields['id_like'] ?? '').split(RegExp(r'\s+'));
|
||||||
lower.contains('id_like=fedora')) {
|
final ids = {id, ...idLike};
|
||||||
|
if (ids.contains('fedora')) {
|
||||||
return _LinuxDistro.fedora;
|
return _LinuxDistro.fedora;
|
||||||
}
|
}
|
||||||
if (lower.contains('id=ubuntu') ||
|
if (ids.contains('ubuntu') || ids.contains('debian')) {
|
||||||
lower.contains('id=debian') ||
|
|
||||||
lower.contains('id_like=debian') ||
|
|
||||||
lower.contains('id_like="ubuntu debian"')) {
|
|
||||||
return _LinuxDistro.debian;
|
return _LinuxDistro.debian;
|
||||||
}
|
}
|
||||||
if (lower.contains('id=arch') || lower.contains('id_like=arch')) {
|
if (ids.contains('arch')) {
|
||||||
return _LinuxDistro.arch;
|
return _LinuxDistro.arch;
|
||||||
}
|
}
|
||||||
return _LinuxDistro.other;
|
return _LinuxDistro.other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, String> _parseOsRelease(String content) {
|
||||||
|
final fields = <String, String>{};
|
||||||
|
for (final line in content.split('\n')) {
|
||||||
|
final separator = line.indexOf('=');
|
||||||
|
if (separator <= 0) continue;
|
||||||
|
final key = line.substring(0, separator).trim().toLowerCase();
|
||||||
|
var value = line.substring(separator + 1).trim().toLowerCase();
|
||||||
|
if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
|
||||||
|
value = value.substring(1, value.length - 1);
|
||||||
|
}
|
||||||
|
fields[key] = value;
|
||||||
|
}
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
|
||||||
_LinuxArch _detectLinuxArch() {
|
_LinuxArch _detectLinuxArch() {
|
||||||
return switch (_currentAbiProvider()) {
|
return switch (_currentAbiProvider()) {
|
||||||
Abi.linuxX64 => _LinuxArch.x64,
|
Abi.linuxX64 => _LinuxArch.x64,
|
||||||
|
|||||||
@@ -38,6 +38,25 @@ void main() {
|
|||||||
expect(sdl.installHints.single.command, 'sudo apt install libsdl2-2.0-0');
|
expect(sdl.installHints.single.command, 'sudo apt install libsdl2-2.0-0');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('distro detection parses quoted ID_LIKE lists', () async {
|
||||||
|
debugResetStartupDependencyCheck(
|
||||||
|
platformIsLinux: () => true,
|
||||||
|
libraryProbe: (candidate) => false,
|
||||||
|
fileExists: (_) async => true,
|
||||||
|
osReleaseProvider: () async => 'ID=rocky\nID_LIKE="fedora rhel"\n',
|
||||||
|
resolvedExecutableProvider: () => '/opt/chanora/chanora_flutter',
|
||||||
|
currentDirectoryProvider: () => '/tmp',
|
||||||
|
);
|
||||||
|
|
||||||
|
final result = await checkStartupDependencies();
|
||||||
|
|
||||||
|
expect(result.platformLabel, 'Fedora');
|
||||||
|
final sdl = result.issues.singleWhere(
|
||||||
|
(issue) => issue.id == 'linux-sdl2-runtime',
|
||||||
|
);
|
||||||
|
expect(sdl.installHints.single.command, 'sudo dnf install SDL2');
|
||||||
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'missing ONNX runtime is reported as recommended when SDL2 is present',
|
'missing ONNX runtime is reported as recommended when SDL2 is present',
|
||||||
() async {
|
() async {
|
||||||
|
|||||||
Reference in New Issue
Block a user