diff --git a/esphome/build_gen/arduino8266.py b/esphome/build_gen/arduino8266.py index 251b6e19eb..2e562c8870 100644 --- a/esphome/build_gen/arduino8266.py +++ b/esphome/build_gen/arduino8266.py @@ -1295,21 +1295,22 @@ def write_project(paths: InstalledPaths, ccache: str | None) -> bool: if pch_strict(): # Consumers wait on the probe stamp, so an unloadable .gch # reds the build here instead of warning ~100 times + # $out only expands in rule text, so the stamp command is + # baked into the rule (generation host == build host) + stamp = ( + "cmd /c copy /y nul $out >nul" if os.name == "nt" else "touch $out" + ) lines.append("rule pchprobe") lines.append( " command = $cxx $cxxflags $flags -Winvalid-pch" " -Werror=invalid-pch" f" -include {PCH_HEADER_NAME} -fsyntax-only -x c++" - f" {_q(Path(os.devnull))} && $stamp" + f" {_q(Path(os.devnull))} && {stamp}" ) lines.append(" description = PCHPROBE $out") lines.append(f"build esphome_pch.probe: pchprobe {gch}") if src_other: lines.append(f" flags = {' '.join(src_other)}") - stamp = ( - "cmd /c copy /y nul $out >nul" if os.name == "nt" else "touch $out" - ) - lines.append(f" stamp = {stamp}") pch_dep = f"{gch} esphome_pch.probe" src_cxx_override = ("$srccxxflags", pch_dep) mark_pch_emitted() diff --git a/tests/unit_tests/build_gen/test_arduino8266.py b/tests/unit_tests/build_gen/test_arduino8266.py index ceada787a5..56f8d7c867 100644 --- a/tests/unit_tests/build_gen/test_arduino8266.py +++ b/tests/unit_tests/build_gen/test_arduino8266.py @@ -1871,6 +1871,10 @@ def test_write_project_pch_strict_emits_probe_edge( content = _write_ninja(paths, ccache="/usr/bin/ccache") assert "build esphome_pch.probe: pchprobe esphome_pch.h.gch" in content assert "-Werror=invalid-pch" in content + # $out only expands in rule text; an edge-level binding would emit a + # bare "touch " and fail every strict build + assert "&& touch $out" in content + assert "$stamp" not in content # With extra src flags the probe edge carries them like the .gch edge CORE.platformio_options["build_src_flags"] = (