[core] Leave the precompiled header off on Windows for a GCC with bug 14940 (#19875)

This commit is contained in:
J. Nick Koston
2026-09-29 18:51:12 +02:00
committed by GitHub
parent a7e0afeb46
commit b22f2e6b4c
17 changed files with 410 additions and 35 deletions
+22 -9
View File
@@ -13,7 +13,7 @@ from esphome.core import CORE, EsphomeError
SUM = "CMakeFiles/app.dir/cmake_pch.hxx.gch.sum"
def _generate_cmake(tmp_path: Path) -> str:
def _generate_cmake(tmp_path: Path, pch_on: bool = True) -> str:
CORE.config_path = tmp_path / "test.yaml"
CORE.build_path = tmp_path / "build"
CORE.name = "livingroom"
@@ -25,7 +25,7 @@ def _generate_cmake(tmp_path: Path) -> str:
patch.object(nrf52, "get_project_compile_flags", return_value=["-Os"]),
patch.object(nrf52, "get_project_link_flags", return_value=[]),
):
nrf52._generate_cmake_lists()
nrf52._generate_cmake_lists(pch_on)
return (tmp_path / "build" / "zephyr" / "CMakeLists.txt").read_text()
@@ -43,15 +43,27 @@ def test_cmake_lists_precompile_the_core_headers(tmp_path: Path) -> None:
assert "if(NOT esphome_pch_headers)\n message(FATAL_ERROR" in text
def test_cmake_lists_pch_block_disabled(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
) -> None:
monkeypatch.setenv("ESPHOME_PCH_ENABLE", "0")
text = _generate_cmake(tmp_path)
def test_cmake_lists_pch_block_disabled(tmp_path: Path) -> None:
text = _generate_cmake(tmp_path, pch_on=False)
assert "precompile" not in text
assert "zephyr_interface" not in text
@pytest.mark.parametrize(("version", "on"), [((12, 2, 0), False), ((14, 4, 0), True)])
def test_the_zephyr_compiler_decides_on_windows(
windows_gcc_rule: None, version: tuple[int, ...], on: bool
) -> None:
from esphome.build_helpers import pch
# platformdirs would pick its Windows backend from the patched sys.platform
with (
patch.object(nrf52, "toolchain_tool", lambda name: Path(f"/sdk/{name}.exe")),
patch.object(pch, "gcc_version", return_value=version) as asked,
):
assert nrf52._pch_usable() is on
assert asked.call_args.args[0] == (Path("/sdk/g++.exe"),)
def _write_checksum(tmp_path: Path, app: str, conf: str = "CONFIG_X=y\n") -> Path:
"""Write the checksum for a build dir whose app image sits in ``app``."""
CORE.build_path = tmp_path
@@ -114,9 +126,10 @@ def run_cmd(tmp_path: Path) -> Mock:
def test_ccache_pch_settings_reach_west(run_cmd: Mock) -> None:
# clear=True also drops ambient CCACHE_* and ESPHOME_PCH_* overrides
# clear=True also drops ambient CCACHE_* overrides; the header is on
# explicitly since Windows hosts start with it off
with (
patch.dict("os.environ", {}, clear=True),
patch.dict("os.environ", {"ESPHOME_PCH_ENABLE": "1"}, clear=True),
pytest.raises(EsphomeError, match="nRF52 native build failed"),
):
nrf52.run_compile(None, {})