Unverified Commit 9970481b authored by Tong Mu's avatar Tong Mu Committed by GitHub

[gen_keycodes] Mark generated file names with infix `.g.` (#106142)

parent f0200f01
......@@ -5,8 +5,8 @@ the `LogicalKeyboardKey` and `PhysicalKeyboardKey` classes.
It generates multiple files across Flutter. For framework, it generates
* [`keyboard_key.dart`](../../../packages/flutter/lib/src/services/keyboard_key.dart), which contains the definition and list of logical keys and physical keys; and
* [`keyboard_maps.dart`](../../../packages/flutter/lib/src/services/keyboard_maps.dart), which contains platform-specific immutable maps used for the `RawKeyboard` API.
* [`keyboard_key.g.dart`](../../../packages/flutter/lib/src/services/keyboard_key.g.dart), which contains the definition and list of logical keys and physical keys; and
* [`keyboard_maps.g.dart`](../../../packages/flutter/lib/src/services/keyboard_maps.g.dart), which contains platform-specific immutable maps used for the `RawKeyboard` API.
For engine, it generates one key mapping file for each platform, as well as some
files for testing purposes.
......@@ -14,9 +14,9 @@ files for testing purposes.
It draws information from various source bases, including online
repositories, and manual mapping in the `data` subdirectory. It incorporates
this information into a giant list of physical keys
([`physical_key_data.json`](data/physical_key_data.json)),
([`physical_key_data.g.json`](data/physical_key_data.g.json)),
and another for logical keys
([`logical_key_data.json`](data/logical_key_data.json)).
([`logical_key_data.g.json`](data/logical_key_data.g.json)).
The two files are checked in, and can be used as the data source next time so that
output files can be generated without the Internet.
......@@ -35,7 +35,7 @@ anew before generating the files. To do this, run:
/PATH/TO/ROOT/bin/gen_keycodes --collect
```
This will generate `physical_key_data.json` and `logical_key_data.json`. These
This will generate `physical_key_data.g.json` and `logical_key_data.g.json`. These
files should be checked in.
By default this tool assumes that the gclient directory for flutter/engine
......@@ -121,7 +121,7 @@ The planes are planned as follows:
platforms managed by Flutter will start to send the new value, making it a
breaking change. Therefore, when handling an unrecognized key on a platform
managed by Flutter, it is recommended to file a new issue to add this value
to `keyboard_key.dart` instead of using the platform-plane value. However,
to `keyboard_key.g.dart` instead of using the platform-plane value. However,
for a custom platform (see below), since the platform author has full control
over key mapping, such change will not cause breakage and it is recommended
to use the platform-plane value to avoid adding platform-exclusive values
......
......@@ -108,7 +108,7 @@ Future<void> main(List<String> rawArguments) async {
);
argParser.addOption(
'physical-data',
defaultsTo: path.join(dataRoot, 'physical_key_data.json'),
defaultsTo: path.join(dataRoot, 'physical_key_data.g.json'),
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 '
......@@ -117,7 +117,7 @@ Future<void> main(List<String> rawArguments) async {
);
argParser.addOption(
'logical-data',
defaultsTo: path.join(dataRoot, 'logical_key_data.json'),
defaultsTo: path.join(dataRoot, 'logical_key_data.g.json'),
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 '
......@@ -126,16 +126,16 @@ Future<void> main(List<String> rawArguments) async {
);
argParser.addOption(
'code',
defaultsTo: path.join(flutterRoot.path, 'packages', 'flutter', 'lib', 'src', 'services', 'keyboard_key.dart'),
help: 'The path to where the output "keyboard_key.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.dart'),
help: 'The path to where the output "keyboard_maps.dart" file should be '
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.',
......@@ -145,7 +145,7 @@ Future<void> main(List<String> rawArguments) async {
negatable: false,
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.json" and "logical_key_data.json", and then '
'"physical_key_data.g.json" and "logical_key_data.g.json", and then '
'update these files with the fresh data.',
);
argParser.addFlag(
......@@ -226,7 +226,7 @@ Future<void> main(List<String> rawArguments) async {
KeyboardMapsCodeGenerator(physicalData, logicalData));
await generate('engine utils',
path.join(PlatformCodeGenerator.engineRoot,
'shell', 'platform', 'embedder', 'test_utils', 'key_codes.h'),
'shell', 'platform', 'embedder', 'test_utils', 'key_codes.g.h'),
KeyCodesCcGenerator(physicalData, logicalData));
await generate('android utils',
path.join(PlatformCodeGenerator.engineRoot, 'shell', 'platform',
......
......@@ -4,8 +4,8 @@
| File name | Explanation |
| ---- | ---- |
| [`physical_key_data.json`](physical_key_data.json) | Contains the merged physical key data from all the other sources. This file is regenerated if "--collect" is specified for the gen_keycodes script, or used as a source otherwise. |
| [`logical_key_data.json`](logical_key_data.json) | Contains the merged logical key data from all the other sources. This file is regenerated if "--collect" is specified for the gen_keycodes script, or used as a source otherwise. |
| [`physical_key_data.g.json`](physical_key_data.g.json) | Contains the merged physical key data from all the other sources. This file is regenerated if "--collect" is specified for the gen_keycodes script, or used as a source otherwise. |
| [`logical_key_data.g.json`](logical_key_data.g.json) | Contains the merged logical key data from all the other sources. This file is regenerated if "--collect" is specified for the gen_keycodes script, or used as a source otherwise. |
| [`supplemental_hid_codes.inc`](supplemental_hid_codes.inc) | A supplementary HID list on top of Chromium's list of HID codes for extra physical keys. Certain entries may also overwrite Chromium's corresponding entries. |
| [`supplemental_key_data.inc`](supplemental_key_data.inc) | A supplementary key list on top of Chromium's list of keys for extra logical keys.|
| [`chromium_modifiers.json`](chromium_modifiers.json) | Maps the web's `key` for modifier keys to the names of the logical keys for these keys' left and right variations.This is used when generating logical keys to provide independent values for sided logical keys. Web uses the same `key` for modifier keys of different sides, but Flutter's logical key model treats them as different keys.|
......@@ -17,8 +17,8 @@
| File name | Explanation |
| ---- | ---- |
| [`keyboard_key.tmpl`](keyboard_key.tmpl) | The template for `keyboard_key.dart`. |
| [`keyboard_maps.tmpl`](keyboard_maps.tmpl) | The template for `keyboard_maps.dart`. |
| [`keyboard_key.tmpl`](keyboard_key.tmpl) | The template for `keyboard_key.g.dart`. |
| [`keyboard_maps.tmpl`](keyboard_maps.tmpl) | The template for `keyboard_maps.g.dart`. |
### Android
......
......@@ -9,9 +9,9 @@
// Edit the template dev/tools/gen_keycodes/data/keyboard_maps.tmpl instead.
// See dev/tools/gen_keycodes/README.md for more information.
import 'keyboard_key.dart';
import 'keyboard_key.g.dart';
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
/// Maps Android-specific key codes to the matching [LogicalKeyboardKey].
const Map<int, LogicalKeyboardKey> kAndroidToLogicalKey = <int, LogicalKeyboardKey>{
......
......@@ -34,7 +34,7 @@ abstract class BaseCodeGenerator {
Map<String, String> mappings();
/// Substitutes the various platform specific maps into the template file for
/// keyboard_maps.dart.
/// keyboard_maps.g.dart.
String generate() {
final String template = File(templatePath).readAsStringSync();
return _injectDictionary(template, mappings());
......
......@@ -129,7 +129,7 @@ class GtkCodeGenerator extends PlatformCodeGenerator {
@override
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
'shell', 'platform', 'linux', 'key_mapping.cc');
'shell', 'platform', 'linux', 'key_mapping.g.cc');
@override
Map<String, String> mappings() {
......
......@@ -122,7 +122,7 @@ class IOSCodeGenerator extends PlatformCodeGenerator {
@override
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
'shell', 'platform', 'darwin', 'ios', 'framework', 'Source', 'KeyCodeMap.mm');
'shell', 'platform', 'darwin', 'ios', 'framework', 'Source', 'KeyCodeMap.g.mm');
@override
Map<String, String> mappings() {
......
......@@ -46,7 +46,7 @@ class SynonymKeyInfo {
String get constantName => upperCamelToLowerCamel(name);
}
/// Generates the keyboard_key.dart based on the information in the key data
/// Generates the keyboard_key.g.dart based on the information in the key data
/// structure given to it.
class KeyboardKeysCodeGenerator extends BaseCodeGenerator {
KeyboardKeysCodeGenerator(super.keyData, super.logicalData);
......
......@@ -34,7 +34,7 @@ bool _isDigit(String? char) {
return charCode >= charDigit0 && charCode <= charDigit9;
}
/// Generates the keyboard_maps.dart files, based on the information in the key
/// Generates the keyboard_maps.g.dart files, based on the information in the key
/// data structure given to it.
class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
KeyboardMapsCodeGenerator(super.keyData, super.logicalData);
......@@ -176,7 +176,7 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
String get _windowsKeyCodeMap {
final OutputLines<int> lines = OutputLines<int>('Windows key code map');
for (final LogicalKeyEntry entry in logicalData.entries) {
// Letter keys on Windows are not recorded in logical_key_data.json,
// Letter keys on Windows are not recorded in logical_key_data.g.json,
// because they are not used by the embedding. Add them manually.
final List<int>? keyCodes = entry.windowsValues.isNotEmpty
? entry.windowsValues
......
......@@ -569,7 +569,7 @@ class LogicalKeyEntry {
/// A string indicating the letter on the keycap of a letter key.
///
/// This is only used to generate the key label mapping in keyboard_map.dart.
/// This is only used to generate the key label mapping in keyboard_maps.g.dart.
/// [LogicalKeyboardKey.keyLabel] uses a different definition and is generated
/// differently.
final String? keyLabel;
......@@ -607,7 +607,7 @@ class LogicalKeyEntry {
}
/// Gets the named used for the key constant in the definitions in
/// keyboard_key.dart.
/// keyboard_key.g.dart.
///
/// If set by the constructor, returns the name set, but otherwise constructs
/// the name from the various different names available, making sure that the
......
......@@ -119,7 +119,7 @@ class MacOSCodeGenerator extends PlatformCodeGenerator {
@override
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
'shell', 'platform', 'darwin', 'macos', 'framework', 'Source', 'KeyCodeMap.mm');
'shell', 'platform', 'darwin', 'macos', 'framework', 'Source', 'KeyCodeMap.g.mm');
@override
Map<String, String> mappings() {
......
......@@ -313,7 +313,7 @@ class PhysicalKeyEntry {
String get commentName => getCommentName(constantName);
/// Gets the named used for the key constant in the definitions in
/// keyboard_key.dart.
/// keyboard_key.g.dart.
///
/// If set by the constructor, returns the name set, but otherwise constructs
/// the name from the various different names available, making sure that the
......
......@@ -66,7 +66,7 @@ class WebCodeGenerator extends PlatformCodeGenerator {
@override
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
'lib', 'web_ui', 'lib', 'src', 'engine', 'key_map.dart');
'lib', 'web_ui', 'lib', 'src', 'engine', 'key_map.g.dart');
@override
Map<String, String> mappings() {
......
......@@ -83,7 +83,7 @@ class WindowsCodeGenerator extends PlatformCodeGenerator {
@override
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
'shell', 'platform', 'windows', 'flutter_key_map.cc');
'shell', 'platform', 'windows', 'flutter_key_map.g.cc');
@override
Map<String, String> mappings() {
......
......@@ -23,9 +23,9 @@ String readDataFile(String fileName) {
}
final PhysicalKeyData physicalData = PhysicalKeyData.fromJson(
json.decode(readDataFile('physical_key_data.json')) as Map<String, dynamic>);
json.decode(readDataFile('physical_key_data.g.json')) as Map<String, dynamic>);
final LogicalKeyData logicalData = LogicalKeyData.fromJson(
json.decode(readDataFile('logical_key_data.json')) as Map<String, dynamic>);
json.decode(readDataFile('logical_key_data.g.json')) as Map<String, dynamic>);
final Map<String, bool> keyGoals = parseMapOfBool(
readDataFile('layout_goals.json'));
......@@ -71,7 +71,7 @@ void main() {
);
final String output = codeGenerator.generate();
expect(codeGenerator.outputPath(platform), endsWith('KeyCodeMap.mm'));
expect(codeGenerator.outputPath(platform), endsWith('KeyCodeMap.g.mm'));
expect(output, contains('kValueMask'));
expect(output, contains('keyCodeToPhysicalKey'));
expect(output, contains('keyCodeToLogicalKey'));
......@@ -89,7 +89,7 @@ void main() {
);
final String output = codeGenerator.generate();
expect(codeGenerator.outputPath(platform), endsWith('KeyCodeMap.mm'));
expect(codeGenerator.outputPath(platform), endsWith('KeyCodeMap.g.mm'));
expect(output, contains('kValueMask'));
expect(output, contains('keyCodeToPhysicalKey'));
expect(output, contains('keyCodeToLogicalKey'));
......@@ -109,7 +109,7 @@ void main() {
);
final String output = codeGenerator.generate();
expect(codeGenerator.outputPath(platform), endsWith('flutter_key_map.cc'));
expect(codeGenerator.outputPath(platform), endsWith('flutter_key_map.g.cc'));
expect(output, contains('KeyboardKeyEmbedderHandler::windowsToPhysicalMap_'));
expect(output, contains('KeyboardKeyEmbedderHandler::windowsToLogicalMap_'));
expect(output, contains('KeyboardKeyEmbedderHandler::scanCodeToLogicalMap_'));
......@@ -126,7 +126,7 @@ void main() {
);
final String output = codeGenerator.generate();
expect(codeGenerator.outputPath(platform), endsWith('key_mapping.cc'));
expect(codeGenerator.outputPath(platform), endsWith('key_mapping.g.cc'));
expect(output, contains('initialize_modifier_bit_to_checked_keys'));
expect(output, contains('initialize_lock_bit_to_checked_keys'));
checkCommonOutput(output);
......@@ -140,7 +140,7 @@ void main() {
);
final String output = codeGenerator.generate();
expect(codeGenerator.outputPath(platform), endsWith('key_map.dart'));
expect(codeGenerator.outputPath(platform), endsWith('key_map.g.dart'));
expect(output, contains('kWebToLogicalKey'));
expect(output, contains('kWebToPhysicalKey'));
expect(output, contains('kWebLogicalLocationMap'));
......
......@@ -20,8 +20,8 @@ export 'src/services/deferred_component.dart';
export 'src/services/font_loader.dart';
export 'src/services/haptic_feedback.dart';
export 'src/services/hardware_keyboard.dart';
export 'src/services/keyboard_key.dart';
export 'src/services/keyboard_maps.dart';
export 'src/services/keyboard_key.g.dart';
export 'src/services/keyboard_maps.g.dart';
export 'src/services/message_codec.dart';
export 'src/services/message_codecs.dart';
export 'src/services/mouse_cursor.dart';
......
......@@ -13,7 +13,7 @@ export 'dart:ui' show KeyData;
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show RawKeyboard, RawKeyEvent;
/// Represents a lock mode of a keyboard, such as [KeyboardLockMode.capsLock].
......
......@@ -9,9 +9,9 @@
// Edit the template dev/tools/gen_keycodes/data/keyboard_maps.tmpl instead.
// See dev/tools/gen_keycodes/README.md for more information.
import 'keyboard_key.dart';
import 'keyboard_key.g.dart';
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
/// Maps Android-specific key codes to the matching [LogicalKeyboardKey].
const Map<int, LogicalKeyboardKey> kAndroidToLogicalKey = <int, LogicalKeyboardKey>{
......
......@@ -7,7 +7,7 @@ import 'package:flutter/foundation.dart';
import 'binding.dart';
import 'hardware_keyboard.dart';
import 'keyboard_key.dart';
import 'keyboard_key.g.dart';
import 'raw_keyboard_android.dart';
import 'raw_keyboard_fuchsia.dart';
import 'raw_keyboard_ios.dart';
......@@ -19,7 +19,7 @@ import 'system_channels.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder, ValueChanged;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
/// An enum describing the side of the keyboard that a key is on, to allow
/// discrimination between which key is pressed (e.g. the left or right SHIFT
......
......@@ -4,12 +4,12 @@
import 'package:flutter/foundation.dart';
import 'keyboard_maps.dart';
import 'keyboard_maps.g.dart';
import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
// Android sets the 0x80000000 bit on a character to indicate that it is a
......
......@@ -4,12 +4,12 @@
import 'package:flutter/foundation.dart';
import 'keyboard_maps.dart';
import 'keyboard_maps.g.dart';
import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Platform-specific key event data for Fuchsia.
......
......@@ -4,12 +4,12 @@
import 'package:flutter/foundation.dart';
import 'keyboard_maps.dart';
import 'keyboard_maps.g.dart';
import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Maps iOS specific string values of nonvisible keys to logical keys
......
......@@ -4,12 +4,12 @@
import 'package:flutter/foundation.dart';
import 'keyboard_maps.dart';
import 'keyboard_maps.g.dart';
import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Platform-specific key event data for Linux.
......
......@@ -4,12 +4,12 @@
import 'package:flutter/foundation.dart';
import 'keyboard_maps.dart';
import 'keyboard_maps.g.dart';
import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
/// Convert a UTF32 rune to its lower case.
......
......@@ -4,12 +4,12 @@
import 'package:flutter/foundation.dart';
import 'keyboard_maps.dart';
import 'keyboard_maps.g.dart';
import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
String? _unicodeChar(String key) {
......
......@@ -4,12 +4,12 @@
import 'package:flutter/foundation.dart';
import 'keyboard_maps.dart';
import 'keyboard_maps.g.dart';
import 'raw_keyboard.dart';
export 'package:flutter/foundation.dart' show DiagnosticPropertiesBuilder;
export 'keyboard_key.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'keyboard_key.g.dart' show LogicalKeyboardKey, PhysicalKeyboardKey;
export 'raw_keyboard.dart' show KeyboardSide, ModifierKey;
// Virtual key VK_PROCESSKEY in Win32 API.
......
......@@ -5,7 +5,7 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/src/services/keyboard_key.dart';
import 'package:flutter/src/services/keyboard_key.g.dart';
import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart';
......
......@@ -6,7 +6,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/src/services/keyboard_key.dart';
import 'package:flutter/src/services/keyboard_key.g.dart';
import 'package:flutter_test/flutter_test.dart';
import '../rendering/mock_canvas.dart';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment