Skip to content

Commit b7dc7ab

Browse files
authored
Merge pull request #1 from matoro/main-numpymeson
Backport mips64 fix from upstream meson
2 parents 82d41db + 9569d68 commit b7dc7ab

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

mesonbuild/environment.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def detect_cpu_family(compilers: CompilersDict) -> str:
343343
# MIPS64 is able to run MIPS32 code natively, so there is a chance that
344344
# such mixture mentioned above exists.
345345
elif trial == 'mips64':
346-
if not any_compiler_has_define(compilers, '__mips64'):
346+
if compilers and not any_compiler_has_define(compilers, '__mips64'):
347347
trial = 'mips'
348348

349349
if trial not in known_cpu_families:
@@ -383,7 +383,7 @@ def detect_cpu(compilers: CompilersDict) -> str:
383383
if '64' not in trial:
384384
trial = 'mips'
385385
else:
386-
if not any_compiler_has_define(compilers, '__mips64'):
386+
if compilers and not any_compiler_has_define(compilers, '__mips64'):
387387
trial = 'mips'
388388
else:
389389
trial = 'mips64'
@@ -469,6 +469,7 @@ def machine_info_can_run(machine_info: MachineInfo):
469469
return \
470470
(machine_info.cpu_family == true_build_cpu_family) or \
471471
((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86')) or \
472+
((true_build_cpu_family == 'mips64') and (machine_info.cpu_family == 'mips')) or \
472473
((true_build_cpu_family == 'aarch64') and (machine_info.cpu_family == 'arm'))
473474

474475
class Environment:

unittests/internaltests.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,15 +1596,27 @@ def mock_trial(value: str) -> T.Iterable[None]:
15961596
('aarch64_be', 'aarch64'),
15971597
]
15981598

1599+
cc = ClangCCompiler([], [], 'fake', MachineChoice.HOST, False, mock.Mock())
1600+
15991601
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)):
16001602
for test, expected in cases:
16011603
with self.subTest(test, has_define=False), mock_trial(test):
1602-
actual = mesonbuild.environment.detect_cpu_family({})
1604+
actual = mesonbuild.environment.detect_cpu_family({'c': cc})
16031605
self.assertEqual(actual, expected)
16041606

16051607
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
16061608
for test, expected in [('x86_64', 'x86'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
16071609
with self.subTest(test, has_define=True), mock_trial(test):
1610+
actual = mesonbuild.environment.detect_cpu_family({'c': cc})
1611+
self.assertEqual(actual, expected)
1612+
1613+
# machine_info_can_run calls detect_cpu_family with no compilers at all
1614+
with mock.patch(
1615+
'mesonbuild.environment.any_compiler_has_define',
1616+
mock.Mock(side_effect=AssertionError('Should not be called')),
1617+
):
1618+
for test, expected in [('mips64', 'mips64')]:
1619+
with self.subTest(test, has_compiler=False), mock_trial(test):
16081620
actual = mesonbuild.environment.detect_cpu_family({})
16091621
self.assertEqual(actual, expected)
16101622

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

1648+
cc = ClangCCompiler([], [], 'fake', MachineChoice.HOST, False, mock.Mock())
1649+
16361650
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=False)):
16371651
for test, expected in cases:
16381652
with self.subTest(test, has_define=False), mock_trial(test):
1639-
actual = mesonbuild.environment.detect_cpu({})
1653+
actual = mesonbuild.environment.detect_cpu({'c': cc})
16401654
self.assertEqual(actual, expected)
16411655

16421656
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
16431657
for test, expected in [('x86_64', 'i686'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
16441658
with self.subTest(test, has_define=True), mock_trial(test):
1659+
actual = mesonbuild.environment.detect_cpu({'c': cc})
1660+
self.assertEqual(actual, expected)
1661+
1662+
with mock.patch(
1663+
'mesonbuild.environment.any_compiler_has_define',
1664+
mock.Mock(side_effect=AssertionError('Should not be called')),
1665+
):
1666+
for test, expected in [('mips64', 'mips64')]:
1667+
with self.subTest(test, has_compiler=False), mock_trial(test):
16451668
actual = mesonbuild.environment.detect_cpu({})
16461669
self.assertEqual(actual, expected)
16471670

0 commit comments

Comments
 (0)