Address review: cover all source suffixes, pass PIOPLATFORM through, link library -Wl flags

This commit is contained in:
J. Nick Koston
2026-08-19 23:50:16 -05:00
parent 9429243d2b
commit 66f6f5c004
6 changed files with 73 additions and 11 deletions
+13 -1
View File
@@ -63,6 +63,13 @@ def test_board_build_covers_every_board() -> None:
assert set(BOARDS) <= set(ESP8266_BOARD_BUILD)
def test_rule_map_covers_all_source_suffixes() -> None:
"""Every suffix a library manifest can select must map to a ninja rule."""
from esphome.platformio.library import SRC_FILE_EXTENSIONS
assert set(arduino8266._RULE_FOR_SUFFIX) == set(SRC_FILE_EXTENSIONS)
def test_build_config_defaults() -> None:
_set_flags()
@@ -409,14 +416,16 @@ def test_write_project_libraries_and_variant(tmp_path: Path) -> None:
lib_dir = tmp_path / "libsrc"
lib_dir.mkdir()
(lib_dir / "lib.cpp").write_text("")
(lib_dir / "impl.cc").write_text("")
headers_only = ArduinoLibrary(name="HeadersOnly", include_dirs=[lib_dir])
library = ArduinoLibrary(
name="MyLib",
sources=[lib_dir / "lib.cpp"],
sources=[lib_dir / "impl.cc", lib_dir / "lib.cpp"],
include_dirs=[lib_dir],
flags=["-DMYLIB=1"],
link_dirs=[lib_dir / "blobs"],
link_libs=["algobsec"],
link_flags=["-Wl,--wrap=malloc"],
)
_set_flags("-DPIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS")
@@ -430,6 +439,9 @@ def test_write_project_libraries_and_variant(tmp_path: Path) -> None:
assert "libHeadersOnly.a" not in content
assert " flags = -DMYLIB=1" in content
assert "-lalgobsec" in content
# Library link flags reach the firmware link line; .cc compiles as C++
assert "-Wl,--wrap=malloc" in content
assert "impl.cc.o: cxx" in content
assert f'-L"{lib_dir / "blobs"}"' in content
# Exceptions knob: -fexceptions and the exception-enabled stdc++
assert "-fexceptions" in content
@@ -65,6 +65,7 @@ def test_library_info_flags_parsing(tmp_path: Path) -> None:
"-DFOO=1 -I inc",
"-lalgobsec",
"-fno-lto",
"-Wl,--wrap=malloc",
"-l",
"m",
"-L",
@@ -80,6 +81,7 @@ def test_library_info_flags_parsing(tmp_path: Path) -> None:
]
assert lib.link_dirs == [(read_path / "blobs").resolve()]
assert lib.link_libs == ["algobsec", "m"]
assert lib.link_flags == ["-Wl,--wrap=malloc"]
def test_library_info_no_src_dir(tmp_path: Path) -> None:
@@ -144,7 +146,9 @@ def test_resolve_libraries_external_and_bundled_deps(tmp_path: Path) -> None:
):
libs = component.resolve_libraries(framework)
mock_extra.assert_called_once_with(converted, "esp8266")
mock_extra.assert_called_once_with(
converted, "esp8266", pio_platform="espressif8266"
)
assert [lib.name for lib in libs] == [
"Wire",
"esp32async__ESPAsyncWebServer",
+13
View File
@@ -1254,3 +1254,16 @@ def test_apply_extra_script_swallows_script_errors(tmp_path, caplog) -> None:
apply_extra_script(c, "esp8266")
assert "flags" not in c.data["build"]
assert "skipping" in caplog.text
def test_apply_extra_script_pio_platform(tmp_path) -> None:
"""The backend's platform token is exposed to the script as PIOPLATFORM."""
from esphome.espidf.extra_script import apply_extra_script
script = tmp_path / "extra.py"
script.write_text("env.Append(LIBS=[env.get('PIOPLATFORM')])\n")
c = IDFComponent("owner/name", "1.0", source=URLSource("http://dummy"))
c.path = tmp_path
c.data = {"build": {"extraScript": "extra.py"}}
apply_extra_script(c, "esp8266", pio_platform="espressif8266")
assert c.data["build"]["flags"] == ["-lespressif8266"]