Handle Windows newlines in tools/VERSION when generating package_config

Fixes https://github.com/dart-lang/sdk/issues/60497 which was caused by the parsed values for version numbers having trailing `\r`s.

Change-Id: Icf40727c540c2c5dfea1c18cc91a00acf81ba6b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421222
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
This commit is contained in:
Danny Tuppeny
2025-04-08 09:22:16 -07:00
committed by Commit Queue
parent 7a44485843
commit 77f0ed1c7a
+6 -7
View File
@@ -102,12 +102,11 @@ $overrides
String currentSDKVersion() {
final versionContents =
File.fromUri(repoRoot.resolve('tools/VERSION')).readAsStringSync();
final lines = versionContents
.split('\n')
.where((line) => !line.startsWith('#') && line.isNotEmpty);
final versionParts = Map.fromEntries(lines.map((line) {
final parts = line.split(' ');
return MapEntry(parts[0], parts[1]);
}));
final lines = LineSplitter.split(versionContents);
final versionParts = {
for (var line in lines)
if (line.isNotEmpty && !line.startsWith('#'))
if (line.split(' ') case [final key, final value]) key: value
};
return '${versionParts['MAJOR']}.${versionParts['MINOR']}.${versionParts['PATCH']}';
}