Skip to content

Commit

Permalink
[gen_keycodes] Mark generated file names with infix .g. (#106142)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkwingsmt authored Jun 30, 2022
1 parent f0200f0 commit 9970481
Show file tree
Hide file tree
Showing 31 changed files with 62 additions and 62 deletions.
12 changes: 6 additions & 6 deletions dev/tools/gen_keycodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ 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.

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.

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions dev/tools/gen_keycodes/bin/gen_keycodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand All @@ -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 '
Expand All @@ -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.',
Expand All @@ -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(
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions dev/tools/gen_keycodes/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.|
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/gen_keycodes/data/keyboard_maps.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>{
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/lib/base_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/lib/gtk_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/lib/ios_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/lib/keyboard_keys_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/gen_keycodes/lib/keyboard_maps_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dev/tools/gen_keycodes/lib/logical_key_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/lib/macos_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/lib/physical_key_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/lib/web_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/gen_keycodes/lib/windows_code_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions dev/tools/gen_keycodes/test/gen_keycodes_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down Expand Up @@ -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'));
Expand All @@ -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'));
Expand All @@ -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_'));
Expand All @@ -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);
Expand All @@ -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'));
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/services/hardware_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>{
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/services/raw_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/services/raw_keyboard_android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/services/raw_keyboard_fuchsia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/services/raw_keyboard_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9970481

Please sign in to comment.