summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorCharles Brunet <charles.brunet@optelgroup.com>2024-01-11 15:20:44 -0500
committerDylan Baker <dylan@pnwbakers.com>2024-03-15 09:23:46 -0700
commitdacb25db101e7ede60b6ba3dd5a7d1935dc5ff73 (patch)
treeeef37958f0c54683829453d03d4e13bf5e02377f /mesonbuild/compilers
parentd08ef2c08bb0120f0ba20dbc10575b7e15577349 (diff)
downloadmeson-dacb25db101e7ede60b6ba3dd5a7d1935dc5ff73.tar.gz
Improve error messages for invalid option values
By adding the option name to UserOption object, it is now possible to display the name of the affected option when the given option value is not valid. Fixes #12635
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py39
-rw-r--r--mesonbuild/compilers/compilers.py78
-rw-r--r--mesonbuild/compilers/cpp.py173
-rw-r--r--mesonbuild/compilers/cuda.py23
-rw-r--r--mesonbuild/compilers/cython.py27
-rw-r--r--mesonbuild/compilers/fortran.py18
-rw-r--r--mesonbuild/compilers/mixins/emscripten.py15
-rw-r--r--mesonbuild/compilers/objc.py17
-rw-r--r--mesonbuild/compilers/objcpp.py23
-rw-r--r--mesonbuild/compilers/rust.py15
10 files changed, 234 insertions, 194 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 048649a32..7e2146111 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -152,12 +152,13 @@ class ClangCCompiler(_ClangCStds, ClangCompiler, CCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
if self.info.is_windows() or self.info.is_cygwin():
- opts.update({
- OptionKey('winlibs', machine=self.for_machine, lang=self.language): coredata.UserArrayOption(
- 'Standard Win libraries to link against',
- gnu_winlibs,
- ),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserArrayOption,
+ OptionKey('winlibs', machine=self.for_machine, lang=self.language),
+ 'Standard Win libraries to link against',
+ gnu_winlibs),
+ )
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -290,12 +291,13 @@ class GnuCCompiler(GnuCompiler, CCompiler):
assert isinstance(std_opt, coredata.UserStdOption), 'for mypy'
std_opt.set_versions(stds, gnu=True)
if self.info.is_windows() or self.info.is_cygwin():
- opts.update({
- key.evolve('winlibs'): coredata.UserArrayOption(
- 'Standard Win libraries to link against',
- gnu_winlibs,
- ),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserArrayOption,
+ key.evolve('winlibs'),
+ 'Standard Win libraries to link against',
+ gnu_winlibs),
+ )
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -425,15 +427,16 @@ class VisualStudioLikeCCompilerMixin(CompilerMixinBase):
"""Shared methods that apply to MSVC-like C compilers."""
- def get_options(self) -> 'MutableKeyedOptionDictType':
- opts = super().get_options()
- opts.update({
- OptionKey('winlibs', machine=self.for_machine, lang=self.language): coredata.UserArrayOption(
+ def get_options(self) -> MutableKeyedOptionDictType:
+ return self.update_options(
+ super().get_options(),
+ self.create_option(
+ coredata.UserArrayOption,
+ OptionKey('winlibs', machine=self.for_machine, lang=self.language),
'Windows libs to link against.',
msvc_winlibs,
),
- })
- return opts
+ )
def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
# need a TypeDict to make this work
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 9e99706c0..5854c9e60 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -9,6 +9,7 @@ import contextlib, os.path, re
import enum
import itertools
import typing as T
+from dataclasses import dataclass
from functools import lru_cache
from .. import coredata
@@ -34,6 +35,7 @@ if T.TYPE_CHECKING:
CompilerType = T.TypeVar('CompilerType', bound='Compiler')
_T = T.TypeVar('_T')
+ UserOptionType = T.TypeVar('UserOptionType', bound=coredata.UserOption)
"""This file contains the data files of all compilers Meson knows
about. To support a new compiler, add its information below.
@@ -206,36 +208,46 @@ clike_debug_args: T.Dict[bool, T.List[str]] = {
MSCRT_VALS = ['none', 'md', 'mdd', 'mt', 'mtd']
-base_options: 'KeyedOptionDictType' = {
- OptionKey('b_pch'): coredata.UserBooleanOption('Use precompiled headers', True),
- OptionKey('b_lto'): coredata.UserBooleanOption('Use link time optimization', False),
- OptionKey('b_lto_threads'): coredata.UserIntegerOption('Use multiple threads for Link Time Optimization', (None, None, 0)),
- OptionKey('b_lto_mode'): coredata.UserComboOption('Select between different LTO modes.',
- ['default', 'thin'],
- 'default'),
- OptionKey('b_thinlto_cache'): coredata.UserBooleanOption('Use LLVM ThinLTO caching for faster incremental builds', False),
- OptionKey('b_thinlto_cache_dir'): coredata.UserStringOption('Directory to store ThinLTO cache objects', ''),
- OptionKey('b_sanitize'): coredata.UserComboOption('Code sanitizer to use',
- ['none', 'address', 'thread', 'undefined', 'memory', 'leak', 'address,undefined'],
- 'none'),
- OptionKey('b_lundef'): coredata.UserBooleanOption('Use -Wl,--no-undefined when linking', True),
- OptionKey('b_asneeded'): coredata.UserBooleanOption('Use -Wl,--as-needed when linking', True),
- OptionKey('b_pgo'): coredata.UserComboOption('Use profile guided optimization',
- ['off', 'generate', 'use'],
- 'off'),
- OptionKey('b_coverage'): coredata.UserBooleanOption('Enable coverage tracking.', False),
- OptionKey('b_colorout'): coredata.UserComboOption('Use colored output',
- ['auto', 'always', 'never'],
- 'always'),
- OptionKey('b_ndebug'): coredata.UserComboOption('Disable asserts', ['true', 'false', 'if-release'], 'false'),
- OptionKey('b_staticpic'): coredata.UserBooleanOption('Build static libraries as position independent', True),
- OptionKey('b_pie'): coredata.UserBooleanOption('Build executables as position independent', False),
- OptionKey('b_bitcode'): coredata.UserBooleanOption('Generate and embed bitcode (only macOS/iOS/tvOS)', False),
- OptionKey('b_vscrt'): coredata.UserComboOption('VS run-time library type to use.',
- MSCRT_VALS + ['from_buildtype', 'static_from_buildtype'],
- 'from_buildtype'),
+@dataclass
+class BaseOption(T.Generic[coredata._T, coredata._U]):
+ opt_type: T.Type[coredata._U]
+ description: str
+ default: T.Any = None
+ choices: T.Any = None
+
+ def init_option(self, name: OptionKey) -> coredata._U:
+ keywords = {'value': self.default}
+ if self.choices:
+ keywords['choices'] = self.choices
+ return self.opt_type(name.name, self.description, **keywords)
+
+BASE_OPTIONS: T.Mapping[OptionKey, BaseOption] = {
+ OptionKey('b_pch'): BaseOption(coredata.UserBooleanOption, 'Use precompiled headers', True),
+ OptionKey('b_lto'): BaseOption(coredata.UserBooleanOption, 'Use link time optimization', False),
+ OptionKey('b_lto_threads'): BaseOption(coredata.UserIntegerOption, 'Use multiple threads for Link Time Optimization', (None, None, 0)),
+ OptionKey('b_lto_mode'): BaseOption(coredata.UserComboOption, 'Select between different LTO modes.', 'default',
+ choices=['default', 'thin']),
+ OptionKey('b_thinlto_cache'): BaseOption(coredata.UserBooleanOption, 'Use LLVM ThinLTO caching for faster incremental builds', False),
+ OptionKey('b_thinlto_cache_dir'): BaseOption(coredata.UserStringOption, 'Directory to store ThinLTO cache objects', ''),
+ OptionKey('b_sanitize'): BaseOption(coredata.UserComboOption, 'Code sanitizer to use', 'none',
+ choices=['none', 'address', 'thread', 'undefined', 'memory', 'leak', 'address,undefined']),
+ OptionKey('b_lundef'): BaseOption(coredata.UserBooleanOption, 'Use -Wl,--no-undefined when linking', True),
+ OptionKey('b_asneeded'): BaseOption(coredata.UserBooleanOption, 'Use -Wl,--as-needed when linking', True),
+ OptionKey('b_pgo'): BaseOption(coredata.UserComboOption, 'Use profile guided optimization', 'off',
+ choices=['off', 'generate', 'use']),
+ OptionKey('b_coverage'): BaseOption(coredata.UserBooleanOption, 'Enable coverage tracking.', False),
+ OptionKey('b_colorout'): BaseOption(coredata.UserComboOption, 'Use colored output', 'always',
+ choices=['auto', 'always', 'never']),
+ OptionKey('b_ndebug'): BaseOption(coredata.UserComboOption, 'Disable asserts', 'false', choices=['true', 'false', 'if-release']),
+ OptionKey('b_staticpic'): BaseOption(coredata.UserBooleanOption, 'Build static libraries as position independent', True),
+ OptionKey('b_pie'): BaseOption(coredata.UserBooleanOption, 'Build executables as position independent', False),
+ OptionKey('b_bitcode'): BaseOption(coredata.UserBooleanOption, 'Generate and embed bitcode (only macOS/iOS/tvOS)', False),
+ OptionKey('b_vscrt'): BaseOption(coredata.UserComboOption, 'VS run-time library type to use.', 'from_buildtype',
+ choices=MSCRT_VALS + ['from_buildtype', 'static_from_buildtype']),
}
+base_options: KeyedOptionDictType = {key: base_opt.init_option(key) for key, base_opt in BASE_OPTIONS.items()}
+
def option_enabled(boptions: T.Set[OptionKey], options: 'KeyedOptionDictType',
option: OptionKey) -> bool:
try:
@@ -577,6 +589,14 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
"""
return []
+ def create_option(self, option_type: T.Type[UserOptionType], option_key: OptionKey, *args: T.Any, **kwargs: T.Any) -> T.Tuple[OptionKey, UserOptionType]:
+ return option_key, option_type(f'{self.language}_{option_key.name}', *args, **kwargs)
+
+ @staticmethod
+ def update_options(options: MutableKeyedOptionDictType, *args: T.Tuple[OptionKey, UserOptionType]) -> MutableKeyedOptionDictType:
+ options.update(args)
+ return options
+
def get_options(self) -> 'MutableKeyedOptionDictType':
return {}
@@ -1346,10 +1366,12 @@ def get_global_options(lang: str,
link_options = env.options.get(largkey, [])
cargs = coredata.UserArrayOption(
+ f'{lang}_{argkey.name}',
description + ' compiler',
comp_options, split_args=True, allow_dups=True)
largs = coredata.UserArrayOption(
+ f'{lang}_{largkey.name}',
description + ' linker',
link_options, split_args=True, allow_dups=True)
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 5e412e7a5..540dedb18 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -237,18 +237,22 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
key = OptionKey('key', machine=self.for_machine, lang=self.language)
- opts.update({
- key.evolve('debugstl'): coredata.UserBooleanOption(
- 'STL debug mode',
- False,
- ),
- key.evolve('eh'): coredata.UserComboOption(
- 'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default',
- ),
- key.evolve('rtti'): coredata.UserBooleanOption('Enable RTTI', True),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserComboOption,
+ key.evolve('eh'),
+ 'C++ exception handling type.',
+ ['none', 'default', 'a', 's', 'sc'],
+ 'default'),
+ self.create_option(coredata.UserBooleanOption,
+ key.evolve('rtti'),
+ 'Enable RTTI',
+ True),
+ self.create_option(coredata.UserBooleanOption,
+ key.evolve('debugstl'),
+ 'STL debug mode',
+ False),
+ )
cppstd_choices = [
'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z', 'c++2a', 'c++20',
]
@@ -260,12 +264,13 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler):
assert isinstance(std_opt, coredata.UserStdOption), 'for mypy'
std_opt.set_versions(cppstd_choices, gnu=True)
if self.info.is_windows() or self.info.is_cygwin():
- opts.update({
- key.evolve('winlibs'): coredata.UserArrayOption(
- 'Standard Win libraries to link against',
- gnu_winlibs,
- ),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserArrayOption,
+ key.evolve('winlibs'),
+ 'Standard Win libraries to link against',
+ gnu_winlibs),
+ )
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -378,13 +383,14 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = CPPCompiler.get_options(self)
key = OptionKey('std', machine=self.for_machine, lang=self.language)
- opts.update({
- key.evolve('eh'): coredata.UserComboOption(
- 'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default',
- ),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserComboOption,
+ key.evolve('eh'),
+ 'C++ exception handling type.',
+ ['none', 'default', 'a', 's', 'sc'],
+ 'default'),
+ )
std_opt = opts[key]
assert isinstance(std_opt, coredata.UserStdOption), 'for mypy'
std_opt.set_versions(['c++98', 'c++03', 'c++11', 'c++14', 'c++17'], gnu=True)
@@ -426,18 +432,22 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
key = OptionKey('std', machine=self.for_machine, lang=self.language)
opts = CPPCompiler.get_options(self)
- opts.update({
- key.evolve('eh'): coredata.UserComboOption(
- 'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default',
- ),
- key.evolve('rtti'): coredata.UserBooleanOption('Enable RTTI', True),
- key.evolve('debugstl'): coredata.UserBooleanOption(
- 'STL debug mode',
- False,
- )
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserComboOption,
+ key.evolve('eh'),
+ 'C++ exception handling type.',
+ ['none', 'default', 'a', 's', 'sc'],
+ 'default'),
+ self.create_option(coredata.UserBooleanOption,
+ key.evolve('rtti'),
+ 'Enable RTTI',
+ True),
+ self.create_option(coredata.UserBooleanOption,
+ key.evolve('debugstl'),
+ 'STL debug mode',
+ False),
+ )
cppstd_choices = [
'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z',
'c++2a', 'c++20',
@@ -450,12 +460,13 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
assert isinstance(std_opt, coredata.UserStdOption), 'for mypy'
std_opt.set_versions(cppstd_choices, gnu=True)
if self.info.is_windows() or self.info.is_cygwin():
- opts.update({
- key.evolve('winlibs'): coredata.UserArrayOption(
- 'Standard Win libraries to link against',
- gnu_winlibs,
- ),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserArrayOption,
+ key.evolve('winlibs'),
+ 'Standard Win libraries to link against',
+ gnu_winlibs),
+ )
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -550,17 +561,18 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler):
cpp_stds += ['c++20']
key = OptionKey('std', machine=self.for_machine, lang=self.language)
- opts.update({
- key.evolve('eh'): coredata.UserComboOption(
- 'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default',
- ),
- key.evolve('debugstl'): coredata.UserBooleanOption(
- 'STL debug mode',
- False,
- ),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserComboOption,
+ key.evolve('eh'),
+ 'C++ exception handling type.',
+ ['none', 'default', 'a', 's', 'sc'],
+ 'default'),
+ self.create_option(coredata.UserBooleanOption,
+ key.evolve('debugstl'),
+ 'STL debug mode',
+ False),
+ )
std_opt = opts[key]
assert isinstance(std_opt, coredata.UserStdOption), 'for mypy'
std_opt.set_versions(cpp_stds, gnu=True)
@@ -628,15 +640,22 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
g_stds += ['gnu++2a']
key = OptionKey('std', machine=self.for_machine, lang=self.language)
- opts.update({
- key.evolve('eh'): coredata.UserComboOption(
- 'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default',
- ),
- key.evolve('rtti'): coredata.UserBooleanOption('Enable RTTI', True),
- key.evolve('debugstl'): coredata.UserBooleanOption('STL debug mode', False),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserComboOption,
+ key.evolve('eh'),
+ 'C++ exception handling type.',
+ ['none', 'default', 'a', 's', 'sc'],
+ 'default'),
+ self.create_option(coredata.UserBooleanOption,
+ key.evolve('rtti'),
+ 'Enable RTTI',
+ True),
+ self.create_option(coredata.UserBooleanOption,
+ key.evolve('debugstl'),
+ 'STL debug mode',
+ False),
+ )
std_opt = opts[key]
assert isinstance(std_opt, coredata.UserStdOption), 'for mypy'
std_opt.set_versions(c_stds + g_stds)
@@ -694,18 +713,22 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List[str]) -> 'MutableKeyedOptionDictType':
key = OptionKey('std', machine=self.for_machine, lang=self.language)
- opts.update({
- key.evolve('eh'): coredata.UserComboOption(
- 'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default',
- ),
- key.evolve('rtti'): coredata.UserBooleanOption('Enable RTTI', True),
- key.evolve('winlibs'): coredata.UserArrayOption(
- 'Windows libs to link against.',
- msvc_winlibs,
- ),
- })
+ self.update_options(
+ opts,
+ self.create_option(coredata.UserComboOption,
+ key.evolve('eh'),
+ 'C++ exception handling type.',
+ ['none', 'default', 'a', 's', 'sc'],
+ 'default'),
+ self.create_option(coredata.UserBooleanOption,
+ key.evolve('rtti'),
+ 'Enable RTTI',
+ True),
+ self.create_option(coredata.UserArrayOption,
+ key.evolve('winlibs'),
+ 'Windows libs to link against.',
+ msvc_winlibs),
+ )
std_opt = opts[key]
assert isinstance(std_opt, coredata.UserStdOption), 'for mypy'
std_opt.set_versions(cpp_stds)
diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py
index 391107f84..ab4810798 100644
--- a/mesonbuild/compilers/cuda.py
+++ b/mesonbuild/compilers/cuda.py
@@ -630,10 +630,6 @@ class CudaCompiler(Compiler):
_CPP20_VERSION = '>=12.0'
def get_options(self) -> 'MutableKeyedOptionDictType':
- opts = super().get_options()
- std_key = OptionKey('std', machine=self.for_machine, lang=self.language)
- ccbindir_key = OptionKey('ccbindir', machine=self.for_machine, lang=self.language)
-
cpp_stds = ['none', 'c++03', 'c++11']
if version_compare(self.version, self._CPP14_VERSION):
cpp_stds += ['c++14']
@@ -642,13 +638,18 @@ class CudaCompiler(Compiler):
if version_compare(self.version, self._CPP20_VERSION):
cpp_stds += ['c++20']
- opts.update({
- std_key: coredata.UserComboOption('C++ language standard to use with CUDA',
- cpp_stds, 'none'),
- ccbindir_key: coredata.UserStringOption('CUDA non-default toolchain directory to use (-ccbin)',
- ''),
- })
- return opts
+ return self.update_options(
+ super().get_options(),
+ self.create_option(coredata.UserComboOption,
+ OptionKey('std', machine=self.for_machine, lang=self.language),
+ 'C++ language standard to use with CUDA',
+ cpp_stds,
+ 'none'),
+ self.create_option(coredata.UserStringOption,
+ OptionKey('ccbindir', machine=self.for_machine, lang=self.language),
+ 'CUDA non-default toolchain directory to use (-ccbin)',
+ ''),
+ )
def _to_host_compiler_options(self, options: 'KeyedOptionDictType') -> 'KeyedOptionDictType':
"""
diff --git a/mesonbuild/compilers/cython.py b/mesonbuild/compilers/cython.py
index a58b3a814..30cec81e3 100644
--- a/mesonbuild/compilers/cython.py
+++ b/mesonbuild/compilers/cython.py
@@ -67,20 +67,19 @@ class CythonCompiler(Compiler):
return new
def get_options(self) -> 'MutableKeyedOptionDictType':
- opts = super().get_options()
- opts.update({
- OptionKey('version', machine=self.for_machine, lang=self.language): coredata.UserComboOption(
- 'Python version to target',
- ['2', '3'],
- '3',
- ),
- OptionKey('language', machine=self.for_machine, lang=self.language): coredata.UserComboOption(
- 'Output C or C++ files',
- ['c', 'cpp'],
- 'c',
- )
- })
- return opts
+ return self.update_options(
+ super().get_options(),
+ self.create_option(coredata.UserComboOption,
+ OptionKey('version', machine=self.for_machine, lang=self.language),
+ 'Python version to target',
+ ['2', '3'],
+ '3'),
+ self.create_option(coredata.UserComboOption,
+ OptionKey('language', machine=self.for_machine, lang=self.language),
+ 'Output C or C++ files',
+ ['c', 'cpp'],
+ 'c'),
+ )
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args: T.List[str] = []
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index 3a7365046..2cdff36de 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -112,16 +112,14 @@ class FortranCompiler(CLikeCompiler, Compiler):
return self._has_multi_link_arguments(args, env, 'stop; end program')
def get_options(self) -> 'MutableKeyedOptionDictType':
- opts = super().get_options()
- key = OptionKey('std', machine=self.for_machine, lang=self.language)
- opts.update({
- key: coredata.UserComboOption(
- 'Fortran language standard to use',
- ['none'],
- 'none',
- ),
- })
- return opts
+ return self.update_options(
+ super().get_options(),
+ self.create_option(coredata.UserComboOption,
+ OptionKey('std', machine=self.for_machine, lang=self.language),
+ 'Fortran language standard to use',
+ ['none'],
+ 'none'),
+ )
class GnuFortranCompiler(GnuCompiler, FortranCompiler):
diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py
index d10c49987..bb8a52054 100644
--- a/mesonbuild/compilers/mixins/emscripten.py
+++ b/mesonbuild/compilers/mixins/emscripten.py
@@ -55,17 +55,16 @@ class EmscriptenMixin(Compiler):
args.append(f'-sPTHREAD_POOL_SIZE={count}')
return args
- def get_options(self) -> 'coredata.MutableKeyedOptionDictType':
- opts = super().get_options()
- key = OptionKey('thread_count', machine=self.for_machine, lang=self.language)
- opts.update({
- key: coredata.UserIntegerOption(
+ def get_options(self) -> coredata.MutableKeyedOptionDictType:
+ return self.update_options(
+ super().get_options(),
+ self.create_option(
+ coredata.UserIntegerOption,
+ OptionKey('thread_count', machine=self.for_machine, lang=self.language),
'Number of threads to use in web assembly, set to 0 to disable',
(0, None, 4), # Default was picked at random
),
- })
-
- return opts
+ )
@classmethod
def native_args_to_unix(cls, args: T.List[str]) -> T.List[str]:
diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py
index f805bd6be..7c19c1b7d 100644
--- a/mesonbuild/compilers/objc.py
+++ b/mesonbuild/compilers/objc.py
@@ -78,15 +78,14 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
'everything': ['-Weverything']}
def get_options(self) -> 'coredata.MutableKeyedOptionDictType':
- opts = super().get_options()
- opts.update({
- OptionKey('std', machine=self.for_machine, lang='c'): coredata.UserComboOption(
- 'C language standard to use',
- ['none', 'c89', 'c99', 'c11', 'c17', 'gnu89', 'gnu99', 'gnu11', 'gnu17'],
- 'none',
- )
- })
- return opts
+ return self.update_options(
+ super().get_options(),
+ self.create_option(coredata.UserComboOption,
+ OptionKey('std', machine=self.for_machine, lang='c'),
+ 'C language standard to use',
+ ['none', 'c89', 'c99', 'c11', 'c17', 'gnu89', 'gnu99', 'gnu11', 'gnu17'],
+ 'none'),
+ )
def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
args = []
diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py
index baf4fb5ca..46eaa5049 100644
--- a/mesonbuild/compilers/objcpp.py
+++ b/mesonbuild/compilers/objcpp.py
@@ -77,18 +77,17 @@ class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
'3': default_warn_args + ['-Wextra', '-Wpedantic'],
'everything': ['-Weverything']}
- def get_options(self) -> 'coredata.MutableKeyedOptionDictType':
- opts = super().get_options()
- opts.update({
- OptionKey('std', machine=self.for_machine, lang='cpp'): coredata.UserComboOption(
- 'C++ language standard to use',
- ['none', 'c++98', 'c++11', 'c++14', 'c++17', 'c++20', 'c++2b',
- 'gnu++98', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++20',
- 'gnu++2b'],
- 'none',
- )
- })
- return opts
+ def get_options(self) -> coredata.MutableKeyedOptionDictType:
+ return self.update_options(
+ super().get_options(),
+ self.create_option(coredata.UserComboOption,
+ OptionKey('std', machine=self.for_machine, lang='cpp'),
+ 'C++ language standard to use',
+ ['none', 'c++98', 'c++11', 'c++14', 'c++17', 'c++20', 'c++2b',
+ 'gnu++98', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++20',
+ 'gnu++2b'],
+ 'none'),
+ )
def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]:
args = []
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index 65f4ac1b1..05e8b2b27 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -156,15 +156,12 @@ class RustCompiler(Compiler):
# C compiler for dynamic linking, as such we invoke the C compiler's
# use_linker_args method instead.
- def get_options(self) -> 'MutableKeyedOptionDictType':
- key = OptionKey('std', machine=self.for_machine, lang=self.language)
- return {
- key: coredata.UserComboOption(
- 'Rust edition to use',
- ['none', '2015', '2018', '2021'],
- 'none',
- ),
- }
+ def get_options(self) -> MutableKeyedOptionDictType:
+ return dict((self.create_option(coredata.UserComboOption,
+ OptionKey('std', machine=self.for_machine, lang=self.language),
+ 'Rust edition to use',
+ ['none', '2015', '2018', '2021'],
+ 'none'),))
def get_dependency_compile_args(self, dep: 'Dependency') -> T.List[str]:
# Rust doesn't have dependency compile arguments so simply return