diff --git a/esphome/arduino8266/framework.py b/esphome/arduino8266/framework.py index dfe193583b..63f4992a9c 100644 --- a/esphome/arduino8266/framework.py +++ b/esphome/arduino8266/framework.py @@ -116,13 +116,21 @@ def _pio_system() -> str: return "darwin_arm64" if machine == "arm64" else "darwin_x86_64" if sysname == "windows": return "windows_amd64" if machine in ("amd64", "arm64") else "windows_x86" - if machine in ("arm64", "aarch64"): - return "linux_aarch64" - if machine in ("i686", "i386", "x86"): - return "linux_i686" - if machine.startswith("arm"): - return f"linux_{machine}" - return "linux_x86_64" + if sysname == "linux": + if machine in ("arm64", "aarch64"): + return "linux_aarch64" + if machine in ("i686", "i386", "x86"): + return "linux_i686" + if machine.startswith("arm"): + return f"linux_{machine}" + if machine in ("x86_64", "amd64"): + return "linux_x86_64" + # Fail here, near the cause, rather than installing a toolchain whose + # binaries cannot execute on this host. + raise EsphomeError( + f"No {sysname}/{machine} build of the ESP8266 toolchain exists; " + "use 'toolchain: platformio'" + ) def _registry_download(package: str, version: str) -> tuple[str, str, int | None]: diff --git a/tests/unit_tests/test_arduino8266_framework.py b/tests/unit_tests/test_arduino8266_framework.py index 7d9d56796d..810f9aee44 100644 --- a/tests/unit_tests/test_arduino8266_framework.py +++ b/tests/unit_tests/test_arduino8266_framework.py @@ -58,6 +58,23 @@ def test_pio_system(system: str, machine: str, expected: str) -> None: assert framework._pio_system() == expected +@pytest.mark.parametrize( + ("system", "machine"), + [ + ("FreeBSD", "amd64"), + ("Linux", "ppc64le"), + ], +) +def test_pio_system_unsupported_host_raises(system: str, machine: str) -> None: + # Fails at resolution rather than installing a toolchain that can't run + with ( + patch("platform.system", return_value=system), + patch("platform.machine", return_value=machine), + pytest.raises(EsphomeError, match="use 'toolchain: platformio'"), + ): + framework._pio_system() + + def _registry_response(files: list[dict]) -> MagicMock: resp = MagicMock() resp.json.return_value = {"versions": [{"name": "1.0.0", "files": files}]}