summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-08-29 15:47:20 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2025-02-05 17:45:38 +0200
commitba3460eb11bbceaf4fef7352bf286cf27184c99a (patch)
treeef001dc11ac342d82296a7e41560dac04f8b89ce /mesonbuild/compilers
parent0e11b90d6f2f9c3e18cb8ff84b1622640666e826 (diff)
downloadmeson-ba3460eb11bbceaf4fef7352bf286cf27184c99a.tar.gz
options: Add an EnumeratedUserOption class
This will allow us to take choices out of the UserOption class, which doesn't actually use this attribute.
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/c.py14
-rw-r--r--mesonbuild/compilers/compilers.py13
-rw-r--r--mesonbuild/compilers/cpp.py28
-rw-r--r--mesonbuild/compilers/cuda.py3
-rw-r--r--mesonbuild/compilers/cython.py4
-rw-r--r--mesonbuild/compilers/fortran.py15
-rw-r--r--mesonbuild/compilers/rust.py2
7 files changed, 37 insertions, 42 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index d8ad9f793..4f93ea14e 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -124,7 +124,7 @@ class ClangCCompiler(ClangCStds, ClangCompiler, CCompiler):
opts = super().get_options()
if self.info.is_windows() or self.info.is_cygwin():
key = self.form_compileropt_key('winlibs')
- opts[key] = options.UserArrayOption(
+ opts[key] = options.UserStringArrayOption(
self.make_option_name(key),
'Standard Windows libraries to link against',
gnu_winlibs)
@@ -257,7 +257,7 @@ class GnuCCompiler(GnuCStds, GnuCompiler, CCompiler):
opts = super().get_options()
if self.info.is_windows() or self.info.is_cygwin():
key = self.form_compileropt_key('winlibs')
- opts[key] = options.UserArrayOption(
+ opts[key] = options.UserStringArrayOption(
self.make_option_name(key),
'Standard Windows libraries to link against',
gnu_winlibs)
@@ -406,7 +406,7 @@ class VisualStudioLikeCCompilerMixin(CompilerMixinBase):
def get_options(self) -> MutableKeyedOptionDictType:
opts = super().get_options()
key = self.form_compileropt_key('winlibs')
- opts[key] = options.UserArrayOption(
+ opts[key] = options.UserStringArrayOption(
self.make_option_name(key),
'Standard Windows libraries to link against',
msvc_winlibs)
@@ -733,9 +733,7 @@ class MetrowerksCCompilerARM(MetrowerksCompiler, CCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
- c_stds = ['c99']
- key = self.form_compileropt_key('std')
- opts[key].choices = ['none'] + c_stds
+ self._update_language_stds(opts, ['c99'])
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -763,9 +761,7 @@ class MetrowerksCCompilerEmbeddedPowerPC(MetrowerksCompiler, CCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
- c_stds = ['c99']
- key = self.form_compileropt_key('std')
- opts[key].choices = ['none'] + c_stds
+ self._update_language_stds(opts, ['c99'])
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 1432afb85..5777f19f1 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1359,6 +1359,15 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def form_compileropt_key(self, basename: str) -> OptionKey:
return OptionKey(f'{self.language}_{basename}', machine=self.for_machine)
+ def _update_language_stds(self, opts: MutableKeyedOptionDictType, value: T.List[str]) -> None:
+ key = self.form_compileropt_key('std')
+ std = opts[key]
+ assert isinstance(std, (options.UserStdOption, options.UserComboOption)), 'for mypy'
+ if 'none' not in value:
+ value = ['none'] + value
+ std.choices = value
+
+
def get_global_options(lang: str,
comp: T.Type[Compiler],
for_machine: MachineChoice,
@@ -1374,12 +1383,12 @@ def get_global_options(lang: str,
comp_options = env.options.get(comp_key, [])
link_options = env.options.get(largkey, [])
- cargs = options.UserArrayOption(
+ cargs = options.UserStringArrayOption(
f'{lang}_{argkey.name}',
description + ' compiler',
comp_options, split_args=True, allow_dups=True)
- largs = options.UserArrayOption(
+ largs = options.UserStringArrayOption(
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 7fa9aa833..80f84b38e 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -243,7 +243,7 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler
self.make_option_name(key),
'C++ exception handling type.',
'default',
- ['none', 'default', 'a', 's', 'sc'])
+ choices=['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('rtti')
opts[key] = options.UserBooleanOption(
@@ -259,7 +259,7 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler
if self.info.is_windows() or self.info.is_cygwin():
key = self.form_compileropt_key('winlibs')
- opts[key] = options.UserArrayOption(
+ opts[key] = options.UserStringArrayOption(
self.make_option_name(key),
'Standard Win libraries to link against',
gnu_winlibs)
@@ -399,7 +399,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
self.make_option_name(key),
'C++ exception handling type.',
'default',
- ['none', 'default', 'a', 's', 'sc'])
+ choices=['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('std')
std_opt = opts[key]
@@ -449,7 +449,7 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCPPStds, GnuCompiler, CPPCompiler):
self.make_option_name(key),
'C++ exception handling type.',
'default',
- ['none', 'default', 'a', 's', 'sc'])
+ choices=['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('rtti')
opts[key] = options.UserBooleanOption(
@@ -465,7 +465,7 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCPPStds, GnuCompiler, CPPCompiler):
if self.info.is_windows() or self.info.is_cygwin():
key = key.evolve(name='cpp_winlibs')
- opts[key] = options.UserArrayOption(
+ opts[key] = options.UserStringArrayOption(
self.make_option_name(key),
'Standard Win libraries to link against',
gnu_winlibs)
@@ -578,7 +578,7 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler):
self.make_option_name(key),
'C++ exception handling type.',
'default',
- ['none', 'default', 'a', 's', 'sc'])
+ choices=['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('debugstl')
opts[key] = options.UserBooleanOption(
@@ -661,7 +661,7 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
self.make_option_name(key),
'C++ exception handling type.',
'default',
- ['none', 'default', 'a', 's', 'sc'])
+ choices=['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('rtti')
opts[key] = options.UserBooleanOption(
@@ -691,9 +691,7 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
c_stds += ['c++2a']
g_stds += ['gnu++2a']
- std_opt = opts[self.form_compileropt_key('std')]
- assert isinstance(std_opt, options.UserStdOption), 'for mypy'
- std_opt.set_versions(c_stds + g_stds)
+ self._update_language_stds(opts, c_stds + g_stds)
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -754,7 +752,7 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
self.make_option_name(key),
'C++ exception handling type.',
'default',
- ['none', 'default', 'a', 's', 'sc'])
+ choices=['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('rtti')
opts[key] = options.UserBooleanOption(
@@ -763,7 +761,7 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
True)
key = self.form_compileropt_key('winlibs')
- opts[key] = options.UserArrayOption(
+ opts[key] = options.UserStringArrayOption(
self.make_option_name(key),
'Standard Win libraries to link against',
msvc_winlibs)
@@ -1040,8 +1038,7 @@ class MetrowerksCPPCompilerARM(MetrowerksCompiler, CPPCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
- key = self.form_compileropt_key('std')
- opts[key].choices = ['none']
+ self._update_language_stds(opts, [])
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -1069,8 +1066,7 @@ class MetrowerksCPPCompilerEmbeddedPowerPC(MetrowerksCompiler, CPPCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
- key = self.form_compileropt_key('std')
- opts[key].choices = ['none']
+ self._update_language_stds(opts, [])
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py
index aefcc512b..6a49d95ae 100644
--- a/mesonbuild/compilers/cuda.py
+++ b/mesonbuild/compilers/cuda.py
@@ -648,13 +648,12 @@ class CudaCompiler(Compiler):
opts = super().get_options()
- # XXX: cpp_std is correct, the annotations are wrong
key = self.form_compileropt_key('std')
opts[key] = options.UserComboOption(
self.make_option_name(key),
'C++ language standard to use with CUDA',
'none',
- cpp_stds)
+ choices=cpp_stds)
key = self.form_compileropt_key('ccbindir')
opts[key] = options.UserStringOption(
diff --git a/mesonbuild/compilers/cython.py b/mesonbuild/compilers/cython.py
index ba04aea0b..ed0ab31ad 100644
--- a/mesonbuild/compilers/cython.py
+++ b/mesonbuild/compilers/cython.py
@@ -74,14 +74,14 @@ class CythonCompiler(Compiler):
self.make_option_name(key),
'Python version to target',
'3',
- ['2', '3'])
+ choices=['2', '3'])
key = self.form_compileropt_key('language')
opts[key] = options.UserComboOption(
self.make_option_name(key),
'Output C or C++ files',
'c',
- ['c', 'cpp'])
+ choices=['c', 'cpp'])
return opts
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index b004727b4..72c9a5a97 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -121,7 +121,7 @@ class FortranCompiler(CLikeCompiler, Compiler):
self.make_option_name(key),
'Fortran language standard to use',
'none',
- ['none'])
+ choices=['none'])
return opts
@@ -281,8 +281,7 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
fortran_stds += ['f2008']
if version_compare(self.version, '>=8.0.0'):
fortran_stds += ['f2018']
- key = self.form_compileropt_key('std')
- opts[key].choices = ['none'] + fortran_stds
+ self._update_language_stds(opts, fortran_stds)
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -338,9 +337,7 @@ class ElbrusFortranCompiler(ElbrusCompiler, FortranCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
- fortran_stds = ['f95', 'f2003', 'f2008', 'gnu', 'legacy', 'f2008ts']
- key = self.form_compileropt_key('std')
- opts[key].choices = ['none'] + fortran_stds
+ self._update_language_stds(opts, ['f95', 'f2003', 'f2008', 'gnu', 'legacy', 'f2008ts'])
return opts
def get_module_outdir_args(self, path: str) -> T.List[str]:
@@ -418,8 +415,7 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
- key = self.form_compileropt_key('std')
- opts[key].choices = ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018']
+ self._update_language_stds(opts, ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018'])
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@@ -473,8 +469,7 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
def get_options(self) -> 'MutableKeyedOptionDictType':
opts = super().get_options()
- key = self.form_compileropt_key('std')
- opts[key].choices = ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018']
+ self._update_language_stds(opts, ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018'])
return opts
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index 7fe16c6f8..aacdc07d7 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -241,7 +241,7 @@ class RustCompiler(Compiler):
self.make_option_name(key),
'Rust edition to use',
'none',
- ['none', '2015', '2018', '2021', '2024'])
+ choices=['none', '2015', '2018', '2021', '2024'])
return opts