From 48cc76f114762deb677733f25259fd2f07dea3a0 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Tue, 26 Sep 2023 14:46:59 +0200
Subject: [PATCH] python/build/toolchain: add is_android, is_darwin

---
 python/build/cmake.py     | 4 ++--
 python/build/meson.py     | 2 +-
 python/build/toolchain.py | 4 ++++
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/python/build/cmake.py b/python/build/cmake.py
index 3b7e86405..53db47ddf 100644
--- a/python/build/cmake.py
+++ b/python/build/cmake.py
@@ -15,7 +15,7 @@ def __write_cmake_compiler(f: TextIO, language: str, compiler: str) -> None:
     print(f'set(CMAKE_{language}_COMPILER {compiler})', file=f)
 
 def __write_cmake_toolchain_file(f: TextIO, toolchain: AnyToolchain) -> None:
-    if '-darwin' in toolchain.actual_arch:
+    if toolchain.is_darwin:
         cmake_system_name = 'Darwin'
     elif toolchain.is_windows:
         cmake_system_name = 'Windows'
@@ -65,7 +65,7 @@ def configure(toolchain: AnyToolchain, src: str, build: str, args: list[str]=[],
     # looking for libraries on the build host (TODO: fix this
     # properly); but we must not do that on Android because the NDK
     # has a sysroot already
-    if '-android' not in toolchain.actual_arch and '-darwin' not in toolchain.actual_arch:
+    if not toolchain.is_android and not toolchain.is_darwin:
         cross_args.append('-DCMAKE_SYSROOT=' + toolchain.install_prefix)
 
     os.makedirs(build, exist_ok=True)
diff --git a/python/build/meson.py b/python/build/meson.py
index 1a7311955..b6517d33b 100644
--- a/python/build/meson.py
+++ b/python/build/meson.py
@@ -63,7 +63,7 @@ pkgconfig = '{toolchain.pkg_config}'
 root = '{toolchain.install_prefix}'
 """)
 
-        if 'android' in toolchain.arch:
+        if toolchain.is_android:
             f.write("""
 # Keep Meson from executing Android-x86 test binariees
 needs_exe_wrapper = true
diff --git a/python/build/toolchain.py b/python/build/toolchain.py
index 15a29ca20..3e615286f 100644
--- a/python/build/toolchain.py
+++ b/python/build/toolchain.py
@@ -91,6 +91,8 @@ class AndroidNdkToolchain:
         self.is_armv7 = self.is_arm and 'armv7' in self.cflags
         self.is_aarch64 = ndk_arch == 'arm64'
         self.is_windows = False
+        self.is_android = True
+        self.is_darwin = False
 
         libstdcxx_flags = ''
         libstdcxx_cxxflags = ''
@@ -162,6 +164,8 @@ class MingwToolchain:
         self.is_armv7 = self.is_arm and 'armv7' in self.cflags
         self.is_aarch64 = arch == 'aarch64'
         self.is_windows = 'mingw32' in arch
+        self.is_android = False
+        self.is_darwin = False
 
         self.env = dict(os.environ)