diff --git a/conan/tools/apple/__init__.py b/conan/tools/apple/__init__.py index e205ff0fcb2..22f18bb1286 100644 --- a/conan/tools/apple/__init__.py +++ b/conan/tools/apple/__init__.py @@ -3,8 +3,7 @@ # from conan.tools.apple.apple import apple_dot_clean # from conan.tools.apple.apple import apple_sdk_name # from conan.tools.apple.apple import apple_deployment_target_flag -# from conan.tools.apple.apple import to_apple_arch -from conan.tools.apple.apple import fix_apple_shared_install_name, is_apple_os +from conan.tools.apple.apple import fix_apple_shared_install_name, is_apple_os, to_apple_arch from conan.tools.apple.xcodedeps import XcodeDeps from conan.tools.apple.xcodebuild import XcodeBuild from conan.tools.apple.xcodetoolchain import XcodeToolchain diff --git a/conan/tools/apple/apple.py b/conan/tools/apple/apple.py index eac71094cfc..b796de342dc 100644 --- a/conan/tools/apple/apple.py +++ b/conan/tools/apple/apple.py @@ -3,6 +3,7 @@ import os from conans.util.runners import check_output_runner +from conans.client.tools.apple import to_apple_arch as _to_apple_arch def is_apple_os(conanfile): @@ -11,16 +12,10 @@ def is_apple_os(conanfile): return str(os_) in ['Macos', 'iOS', 'watchOS', 'tvOS'] -def to_apple_arch(arch): +def to_apple_arch(conanfile): """converts conan-style architecture into Apple-style arch""" - return {'x86': 'i386', - 'x86_64': 'x86_64', - 'armv7': 'armv7', - 'armv8': 'arm64', - 'armv8_32': 'arm64_32', - 'armv8.3': 'arm64e', - 'armv7s': 'armv7s', - 'armv7k': 'armv7k'}.get(str(arch)) + arch_ = conanfile.settings.get_safe("arch") + return _to_apple_arch(arch_) def _guess_apple_sdk_name(os_, arch): diff --git a/conan/tools/apple/xcodebuild.py b/conan/tools/apple/xcodebuild.py index a822a57a745..10403d75375 100644 --- a/conan/tools/apple/xcodebuild.py +++ b/conan/tools/apple/xcodebuild.py @@ -1,6 +1,6 @@ import os -from conan.tools.apple.apple import to_apple_arch +from conan.tools.apple import to_apple_arch from conans.errors import ConanException @@ -8,7 +8,7 @@ class XcodeBuild(object): def __init__(self, conanfile): self._conanfile = conanfile self._build_type = conanfile.settings.get_safe("build_type") - self._arch = to_apple_arch(conanfile.settings.get_safe("arch")) + self._arch = to_apple_arch(self._conanfile) self._sdk = conanfile.settings.get_safe("os.sdk") or "" self._sdk_version = conanfile.settings.get_safe("os.sdk_version") or "" diff --git a/conan/tools/apple/xcodedeps.py b/conan/tools/apple/xcodedeps.py index 7f3f87d70da..8a1c7cd35ad 100644 --- a/conan/tools/apple/xcodedeps.py +++ b/conan/tools/apple/xcodedeps.py @@ -7,7 +7,7 @@ from conan.tools._check_build_profile import check_using_build_profile from conans.errors import ConanException from conans.util.files import load, save -from conan.tools.apple.apple import to_apple_arch +from conans.client.tools.apple import to_apple_arch GLOBAL_XCCONFIG_TEMPLATE = textwrap.dedent("""\ // Includes both the toolchain and the dependencies diff --git a/conan/tools/apple/xcodetoolchain.py b/conan/tools/apple/xcodetoolchain.py index bc08b2a3ec2..892aac9f443 100644 --- a/conan/tools/apple/xcodetoolchain.py +++ b/conan/tools/apple/xcodetoolchain.py @@ -2,7 +2,7 @@ from conan.tools._check_build_profile import check_using_build_profile from conan.tools._compilers import cppstd_flag -from conan.tools.apple.apple import to_apple_arch +from conan.tools.apple import to_apple_arch from conan.tools.apple.xcodedeps import GLOBAL_XCCONFIG_FILENAME, GLOBAL_XCCONFIG_TEMPLATE, \ _add_includes_to_file_or_create, _xcconfig_settings_filename, _xcconfig_conditional from conans.util.files import save @@ -36,7 +36,7 @@ class XcodeToolchain(object): def __init__(self, conanfile): self._conanfile = conanfile arch = conanfile.settings.get_safe("arch") - self.architecture = to_apple_arch(arch) or arch + self.architecture = to_apple_arch(self._conanfile) or arch self.configuration = conanfile.settings.build_type self.sdk = conanfile.settings.get_safe("os.sdk") self.sdk_version = conanfile.settings.get_safe("os.sdk_version") diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index 3e36e52e861..52608545ee4 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -405,8 +405,7 @@ def context(self): if not is_apple_os(self._conanfile): return None - arch = self._conanfile.settings.get_safe("arch") - host_architecture = to_apple_arch(arch) + host_architecture = to_apple_arch(self._conanfile) host_os_version = self._conanfile.settings.get_safe("os.version") host_sdk_name = self._apple_sdk_name() is_debug = self._conanfile.settings.get_safe('build_type') == "Debug" @@ -808,7 +807,7 @@ def _get_cross_build(self): system_name = {'Macos': 'Darwin'}.get(os_host, os_host) # CMAKE_SYSTEM_VERSION for Apple sets the sdk version, not the os version _system_version = self._conanfile.settings.get_safe("os.sdk_version") - _system_processor = to_apple_arch(arch_host) + _system_processor = to_apple_arch(self._conanfile) elif os_host != 'Android': system_name = self._get_generic_system_name() _system_version = self._conanfile.settings.get_safe("os.version") diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index a46ed30cfbf..c747f7903df 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -63,7 +63,7 @@ def __init__(self, conanfile, namespace=None): # Apple Stuff if os_build == "Macos": sdk_path = apple_sdk_path(conanfile) - apple_arch = to_apple_arch(self._conanfile.settings.get_safe("arch")) + apple_arch = to_apple_arch(self._conanfile) # https://man.archlinux.org/man/clang.1.en#Target_Selection_Options self.apple_arch_flag = "-arch {}".format(apple_arch) if apple_arch else None # -isysroot makes all includes for your library relative to the build directory diff --git a/conan/tools/meson/toolchain.py b/conan/tools/meson/toolchain.py index fa5f52cf3ea..2daa47d2a27 100644 --- a/conan/tools/meson/toolchain.py +++ b/conan/tools/meson/toolchain.py @@ -244,7 +244,7 @@ def _resolve_apple_flags_and_variables(self, build_env): raise ConanException("Please, specify a suitable value for os.sdk.") # Calculating the main Apple flags - arch = to_apple_arch(self._conanfile.settings.get_safe("arch")) + arch = to_apple_arch(self._conanfile) self.apple_arch_flag = ["-arch", arch] if arch else [] self.apple_isysroot_flag = ["-isysroot", sdk_path] if sdk_path else [] self.apple_min_version_flag = [apple_min_version_flag(self._conanfile)] diff --git a/conans/test/functional/toolchains/gnu/autotools/test_apple_toolchain.py b/conans/test/functional/toolchains/gnu/autotools/test_apple_toolchain.py index 5836c8e0438..c9217eac77c 100644 --- a/conans/test/functional/toolchains/gnu/autotools/test_apple_toolchain.py +++ b/conans/test/functional/toolchains/gnu/autotools/test_apple_toolchain.py @@ -4,7 +4,7 @@ import pytest -from conan.tools.apple.apple import to_apple_arch +from conans.client.tools.apple import to_apple_arch from conans.test.assets.autotools import gen_makefile from conans.test.assets.sources import gen_function_h, gen_function_cpp from conans.test.utils.tools import TestClient diff --git a/conans/test/unittests/tools/apple/test_apple_tools.py b/conans/test/unittests/tools/apple/test_apple_tools.py new file mode 100644 index 00000000000..4146d0e509c --- /dev/null +++ b/conans/test/unittests/tools/apple/test_apple_tools.py @@ -0,0 +1,24 @@ +from conans.test.utils.mocks import ConanFileMock, MockSettings +from conan.tools.apple import is_apple_os, to_apple_arch + +def test_tools_apple_is_apple_os(): + conanfile = ConanFileMock() + + conanfile.settings = MockSettings({"os": "Macos"}) + assert is_apple_os(conanfile) == True + + conanfile.settings = MockSettings({"os": "watchOS"}) + assert is_apple_os(conanfile) == True + + conanfile.settings = MockSettings({"os": "Windows"}) + assert is_apple_os(conanfile) == False + + +def test_tools_apple_to_apple_arch(): + conanfile = ConanFileMock() + + conanfile.settings = MockSettings({"arch": "armv8"}) + assert to_apple_arch(conanfile) == "arm64" + + conanfile.settings = MockSettings({"arch": "x86_64"}) + assert to_apple_arch(conanfile) == "x86_64"