Bake the probe stamp into the rule text; edge bindings cannot expand $out

This commit is contained in:
J. Nick Koston
2026-08-26 23:10:55 -05:00
parent 21643396c4
commit 15d4f187c7
2 changed files with 10 additions and 5 deletions
+6 -5
View File
@@ -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()
@@ -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"] = (