Skip to content
forked from mesonbuild/meson
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
5 changes: 3 additions & 2 deletions mesonbuild/environment.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -343,7 +343,7 @@ def detect_cpu_family(compilers: CompilersDict) -> str:
# MIPS64 is able to run MIPS32 code natively, so there is a chance that
# such mixture mentioned above exists.
elif trial == 'mips64':
if not any_compiler_has_define(compilers, '__mips64'):
if compilers and not any_compiler_has_define(compilers, '__mips64'):
trial = 'mips'

if trial not in known_cpu_families:
Expand DownExpand Up@@ -383,7 +383,7 @@ def detect_cpu(compilers: CompilersDict) -> str:
if '64' not in trial:
trial = 'mips'
else:
if not any_compiler_has_define(compilers, '__mips64'):
if compilers and not any_compiler_has_define(compilers, '__mips64'):
trial = 'mips'
else:
trial = 'mips64'
Expand DownExpand Up@@ -469,6 +469,7 @@ def machine_info_can_run(machine_info: MachineInfo):
return \
(machine_info.cpu_family == true_build_cpu_family) or \
((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86')) or \
((true_build_cpu_family == 'mips64') and (machine_info.cpu_family == 'mips')) or \
((true_build_cpu_family == 'aarch64') and (machine_info.cpu_family == 'arm'))

class Environment:
Expand Down
27 changes: 25 additions & 2 deletions unittests/internaltests.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -1596,15 +1596,27 @@ def mock_trial(value: str) -> T.Iterable[None]:
('aarch64_be', 'aarch64'),
]

cc = ClangCCompiler([], [], 'fake', MachineChoice.HOST, False, mock.Mock())

with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)):
for test, expected in cases:
with self.subTest(test, has_define=False), mock_trial(test):
actual = mesonbuild.environment.detect_cpu_family({})
actual = mesonbuild.environment.detect_cpu_family({'c': cc})
self.assertEqual(actual, expected)

with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
for test, expected in [('x86_64', 'x86'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
with self.subTest(test, has_define=True), mock_trial(test):
actual = mesonbuild.environment.detect_cpu_family({'c': cc})
self.assertEqual(actual, expected)

# machine_info_can_run calls detect_cpu_family with no compilers at all
with mock.patch(
'mesonbuild.environment.any_compiler_has_define',
mock.Mock(side_effect=AssertionError('Should not be called')),
):
for test, expected in [('mips64', 'mips64')]:
with self.subTest(test, has_compiler=False), mock_trial(test):
actual = mesonbuild.environment.detect_cpu_family({})
self.assertEqual(actual, expected)

Expand DownExpand Up@@ -1633,15 +1645,26 @@ def mock_trial(value: str) -> T.Iterable[None]:
('aarch64_be', 'aarch64'),
]

cc = ClangCCompiler([], [], 'fake', MachineChoice.HOST, False, mock.Mock())

with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)):
for test, expected in cases:
with self.subTest(test, has_define=False), mock_trial(test):
actual = mesonbuild.environment.detect_cpu({})
actual = mesonbuild.environment.detect_cpu({'c': cc})
self.assertEqual(actual, expected)

with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
for test, expected in [('x86_64', 'i686'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
with self.subTest(test, has_define=True), mock_trial(test):
actual = mesonbuild.environment.detect_cpu({'c': cc})
self.assertEqual(actual, expected)

with mock.patch(
'mesonbuild.environment.any_compiler_has_define',
mock.Mock(side_effect=AssertionError('Should not be called')),
):
for test, expected in [('mips64', 'mips64')]:
with self.subTest(test, has_compiler=False), mock_trial(test):
actual = mesonbuild.environment.detect_cpu({})
self.assertEqual(actual, expected)

Expand Down