mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
[core] Fix incremental build failures when adding components on ESP32-Arduino (#12745)
This commit is contained in:
@@ -103,14 +103,11 @@ def storage_should_clean(old: StorageJSON | None, new: StorageJSON) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def storage_should_update_cmake_cache(old: StorageJSON, 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
|
old.loaded_integrations != new.loaded_integrations
|
||||||
or old.loaded_platforms != new.loaded_platforms
|
or old.loaded_platforms != new.loaded_platforms
|
||||||
) and new.core_platform == PLATFORM_ESP32:
|
) and new.core_platform == PLATFORM_ESP32
|
||||||
from esphome.components.esp32 import FRAMEWORK_ESP_IDF
|
|
||||||
|
|
||||||
return new.framework == FRAMEWORK_ESP_IDF
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def update_storage_json() -> None:
|
def update_storage_json() -> None:
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ from unittest.mock import MagicMock, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from esphome.const import (
|
||||||
|
PLATFORM_BK72XX,
|
||||||
|
PLATFORM_ESP32,
|
||||||
|
PLATFORM_ESP8266,
|
||||||
|
PLATFORM_RP2040,
|
||||||
|
PLATFORM_RTL87XX,
|
||||||
|
)
|
||||||
from esphome.core import EsphomeError
|
from esphome.core import EsphomeError
|
||||||
from esphome.storage_json import StorageJSON
|
from esphome.storage_json import StorageJSON
|
||||||
from esphome.writer import (
|
from esphome.writer import (
|
||||||
@@ -28,6 +35,7 @@ from esphome.writer import (
|
|||||||
generate_build_info_data_h,
|
generate_build_info_data_h,
|
||||||
get_build_info,
|
get_build_info,
|
||||||
storage_should_clean,
|
storage_should_clean,
|
||||||
|
storage_should_update_cmake_cache,
|
||||||
update_storage_json,
|
update_storage_json,
|
||||||
write_cpp,
|
write_cpp,
|
||||||
write_gitignore,
|
write_gitignore,
|
||||||
@@ -171,6 +179,86 @@ def test_storage_edge_case_from_empty_integrations(
|
|||||||
assert storage_should_clean(old, new) is False
|
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.clean_build")
|
||||||
@patch("esphome.writer.StorageJSON")
|
@patch("esphome.writer.StorageJSON")
|
||||||
@patch("esphome.writer.storage_path")
|
@patch("esphome.writer.storage_path")
|
||||||
|
|||||||
Reference in New Issue
Block a user