From 2dac9112bec60db38fedcfe28da67d6db668d60c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Aug 2026 13:15:47 -0500 Subject: [PATCH] Pin the scalar shape for the honored board_build options; note the dispatch coupling The schema permits the list form, so the routing now stores the last value (like a later platformio.ini line) and the generator always sees a scalar. The using_native_toolchain docstring points at write_cpp_file's dispatch so NATIVE_TOOLCHAINS membership and the project-writing branch flip together. --- esphome/core/__init__.py | 3 ++- esphome/core/config.py | 6 ++++-- tests/unit_tests/core/test_config.py | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) 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 063da34556..5bbfb89ee1 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", }