From 7f183b62fcf950e22e6b1bfce0598e79cba4c134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Mon, 6 May 2024 12:49:29 +0200 Subject: [PATCH] compat: Fail if explicitly enabled and toolchain is missing --- compat/build.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/compat/build.py b/compat/build.py index fd85a10c8..e8d1ae3fd 100644 --- a/compat/build.py +++ b/compat/build.py @@ -102,31 +102,27 @@ def setup(role: Role, ensure_submodules_checked_out(releng_location) configure_import_path(releng_location) - if "auto" in compat: + auto_detect = "auto" in compat + if auto_detect: compat = {"native", "emulated"} if host_os in {"windows", "macos", "linux", "ios", "tvos", "android"} else set() elif "disabled" in compat: compat = set() if "native" in compat: + have_toolchain = True other_triplet: Optional[str] = None + if host_os == "windows" and host_config == "mingw": - triplet = "i686-w64-mingw32" if host_arch == "x86_64" else "x86_64-w64-mingw32" - if shutil.which(triplet + "-gcc") is not None: - other_triplet = triplet - have_compiler = True - else: - have_compiler = False + other_triplet = "i686-w64-mingw32" if host_arch == "x86_64" else "x86_64-w64-mingw32" + have_toolchain = shutil.which(other_triplet + "-gcc") is not None elif host_os == "linux" and host_config is None: - triplet = "i686-linux-gnu" if host_arch == "x86_64" else "x86_64-linux-gnu" - if shutil.which(triplet + "-gcc") is not None: - other_triplet = triplet - have_compiler = True - else: - have_compiler = False - else: - have_compiler = True + other_triplet = "i686-linux-gnu" if host_arch == "x86_64" else "x86_64-linux-gnu" + have_toolchain = shutil.which(other_triplet + "-gcc") is not None - if host_os == "windows" and host_arch in {"x86_64", "x86"} and have_compiler: + if not auto_detect and not have_toolchain: + raise ToolchainNotFoundError(f"unable to locate toolchain for {other_triplet}") + + if host_os == "windows" and host_arch in {"x86_64", "x86"} and have_toolchain: if host_arch == "x86_64": other_arch = "x86" kind = "legacy" @@ -183,7 +179,7 @@ def setup(role: Role, target=SERVER_TARGET), ] - if host_os == "linux" and host_arch in {"x86_64", "x86"} and have_compiler: + if host_os == "linux" and host_arch in {"x86_64", "x86"} and have_toolchain: if host_arch == "x86_64": other_arch = "x86" kind = "legacy" @@ -257,6 +253,10 @@ def setup(role: Role, print(f"error {e}\n\n{'\n'.join(traceback.format_exception(e))}") +class ToolchainNotFoundError(Exception): + pass + + @dataclass class State: role: Role