diff --git a/esphome/build_gen/arduino8266.py b/esphome/build_gen/arduino8266.py index 50b506ef821..4b6f44566d3 100644 --- a/esphome/build_gen/arduino8266.py +++ b/esphome/build_gen/arduino8266.py @@ -932,23 +932,16 @@ def write_project(paths: InstalledPaths, ccache: str | None) -> bool: raise EsphomeError(f"Invalid flash mode {flash_mode!r}") flash_ld_name = _flash_ld_name(board) - generate_ld_scripts(paths, config, flash_ld_name) - sdk = framework / "tools" / "sdk" core_dir = framework / "cores" / "esp8266" variant_dir = framework / "variants" / board_build["variant"] src_dir = CORE.relative_src_path() - libraries = resolve_libraries( - framework, - pio_platform="espressif8266", - board_mcu="esp8266", - cache_key="arduino8266", - ) - if not src_dir.is_dir(): # Generated project state, not install state: clean-all would not help raise EsphomeError(f"Generated source directory {src_dir} is missing") + # Completeness checks run before generate_ld_scripts spawns gcc so a + # half-extracted install names the missing path, not a gcc error. # A missing install directory would otherwise surface as a wall of # include errors; failing here names the path instead. include_dirs = [ @@ -974,6 +967,15 @@ def write_project(paths: InstalledPaths, ccache: str | None) -> bool: raise EsphomeError( f"{_INCOMPLETE_INSTALL}: missing {required_file}; {_CLEAN_HINT}" ) + + generate_ld_scripts(paths, config, flash_ld_name) + + libraries = resolve_libraries( + framework, + pio_platform="espressif8266", + board_mcu="esp8266", + cache_key="arduino8266", + ) for lib in libraries: include_dirs += lib.include_dirs diff --git a/tests/unit_tests/build_gen/test_arduino8266.py b/tests/unit_tests/build_gen/test_arduino8266.py index cd9ffcd3cec..4ad88347e2a 100644 --- a/tests/unit_tests/build_gen/test_arduino8266.py +++ b/tests/unit_tests/build_gen/test_arduino8266.py @@ -1709,5 +1709,7 @@ def test_write_project_rejects_spaced_ldscript_override(tmp_path: Path) -> None: CORE.platformio_options = {"board_build.ldscript": "my script.ld"} paths = _make_framework(tmp_path) _set_flags() + # The completeness checks run first; give them a src dir to pass + CORE.relative_src_path().mkdir(parents=True, exist_ok=True) with pytest.raises(EsphomeError, match="Invalid flash linker script name"): arduino8266.write_project(paths, None)