From f6f0e52d5e7bdef9e2b36990307779d6624a5f36 Mon Sep 17 00:00:00 2001 From: Aleksey Zinchenko Date: Wed, 2 Jul 2025 10:37:31 +0300 Subject: [PATCH] [core] Deleting CMakeCache.txt for fast recompilation with ESP-IDF (#8750) --- esphome/writer.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/esphome/writer.py b/esphome/writer.py index 7a5089e384..943dfa78cc 100644 --- a/esphome/writer.py +++ b/esphome/writer.py @@ -107,6 +107,11 @@ def storage_should_clean(old: StorageJSON, new: StorageJSON) -> bool: return True if old.build_path != new.build_path: return True + + return False + + +def storage_should_update_cmake_cache(old: StorageJSON, new: StorageJSON) -> bool: if ( old.loaded_integrations != new.loaded_integrations or old.loaded_platforms != new.loaded_platforms @@ -126,10 +131,11 @@ def update_storage_json(): return if storage_should_clean(old, new): - _LOGGER.info( - "Core config, version or integrations changed, cleaning build files..." - ) + _LOGGER.info("Core config, version changed, cleaning build files...") clean_build() + elif storage_should_update_cmake_cache(old, new): + _LOGGER.info("Integrations changed, cleaning cmake cache...") + clean_cmake_cache() new.save(path) @@ -353,6 +359,15 @@ def write_cpp(code_s): write_file_if_changed(path, full_file) +def clean_cmake_cache(): + pioenvs = CORE.relative_pioenvs_path() + if os.path.isdir(pioenvs): + pioenvs_cmake_path = CORE.relative_pioenvs_path(CORE.name, "CMakeCache.txt") + if os.path.isfile(pioenvs_cmake_path): + _LOGGER.info("Deleting %s", pioenvs_cmake_path) + os.remove(pioenvs_cmake_path) + + def clean_build(): import shutil