1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-31 23:21:54 +00:00

[ci] Remove base bus components exclusion from memory impact analysis (#11572)

This commit is contained in:
J. Nick Koston
2025-10-28 14:08:13 -05:00
committed by GitHub
parent c3f40de844
commit 0119e17f04
2 changed files with 28 additions and 21 deletions

View File

@@ -48,7 +48,6 @@ import sys
from typing import Any from typing import Any
from helpers import ( from helpers import (
BASE_BUS_COMPONENTS,
CPP_FILE_EXTENSIONS, CPP_FILE_EXTENSIONS,
PYTHON_FILE_EXTENSIONS, PYTHON_FILE_EXTENSIONS,
changed_files, changed_files,
@@ -453,7 +452,7 @@ def detect_memory_impact_config(
# Get actually changed files (not dependencies) # Get actually changed files (not dependencies)
files = changed_files(branch) files = changed_files(branch)
# Find all changed components (excluding core and base bus components) # Find all changed components (excluding core)
# Also collect platform hints from platform-specific filenames # Also collect platform hints from platform-specific filenames
changed_component_set: set[str] = set() changed_component_set: set[str] = set()
has_core_cpp_changes = False has_core_cpp_changes = False
@@ -462,13 +461,13 @@ def detect_memory_impact_config(
for file in files: for file in files:
component = get_component_from_path(file) component = get_component_from_path(file)
if component: if component:
# Skip base bus components as they're used across many builds # Add all changed components, including base bus components
if component not in BASE_BUS_COMPONENTS: # Base bus components (uart, i2c, spi, etc.) should still be analyzed
changed_component_set.add(component) # when directly changed, even though they're also used as dependencies
# Check if this is a platform-specific file changed_component_set.add(component)
platform_hint = _detect_platform_hint_from_filename(file) # Check if this is a platform-specific file
if platform_hint: if platform_hint := _detect_platform_hint_from_filename(file):
platform_hints.append(platform_hint) platform_hints.append(platform_hint)
elif file.startswith("esphome/") and file.endswith(CPP_FILE_EXTENSIONS): elif file.startswith("esphome/") and file.endswith(CPP_FILE_EXTENSIONS):
# Core ESPHome C++ files changed (not component-specific) # Core ESPHome C++ files changed (not component-specific)
# Only C++ files affect memory usage # Only C++ files affect memory usage

View File

@@ -849,39 +849,47 @@ def test_detect_memory_impact_config_no_components_with_tests(tmp_path: Path) ->
assert result["should_run"] == "false" assert result["should_run"] == "false"
def test_detect_memory_impact_config_skips_base_bus_components(tmp_path: Path) -> None: def test_detect_memory_impact_config_includes_base_bus_components(
"""Test that base bus components (i2c, spi, uart) are skipped.""" tmp_path: Path,
) -> None:
"""Test that base bus components (i2c, spi, uart) are included when directly changed.
Base bus components should be analyzed for memory impact when they are directly
changed, even though they are often used as dependencies. This ensures that
optimizations to base components (like using move semantics or initializer_list)
are properly measured.
"""
# Create test directory structure # Create test directory structure
tests_dir = tmp_path / "tests" / "components" tests_dir = tmp_path / "tests" / "components"
# i2c component (should be skipped as it's a base bus component) # uart component (base bus component that should be included)
i2c_dir = tests_dir / "i2c" uart_dir = tests_dir / "uart"
i2c_dir.mkdir(parents=True) uart_dir.mkdir(parents=True)
(i2c_dir / "test.esp32-idf.yaml").write_text("test: i2c") (uart_dir / "test.esp32-idf.yaml").write_text("test: uart")
# wifi component (should not be skipped) # wifi component (regular component)
wifi_dir = tests_dir / "wifi" wifi_dir = tests_dir / "wifi"
wifi_dir.mkdir(parents=True) wifi_dir.mkdir(parents=True)
(wifi_dir / "test.esp32-idf.yaml").write_text("test: wifi") (wifi_dir / "test.esp32-idf.yaml").write_text("test: wifi")
# Mock changed_files to return both i2c and wifi # Mock changed_files to return both uart and wifi
with ( with (
patch.object(determine_jobs, "root_path", str(tmp_path)), patch.object(determine_jobs, "root_path", str(tmp_path)),
patch.object(helpers, "root_path", str(tmp_path)), patch.object(helpers, "root_path", str(tmp_path)),
patch.object(determine_jobs, "changed_files") as mock_changed_files, patch.object(determine_jobs, "changed_files") as mock_changed_files,
): ):
mock_changed_files.return_value = [ mock_changed_files.return_value = [
"esphome/components/i2c/i2c.cpp", "esphome/components/uart/automation.h", # Header file with inline code
"esphome/components/wifi/wifi.cpp", "esphome/components/wifi/wifi.cpp",
] ]
determine_jobs._component_has_tests.cache_clear() determine_jobs._component_has_tests.cache_clear()
result = determine_jobs.detect_memory_impact_config() result = determine_jobs.detect_memory_impact_config()
# Should only include wifi, not i2c # Should include both uart and wifi
assert result["should_run"] == "true" assert result["should_run"] == "true"
assert result["components"] == ["wifi"] assert set(result["components"]) == {"uart", "wifi"}
assert "i2c" not in result["components"] assert result["platform"] == "esp32-idf" # Common platform
def test_detect_memory_impact_config_with_variant_tests(tmp_path: Path) -> None: def test_detect_memory_impact_config_with_variant_tests(tmp_path: Path) -> None: