Warn instead of failing when the post-build idedata is unusable

This commit is contained in:
J. Nick Koston
2026-08-20 18:41:38 -05:00
parent 8e63fa3c2a
commit 406d5c87ed
2 changed files with 32 additions and 5 deletions
+11 -5
View File
@@ -91,11 +91,17 @@ def run_compile(config: ConfigType, verbose: bool) -> int:
return rc
_print_size_summary(build_dir)
if get_idedata() is None:
_LOGGER.warning(
"Could not generate idedata from %s",
build_dir / "compile_commands.json",
)
try:
idedata = get_idedata()
except EsphomeError as err:
# The firmware already built; idedata is a bonus artifact here
_LOGGER.warning("Could not generate idedata: %s", err)
else:
if idedata is None:
_LOGGER.warning(
"Could not generate idedata from %s",
build_dir / "compile_commands.json",
)
return 0
@@ -337,3 +337,24 @@ def test_warn_ignored_platformio_options(caplog: pytest.LogCaptureFixture) -> No
assert "native 'arduino' toolchain" in caplog.text
assert "lib_ignore" not in caplog.text
assert "upload_speed" not in caplog.text
def test_run_compile_idedata_error_does_not_fail_build(
tmp_path: Path, caplog: pytest.LogCaptureFixture
) -> None:
"""An unusable compile DB after a successful build warns, never fails."""
with (
patch.object(framework, "check_and_install", return_value=_paths(tmp_path)),
patch.object(framework, "get_build_env", return_value={}),
patch("esphome.build_gen.arduino8266.write_project"),
patch.object(toolchain.subprocess, "run", return_value=MagicMock(returncode=0)),
patch.object(toolchain, "_write_compile_commands"),
patch.object(toolchain, "_print_size_summary"),
patch.object(
toolchain,
"get_idedata",
side_effect=EsphomeError("compile database is unusable"),
),
):
assert toolchain.run_compile({CONF_ESPHOME: {}}, verbose=False) == 0
assert "Could not generate idedata: compile database is unusable" in caplog.text