meson: validate cpu_family

Meson has a defined list of known CPU families but these are not currently
validated, so mistakes in cross files or new architectures are not noticed.

Backport a patch from upstream which warns on unknown architectures, but tweak
it to fatally error instead.  When we upgrade to Meson 0.47 the first half of
this patch can be dropped.

(From OE-Core rev: be194a459944dfcc41bae7315643a5d284683efc)

Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ross Burton
2018-07-03 14:04:11 +01:00
committed by Richard Purdie
parent 5193aedb45
commit e03660f46e
2 changed files with 119 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ SRC_URI = "https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${P
file://0003-native_bindir.patch \
file://0004-Prettifying-some-output-with-pathlib.patch \
file://0005-Set-the-meson-command-to-use-when-we-know-what-it-is.patch \
file://validate-cpu.patch \
"
SRC_URI[md5sum] = "1698f6526574839de5dcdc45e3f7d582"

View File

@@ -0,0 +1,118 @@
Validate the passed CPU family (US: backport) and turn the upstream warning to
an error (US: inappropriate).
Upstream-Status: Backport
Signed-off-by: Ross Burton <ross.burton@intel.com>
From 456f7ea48503731d50a2b7287a0f198b73b4fe61 Mon Sep 17 00:00:00 2001
From: Ross Burton <ross@burtonini.com>
Date: Wed, 20 Jun 2018 13:45:44 +0100
Subject: [PATCH 1/2] 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
---
mesonbuild/environment.py | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 6920b8d6..091d92dc 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -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'
+)
+
# Environment variables that each lang uses.
cflags_mapping = {'c': 'CFLAGS',
'cpp': 'CXXFLAGS',
@@ -210,6 +226,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):
@@ -1021,6 +1041,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):
--
2.11.0
From 202e0199d3ffd2637f4dbee08f8351520f7dde3b Mon Sep 17 00:00:00 2001
From: Ross Burton <ross.burton@intel.com>
Date: Tue, 3 Jul 2018 13:59:09 +0100
Subject: [PATCH 2/2] Make CPU family warnings fatal
---
mesonbuild/environment.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 091d92dc..67177c1f 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -228,7 +228,7 @@ def detect_cpu_family(compilers):
# 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)
+ raise EnvironmentException('Unknown CPU family %s, please report this at https://github.com/mesonbuild/meson/issues/new' % trial)
return trial
@@ -1043,7 +1043,7 @@ class CrossBuildInfo:
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)
+ raise EnvironmentException('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
--
2.11.0