aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-02-22 13:10:24 -0800
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2023-04-21 15:18:56 +0530
commitbfce5c45a4784d86be8472a00f628f2ffac74cf2 (patch)
tree420ebb65147f91175e9b84bc9dbb50cbf20b8684 /mesonbuild
parentc0c9f755a40a51889e73275578cb49296de84e43 (diff)
downloadmeson-bfce5c45a4784d86be8472a00f628f2ffac74cf2.zip
meson-bfce5c45a4784d86be8472a00f628f2ffac74cf2.tar.gz
meson-bfce5c45a4784d86be8472a00f628f2ffac74cf2.tar.bz2
compilers: convert method to get assert control to a boolean
C like compilers only off `-DNDEBUG` to disable asserts. This is not a universal paradigm however. Rust, for example has an argument that takes a boolean. To better represent this, we allow passing a `disable` boolean. `disable` was chosen rather than `enable` because it allowed all existing logic to be left in place
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/compilers/compilers.py15
-rw-r--r--mesonbuild/compilers/cuda.py4
-rw-r--r--mesonbuild/compilers/d.py18
-rw-r--r--mesonbuild/compilers/mixins/clike.py6
4 files changed, 28 insertions, 15 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 2f3086a..ee382f0 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -365,10 +365,10 @@ def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler')
except KeyError:
pass
try:
- if (options[OptionKey('b_ndebug')].value == 'true' or
- (options[OptionKey('b_ndebug')].value == 'if-release' and
- options[OptionKey('buildtype')].value in {'release', 'plain'})):
- args += compiler.get_disable_assert_args()
+ disable = (options[OptionKey('b_ndebug')].value == 'true' or
+ (options[OptionKey('b_ndebug')].value == 'if-release' and
+ options[OptionKey('buildtype')].value in {'release', 'plain'}))
+ args += compiler.get_assert_args(disable)
except KeyError:
pass
# This does not need a try...except
@@ -1071,7 +1071,12 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def get_coverage_link_args(self) -> T.List[str]:
return self.linker.get_coverage_args()
- def get_disable_assert_args(self) -> T.List[str]:
+ def get_assert_args(self, disable: bool) -> T.List[str]:
+ """Get arguments to enable or disable assertion.
+
+ :param disable: Whether to disable assertions
+ :return: A list of string arguments for this compiler
+ """
return []
def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]:
diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py
index 70a4fe9..bbc2fc8 100644
--- a/mesonbuild/compilers/cuda.py
+++ b/mesonbuild/compilers/cuda.py
@@ -787,5 +787,5 @@ class CudaCompiler(Compiler):
def get_profile_use_args(self) -> T.List[str]:
return ['-Xcompiler=' + x for x in self.host_compiler.get_profile_use_args()]
- def get_disable_assert_args(self) -> T.List[str]:
- return self.host_compiler.get_disable_assert_args()
+ def get_assert_args(self, disable: bool) -> T.List[str]:
+ return self.host_compiler.get_assert_args(disable)
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 5d43a60..4cdda00 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -855,8 +855,10 @@ class GnuDCompiler(GnuCompiler, DCompiler):
return args
return args + ['-shared-libphobos']
- def get_disable_assert_args(self) -> T.List[str]:
- return ['-frelease']
+ def get_assert_args(self, disable: bool) -> T.List[str]:
+ if disable:
+ return ['-frelease']
+ return []
# LDC uses the DMD frontend code to parse and analyse the code.
# It then uses LLVM for the binary code generation and optimizations.
@@ -927,8 +929,10 @@ class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler):
return args
return args + ['-link-defaultlib-shared']
- def get_disable_assert_args(self) -> T.List[str]:
- return ['--release']
+ def get_assert_args(self, disable: bool) -> T.List[str]:
+ if disable:
+ return ['--release']
+ return []
def rsp_file_syntax(self) -> RSPFileSyntax:
# We use `mesonlib.is_windows` here because we want to know what the
@@ -1015,8 +1019,10 @@ class DmdDCompiler(DmdLikeCompilerMixin, DCompiler):
return args
return args + ['-defaultlib=phobos2', '-debuglib=phobos2']
- def get_disable_assert_args(self) -> T.List[str]:
- return ['-release']
+ def get_assert_args(self, disable: bool) -> T.List[str]:
+ if disable:
+ return ['-release']
+ return []
def rsp_file_syntax(self) -> RSPFileSyntax:
return RSPFileSyntax.MSVC
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index f8c7ebc..4ebec3f 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -1332,8 +1332,10 @@ class CLikeCompiler(Compiler):
return self.compiles(self.attribute_check_func(name), env,
extra_args=self.get_has_func_attribute_extra_args(name))
- def get_disable_assert_args(self) -> T.List[str]:
- return ['-DNDEBUG']
+ def get_assert_args(self, disable: bool) -> T.List[str]:
+ if disable:
+ return ['-DNDEBUG']
+ return []
@functools.lru_cache(maxsize=None)
def can_compile(self, src: 'mesonlib.FileOrString') -> bool: