[espidf] Trim has_outdated_files watch list; embed IDF version in sdkconfig (#16416)

This commit is contained in:
Jonathan Swoboda
2026-05-14 00:02:22 -04:00
committed by Jesse Hills
parent c863d58999
commit 84b5931299
2 changed files with 35 additions and 18 deletions
+7 -1
View File
@@ -2464,8 +2464,14 @@ def _write_sdkconfig():
) )
want_opts = CORE.data[KEY_ESP32][KEY_SDKCONFIG_OPTIONS] want_opts = CORE.data[KEY_ESP32][KEY_SDKCONFIG_OPTIONS]
# Include the resolved framework version as a Kconfig comment so a
# version switch that happens to leave the option set unchanged still
# bumps this file's content -- which is what has_outdated_files()
# uses to decide whether to reconfigure.
framework_version = CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION]
contents = ( contents = (
"\n".join( f"# ESPHOME_IDF_VERSION={framework_version}\n"
+ "\n".join(
f"{name}={_format_sdkconfig_val(value)}" f"{name}={_format_sdkconfig_val(value)}"
for name, value in sorted(want_opts.items()) for name, value in sorted(want_opts.items())
) )
+28 -17
View File
@@ -191,23 +191,38 @@ def run_reconfigure() -> int:
def has_outdated_files(): def has_outdated_files():
"""Check if the build configuration is stale. """Check if the build configuration is stale.
Returns True if required build files are missing or if external Returns True if required build files are missing or if ESPHome's
configuration inputs (IDF install, sdkconfig, CMake's own build/config resolved build inputs are newer than CMakeCache.txt:
dir) are newer than CMakeCache.txt. We deliberately don't watch the
top-level/src ``CMakeLists.txt`` here -- those are written by - ``sdkconfig.<name>.esphomeinternal`` -- the canonical "what state
``write_project`` via ``write_file_if_changed`` (so an mtime bump did ESPHome resolve the YAML to" snapshot. Any change in build
means our content actually changed) and ninja already tracks them as flags, enabled components, framework version, or target ends up
configure-time deps via ``build.ninja``. Including them in this check rewriting it (we embed a ``# ESPHOME_IDF_VERSION=`` comment line
causes a perpetual reconfigure loop: the two-pass write leaves for the version case where the option set would otherwise be
CMakeLists newer than CMakeCache.txt, and CMake doesn't restamp the identical).
cache when only ``idf_build_set_property`` values change, so the - ``src/idf_component.yml`` -- the project manifest. Managed
check would trip on every subsequent build. component additions/removals (e.g. via ``add_idf_component``) can
happen without any sdkconfig impact, and ``_write_idf_component_yml``
already deletes ``dependencies.lock`` on a change but that signal
gets lost as soon as the lock is missing.
We deliberately don't watch:
- The top-level/src ``CMakeLists.txt`` -- ESPHome owns those, and
ninja already tracks them as configure-time deps. Including them
causes a perpetual reconfigure loop because CMake doesn't restamp
``CMakeCache.txt`` when only ``idf_build_set_property`` values
change between configures.
- ``$IDF_PATH`` and CMake's ``build/config/`` -- both have mtime
semantics that fire after the wrong configure (or not at all in
common cases like in-place IDF version replacement). The sdkconfig
and manifest hashes subsume the meaningful signal.
""" """
cmakecache_txt_path = CORE.relative_build_path("build/CMakeCache.txt") cmakecache_txt_path = CORE.relative_build_path("build/CMakeCache.txt")
build_config_path = CORE.relative_build_path("build/config") build_config_path = CORE.relative_build_path("build/config")
sdkconfig_internal_path = CORE.relative_build_path( sdkconfig_internal_path = CORE.relative_build_path(
f"sdkconfig.{CORE.name}.esphomeinternal" f"sdkconfig.{CORE.name}.esphomeinternal"
) )
idf_component_yml_path = CORE.relative_build_path("src/idf_component.yml")
dependency_lock_path = CORE.relative_build_path("dependencies.lock") dependency_lock_path = CORE.relative_build_path("dependencies.lock")
build_ninja_path = CORE.relative_build_path("build/build.ninja") build_ninja_path = CORE.relative_build_path("build/build.ninja")
@@ -225,12 +240,8 @@ def has_outdated_files():
cmakecache_txt_mtime = os.path.getmtime(cmakecache_txt_path) cmakecache_txt_mtime = os.path.getmtime(cmakecache_txt_path)
return any( return any(
os.path.getmtime(f) > cmakecache_txt_mtime os.path.getmtime(f) > cmakecache_txt_mtime
for f in [ for f in [sdkconfig_internal_path, idf_component_yml_path]
_get_idf_path(), if f.exists()
sdkconfig_internal_path,
build_config_path,
]
if f and os.path.exists(f)
) )