Simplify: shared tool-step runner, probe args helper, buildtool touch stamp, knob-spelling parity

This commit is contained in:
J. Nick Koston
2026-08-26 23:20:06 -05:00
parent 15d4f187c7
commit 833af674bf
10 changed files with 136 additions and 115 deletions
@@ -1872,8 +1872,8 @@ def test_write_project_pch_strict_emits_probe_edge(
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
# bare stamp command and fail every strict build
assert "&& $python $buildtool touch $out" in content
assert "$stamp" not in content
# With extra src flags the probe edge carries them like the .gch edge
@@ -2,6 +2,7 @@
from __future__ import annotations
import os
from pathlib import Path
import subprocess
import sys
@@ -244,3 +245,12 @@ def test_copy_failure_leaves_no_partial_output(tmp_path: Path) -> None:
):
assert build_tool.main() == 1
assert not dst.exists()
def test_touch_creates_and_updates_stamp(tmp_path: Path) -> None:
stamp = tmp_path / "esphome_pch.probe"
assert build_tool._run_touch(str(stamp)) == 0
assert stamp.is_file()
os.utime(stamp, (1, 1))
assert build_tool._run_touch(str(stamp)) == 0
assert stamp.stat().st_mtime > 1
+21 -17
View File
@@ -903,30 +903,34 @@ def test_prepare_pch_probe_spawn_failure_degrades(
prepare_pch()
@pytest.mark.parametrize(
("stderr", "code"),
[("", -9), ("fatal: No space left on device", 1)],
ids=("signal-kill", "enospc"),
)
def test_prepare_pch_probe_environmental_failures_do_not_latch(
tmp_path: Path,
tmp_path: Path, stderr: str, code: int
) -> None:
"""A signal-killed or ENOSPC probe retries next build, no marker."""
from esphome.build_gen.espidf import prepare_pch
for stderr, code in (("", -9), ("fatal: No space left on device", 1)):
dev = _make_pch_device(tmp_path, f"dev_pe{code}")
CORE.build_path = dev
gch = dev / "build" / "esphome_pch.h.gch"
dev = _make_pch_device(tmp_path, "dev_pe")
CORE.build_path = dev
gch = dev / "build" / "esphome_pch.h.gch"
def env_probe(cmd, _gch=gch, _stderr=stderr, _code=code, **kwargs):
if "-fsyntax-only" in cmd:
return subprocess.CompletedProcess(cmd, _code, "", _stderr)
_gch.write_bytes(b"gch")
return subprocess.CompletedProcess(cmd, 0, "", "")
def env_probe(cmd, **kwargs):
if "-fsyntax-only" in cmd:
return subprocess.CompletedProcess(cmd, code, "", stderr)
gch.write_bytes(b"gch")
return subprocess.CompletedProcess(cmd, 0, "", "")
with (
patch.object(CORE, "name", "test"),
patch("esphome.build_helpers.pch.subprocess.run", side_effect=env_probe),
):
prepare_pch()
assert not gch.exists()
assert not (dev / "build" / "esphome_pch.h.gch.failed").exists()
with (
patch.object(CORE, "name", "test"),
patch("esphome.build_helpers.pch.subprocess.run", side_effect=env_probe),
):
prepare_pch()
assert not gch.exists()
assert not (dev / "build" / "esphome_pch.h.gch.failed").exists()
def test_prepare_pch_signal_kill_strict_raises(