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
pull/11716/head
Dylan Baker 2 years ago committed by Nirbheek Chauhan
parent c0c9f755a4
commit bfce5c45a4
  1. 15
      mesonbuild/compilers/compilers.py
  2. 4
      mesonbuild/compilers/cuda.py
  3. 18
      mesonbuild/compilers/d.py
  4. 6
      mesonbuild/compilers/mixins/clike.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]:

@ -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)

@ -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

@ -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:

Loading…
Cancel
Save