Validate cpu_family (#3753)

* environment: validate cpu_family in cross file

* run_unittests: add unittest to ensure CPU family list in docs and environment matches

* run_unittests: skip compiler options test if not in a git repository

* environment: validate the detected cpu_family

* docs: add 32-bit PowerPC and 32/64-bit MIPS to CPU Families table

Names gathered by booting Linux in Qemu and running:

$ python3
import platform; platform.machine()

Partial fix for #3751
pull/3528/merge
Ross Burton 7 years ago committed by Nirbheek Chauhan
parent 9fdf4d83e6
commit ecde1789b2
  1. 3
      docs/markdown/Reference-tables.md
  2. 24
      mesonbuild/environment.py
  3. 19
      run_unittests.py

@ -46,6 +46,9 @@ set in the cross file.
| ia64 | Itanium processor |
| arm | 32 bit ARM processor |
| aarch64 | 64 bit ARM processor |
| mips | 32 bit MIPS processor |
| mips64 | 64 bit MIPS processor |
| ppc | 32 bit PPC processors (Big Endian) |
| ppc64 | 64 bit PPC processors (Big Endian) |
| ppc64le | 64 bit PPC processors (Little Endian) |
| e2k | MCST Elbrus processor |

@ -72,6 +72,22 @@ from .compilers import (
build_filename = 'meson.build'
known_cpu_families = (
'aarch64',
'arm',
'e2k',
'ia64',
'mips',
'mips64',
'parisc',
'ppc',
'ppc64',
'ppc64le',
'sparc64',
'x86',
'x86_64'
)
def detect_gcovr(version='3.1', log=False):
gcovr_exe = 'gcovr'
try:
@ -209,6 +225,10 @@ def detect_cpu_family(compilers):
pass
return 'x86_64'
# Add fixes here as bugs are reported.
if trial not in known_cpu_families:
mlog.warning('Unknown CPU family %s, please report this at https://github.com/mesonbuild/meson/issues/new' % trial)
return trial
def detect_cpu(compilers):
@ -953,6 +973,10 @@ class CrossBuildInfo:
res = eval(value, {'__builtins__': None}, {'true': True, 'false': False})
except Exception:
raise EnvironmentException('Malformed value in cross file variable %s.' % entry)
if entry == 'cpu_family' and res not in known_cpu_families:
mlog.warning('Unknown CPU family %s, please report this at https://github.com/mesonbuild/meson/issues/new' % value)
if self.ok_type(res):
self.config[s][entry] = res
elif isinstance(res, list):

@ -2206,6 +2206,7 @@ recommended as it is not supported on some platforms''')
# they used to fail this test with Meson 0.46 an earlier versions.
pass
@unittest.skipIf(not os.path.isdir('docs'), 'Doc dir not found, presumably because this is a tarball release.')
def test_compiler_options_documented(self):
'''
Test that C and C++ compiler options and base options are documented in
@ -2227,6 +2228,24 @@ recommended as it is not supported on some platforms''')
self.assertIn(opt, md)
self.assertNotIn('b_unknown', md)
@unittest.skipIf(not os.path.isdir('docs'), 'Doc dir not found, presumably because this is a tarball release.')
def test_cpu_families_documented(self):
with open("docs/markdown/Reference-tables.md") as f:
md = f.read()
self.assertIsNotNone(md)
sections = list(re.finditer(r"^## (.+)$", md, re.MULTILINE))
for s1, s2 in zip(sections[::2], sections[1::2]):
if s1.group(1) == "CPU families":
# Extract the content for this section
content = md[s1.end():s2.start()]
# Find the list entries
arches = [m.group(1) for m in re.finditer(r"^\| (\w+) +\|", content, re.MULTILINE)]
# Drop the header
arches = set(arches[1:])
self.assertEqual(arches, set(mesonbuild.environment.known_cpu_families))
class FailureTests(BasePlatformTests):
'''
Tests that test failure conditions. Build files here should be dynamically

Loading…
Cancel
Save