mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
Merge branch 'esp8266-native-library-backend' into esp8266-native-build-spec
This commit is contained in:
+13
-27
@@ -27,7 +27,6 @@ from esphome.platformio.library import (
|
|||||||
LIBRARY_HEADER_SUFFIXES,
|
LIBRARY_HEADER_SUFFIXES,
|
||||||
SRC_FILE_EXTENSIONS,
|
SRC_FILE_EXTENSIONS,
|
||||||
ConvertedLibrary,
|
ConvertedLibrary,
|
||||||
IncompatiblePlatform,
|
|
||||||
InvalidLibrary,
|
InvalidLibrary,
|
||||||
LibraryBackend,
|
LibraryBackend,
|
||||||
_url_or_none,
|
_url_or_none,
|
||||||
@@ -104,11 +103,10 @@ def _warn_dropped_link_fields(name: str, data: dict) -> None:
|
|||||||
for dropped_key in ("precompiled", "ldflags"):
|
for dropped_key in ("precompiled", "ldflags"):
|
||||||
if data.get(dropped_key):
|
if data.get(dropped_key):
|
||||||
# PIO's Arduino lib builder honors these; building without them
|
# PIO's Arduino lib builder honors these; building without them
|
||||||
# would fail far away at link with no stated cause
|
# would fail at link with no stated cause
|
||||||
_LOGGER.warning(
|
raise EsphomeError(
|
||||||
"Library %s declares %s, which this backend does not honor",
|
f"Library {name} declares {dropped_key}, which this backend "
|
||||||
name,
|
"does not support"
|
||||||
dropped_key,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -278,12 +276,11 @@ def _bundled_library(framework_path: Path, name: str) -> ArduinoLibrary:
|
|||||||
warn_properties_depends(name, data)
|
warn_properties_depends(name, data)
|
||||||
build = data.get("build")
|
build = data.get("build")
|
||||||
if isinstance(build, dict) and build.get("extraScript"):
|
if isinstance(build, dict) and build.get("extraScript"):
|
||||||
# apply_extra_script only runs on the converted path; a bundled
|
# apply_extra_script only runs on the converted path; building
|
||||||
# manifest relying on one would build with missing flags
|
# without the script's flags would miscompile
|
||||||
_LOGGER.warning(
|
raise EsphomeError(
|
||||||
"Bundled library %s declares an extraScript, which is not "
|
f"Bundled library {name} declares an extraScript, which is "
|
||||||
"run for bundled libraries",
|
"not run for bundled libraries"
|
||||||
name,
|
|
||||||
)
|
)
|
||||||
lib = _library_info(name, lib_dir, data)
|
lib = _library_info(name, lib_dir, data)
|
||||||
_assert_tree_has_code(
|
_assert_tree_has_code(
|
||||||
@@ -430,23 +427,12 @@ def resolve_libraries(
|
|||||||
# via the converter, and the walk reports any real drops
|
# via the converter, and the walk reports any real drops
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
# framework=None: the walk already warned for a frameworks
|
# framework=None: the walk already ran dependency_is_usable
|
||||||
# mismatch; re-checking would warn twice
|
# on this entry (and warned for any non-platform cause);
|
||||||
|
# re-checking with a framework would warn twice
|
||||||
check_library_data(dep, pio_platform, None)
|
check_library_data(dep, pio_platform, None)
|
||||||
except InvalidLibrary as err:
|
except InvalidLibrary as err:
|
||||||
if isinstance(err, IncompatiblePlatform) or "version" not in dep:
|
_LOGGER.debug("Skip bundled candidate %s: %s", name, err)
|
||||||
# The platform skip is routine; the walk's version-less
|
|
||||||
# filter already warned for other version-less causes
|
|
||||||
_LOGGER.debug("Skip bundled candidate %s: %s", name, err)
|
|
||||||
else:
|
|
||||||
# Versioned deps skip the walk's filter via provides();
|
|
||||||
# this is the only place the fault can be seen
|
|
||||||
_LOGGER.warning(
|
|
||||||
"Skipping bundled dependency %s of %s: %s",
|
|
||||||
name,
|
|
||||||
component.name,
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
# Deferred: a later-emitted library's manifest name may satisfy
|
# Deferred: a later-emitted library's manifest name may satisfy
|
||||||
# this; adding now could double the archive
|
# this; adding now could double the archive
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ _MODES = {"ar": (_run_ar, 3), "copy": (_run_copy, 2)}
|
|||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
mode = sys.argv[1]
|
mode = sys.argv[1] if len(sys.argv) > 1 else ""
|
||||||
if entry := _MODES.get(mode):
|
if entry := _MODES.get(mode):
|
||||||
handler, argc = entry
|
handler, argc = entry
|
||||||
args = sys.argv[2:]
|
args = sys.argv[2:]
|
||||||
|
|||||||
@@ -490,27 +490,33 @@ def test_url_pinned_bundled_name_not_doubled(tmp_path: Path) -> None:
|
|||||||
assert "Wire" not in [lib.name for lib in libs]
|
assert "Wire" not in [lib.name for lib in libs]
|
||||||
|
|
||||||
|
|
||||||
def test_versioned_bundled_candidate_fault_warns(
|
def test_versioned_bundled_candidate_fault_warns_once(
|
||||||
tmp_path: Path, caplog: pytest.LogCaptureFixture
|
tmp_path: Path,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""A versioned bundled-name dependency skips the walk's usability filter
|
"""A versioned bundled-name dependency with a manifest fault warns once,
|
||||||
via provides(), so a non-platform fault warns here."""
|
from the walk's usability filter; the backend-side re-check stays quiet."""
|
||||||
framework = _make_framework(tmp_path)
|
framework = _make_framework(tmp_path)
|
||||||
converted = _webserver(
|
_local_lib(tmp_path, [{"name": "Wire", "version": "*"}])
|
||||||
tmp_path,
|
monkeypatch.setenv("ESPHOME_DATA_DIR", str(tmp_path / ".esphome"))
|
||||||
{"build": {}, "dependencies": [{"name": "Wire", "version": "*"}]},
|
real = pio_library.check_library_data
|
||||||
)
|
|
||||||
with (
|
def flaky(data, platform, framework_name):
|
||||||
_emitting_converter(converted),
|
if data.get("name") == "Wire":
|
||||||
patch.object(
|
raise InvalidLibrary("manifest is corrupt")
|
||||||
component,
|
return real(data, platform, framework_name)
|
||||||
"check_library_data",
|
|
||||||
side_effect=InvalidLibrary("manifest is corrupt"),
|
monkeypatch.setattr(pio_library, "check_library_data", flaky)
|
||||||
),
|
monkeypatch.setattr(component, "check_library_data", flaky)
|
||||||
|
with patch.object(
|
||||||
|
pio_library,
|
||||||
|
"_resolve_registry_version",
|
||||||
|
side_effect=AssertionError("registry touched"),
|
||||||
):
|
):
|
||||||
libs = _resolve(framework)
|
libs = _resolve(framework)
|
||||||
assert "Wire" not in [lib.name for lib in libs]
|
assert "Wire" not in [lib.name for lib in libs]
|
||||||
assert "Skipping bundled dependency Wire" in caplog.text
|
assert caplog.text.count("manifest is corrupt") == 1
|
||||||
|
|
||||||
|
|
||||||
def test_short_name_collision_with_bundled_name_warns(
|
def test_short_name_collision_with_bundled_name_warns(
|
||||||
@@ -589,18 +595,15 @@ def test_library_info_lib_archive_parse(
|
|||||||
assert lib.lib_archive is expected
|
assert lib.lib_archive is expected
|
||||||
|
|
||||||
|
|
||||||
def test_library_info_dropped_link_fields_warn(
|
def test_library_info_unsupported_link_fields_raise(tmp_path: Path) -> None:
|
||||||
tmp_path: Path, caplog: pytest.LogCaptureFixture
|
"""precompiled/ldflags properties are not supported; refuse by name."""
|
||||||
) -> None:
|
|
||||||
"""precompiled/ldflags properties are not honored; the drop is named."""
|
|
||||||
read_path = tmp_path / "lib"
|
read_path = tmp_path / "lib"
|
||||||
(read_path / "src").mkdir(parents=True)
|
(read_path / "src").mkdir(parents=True)
|
||||||
(read_path / "src" / "stub.cpp").write_text("")
|
(read_path / "src" / "stub.cpp").write_text("")
|
||||||
component._library_info(
|
with pytest.raises(EsphomeError, match="declares precompiled"):
|
||||||
"x", read_path, {"precompiled": "true", "ldflags": "-lfoo", "build": {}}
|
component._library_info("x", read_path, {"precompiled": "true", "build": {}})
|
||||||
)
|
with pytest.raises(EsphomeError, match="declares ldflags"):
|
||||||
assert "declares precompiled, which this backend does not honor" in caplog.text
|
component._library_info("x", read_path, {"ldflags": "-lfoo", "build": {}})
|
||||||
assert "declares ldflags, which this backend does not honor" in caplog.text
|
|
||||||
|
|
||||||
|
|
||||||
def test_library_info_unmapped_sources_warn(
|
def test_library_info_unmapped_sources_warn(
|
||||||
@@ -779,19 +782,17 @@ def test_bundled_library_properties_depends_warns(
|
|||||||
assert "Library Wire declares dependencies via library.properties" in caplog.text
|
assert "Library Wire declares dependencies via library.properties" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
def test_bundled_library_extra_script_warns(
|
def test_bundled_library_extra_script_raises(tmp_path: Path) -> None:
|
||||||
tmp_path: Path, caplog: pytest.LogCaptureFixture
|
"""A bundled manifest relying on an extraScript would miscompile;
|
||||||
) -> None:
|
refuse by name."""
|
||||||
"""A bundled manifest relying on an extraScript is a named deviation,
|
|
||||||
not a silently miscompiled library."""
|
|
||||||
framework = _make_framework(tmp_path)
|
framework = _make_framework(tmp_path)
|
||||||
wire = framework / "libraries" / "Wire"
|
wire = framework / "libraries" / "Wire"
|
||||||
(wire / "library.json").write_text(
|
(wire / "library.json").write_text(
|
||||||
'{"name": "Wire", "build": {"extraScript": "extra.py"}}'
|
'{"name": "Wire", "build": {"extraScript": "extra.py"}}'
|
||||||
)
|
)
|
||||||
_add_library("Wire", None)
|
_add_library("Wire", None)
|
||||||
_resolve(framework)
|
with pytest.raises(EsphomeError, match="Wire declares an extraScript"):
|
||||||
assert "declares an extraScript" in caplog.text
|
_resolve(framework)
|
||||||
|
|
||||||
|
|
||||||
def test_dependency_requested_top_level_is_not_a_drop(
|
def test_dependency_requested_top_level_is_not_a_drop(
|
||||||
|
|||||||
Reference in New Issue
Block a user