Skip to content

Commit

Permalink
- fix M1 detection (#8501)
Browse files Browse the repository at this point in the history
Signed-off-by: SSE4 <tomskside@gmail.com>
  • Loading branch information
SSE4 authored Feb 16, 2021
1 parent d71b159 commit e63953e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
27 changes: 12 additions & 15 deletions conans/client/conf/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from conans.client.conf.compiler_id import UNKNOWN_COMPILER, LLVM_GCC, detect_compiler_id
from conans.client.output import Color
from conans.client.tools import detected_os, OSInfo
from conans.client.tools import detected_os, detected_architecture, OSInfo
from conans.client.tools.win import latest_visual_studio_version_installed
from conans.model.version import Version
from conans.util.conan_v2_mode import CONAN_V2_MODE_ENVVAR
Expand Down Expand Up @@ -259,31 +259,28 @@ def _detect_compiler_version(result, output, profile_path):


def _detect_os_arch(result, output):
architectures = {'i386': 'x86',
'i686': 'x86',
'i86pc': 'x86',
'amd64': 'x86_64',
'aarch64': 'armv8',
'sun4v': 'sparc'}
from conans.client.conf import get_default_settings_yml
from conans.model.settings import Settings

the_os = detected_os()
result.append(("os", the_os))
result.append(("os_build", the_os))

platform_machine = platform.machine().lower()
if platform_machine:
arch = architectures.get(platform_machine, platform_machine)
arch = detected_architecture()

if arch:
if arch.startswith('arm'):
for a in ("armv6", "armv7hf", "armv7", "armv8"):
settings = Settings.loads(get_default_settings_yml())
defined_architectures = settings.arch.values_range
defined_arm_architectures = [v for v in defined_architectures if v.startswith("arm")]

for a in defined_arm_architectures:
if arch.startswith(a):
arch = a
break
else:
output.error("Your ARM '%s' architecture is probably not defined in settings.yml\n"
"Please check your conan.conf and settings.yml files" % arch)
elif arch.startswith('e2k'):
arch = OSInfo.get_e2k_architecture() or arch
elif OSInfo().is_aix:
arch = OSInfo.get_aix_architecture() or arch

result.append(("arch", arch))
result.append(("arch_build", arch))
Expand Down
2 changes: 2 additions & 0 deletions conans/client/tools/oss.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def detected_architecture():
return "s390x"
elif "s390" in machine:
return "s390"
elif "sun4v" in machine:
return "sparc"
elif "e2k" in machine:
return OSInfo.get_e2k_architecture()

Expand Down
17 changes: 17 additions & 0 deletions conans/test/unittests/util/detect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,20 @@ def test_detect_aix(self, processor, bitness, version, expected_arch):
self.assertEqual("AIX", result['os_build'])
self.assertEqual(expected_arch, result['arch'])
self.assertEqual(expected_arch, result['arch_build'])

@parameterized.expand([
['arm64', 'armv8'],
['i386', 'x86'],
['i686', 'x86'],
['i86pc', 'x86'],
['amd64', 'x86_64'],
['aarch64', 'armv8'],
['sun4v', 'sparc']
])
def test_detect_arch(self, machine, expected_arch):
with mock.patch("platform.machine", mock.MagicMock(return_value=machine)):
result = detect_defaults_settings(output=TestBufferConanOutput(),
profile_path=DEFAULT_PROFILE_NAME)
result = dict(result)
self.assertEqual(expected_arch, result['arch'])
self.assertEqual(expected_arch, result['arch_build'])

0 comments on commit e63953e

Please sign in to comment.