diff --git a/esphome/core/__init__.py b/esphome/core/__init__.py index a4fd2ced30..2ec2a08e83 100644 --- a/esphome/core/__init__.py +++ b/esphome/core/__init__.py @@ -992,7 +992,8 @@ class EsphomeCore: @property def using_native_toolchain(self): """Whether the selected toolchain builds natively, without reading - ``platformio.ini`` (see ``NATIVE_TOOLCHAINS`` in ``esphome.const``).""" + ``platformio.ini`` (see ``NATIVE_TOOLCHAINS`` in ``esphome.const``; + keep its membership in sync with ``write_cpp_file``'s dispatch).""" return self.toolchain in NATIVE_TOOLCHAINS @property diff --git a/esphome/core/config.py b/esphome/core/config.py index 34d5f8c67f..3d57c5af1d 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -596,9 +596,11 @@ async def _add_platformio_options(pio_options: dict[str, str | list[str]]) -> No # discovered dependencies cg.add_platformio_option(key, vals) elif key in NATIVE_ARDUINO_PIO_OPTIONS and CORE.using_toolchain_arduino: - # The esp8266 native generator reads these; other native + # The esp8266 native generator reads these as scalars; the + # schema also permits the list form, where the last value + # wins like a later platformio.ini line. Other native # toolchains have no equivalent and fall through to the warning. - cg.add_platformio_option(key, val) + cg.add_platformio_option(key, vals[-1]) elif key != "upload_speed": # upload_speed needs no handling: it is read from the raw # config at upload time (upload_using_esptool) diff --git a/tests/unit_tests/core/test_config.py b/tests/unit_tests/core/test_config.py index 53ed85dacb..1e632d9628 100644 --- a/tests/unit_tests/core/test_config.py +++ b/tests/unit_tests/core/test_config.py @@ -1408,7 +1408,9 @@ async def test_add_platformio_options_native_arduino( await config._add_platformio_options( { "board_build.f_cpu": "160000000L", - "board_build.ldscript": "eagle.flash.4m2m.ld", + # The schema also permits the list form; the last value wins + # and reaches the generator as a scalar + "board_build.ldscript": ["eagle.flash.2m.ld", "eagle.flash.4m2m.ld"], "board_build.filesystem": "littlefs", "upload_speed": "115200", }