From 7096546d83c6702a6783b3f3ccb59eab16f2933a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 2 Oct 2026 10:07:13 -0500 Subject: [PATCH] [nrf52] Create the precompiled header in ccache depend mode (#20019) --- esphome/components/nrf52/__init__.py | 3 +++ tests/unit_tests/components/nrf52/test_pch.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/esphome/components/nrf52/__init__.py b/esphome/components/nrf52/__init__.py index 5ebf5b747f..07507901ba 100644 --- a/esphome/components/nrf52/__init__.py +++ b/esphome/components/nrf52/__init__.py @@ -978,6 +978,9 @@ def run_compile(args, config: ConfigType) -> bool: pch.log_pch_in_use() # Zephyr turns ccache on by itself when it is installed env.update(pch.ccache_pch_env()) + # Depend mode, or a Kconfig flip reuses a stale .gch: autoconf.h is + # all #defines, which vanish from the preprocessed creation hash. + env.setdefault("CCACHE_DEPEND", "1") _write_pch_checksum(build_dir, source_dir) west_cmd = _west_build_command( diff --git a/tests/unit_tests/components/nrf52/test_pch.py b/tests/unit_tests/components/nrf52/test_pch.py index 0dcac3cad4..04932e76cc 100644 --- a/tests/unit_tests/components/nrf52/test_pch.py +++ b/tests/unit_tests/components/nrf52/test_pch.py @@ -138,6 +138,18 @@ def test_ccache_pch_settings_reach_west(run_cmd: Mock) -> None: env = run_cmd.call_args.kwargs["env"] assert env["CCACHE_PCH_EXTSUM"] == "true" assert env["CCACHE_SLOPPINESS"] == "pch_defines,time_macros" + # Without depend mode a Kconfig flip reuses a stale .gch + assert env["CCACHE_DEPEND"] == "1" + + +def test_ccache_depend_respects_a_user_override(run_cmd: Mock) -> None: + with ( + patch.object(nrf52, "get_build_env", return_value={"CCACHE_DEPEND": "0"}), + patch.dict("os.environ", {"ESPHOME_PCH_ENABLE": "1"}, clear=True), + pytest.raises(EsphomeError, match="nRF52 native build failed"), + ): + nrf52.run_compile(None, {}) + assert run_cmd.call_args.kwargs["env"]["CCACHE_DEPEND"] == "0" def test_disabled_leaves_the_west_environment_alone( @@ -147,3 +159,4 @@ def test_disabled_leaves_the_west_environment_alone( with pytest.raises(EsphomeError, match="nRF52 native build failed"): nrf52.run_compile(None, {}) assert "CCACHE_PCH_EXTSUM" not in run_cmd.call_args.kwargs["env"] + assert "CCACHE_DEPEND" not in run_cmd.call_args.kwargs["env"]