mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 13:43:00 +00:00
[espidf] Write version.txt after extract so bootloader shows the real version (#16532)
This commit is contained in:
@@ -783,6 +783,34 @@ def download_from_mirrors(
|
||||
return None
|
||||
|
||||
|
||||
def _write_idf_version_txt(framework_path: Path, version: str) -> None:
|
||||
"""Write <framework_path>/version.txt if missing.
|
||||
|
||||
IDF's build.cmake picks the version it embeds in the firmware (and
|
||||
stamps onto the bootloader) in this order: ``${IDF_PATH}/version.txt``
|
||||
if present, else ``git describe`` against IDF_PATH, else the
|
||||
``IDF_VERSION_MAJOR/MINOR/PATCH`` triplet from ``tools/cmake/version.cmake``.
|
||||
On a clean esphome-libs tarball ``.git`` is fully stripped, so
|
||||
git_describe returns ``HEAD-HASH-NOTFOUND`` (falsy) and the triplet
|
||||
wins -- correct by luck. But a *partial* ``.git`` (e.g. a custom
|
||||
framework.source pointed at a real git URL where build artifacts
|
||||
mark the tree dirty) makes git_describe return ``<hash>-dirty``,
|
||||
which is what then gets baked into the bootloader. Dropping
|
||||
version.txt forces the right answer regardless.
|
||||
"""
|
||||
version_txt = framework_path / "version.txt"
|
||||
if version_txt.exists():
|
||||
return
|
||||
try:
|
||||
version_txt.write_text(f"v{version}\n", encoding="utf-8")
|
||||
except OSError as e:
|
||||
_LOGGER.warning(
|
||||
"Could not write %s (%s); bootloader version string may be incorrect.",
|
||||
version_txt,
|
||||
e,
|
||||
)
|
||||
|
||||
|
||||
def _check_esphome_idf_framework_install(
|
||||
version: str,
|
||||
targets: list[str],
|
||||
@@ -864,6 +892,11 @@ def _check_esphome_idf_framework_install(
|
||||
archive_extract_all(tmp.file, framework_path, progress_header="Extracting")
|
||||
extracted_marker.touch()
|
||||
|
||||
# Idempotent post-extract patch: written every invocation so a build
|
||||
# dir extracted before this fix gets the file too, without forcing a
|
||||
# clean. Skips when version.txt already exists.
|
||||
_write_idf_version_txt(framework_path, version)
|
||||
|
||||
# 3. Check if the framework tools are the same and correctly installed
|
||||
if not install:
|
||||
install = True
|
||||
|
||||
Reference in New Issue
Block a user