mirror of
https://github.com/esphome/esphome.git
synced 2026-10-01 17:00:21 +00:00
[libretiny] Enable the PlatformIO precompiled header on Linux hosts (#19827)
This commit is contained in:
@@ -9,6 +9,7 @@ import os
|
||||
from pathlib import Path
|
||||
import posixpath
|
||||
import re
|
||||
import sys
|
||||
|
||||
from esphome.build_helpers.ccache import effective_ccache_basedir, parse_enable_env
|
||||
from esphome.const import (
|
||||
@@ -47,10 +48,18 @@ PCH_DEFAULT_HEADERS = ("esphome/core/pch_prefix.h",)
|
||||
|
||||
# PlatformIO platforms that do not take the pch script
|
||||
PCH_SCRIPT_EXCLUDED_PLATFORMS = frozenset(
|
||||
{
|
||||
PLATFORM_NRF52,
|
||||
}
|
||||
)
|
||||
|
||||
# The GCC 10.3 of LibreTiny only loads its own .gch back on Linux: elsewhere
|
||||
# the compiler is loaded at a new address each run, which GCC accepts from
|
||||
# version 12. Remove once LibreTiny ships GCC 12 or newer
|
||||
PCH_SCRIPT_LINUX_ONLY_PLATFORMS = frozenset(
|
||||
{
|
||||
PLATFORM_BK72XX,
|
||||
PLATFORM_LN882X,
|
||||
PLATFORM_NRF52,
|
||||
PLATFORM_RTL87XX,
|
||||
}
|
||||
)
|
||||
@@ -94,7 +103,10 @@ def pch_script_enabled() -> bool:
|
||||
"""Whether this PlatformIO build takes the pch script."""
|
||||
from esphome.core import CORE
|
||||
|
||||
return pch_enabled() and CORE.target_platform not in PCH_SCRIPT_EXCLUDED_PLATFORMS
|
||||
platform = CORE.target_platform
|
||||
if platform in PCH_SCRIPT_LINUX_ONLY_PLATFORMS and sys.platform != "linux":
|
||||
return False
|
||||
return pch_enabled() and platform not in PCH_SCRIPT_EXCLUDED_PLATFORMS
|
||||
|
||||
|
||||
def pch_header_text(include_headers: Iterable[str]) -> str:
|
||||
|
||||
@@ -109,14 +109,27 @@ def test_pch_checksum_tracks_closure_content(tmp_path: Path) -> None:
|
||||
assert base != pch.pch_checksum(tmp_path, ["root.h"], ["id"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform", ["esp32", "esp8266", "rp2"])
|
||||
@pytest.mark.parametrize(
|
||||
"platform", ["bk72xx", "esp32", "esp8266", "ln882x", "rp2", "rtl87xx"]
|
||||
)
|
||||
def test_pch_script_enabled(platform: str, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
monkeypatch.setattr(pch.sys, "platform", "linux")
|
||||
CORE.data[KEY_CORE] = {KEY_TARGET_PLATFORM: platform}
|
||||
assert pch.pch_script_enabled()
|
||||
monkeypatch.setenv("ESPHOME_PCH_ENABLE", "0")
|
||||
assert not pch.pch_script_enabled()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("host", ["darwin", "win32"])
|
||||
@pytest.mark.parametrize("platform", sorted(pch.PCH_SCRIPT_LINUX_ONLY_PLATFORMS))
|
||||
def test_pch_script_linux_only_platform(
|
||||
platform: str, host: str, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.setattr(pch.sys, "platform", host)
|
||||
CORE.data[KEY_CORE] = {KEY_TARGET_PLATFORM: platform}
|
||||
assert not pch.pch_script_enabled()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform", sorted(pch.PCH_SCRIPT_EXCLUDED_PLATFORMS))
|
||||
def test_pch_script_excluded_platform(platform: str) -> None:
|
||||
CORE.data[KEY_CORE] = {KEY_TARGET_PLATFORM: platform}
|
||||
|
||||
Reference in New Issue
Block a user