[nrf52] Create the precompiled header in ccache depend mode (#20019)

This commit is contained in:
J. Nick Koston
2026-10-02 15:07:13 +00:00
committed by GitHub
parent 1c31e9d28d
commit 7096546d83
2 changed files with 16 additions and 0 deletions
+3
View File
@@ -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(
@@ -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"]