Update the tool to know about all our new platforms (#132423)
...and add a test so we remember to keep it in sync.
This commit is contained in:
@@ -87,6 +87,9 @@ Future<void> run(List<String> arguments) async {
|
||||
foundError(<String>['The analyze.dart script must be run with --enable-asserts.']);
|
||||
}
|
||||
|
||||
printProgress('TargetPlatform tool/framework consistency');
|
||||
await verifyTargetPlatform(flutterRoot);
|
||||
|
||||
printProgress('No Double.clamp');
|
||||
await verifyNoDoubleClamp(flutterRoot);
|
||||
|
||||
@@ -266,6 +269,84 @@ class _DoubleClampVisitor extends RecursiveAstVisitor<CompilationUnit> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> verifyTargetPlatform(String workingDirectory) async {
|
||||
final File framework = File('$workingDirectory/packages/flutter/lib/src/foundation/platform.dart');
|
||||
final Set<String> frameworkPlatforms = <String>{};
|
||||
List<String> lines = framework.readAsLinesSync();
|
||||
int index = 0;
|
||||
while (true) {
|
||||
if (index >= lines.length) {
|
||||
foundError(<String>['${framework.path}: Can no longer find TargetPlatform enum.']);
|
||||
return;
|
||||
}
|
||||
if (lines[index].startsWith('enum TargetPlatform {')) {
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
while (true) {
|
||||
if (index >= lines.length) {
|
||||
foundError(<String>['${framework.path}: Could not find end of TargetPlatform enum.']);
|
||||
return;
|
||||
}
|
||||
String line = lines[index].trim();
|
||||
final int comment = line.indexOf('//');
|
||||
if (comment >= 0) {
|
||||
line = line.substring(0, comment);
|
||||
}
|
||||
if (line == '}') {
|
||||
break;
|
||||
}
|
||||
if (line.isNotEmpty) {
|
||||
if (line.endsWith(',')) {
|
||||
frameworkPlatforms.add(line.substring(0, line.length - 1));
|
||||
} else {
|
||||
foundError(<String>['${framework.path}:$index: unparseable line when looking for TargetPlatform values']);
|
||||
}
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
final File tool = File('$workingDirectory/packages/flutter_tools/lib/src/resident_runner.dart');
|
||||
final Set<String> toolPlatforms = <String>{};
|
||||
lines = tool.readAsLinesSync();
|
||||
index = 0;
|
||||
while (true) {
|
||||
if (index >= lines.length) {
|
||||
foundError(<String>['${tool.path}: Can no longer find nextPlatform logic.']);
|
||||
return;
|
||||
}
|
||||
if (lines[index].trim().startsWith('const List<String> platforms = <String>[')) {
|
||||
index += 1;
|
||||
break;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
while (true) {
|
||||
if (index >= lines.length) {
|
||||
foundError(<String>['${tool.path}: Could not find end of nextPlatform logic.']);
|
||||
return;
|
||||
}
|
||||
final String line = lines[index].trim();
|
||||
if (line.startsWith("'") && line.endsWith("',")) {
|
||||
toolPlatforms.add(line.substring(1, line.length - 2));
|
||||
} else if (line == '];') {
|
||||
break;
|
||||
} else {
|
||||
foundError(<String>['${tool.path}:$index: unparseable line when looking for nextPlatform values']);
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
final Set<String> frameworkExtra = frameworkPlatforms.difference(toolPlatforms);
|
||||
if (frameworkExtra.isNotEmpty) {
|
||||
foundError(<String>['TargetPlatform has some extra values not found in the tool: ${frameworkExtra.join(", ")}']);
|
||||
}
|
||||
final Set<String> toolExtra = toolPlatforms.difference(frameworkPlatforms);
|
||||
if (toolExtra.isNotEmpty) {
|
||||
foundError(<String>['The nextPlatform logic in the tool has some extra values not found in TargetPlatform: ${toolExtra.join(", ")}']);
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify that we use clampDouble instead of Double.clamp for performance reasons.
|
||||
///
|
||||
/// We currently can't distinguish valid uses of clamp from problematic ones so
|
||||
|
||||
Reference in New Issue
Block a user