mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 15:27:33 +00:00
Merge branch 'host-pch' into esp32-pio-pch
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
"""Files that affect clang-tidy results, and a content hash over them.
|
||||
"""Files that affect clang-tidy results and the idedata built from them.
|
||||
|
||||
``CLANG_TIDY_GLOBAL_FILES`` (plus ``SDKCONFIG_DEFAULTS_PREFIX``) is the single
|
||||
source of truth for which files influence clang-tidy output. A change to any of
|
||||
them can surface warnings in source files a PR didn't touch, so:
|
||||
|
||||
* ``script/determine-jobs.py`` runs a full clang-tidy scan when one changes, and
|
||||
* ``calculate_clang_tidy_hash()`` folds them into the idedata cache key used by
|
||||
``script/helpers.py`` (a content hash, unlike an mtime check, stays correct
|
||||
across git checkouts).
|
||||
``CLANG_TIDY_GLOBAL_FILES`` (plus ``SDKCONFIG_DEFAULTS_PREFIX``) lists the files
|
||||
that influence clang-tidy output; ``script/determine-jobs.py`` runs a full scan
|
||||
when one changes. ``ESP_IDF_INFRA_TRIGGER_*`` lists the native ESP-IDF build
|
||||
code. ``idedata_cache_hash()`` folds the right set into the idedata cache key
|
||||
used by ``script/helpers.py`` and the CI cache action.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -31,6 +28,18 @@ CLANG_TIDY_GLOBAL_FILES = (
|
||||
# this prefix at the repo root.
|
||||
SDKCONFIG_DEFAULTS_PREFIX = "sdkconfig.defaults"
|
||||
|
||||
# Native ESP-IDF build infra: determine-jobs forces an esp32 compile when these
|
||||
# change, and they feed the clang-tidy idedata cache key.
|
||||
ESP_IDF_INFRA_TRIGGER_PATH_PREFIXES = ("esphome/espidf/", "esphome/build_helpers/")
|
||||
ESP_IDF_INFRA_TRIGGER_FILES = frozenset(
|
||||
{
|
||||
"esphome/build_gen/espidf.py",
|
||||
"esphome/framework_helpers.py",
|
||||
"esphome/platformio/library.py",
|
||||
"esphome/platformio/extra_script.py",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def read_file_bytes(path: Path) -> bytes:
|
||||
"""Read bytes from a file."""
|
||||
@@ -66,3 +75,33 @@ def calculate_clang_tidy_hash(repo_root: Path | None = None) -> str:
|
||||
hasher.update(read_file_bytes(path))
|
||||
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
def calculate_idedata_cache_hash(repo_root: Path | None = None) -> str:
|
||||
"""Clang-tidy hash plus the Python that generates the idedata."""
|
||||
repo_root = _ensure_repo_root(repo_root)
|
||||
|
||||
hasher = hashlib.sha256()
|
||||
hasher.update(calculate_clang_tidy_hash(repo_root).encode())
|
||||
|
||||
paths = {repo_root / name for name in ESP_IDF_INFRA_TRIGGER_FILES}
|
||||
for prefix in ESP_IDF_INFRA_TRIGGER_PATH_PREFIXES:
|
||||
# .pyc files appear between the CI key computation and load_idedata's.
|
||||
paths.update(
|
||||
path
|
||||
for path in (repo_root / prefix).rglob("*")
|
||||
if "__pycache__" not in path.parts
|
||||
)
|
||||
for path in sorted(paths):
|
||||
if path.is_file():
|
||||
hasher.update(str(path.relative_to(repo_root)).encode())
|
||||
hasher.update(read_file_bytes(path))
|
||||
|
||||
return hasher.hexdigest()
|
||||
|
||||
|
||||
def idedata_cache_hash(environment: str, repo_root: Path | None = None) -> str:
|
||||
"""Hash gating the cached idedata of one clang-tidy environment."""
|
||||
if "esp32" in environment:
|
||||
return calculate_idedata_cache_hash(repo_root)
|
||||
return calculate_clang_tidy_hash(repo_root)
|
||||
|
||||
+18
-23
@@ -59,7 +59,12 @@ from pathlib import Path
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
from clang_tidy_hash import CLANG_TIDY_GLOBAL_FILES, SDKCONFIG_DEFAULTS_PREFIX
|
||||
from clang_tidy_hash import (
|
||||
CLANG_TIDY_GLOBAL_FILES,
|
||||
ESP_IDF_INFRA_TRIGGER_FILES,
|
||||
ESP_IDF_INFRA_TRIGGER_PATH_PREFIXES,
|
||||
SDKCONFIG_DEFAULTS_PREFIX,
|
||||
)
|
||||
from helpers import (
|
||||
CPP_FILE_EXTENSIONS,
|
||||
ESPHOME_TESTS_COMPONENTS_PATH,
|
||||
@@ -551,28 +556,6 @@ def _esp32_platformio_path_or_file_trigger(files: list[str]) -> bool:
|
||||
)
|
||||
|
||||
|
||||
# Native-build infra: changes under esphome/espidf/, the shared
|
||||
# esphome/build_helpers/ package, or the modules the native ESP-IDF build
|
||||
# imports affect every esp32 IDF build (now the default toolchain) but aren't
|
||||
# components, so the component matrix wouldn't otherwise force any esp32
|
||||
# compile. When they change we fold the `esp32` component into the matrix so
|
||||
# the default native-IDF build path is still compiled on an infra-only PR.
|
||||
ESP_IDF_INFRA_TRIGGER_PATH_PREFIXES = ("esphome/espidf/", "esphome/build_helpers/")
|
||||
# Shared library-conversion modules every native build imports; a new shared
|
||||
# module added to one native trigger set must not silently skip the other's
|
||||
# smoke test, so both sets union this one.
|
||||
_NATIVE_SHARED_TRIGGER_FILES = frozenset(
|
||||
{
|
||||
"esphome/framework_helpers.py",
|
||||
"esphome/platformio/library.py",
|
||||
"esphome/platformio/extra_script.py",
|
||||
}
|
||||
)
|
||||
ESP_IDF_INFRA_TRIGGER_FILES = _NATIVE_SHARED_TRIGGER_FILES | {
|
||||
"esphome/build_gen/espidf.py",
|
||||
}
|
||||
|
||||
|
||||
def _esp_idf_infra_changed(files: list[str]) -> bool:
|
||||
"""Whether any changed file is ESP-IDF build/runner infrastructure."""
|
||||
return _path_or_file_trigger(
|
||||
@@ -676,6 +659,18 @@ ESP8266_NATIVE_TRIGGER_PATH_PREFIXES = (
|
||||
"esphome/arduino/",
|
||||
"esphome/build_helpers/",
|
||||
)
|
||||
# Shared library-conversion modules every native build imports; espidf-only
|
||||
# infra (build_gen/espidf.py) deliberately stays out of the esp8266 set.
|
||||
_NATIVE_SHARED_TRIGGER_FILES = frozenset(
|
||||
{
|
||||
"esphome/framework_helpers.py",
|
||||
"esphome/platformio/library.py",
|
||||
"esphome/platformio/extra_script.py",
|
||||
}
|
||||
)
|
||||
# Tripwire: the shared modules must stay in the ESP-IDF trigger set too
|
||||
# (now defined in clang_tidy_hash), or its smoke test silently skips them
|
||||
assert _NATIVE_SHARED_TRIGGER_FILES <= ESP_IDF_INFRA_TRIGGER_FILES
|
||||
ESP8266_NATIVE_TRIGGER_FILES = (
|
||||
_NATIVE_SHARED_TRIGGER_FILES
|
||||
| _SMOKE_HARNESS_TRIGGER_FILES
|
||||
|
||||
+4
-7
@@ -809,17 +809,14 @@ def load_idedata(environment: str) -> dict[str, Any]:
|
||||
start_time = time.time()
|
||||
print(f"Loading IDE data for environment '{environment}'...")
|
||||
|
||||
# Reuse the clang-tidy input hash as the cache key: it already covers every
|
||||
# file baked into the generated idedata (platformio.ini, sdkconfig.defaults,
|
||||
# esphome/idf_component.yml), so this can't drift from that file list. A
|
||||
# content hash -- unlike an mtime comparison -- stays correct across git
|
||||
# checkouts, which don't preserve mtimes.
|
||||
from clang_tidy_hash import calculate_clang_tidy_hash
|
||||
# Content hash of the idedata inputs (data files and the generator code); a
|
||||
# content hash, unlike mtimes, stays correct across git checkouts.
|
||||
from clang_tidy_hash import idedata_cache_hash
|
||||
|
||||
temp_idedata = Path(temp_folder) / f"idedata-{environment}.json"
|
||||
temp_hash = Path(temp_folder) / f"idedata-{environment}.hash"
|
||||
|
||||
cache_key = calculate_clang_tidy_hash()
|
||||
cache_key = idedata_cache_hash(environment)
|
||||
changed = (
|
||||
not temp_idedata.is_file()
|
||||
or not temp_hash.is_file()
|
||||
|
||||
Reference in New Issue
Block a user