Skip to content

Commit 71c0994

Browse files
aidanwolter3CQ Bot
authored andcommitted
[assembly] Synchronize InputDeviceType
Assembly config_schema uses the input-device-constants enum to reduce an extra copy of this enum. The bazel rules are updated to reflect all the right options, and a IFTTT is added. Bug: 346413132 Change-Id: Ie860f1d1b1546dc6e52468909c81b9d8c54d3d11 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1179389 Reviewed-by: Filip Filmar <[email protected]> Fuchsia-Auto-Submit: Aidan Wolter <[email protected]> Reviewed-by: Jiaming Li <[email protected]> Commit-Queue: Auto-Submit <[email protected]>
1 parent 5bfc70e commit 71c0994

File tree

4 files changed

+23
-50
lines changed

4 files changed

+23
-50
lines changed

build/bazel_sdk/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_configuration.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ BUILD_TYPES = struct(
3434
INPUT_DEVICE_TYPE = struct(
3535
BUTTON = "button",
3636
KEYBOARD = "keyboard",
37+
LIGHT_SENSOR = "lightsensor",
3738
MOUSE = "mouse",
3839
TOUCHSCREEN = "touchscreen",
3940
)

src/lib/assembly/config_schema/src/platform_config/ui_config.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
use assembly_file_relative_path::{FileRelativePathBuf, SupportsFileRelativePaths};
6-
use input_device_constants::InputDeviceType as PlatformInputDeviceType;
6+
use input_device_constants::InputDeviceType;
77
use schemars::JsonSchema;
88
use serde::{Deserialize, Serialize};
99

@@ -85,32 +85,6 @@ impl Default for PlatformUiConfig {
8585
}
8686
}
8787

88-
// LINT.IfChange
89-
/// Options for input devices that may be supported.
90-
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, JsonSchema)]
91-
#[serde(rename_all = "lowercase", deny_unknown_fields)]
92-
pub enum InputDeviceType {
93-
Button,
94-
Keyboard,
95-
LightSensor,
96-
Mouse,
97-
Touchscreen,
98-
}
99-
100-
// This impl verifies that the platform and assembly enums are kept in sync.
101-
impl From<InputDeviceType> for PlatformInputDeviceType {
102-
fn from(src: InputDeviceType) -> PlatformInputDeviceType {
103-
match src {
104-
InputDeviceType::Button => PlatformInputDeviceType::ConsumerControls,
105-
InputDeviceType::Keyboard => PlatformInputDeviceType::Keyboard,
106-
InputDeviceType::LightSensor => PlatformInputDeviceType::LightSensor,
107-
InputDeviceType::Mouse => PlatformInputDeviceType::Mouse,
108-
InputDeviceType::Touchscreen => PlatformInputDeviceType::Touch,
109-
}
110-
}
111-
}
112-
// LINT.ThenChange(/src/ui/lib/input-device-constants/src/lib.rs)
113-
11488
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, JsonSchema)]
11589
#[serde(rename_all = "lowercase", deny_unknown_fields)]
11690
pub enum ViewingDistance {

src/ui/lib/input-device-constants/BUILD.gn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ rustc_library("lib") {
1717
name = "input_device_constants"
1818
with_unit_tests = true
1919
edition = "2021"
20-
deps = [ "//third_party/rust_crates:tracing" ]
20+
deps = [
21+
"//third_party/rust_crates:schemars",
22+
"//third_party/rust_crates:serde",
23+
"//third_party/rust_crates:tracing",
24+
]
2125
sources = [ "src/lib.rs" ]
2226
}
2327

src/ui/lib/input-device-constants/src/lib.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,25 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
/// Generic types of supported input devices.
6-
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
5+
use schemars::JsonSchema;
6+
use serde::{Deserialize, Serialize};
7+
78
// LINT.IfChange
9+
/// Generic types of supported input devices.
10+
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, Deserialize, Serialize, JsonSchema)]
11+
#[serde(rename_all = "lowercase")]
812
pub enum InputDeviceType {
913
Keyboard,
1014
LightSensor,
15+
#[serde(rename = "button")]
1116
ConsumerControls,
1217
Mouse,
18+
#[serde(rename = "touchscreen")]
1319
Touch,
1420
}
15-
// LINT.ThenChange(/src/lib/assembly/config_schema/src/product_config.rs)
21+
// LINT.ThenChange(/build/bazel_sdk/bazel_rules_fuchsia/fuchsia/private/assembly/fuchsia_product_configuration.bzl)
1622

1723
impl InputDeviceType {
18-
/// Parses an `InputDeviceType` string that has been serialized from
19-
/// `src/lib/assembly/config_schema/src/product_config.rs`: `InputDeviceType`, which has
20-
/// slightly different names.
21-
///
22-
/// If a device string isn't recognized, returns `None`.
23-
pub fn try_from_assembly_config_entry(device: impl AsRef<str>) -> Option<Self> {
24-
match device.as_ref() {
25-
"button" => Some(Self::ConsumerControls),
26-
"keyboard" => Some(Self::Keyboard),
27-
"lightsensor" => Some(Self::LightSensor),
28-
"mouse" => Some(Self::Mouse),
29-
"touchscreen" => Some(Self::Touch),
30-
_ => None,
31-
}
32-
}
33-
3424
/// Parses a list of supported `InputDeviceType`s from a structured configuration
3525
/// `supported_input_devices` list. Unknown device types are logged and skipped.
3626
pub fn list_from_structured_config_list<'a, V, T>(list: V) -> Vec<Self>
@@ -39,9 +29,13 @@ impl InputDeviceType {
3929
T: AsRef<str> + 'a,
4030
{
4131
list.into_iter()
42-
.filter_map(|device| match Self::try_from_assembly_config_entry(device) {
43-
Some(d) => Some(d),
44-
None => {
32+
.filter_map(|device| match device.as_ref() {
33+
"button" => Some(InputDeviceType::ConsumerControls),
34+
"keyboard" => Some(InputDeviceType::Keyboard),
35+
"lightsensor" => Some(InputDeviceType::LightSensor),
36+
"mouse" => Some(InputDeviceType::Mouse),
37+
"touchscreen" => Some(InputDeviceType::Touch),
38+
_ => {
4539
tracing::warn!(
4640
"Ignoring unsupported device configuration: {}",
4741
device.as_ref()

0 commit comments

Comments
 (0)