diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-10-16 14:22:12 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-10-19 08:13:57 -0400 |
commit | 361f7484d2fe9d1cf03b66a66d785618694aa62c (patch) | |
tree | 24c8941baf150ba43706697f67d1c66443d82ea8 /mesonbuild/compilers | |
parent | 890dd31cb0cdfaca6ddf483c8d8ba3b4c1bcb753 (diff) | |
download | meson-361f7484d2fe9d1cf03b66a66d785618694aa62c.zip meson-361f7484d2fe9d1cf03b66a66d785618694aa62c.tar.gz meson-361f7484d2fe9d1cf03b66a66d785618694aa62c.tar.bz2 |
Remove duplicated code to canonicalize b_vscrt option value
Add a common function that infers vscrt from buildtype in Compiler base
class.
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/asm.py | 23 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 26 | ||||
-rw-r--r-- | mesonbuild/compilers/d.py | 26 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/visualstudio.py | 24 |
4 files changed, 29 insertions, 70 deletions
diff --git a/mesonbuild/compilers/asm.py b/mesonbuild/compilers/asm.py index 19f7b64..392a082 100644 --- a/mesonbuild/compilers/asm.py +++ b/mesonbuild/compilers/asm.py @@ -124,28 +124,7 @@ class NasmCompiler(Compiler): def get_crt_link_args(self, crt_val: str, buildtype: str) -> T.List[str]: if not self.info.is_windows(): return [] - if crt_val in self.crt_args: - return self.crt_args[crt_val] - assert crt_val in {'from_buildtype', 'static_from_buildtype'} - dbg = 'mdd' - rel = 'md' - if crt_val == 'static_from_buildtype': - dbg = 'mtd' - rel = 'mt' - # Match what build type flags used to do. - if buildtype == 'plain': - return [] - elif buildtype == 'debug': - return self.crt_args[dbg] - elif buildtype == 'debugoptimized': - return self.crt_args[rel] - elif buildtype == 'release': - return self.crt_args[rel] - elif buildtype == 'minsize': - return self.crt_args[rel] - else: - assert buildtype == 'custom' - raise EnvironmentException('Requested C runtime based on buildtype, but buildtype is "custom".') + return self.crt_args[self.get_crt_val(crt_val, buildtype)] class YasmCompiler(NasmCompiler): id = 'yasm' diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 5f2e304..abf4ef4 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -299,6 +299,8 @@ clike_debug_args: T.Dict[bool, T.List[str]] = { True: ['-g'] } +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), @@ -325,7 +327,7 @@ base_options: 'KeyedOptionDictType' = { 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.', - ['none', 'md', 'mdd', 'mt', 'mtd', 'from_buildtype', 'static_from_buildtype'], + MSCRT_VALS + ['from_buildtype', 'static_from_buildtype'], 'from_buildtype'), } @@ -1105,6 +1107,28 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): """ return [] + def get_crt_val(self, crt_val: str, buildtype: str) -> str: + if crt_val in MSCRT_VALS: + return crt_val + assert crt_val in {'from_buildtype', 'static_from_buildtype'} + + dbg = 'mdd' + rel = 'md' + if crt_val == 'static_from_buildtype': + dbg = 'mtd' + rel = 'mt' + + # Match what build type flags used to do. + if buildtype == 'plain': + return 'none' + elif buildtype == 'debug': + return dbg + elif buildtype in {'debugoptimized', 'release', 'minsize'}: + return rel + else: + assert buildtype == 'custom' + raise EnvironmentException('Requested C runtime based on buildtype, but buildtype is "custom".') + def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]: raise EnvironmentException('This compiler does not support Windows CRT selection') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 05f3b7d..d8a72fd 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -379,31 +379,7 @@ class DmdLikeCompilerMixin(CompilerMixinBase): def _get_crt_args(self, crt_val: str, buildtype: str) -> T.List[str]: if not self.info.is_windows(): return [] - - if crt_val in self.mscrt_args: - return self.mscrt_args[crt_val] - assert crt_val in {'from_buildtype', 'static_from_buildtype'} - - dbg = 'mdd' - rel = 'md' - if crt_val == 'static_from_buildtype': - dbg = 'mtd' - rel = 'mt' - - # Match what build type flags used to do. - if buildtype == 'plain': - return [] - elif buildtype == 'debug': - return self.mscrt_args[dbg] - elif buildtype == 'debugoptimized': - return self.mscrt_args[rel] - elif buildtype == 'release': - return self.mscrt_args[rel] - elif buildtype == 'minsize': - return self.mscrt_args[rel] - else: - assert buildtype == 'custom' - raise EnvironmentException('Requested C runtime based on buildtype, but buildtype is "custom".') + return self.mscrt_args[self.get_crt_val(crt_val, buildtype)] def get_soname_args(self, env: 'Environment', prefix: str, shlib_name: str, suffix: str, soversion: str, diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py index 24f1132..3dd7575 100644 --- a/mesonbuild/compilers/mixins/visualstudio.py +++ b/mesonbuild/compilers/mixins/visualstudio.py @@ -366,28 +366,8 @@ class VisualStudioLikeCompiler(Compiler, metaclass=abc.ABCMeta): return os.environ['INCLUDE'].split(os.pathsep) def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]: - if crt_val in self.crt_args: - return self.crt_args[crt_val] - assert crt_val in {'from_buildtype', 'static_from_buildtype'} - dbg = 'mdd' - rel = 'md' - if crt_val == 'static_from_buildtype': - dbg = 'mtd' - rel = 'mt' - # Match what build type flags used to do. - if buildtype == 'plain': - return [] - elif buildtype == 'debug': - return self.crt_args[dbg] - elif buildtype == 'debugoptimized': - return self.crt_args[rel] - elif buildtype == 'release': - return self.crt_args[rel] - elif buildtype == 'minsize': - return self.crt_args[rel] - else: - assert buildtype == 'custom' - raise mesonlib.EnvironmentException('Requested C runtime based on buildtype, but buildtype is "custom".') + crt_val = self.get_crt_val(crt_val, buildtype) + return self.crt_args[crt_val] def has_func_attribute(self, name: str, env: 'Environment') -> T.Tuple[bool, bool]: # MSVC doesn't have __attribute__ like Clang and GCC do, so just return |