mirror of
https://github.com/esphome/esphome.git
synced 2026-01-09 19:50:49 -07:00
[core] Fix incremental build failures when adding components on ESP32-Arduino (#12745)
This commit is contained in:
committed by
Jonathan Swoboda
parent
339399eb70
commit
0194bfd9ea
@@ -99,14 +99,11 @@ def storage_should_clean(old: StorageJSON | None, new: StorageJSON) -> bool:
|
||||
|
||||
|
||||
def storage_should_update_cmake_cache(old: StorageJSON, new: StorageJSON) -> bool:
|
||||
if (
|
||||
# ESP32 uses CMake for both Arduino and ESP-IDF frameworks
|
||||
return (
|
||||
old.loaded_integrations != new.loaded_integrations
|
||||
or old.loaded_platforms != new.loaded_platforms
|
||||
) and new.core_platform == PLATFORM_ESP32:
|
||||
from esphome.components.esp32 import FRAMEWORK_ESP_IDF
|
||||
|
||||
return new.framework == FRAMEWORK_ESP_IDF
|
||||
return False
|
||||
) and new.core_platform == PLATFORM_ESP32
|
||||
|
||||
|
||||
def update_storage_json() -> None:
|
||||
|
||||
@@ -9,6 +9,13 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.const import (
|
||||
PLATFORM_BK72XX,
|
||||
PLATFORM_ESP32,
|
||||
PLATFORM_ESP8266,
|
||||
PLATFORM_RP2040,
|
||||
PLATFORM_RTL87XX,
|
||||
)
|
||||
from esphome.core import EsphomeError
|
||||
from esphome.storage_json import StorageJSON
|
||||
from esphome.writer import (
|
||||
@@ -21,6 +28,7 @@ from esphome.writer import (
|
||||
clean_build,
|
||||
clean_cmake_cache,
|
||||
storage_should_clean,
|
||||
storage_should_update_cmake_cache,
|
||||
update_storage_json,
|
||||
write_cpp,
|
||||
write_gitignore,
|
||||
@@ -164,6 +172,86 @@ def test_storage_edge_case_from_empty_integrations(
|
||||
assert storage_should_clean(old, new) is False
|
||||
|
||||
|
||||
# Tests for storage_should_update_cmake_cache
|
||||
|
||||
|
||||
@pytest.mark.parametrize("framework", ["arduino", "esp-idf"])
|
||||
def test_storage_should_update_cmake_cache_when_integration_added_esp32(
|
||||
create_storage: Callable[..., StorageJSON],
|
||||
framework: str,
|
||||
) -> None:
|
||||
"""Test cmake cache update triggered when integration added on ESP32."""
|
||||
old = create_storage(
|
||||
loaded_integrations=["api", "wifi"],
|
||||
core_platform=PLATFORM_ESP32,
|
||||
framework=framework,
|
||||
)
|
||||
new = create_storage(
|
||||
loaded_integrations=["api", "wifi", "restart"],
|
||||
core_platform=PLATFORM_ESP32,
|
||||
framework=framework,
|
||||
)
|
||||
assert storage_should_update_cmake_cache(old, new) is True
|
||||
|
||||
|
||||
def test_storage_should_update_cmake_cache_when_platform_changed_esp32(
|
||||
create_storage: Callable[..., StorageJSON],
|
||||
) -> None:
|
||||
"""Test cmake cache update triggered when platforms change on ESP32."""
|
||||
old = create_storage(
|
||||
loaded_integrations=["api", "wifi"],
|
||||
loaded_platforms={"sensor"},
|
||||
core_platform=PLATFORM_ESP32,
|
||||
framework="arduino",
|
||||
)
|
||||
new = create_storage(
|
||||
loaded_integrations=["api", "wifi"],
|
||||
loaded_platforms={"sensor", "binary_sensor"},
|
||||
core_platform=PLATFORM_ESP32,
|
||||
framework="arduino",
|
||||
)
|
||||
assert storage_should_update_cmake_cache(old, new) is True
|
||||
|
||||
|
||||
def test_storage_should_not_update_cmake_cache_when_nothing_changes(
|
||||
create_storage: Callable[..., StorageJSON],
|
||||
) -> None:
|
||||
"""Test cmake cache not updated when nothing changes."""
|
||||
old = create_storage(
|
||||
loaded_integrations=["api", "wifi"],
|
||||
core_platform=PLATFORM_ESP32,
|
||||
framework="arduino",
|
||||
)
|
||||
new = create_storage(
|
||||
loaded_integrations=["api", "wifi"],
|
||||
core_platform=PLATFORM_ESP32,
|
||||
framework="arduino",
|
||||
)
|
||||
assert storage_should_update_cmake_cache(old, new) is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"core_platform",
|
||||
[PLATFORM_ESP8266, PLATFORM_RP2040, PLATFORM_BK72XX, PLATFORM_RTL87XX],
|
||||
)
|
||||
def test_storage_should_not_update_cmake_cache_for_non_esp32(
|
||||
create_storage: Callable[..., StorageJSON],
|
||||
core_platform: str,
|
||||
) -> None:
|
||||
"""Test cmake cache not updated for non-ESP32 platforms."""
|
||||
old = create_storage(
|
||||
loaded_integrations=["api", "wifi"],
|
||||
core_platform=core_platform,
|
||||
framework="arduino",
|
||||
)
|
||||
new = create_storage(
|
||||
loaded_integrations=["api", "wifi", "restart"],
|
||||
core_platform=core_platform,
|
||||
framework="arduino",
|
||||
)
|
||||
assert storage_should_update_cmake_cache(old, new) is False
|
||||
|
||||
|
||||
@patch("esphome.writer.clean_build")
|
||||
@patch("esphome.writer.StorageJSON")
|
||||
@patch("esphome.writer.storage_path")
|
||||
|
||||
Reference in New Issue
Block a user