Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: M1 detection #8501

Merged
merged 1 commit into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])