[usb_uart] Only compile the vendor drivers that are configured (#20190)

This commit is contained in:
J. Nick Koston
2026-10-05 17:56:10 -04:00
committed by GitHub
parent fc441646f4
commit a778baddca
5 changed files with 62 additions and 0 deletions
@@ -0,0 +1,19 @@
"""Tests for the usb_uart component's driver source filtering."""
from collections.abc import Callable
from esphome.core import CORE
def test_only_configured_driver_compiled(
generate_main: Callable[[str], str],
) -> None:
generate_main("tests/component_tests/usb_uart/test_usb_uart_ft232.yaml")
from esphome.components.usb_uart import FILTER_SOURCE_FILES
defines = {define.name for define in CORE.defines}
# cdc_acm is built into usb_uart.cpp and adds no driver define
assert {d for d in defines if d.startswith("USE_USB_UART_")} == {
"USE_USB_UART_FT23XX"
}
assert sorted(FILTER_SOURCE_FILES()) == ["ch34x.cpp", "cp210x.cpp", "pl2303.cpp"]
@@ -0,0 +1,18 @@
esphome:
name: test
esp32:
variant: esp32s3
framework:
type: esp-idf
usb_uart:
- type: ft232
channels:
- id: ft_channel
baud_rate: 115200
- type: cdc_acm
vid: 0x1234
pid: 0x5678
channels:
- id: cdc_channel