summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2024-08-29 09:47:39 -0700
committerJussi Pakkanen <jpakkane@gmail.com>2025-02-05 17:45:38 +0200
commit0e11b90d6f2f9c3e18cb8ff84b1622640666e826 (patch)
tree56772aa8d0b622d6456eb5c58441063d6a6f4c36 /mesonbuild/compilers
parentfe9f8de1ab52af0a6f4c3a1ce054ee3e2eb7a74c (diff)
downloadmeson-0e11b90d6f2f9c3e18cb8ff84b1622640666e826.tar.gz
options: use dataclasses for UserOption
This reduces code, makes this clearer, and will be a nice step toward the goal of getting everything typesafe. For `UserIntegerOption` this makes a fairly nice, but substantial change in that the old method used a tuple of `(min, value, max)` to pass to the initializer, while all other types just passed `value`. The new `UserIntegerOption` does the same, with keyword arguments for the min and max values.
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/compilers.py6
-rw-r--r--mesonbuild/compilers/cpp.py24
-rw-r--r--mesonbuild/compilers/cuda.py5
-rw-r--r--mesonbuild/compilers/cython.py8
-rw-r--r--mesonbuild/compilers/fortran.py4
-rw-r--r--mesonbuild/compilers/mixins/emscripten.py3
-rw-r--r--mesonbuild/compilers/rust.py4
7 files changed, 28 insertions, 26 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 12bcd1e4c..1432afb85 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -224,16 +224,16 @@ class BaseOption(T.Generic[_T]):
choices: T.Any = None
def init_option(self, name: OptionKey) -> options.UserOption[_T]:
- keywords = {'value': self.default}
+ keywords = {}
if self.choices:
keywords['choices'] = self.choices
- return self.opt_type(name.name, self.description, **keywords)
+ return self.opt_type(name.name, self.description, self.default, **keywords)
BASE_OPTIONS: T.Mapping[OptionKey, BaseOption] = {
OptionKey('b_pch'): BaseOption(options.UserBooleanOption, 'Use precompiled headers', True),
OptionKey('b_lto'): BaseOption(options.UserBooleanOption, 'Use link time optimization', False),
- OptionKey('b_lto_threads'): BaseOption(options.UserIntegerOption, 'Use multiple threads for Link Time Optimization', (None, None, 0)),
+ OptionKey('b_lto_threads'): BaseOption(options.UserIntegerOption, 'Use multiple threads for Link Time Optimization', 0),
OptionKey('b_lto_mode'): BaseOption(options.UserComboOption, 'Select between different LTO modes.', 'default',
choices=['default', 'thin']),
OptionKey('b_thinlto_cache'): BaseOption(options.UserBooleanOption, 'Use LLVM ThinLTO caching for faster incremental builds', False),
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index b17e18b3e..7fa9aa833 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -242,8 +242,8 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler
opts[key] = options.UserComboOption(
self.make_option_name(key),
'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default')
+ 'default',
+ ['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('rtti')
opts[key] = options.UserBooleanOption(
@@ -398,8 +398,8 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
opts[key] = options.UserComboOption(
self.make_option_name(key),
'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default')
+ 'default',
+ ['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('std')
std_opt = opts[key]
@@ -448,8 +448,8 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCPPStds, GnuCompiler, CPPCompiler):
opts[key] = options.UserComboOption(
self.make_option_name(key),
'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default')
+ 'default',
+ ['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('rtti')
opts[key] = options.UserBooleanOption(
@@ -577,8 +577,8 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler):
opts[key] = options.UserComboOption(
self.make_option_name(key),
'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default')
+ 'default',
+ ['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('debugstl')
opts[key] = options.UserBooleanOption(
@@ -660,8 +660,8 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
opts[key] = options.UserComboOption(
self.make_option_name(key),
'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default')
+ 'default',
+ ['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('rtti')
opts[key] = options.UserBooleanOption(
@@ -753,8 +753,8 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
opts[key] = options.UserComboOption(
self.make_option_name(key),
'C++ exception handling type.',
- ['none', 'default', 'a', 's', 'sc'],
- 'default')
+ 'default',
+ ['none', 'default', 'a', 's', 'sc'])
key = self.form_compileropt_key('rtti')
opts[key] = options.UserBooleanOption(
diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py
index 07fda95dd..aefcc512b 100644
--- a/mesonbuild/compilers/cuda.py
+++ b/mesonbuild/compilers/cuda.py
@@ -648,12 +648,13 @@ 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',
- cpp_stds,
- 'none')
+ 'none',
+ 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 2d0f21d00..ba04aea0b 100644
--- a/mesonbuild/compilers/cython.py
+++ b/mesonbuild/compilers/cython.py
@@ -73,15 +73,15 @@ class CythonCompiler(Compiler):
opts[key] = options.UserComboOption(
self.make_option_name(key),
'Python version to target',
- ['2', '3'],
- '3')
+ '3',
+ ['2', '3'])
key = self.form_compileropt_key('language')
opts[key] = options.UserComboOption(
self.make_option_name(key),
'Output C or C++ files',
- ['c', 'cpp'],
- 'c')
+ 'c',
+ ['c', 'cpp'])
return opts
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index f771e4c40..b004727b4 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -120,8 +120,8 @@ class FortranCompiler(CLikeCompiler, Compiler):
opts[key] = options.UserComboOption(
self.make_option_name(key),
'Fortran language standard to use',
- ['none'],
- 'none')
+ 'none',
+ ['none'])
return opts
diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py
index fa8620569..24ffceda6 100644
--- a/mesonbuild/compilers/mixins/emscripten.py
+++ b/mesonbuild/compilers/mixins/emscripten.py
@@ -63,7 +63,8 @@ class EmscriptenMixin(Compiler):
opts[key] = options.UserIntegerOption(
self.make_option_name(key),
'Number of threads to use in web assembly, set to 0 to disable',
- (0, None, 4)) # Default was picked at random
+ 4, # Default was picked at random
+ min_value=0)
return opts
diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py
index 40c85ee68..7fe16c6f8 100644
--- a/mesonbuild/compilers/rust.py
+++ b/mesonbuild/compilers/rust.py
@@ -240,8 +240,8 @@ class RustCompiler(Compiler):
opts[key] = options.UserComboOption(
self.make_option_name(key),
'Rust edition to use',
- ['none', '2015', '2018', '2021', '2024'],
- 'none')
+ 'none',
+ ['none', '2015', '2018', '2021', '2024'])
return opts