diff --git a/esphome/build_gen/arduino8266.py b/esphome/build_gen/arduino8266.py index f68eb66984..761ee80446 100644 --- a/esphome/build_gen/arduino8266.py +++ b/esphome/build_gen/arduino8266.py @@ -791,7 +791,8 @@ def write_project(paths: InstalledPaths, ccache: str | None) -> bool: link_flags += project_link_flags link_flags += [_shell_token(flag) for lib in libraries for flag in lib.link_flags] flash_ld = _active_flash_ld_name(flash_ld_name) - link_flags += ["-T", flash_ld] + # A user-overridden script name re-quotes like every other user token + link_flags += ["-T", _shell_token(flash_ld)] lib_dirs = [Path("ld"), sdk / "lib", sdk / "ld", sdk / "lib" / config.nonosdk] lib_dirs += project_lib_dirs @@ -850,7 +851,9 @@ def write_project(paths: InstalledPaths, ccache: str | None) -> bool: " description = LINK $out", "rule elf2bin", # --flash_freq 40: every supported board's f_flash is 40 MHz; - # re-check on a platform bump + # re-check on a platform bump. --flash_size deliberately stays + # board-derived, as under PlatformIO (which reads + # upload.maximum_size, not the ldscript). f" command = $python {_q(framework / 'tools' / 'elf2bin.py')} --eboot {_q(framework / 'bootloaders' / 'eboot' / 'eboot.elf')} --app $in --flash_mode {esp8266_data[KEY_FLASH_MODE]} --flash_freq 40 --flash_size {_flash_size_str(BOARDS[board][KEY_FLASH_SIZE])} --path {_q(toolchain_bin)} --out $out", " description = BIN $out", "rule copy", diff --git a/tests/unit_tests/build_gen/test_arduino8266.py b/tests/unit_tests/build_gen/test_arduino8266.py index e2ca160e26..b2b8f3ae4a 100644 --- a/tests/unit_tests/build_gen/test_arduino8266.py +++ b/tests/unit_tests/build_gen/test_arduino8266.py @@ -1342,3 +1342,14 @@ def test_flash_ld_name_honors_ldscript_override(tmp_path: Path) -> None: CORE.platformio_options = {"board_build.ldscript": "../evil.ld"} with pytest.raises(EsphomeError, match="bare script name"): arduino8266._flash_ld_name("nodemcuv2") + + +def test_write_project_quotes_spaced_ldscript_override(tmp_path: Path) -> None: + """An overridden script name re-quotes on the link line like every other + user token (a space would otherwise split into two argv elements).""" + CORE.platformio_options = {"board_build.ldscript": "my script.ld"} + paths = _make_framework(tmp_path) + _set_flags() + content = _write_ninja(paths) + assert "'my script.ld'" in content or '"my script.ld"' in content + assert "-T my script.ld" not in content