Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -26,25 +26,33 @@ import 'package:path/path.dart' as path;
/// Get contents of the file that contains the physical key mapping in Chromium
/// source.
Future<String> getChromiumCodes() async {
final Uri keyCodesUri = Uri.parse('https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/main/ui/events/keycodes/dom/dom_code_data.inc?format=TEXT');
final Uri keyCodesUri = Uri.parse(
'https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/main/ui/events/keycodes/dom/dom_code_data.inc?format=TEXT',
);
return utf8.decode(base64.decode(await http.read(keyCodesUri)));
}
/// Get contents of the file that contains the logical key mapping in Chromium
/// source.
Future<String> getChromiumKeys() async {
final Uri keyCodesUri = Uri.parse('https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/main/ui/events/keycodes/dom/dom_key_data.inc?format=TEXT');
final Uri keyCodesUri = Uri.parse(
'https://chromium.googlesource.com/codesearch/chromium/src/+/refs/heads/main/ui/events/keycodes/dom/dom_key_data.inc?format=TEXT',
);
return utf8.decode(base64.decode(await http.read(keyCodesUri)));
}
/// Get contents of the file that contains the key codes in Android source.
Future<String> getAndroidKeyCodes() async {
final Uri keyCodesUri = Uri.parse('https://android.googlesource.com/platform/frameworks/native/+/main/include/android/keycodes.h?format=TEXT');
final Uri keyCodesUri = Uri.parse(
'https://android.googlesource.com/platform/frameworks/native/+/main/include/android/keycodes.h?format=TEXT',
);
return utf8.decode(base64.decode(await http.read(keyCodesUri)));
}
Future<String> getWindowsKeyCodes() async {
final Uri keyCodesUri = Uri.parse('https://raw.githubusercontent.com/tpn/winsdk-10/master/Include/10.0.10240.0/um/WinUser.h');
final Uri keyCodesUri = Uri.parse(
'https://raw.githubusercontent.com/tpn/winsdk-10/master/Include/10.0.10240.0/um/WinUser.h',
);
return http.read(keyCodesUri);
}
@@ -55,17 +63,23 @@ Future<String> getWindowsKeyCodes() async {
/// common keyboards. Other than some special keyboards and game pads, this
/// should be OK.
Future<String> getAndroidScanCodes() async {
final Uri scanCodesUri = Uri.parse('https://android.googlesource.com/platform/frameworks/base/+/main/data/keyboards/Generic.kl?format=TEXT');
final Uri scanCodesUri = Uri.parse(
'https://android.googlesource.com/platform/frameworks/base/+/main/data/keyboards/Generic.kl?format=TEXT',
);
return utf8.decode(base64.decode(await http.read(scanCodesUri)));
}
Future<String> getGlfwKeyCodes() async {
final Uri keyCodesUri = Uri.parse('https://raw.githubusercontent.com/glfw/glfw/master/include/GLFW/glfw3.h');
final Uri keyCodesUri = Uri.parse(
'https://raw.githubusercontent.com/glfw/glfw/master/include/GLFW/glfw3.h',
);
return http.read(keyCodesUri);
}
Future<String> getGtkKeyCodes() async {
final Uri keyCodesUri = Uri.parse('https://gitlab.gnome.org/GNOME/gtk/-/raw/gtk-3-24/gdk/gdkkeysyms.h');
final Uri keyCodesUri = Uri.parse(
'https://gitlab.gnome.org/GNOME/gtk/-/raw/gtk-3-24/gdk/gdkkeysyms.h',
);
return http.read(keyCodesUri);
}
@@ -100,7 +114,8 @@ Future<void> main(List<String> rawArguments) async {
argParser.addOption(
'engine-root',
defaultsTo: path.join(flutterRoot.path, '..', 'engine', 'src', 'flutter'),
help: 'The path to the root of the flutter/engine repository. This is used '
help:
'The path to the root of the flutter/engine repository. This is used '
'to place the generated engine mapping files. If --engine-root is not '
r'specified, it will default to $flutterRoot/../engine/src/flutter, '
'assuming the engine gclient folder is placed at the same folder as '
@@ -109,7 +124,8 @@ Future<void> main(List<String> rawArguments) async {
argParser.addOption(
'physical-data',
defaultsTo: path.join(dataRoot, 'physical_key_data.g.json'),
help: 'The path to where the physical key data file should be written when '
help:
'The path to where the physical key data file should be written when '
'collected, and read from when generating output code. If --physical-data is '
'not specified, the output will be written to/read from the current '
"directory. If the output directory doesn't exist, it, and the path to "
@@ -118,7 +134,8 @@ Future<void> main(List<String> rawArguments) async {
argParser.addOption(
'logical-data',
defaultsTo: path.join(dataRoot, 'logical_key_data.g.json'),
help: 'The path to where the logical key data file should be written when '
help:
'The path to where the logical key data file should be written when '
'collected, and read from when generating output code. If --logical-data is '
'not specified, the output will be written to/read from the current '
"directory. If the output directory doesn't exist, it, and the path to "
@@ -126,33 +143,48 @@ Future<void> main(List<String> rawArguments) async {
);
argParser.addOption(
'code',
defaultsTo: path.join(flutterRoot.path, 'packages', 'flutter', 'lib', 'src', 'services', 'keyboard_key.g.dart'),
help: 'The path to where the output "keyboard_key.g.dart" file should be '
defaultsTo: path.join(
flutterRoot.path,
'packages',
'flutter',
'lib',
'src',
'services',
'keyboard_key.g.dart',
),
help:
'The path to where the output "keyboard_key.g.dart" file should be '
'written. If --code is not specified, the output will be written to the '
'correct directory in the flutter tree. If the output directory does not '
'exist, it, and the path to it, will be created.',
);
argParser.addOption(
'maps',
defaultsTo: path.join(flutterRoot.path, 'packages', 'flutter', 'lib', 'src', 'services', 'keyboard_maps.g.dart'),
help: 'The path to where the output "keyboard_maps.g.dart" file should be '
'written. If --maps is not specified, the output will be written to the '
'correct directory in the flutter tree. If the output directory does not '
'exist, it, and the path to it, will be created.',
defaultsTo: path.join(
flutterRoot.path,
'packages',
'flutter',
'lib',
'src',
'services',
'keyboard_maps.g.dart',
),
help:
'The path to where the output "keyboard_maps.g.dart" file should be '
'written. If --maps is not specified, the output will be written to the '
'correct directory in the flutter tree. If the output directory does not '
'exist, it, and the path to it, will be created.',
);
argParser.addFlag(
'collect',
negatable: false,
help: 'If this flag is set, then collect and parse header files from '
help:
'If this flag is set, then collect and parse header files from '
'Chromium and Android instead of reading pre-parsed data from '
'"physical_key_data.g.json" and "logical_key_data.g.json", and then '
'update these files with the fresh data.',
);
argParser.addFlag(
'help',
negatable: false,
help: 'Print help for this command.',
);
argParser.addFlag('help', negatable: false, help: 'Print help for this command.');
final ArgResults parsedArguments = argParser.parse(rawArguments);
@@ -212,45 +244,59 @@ Future<void> main(List<String> rawArguments) async {
final String logicalJson = encoder.convert(logicalData.toJson());
File(parsedArguments['logical-data'] as String).writeAsStringSync('$logicalJson\n');
} else {
physicalData = PhysicalKeyData.fromJson(json.decode(await File(parsedArguments['physical-data'] as String).readAsString()) as Map<String, dynamic>);
logicalData = LogicalKeyData.fromJson(json.decode(await File(parsedArguments['logical-data'] as String).readAsString()) as Map<String, dynamic>);
physicalData = PhysicalKeyData.fromJson(
json.decode(await File(parsedArguments['physical-data'] as String).readAsString())
as Map<String, dynamic>,
);
logicalData = LogicalKeyData.fromJson(
json.decode(await File(parsedArguments['logical-data'] as String).readAsString())
as Map<String, dynamic>,
);
}
final Map<String, bool> layoutGoals = parseMapOfBool(readDataFile('layout_goals.json'));
await generate('key codes',
parsedArguments['code'] as String,
KeyboardKeysCodeGenerator(physicalData, logicalData));
await generate('key maps',
parsedArguments['maps'] as String,
KeyboardMapsCodeGenerator(physicalData, logicalData));
await generate('engine utils',
path.join(PlatformCodeGenerator.engineRoot,
'shell', 'platform', 'embedder', 'test_utils', 'key_codes.g.h'),
KeyCodesCcGenerator(physicalData, logicalData));
await generate('android utils',
path.join(PlatformCodeGenerator.engineRoot, 'shell', 'platform',
path.join('android', 'test', 'io', 'flutter', 'util', 'KeyCodes.java')),
KeyCodesJavaGenerator(physicalData, logicalData));
await generate(
'key codes',
parsedArguments['code'] as String,
KeyboardKeysCodeGenerator(physicalData, logicalData),
);
await generate(
'key maps',
parsedArguments['maps'] as String,
KeyboardMapsCodeGenerator(physicalData, logicalData),
);
await generate(
'engine utils',
path.join(
PlatformCodeGenerator.engineRoot,
'shell',
'platform',
'embedder',
'test_utils',
'key_codes.g.h',
),
KeyCodesCcGenerator(physicalData, logicalData),
);
await generate(
'android utils',
path.join(
PlatformCodeGenerator.engineRoot,
'shell',
'platform',
path.join('android', 'test', 'io', 'flutter', 'util', 'KeyCodes.java'),
),
KeyCodesJavaGenerator(physicalData, logicalData),
);
final Map<String, PlatformCodeGenerator> platforms = <String, PlatformCodeGenerator>{
'android': AndroidCodeGenerator(
physicalData,
logicalData,
),
'macos': MacOSCodeGenerator(
physicalData,
logicalData,
layoutGoals,
),
'ios': IOSCodeGenerator(
physicalData,
logicalData,
),
'android': AndroidCodeGenerator(physicalData, logicalData),
'macos': MacOSCodeGenerator(physicalData, logicalData, layoutGoals),
'ios': IOSCodeGenerator(physicalData, logicalData),
'windows': WindowsCodeGenerator(
physicalData,
logicalData,
readDataFile('windows_scancode_logical_map.json')
readDataFile('windows_scancode_logical_map.json'),
),
'linux': GtkCodeGenerator(
physicalData,
@@ -265,11 +311,11 @@ Future<void> main(List<String> rawArguments) async {
readDataFile('web_logical_location_mapping.json'),
),
};
await Future.wait(platforms.entries.map((MapEntry<String, PlatformCodeGenerator> entry) {
final String platform = entry.key;
final PlatformCodeGenerator codeGenerator = entry.value;
return generate('$platform map',
codeGenerator.outputPath(platform),
codeGenerator);
}));
await Future.wait(
platforms.entries.map((MapEntry<String, PlatformCodeGenerator> entry) {
final String platform = entry.key;
final PlatformCodeGenerator codeGenerator = entry.value;
return generate('$platform map', codeGenerator.outputPath(platform), codeGenerator);
}),
);
}