aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter/interpreter.py
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-03-07 11:41:18 +0100
committerEli Schwartz <eschwartz93@gmail.com>2025-03-09 18:06:14 -0400
commit43ea11ea49948635b1d672fef1bd397233b65b19 (patch)
treee1fa9be70e178fb12d6d01ca8c07d3d4fa437ab9 /mesonbuild/interpreter/interpreter.py
parente629d191b99119c360605b056b954fff0905c83f (diff)
downloadmeson-43ea11ea49948635b1d672fef1bd397233b65b19.zip
meson-43ea11ea49948635b1d672fef1bd397233b65b19.tar.gz
meson-43ea11ea49948635b1d672fef1bd397233b65b19.tar.bz2
compilers: convert `b_sanitize` to a free-form array option
In the preceding commit we have started to perform compiler checks for the value of `b_sanitize`, which allows us to detect sanitizers that aren't supported by the compiler toolchain. But we haven't yet loosened the option itself to accept arbitrary values, so until now it's still only possible to pass sanitizer combinations known by Meson, which is quite restrictive. Lift that restriction by adapting the `b_sanitize` option to become a free-form array. Like this, users can pass whatever combination of comma-separated sanitizers to Meson, which will then figure out whether that combination is supported via the compiler checks. This lifts a couple of restrictions and makes the supporting infrastructure way more future proof. A couple of notes regarding backwards compatibility: - All previous values of `b_sanitize` will remain valid as the syntax for free-form array values and valid combo choices is the same. We also treat 'none' specially so that we know to convert it into an empty array. - Even though the option has been converted into a free-form array, callers of `get_option('b_sanitize')` continue to get a string as value. We may eventually want to introduce a kwarg to alter this behaviour, but for now it is expected to be good enough for most use cases. Fixes #8283 Fixes #7761 Fixes #5154 Fixes #1582 Co-authored-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Patrick Steinhardt <ps@pks.im>
Diffstat (limited to 'mesonbuild/interpreter/interpreter.py')
-rw-r--r--mesonbuild/interpreter/interpreter.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index ff93ac6..42e6243 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -1068,14 +1068,14 @@ class Interpreter(InterpreterBase, HoldableObject):
@typed_pos_args('get_option', str)
@noKwargs
- def func_get_option(self, nodes: mparser.BaseNode, args: T.Tuple[str],
- kwargs: 'TYPE_kwargs') -> T.Union[options.UserOption, 'TYPE_var']:
+ def func_get_option(self, node: mparser.BaseNode, args: T.Tuple[str],
+ kwargs: kwtypes.FuncGetOption) -> T.Union[options.UserOption, 'TYPE_var']:
optname = args[0]
+
if ':' in optname:
raise InterpreterException('Having a colon in option name is forbidden, '
'projects are not allowed to directly access '
'options of other subprojects.')
-
if optname_regex.search(optname.split('.', maxsplit=1)[-1]) is not None:
raise InterpreterException(f'Invalid option name {optname!r}')
@@ -1096,6 +1096,15 @@ class Interpreter(InterpreterBase, HoldableObject):
ocopy.name = optname
ocopy.value = value
return ocopy
+ elif optname == 'b_sanitize':
+ assert isinstance(value_object, options.UserStringArrayOption)
+ # To ensure backwards compatibility this always returns a string.
+ # We may eventually want to introduce a new "format" kwarg that
+ # allows the user to modify this behaviour, but for now this is
+ # likely good enough for most usecases.
+ if not value:
+ return 'none'
+ return ','.join(sorted(value))
elif isinstance(value_object, options.UserOption):
if isinstance(value_object.value, str):
return P_OBJ.OptionString(value, f'{{{optname}}}')
@@ -3090,7 +3099,7 @@ class Interpreter(InterpreterBase, HoldableObject):
if OptionKey('b_sanitize') not in self.coredata.optstore:
return
if (self.coredata.optstore.get_value('b_lundef') and
- self.coredata.optstore.get_value('b_sanitize') != 'none'):
+ self.coredata.optstore.get_value('b_sanitize')):
value = self.coredata.optstore.get_value('b_sanitize')
mlog.warning(textwrap.dedent(f'''\
Trying to use {value} sanitizer on Clang with b_lundef.