diff options
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/c.py | 87 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 67 | ||||
-rw-r--r-- | mesonbuild/compilers/cpp.py | 110 | ||||
-rw-r--r-- | mesonbuild/compilers/cuda.py | 21 | ||||
-rw-r--r-- | mesonbuild/compilers/cython.py | 8 | ||||
-rw-r--r-- | mesonbuild/compilers/fortran.py | 18 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/clike.py | 6 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/elbrus.py | 6 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/emscripten.py | 2 | ||||
-rw-r--r-- | mesonbuild/compilers/objc.py | 6 | ||||
-rw-r--r-- | mesonbuild/compilers/objcpp.py | 6 | ||||
-rw-r--r-- | mesonbuild/compilers/rust.py | 6 |
12 files changed, 174 insertions, 169 deletions
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 7f2efc9..8fda3a5 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -165,16 +165,16 @@ class ClangCCompiler(_ClangCStds, ClangCompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('-std=' + std) return args def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]: if self.info.is_windows() or self.info.is_cygwin(): # without a typedict mypy can't understand this. key = self.form_langopt_key('winlibs') - libs = options[key].value.copy() + libs = options.get_value(key).copy() assert isinstance(libs, list) for l in libs: assert isinstance(l, str) @@ -258,9 +258,9 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('-std=' + std) return args def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]: @@ -318,16 +318,16 @@ class GnuCCompiler(GnuCompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('-std=' + std) return args def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]: if self.info.is_windows() or self.info.is_cygwin(): # without a typeddict mypy can't figure this out key = self.form_langopt_key('winlibs') - libs: T.List[str] = options[key].value.copy() + libs: T.List[str] = options.get_value(key).copy() assert isinstance(libs, list) for l in libs: assert isinstance(l, str) @@ -432,9 +432,9 @@ class IntelCCompiler(IntelGnuLikeCompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('-std=' + std) return args @@ -461,7 +461,7 @@ class VisualStudioLikeCCompilerMixin(CompilerMixinBase): def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]: # need a TypeDict to make this work key = self.form_langopt_key('winlibs') - libs = options[key].value.copy() + libs = options.get_value(key).copy() assert isinstance(libs, list) for l in libs: assert isinstance(l, str) @@ -498,11 +498,11 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] + std = options.get_value(key) # As of MVSC 16.8, /std:c11 and /std:c17 are the only valid C standard options. - if std.value in {'c11'}: + if std == 'c11': args.append('/std:c11') - elif std.value in {'c17', 'c18'}: + elif std in {'c17', 'c18'}: args.append('/std:c17') return args @@ -519,7 +519,7 @@ class ClangClCCompiler(_ClangCStds, ClangClCompiler, VisualStudioLikeCCompilerMi def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: key = self.form_langopt_key('std') - std = options[key].value + std = options.get_value(key) if std != "none": return [f'/clang:-std={std}'] return [] @@ -541,7 +541,10 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM def get_options(self) -> 'MutableKeyedOptionDictType': opts = super().get_options() key = self.form_langopt_key('std') - std_opt = opts[key] + # To shut up mypy. + if isinstance(opts, dict): + raise RuntimeError('This is a transitory issue that should not happen. Please report with full backtrace.') + std_opt = opts.get_value_object(key) assert isinstance(std_opt, options.UserStdOption), 'for mypy' std_opt.set_versions(['c89', 'c99', 'c11']) return opts @@ -549,11 +552,11 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value == 'c89': + std = options.get_value(key) + if std == 'c89': mlog.log("ICL doesn't explicitly implement c89, setting the standard to 'none', which is close.", once=True) - elif std.value != 'none': - args.append('/Qstd:' + std.value) + elif std != 'none': + args.append('/Qstd:' + std) return args @@ -583,9 +586,9 @@ class ArmCCompiler(ArmCompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('--' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('--' + std) return args @@ -616,10 +619,10 @@ class CcrxCCompiler(CcrxCompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value == 'c89': + std = options.get_value(key) + if std == 'c89': args.append('-lang=c') - elif std.value == 'c99': + elif std == 'c99': args.append('-lang=c99') return args @@ -664,10 +667,10 @@ class Xc16CCompiler(Xc16Compiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': + std = options.get_value(key) + if std != 'none': args.append('-ansi') - args.append('-std=' + std.value) + args.append('-std=' + std) return args def get_compile_only_args(self) -> T.List[str]: @@ -748,9 +751,9 @@ class TICCompiler(TICompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('--' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('--' + std) return args class C2000CCompiler(TICCompiler): @@ -784,10 +787,10 @@ class MetrowerksCCompilerARM(MetrowerksCompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': + std = options.get_value(key) + if std != 'none': args.append('-lang') - args.append(std.value) + args.append(std) return args class MetrowerksCCompilerEmbeddedPowerPC(MetrowerksCompiler, CCompiler): @@ -814,7 +817,7 @@ class MetrowerksCCompilerEmbeddedPowerPC(MetrowerksCompiler, CCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('-lang ' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('-lang ' + std) return args diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index ef0ea70..4a1fd98 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -25,6 +25,7 @@ from ..mesonlib import ( from ..arglist import CompilerArgs if T.TYPE_CHECKING: + from typing import Any from ..build import BuildTarget, DFeatures from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType from ..envconfig import MachineInfo @@ -247,14 +248,14 @@ BASE_OPTIONS: T.Mapping[OptionKey, BaseOption] = { choices=MSCRT_VALS + ['from_buildtype', 'static_from_buildtype']), } -base_options: KeyedOptionDictType = {key: base_opt.init_option(key) for key, base_opt in BASE_OPTIONS.items()} +base_options = {key: base_opt.init_option(key) for key, base_opt in BASE_OPTIONS.items()} def option_enabled(boptions: T.Set[OptionKey], options: 'KeyedOptionDictType', option: OptionKey) -> bool: try: if option not in boptions: return False - ret = options[option].value + ret = options.get_value(option) assert isinstance(ret, bool), 'must return bool' # could also be str return ret except KeyError: @@ -264,8 +265,8 @@ def option_enabled(boptions: T.Set[OptionKey], options: 'KeyedOptionDictType', def get_option_value(options: 'KeyedOptionDictType', opt: OptionKey, fallback: '_T') -> '_T': """Get the value of an option, or the fallback value.""" try: - v: '_T' = options[opt].value - except KeyError: + v: '_T' = options.get_value(opt) + except (KeyError, AttributeError): return fallback assert isinstance(v, type(fallback)), f'Should have {type(fallback)!r} but was {type(v)!r}' @@ -279,52 +280,52 @@ def are_asserts_disabled(options: KeyedOptionDictType) -> bool: :param options: OptionDictionary :return: whether to disable assertions or not """ - return (options[OptionKey('b_ndebug')].value == 'true' or - (options[OptionKey('b_ndebug')].value == 'if-release' and - options[OptionKey('buildtype')].value in {'release', 'plain'})) + return (options.get_value('b_ndebug') == 'true' or + (options.get_value('b_ndebug') == 'if-release' and + options.get_value('buildtype') in {'release', 'plain'})) def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler', env: 'Environment') -> T.List[str]: args: T.List[str] = [] try: - if options[OptionKey('b_lto')].value: + if options.get_value(OptionKey('b_lto')): args.extend(compiler.get_lto_compile_args( threads=get_option_value(options, OptionKey('b_lto_threads'), 0), mode=get_option_value(options, OptionKey('b_lto_mode'), 'default'))) - except KeyError: + except (KeyError, AttributeError): pass try: - args += compiler.get_colorout_args(options[OptionKey('b_colorout')].value) - except KeyError: + args += compiler.get_colorout_args(options.get_value(OptionKey('b_colorout'))) + except (KeyError, AttributeError): pass try: - args += compiler.sanitizer_compile_args(options[OptionKey('b_sanitize')].value) - except KeyError: + args += compiler.sanitizer_compile_args(options.get_value(OptionKey('b_sanitize'))) + except (KeyError, AttributeError): pass try: - pgo_val = options[OptionKey('b_pgo')].value + pgo_val = options.get_value(OptionKey('b_pgo')) if pgo_val == 'generate': args.extend(compiler.get_profile_generate_args()) elif pgo_val == 'use': args.extend(compiler.get_profile_use_args()) - except KeyError: + except (KeyError, AttributeError): pass try: - if options[OptionKey('b_coverage')].value: + if options.get_value(OptionKey('b_coverage')): args += compiler.get_coverage_args() - except KeyError: + except (KeyError, AttributeError): pass try: args += compiler.get_assert_args(are_asserts_disabled(options), env) - except KeyError: + except (KeyError, AttributeError): pass # This does not need a try...except if option_enabled(compiler.base_options, options, OptionKey('b_bitcode')): args.append('-fembed-bitcode') try: - crt_val = options[OptionKey('b_vscrt')].value - buildtype = options[OptionKey('buildtype')].value try: + crt_val = options.get_value(OptionKey('b_vscrt')) + buildtype = options.get_value(OptionKey('buildtype')) args += compiler.get_crt_compile_args(crt_val, buildtype) except AttributeError: pass @@ -336,8 +337,8 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler', is_shared_module: bool, build_dir: str) -> T.List[str]: args: T.List[str] = [] try: - if options[OptionKey('b_lto')].value: - if options[OptionKey('werror')].value: + if options.get_value('b_lto'): + if options.get_value('werror'): args.extend(linker.get_werror_args()) thinlto_cache_dir = None @@ -349,24 +350,24 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler', threads=get_option_value(options, OptionKey('b_lto_threads'), 0), mode=get_option_value(options, OptionKey('b_lto_mode'), 'default'), thinlto_cache_dir=thinlto_cache_dir)) - except KeyError: + except (KeyError, AttributeError): pass try: - args += linker.sanitizer_link_args(options[OptionKey('b_sanitize')].value) - except KeyError: + args += linker.sanitizer_link_args(options.get_value('b_sanitize')) + except (KeyError, AttributeError): pass try: - pgo_val = options[OptionKey('b_pgo')].value + pgo_val = options.get_value('b_pgo') if pgo_val == 'generate': args.extend(linker.get_profile_generate_args()) elif pgo_val == 'use': args.extend(linker.get_profile_use_args()) - except KeyError: + except (KeyError, AttributeError): pass try: - if options[OptionKey('b_coverage')].value: + if options.get_value('b_coverage'): args += linker.get_coverage_link_args() - except KeyError: + except (KeyError, AttributeError): pass as_needed = option_enabled(linker.base_options, options, OptionKey('b_asneeded')) @@ -390,9 +391,9 @@ def get_base_link_args(options: 'KeyedOptionDictType', linker: 'Compiler', args.extend(linker.get_allow_undefined_link_args()) try: - crt_val = options[OptionKey('b_vscrt')].value - buildtype = options[OptionKey('buildtype')].value try: + crt_val = options.get_value(OptionKey('b_vscrt')) + buildtype = options.get_value(OptionKey('buildtype')) args += linker.get_crt_link_args(crt_val, buildtype) except AttributeError: pass @@ -1357,7 +1358,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): def get_global_options(lang: str, comp: T.Type[Compiler], for_machine: MachineChoice, - env: 'Environment') -> 'KeyedOptionDictType': + env: 'Environment') -> 'dict[OptionKey, options.UserOption[Any]]': """Retrieve options that apply to all compilers for a given language.""" description = f'Extra arguments passed to the {lang}' argkey = OptionKey('args', lang=lang, machine=for_machine) @@ -1387,6 +1388,6 @@ def get_global_options(lang: str, # autotools compatibility. largs.extend_value(comp_options) - opts: 'KeyedOptionDictType' = {argkey: cargs, largkey: largs} + opts: 'dict[OptionKey, options.UserOption[Any]]' = {argkey: cargs, largkey: largs} return opts diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 12d7201..df2f905 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -278,15 +278,15 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append(self._find_best_cpp_std(std.value)) + std = options.get_value(key) + if std != 'none': + args.append(self._find_best_cpp_std(std)) key = self.form_langopt_key('eh') - non_msvc_eh_options(options[key].value, args) + non_msvc_eh_options(options.get_value(key), args) key = self.form_langopt_key('debugstl') - if options[key].value: + if options.get_value(key): args.append('-D_GLIBCXX_DEBUG=1') # We can't do _LIBCPP_DEBUG because it's unreliable unless libc++ was built with it too: @@ -296,7 +296,7 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): args.append('-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG') key = self.form_langopt_key('rtti') - if not options[key].value: + if not options.get_value(key): args.append('-fno-rtti') return args @@ -305,7 +305,7 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): if self.info.is_windows() or self.info.is_cygwin(): # without a typedict mypy can't understand this. key = self.form_langopt_key('winlibs') - libs = options[key].value.copy() + libs = options.get_value(key).copy() assert isinstance(libs, list) for l in libs: assert isinstance(l, str) @@ -365,9 +365,9 @@ class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append(self._find_best_cpp_std(std.value)) + std = options.get_value(key) + if std != 'none': + args.append(self._find_best_cpp_std(std)) return args @@ -409,12 +409,12 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('-std=' + std) key = self.form_langopt_key('eh') - non_msvc_eh_options(options[key].value, args) + non_msvc_eh_options(options.get_value(key), args) return args @@ -483,16 +483,16 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append(self._find_best_cpp_std(std.value)) + std = options.get_value(key) + if std != 'none': + args.append(self._find_best_cpp_std(std)) - non_msvc_eh_options(options[key.evolve('eh')].value, args) + non_msvc_eh_options(options.get_value(key.evolve('eh')), args) - if not options[key.evolve('rtti')].value: + if not options.get_value(key.evolve('rtti')): args.append('-fno-rtti') - if options[key.evolve('debugstl')].value: + if options.get_value(key.evolve('debugstl')): args.append('-D_GLIBCXX_DEBUG=1') return args @@ -500,7 +500,7 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): if self.info.is_windows() or self.info.is_cygwin(): # without a typedict mypy can't understand this. key = self.form_langopt_key('winlibs') - libs = options[key].value.copy() + libs = options.get_value(key).copy() assert isinstance(libs, list) for l in libs: assert isinstance(l, str) @@ -616,15 +616,15 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] + std = options.get_value(key) if std.value != 'none': args.append(self._find_best_cpp_std(std.value)) key = self.form_langopt_key('eh') - non_msvc_eh_options(options[key].value, args) + non_msvc_eh_options(options.get_value(key), args) key = self.form_langopt_key('debugstl') - if options[key].value: + if options.get_value(key): args.append('-D_GLIBCXX_DEBUG=1') return args @@ -688,18 +688,18 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': + std = options.get_value(key) + if std != 'none': remap_cpp03 = { 'c++03': 'c++98', 'gnu++03': 'gnu++98' } - args.append('-std=' + remap_cpp03.get(std.value, std.value)) - if options[key.evolve('eh')].value == 'none': + args.append('-std=' + remap_cpp03.get(std.value, std)) + if options.get_value(key.evolve('eh')) == 'none': args.append('-fno-exceptions') - if not options[key.evolve('rtti')].value: + if not options.get_value(key.evolve('rtti')): args.append('-fno-rtti') - if options[key.evolve('debugstl')].value: + if options.get_value(key.evolve('debugstl')): args.append('-D_GLIBCXX_DEBUG=1') return args @@ -733,7 +733,7 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase): def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]: # need a typeddict for this key = self.form_langopt_key('winlibs') - return T.cast('T.List[str]', options[key].value[:]) + return T.cast('T.List[str]', options.get_value(key)[:]) def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List[str]) -> 'MutableKeyedOptionDictType': key = self.form_langopt_key('std') @@ -762,18 +762,18 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase): args: T.List[str] = [] key = self.form_langopt_key('std') - eh = options[self.form_langopt_key('eh')] - if eh.value == 'default': + eh = options.get_value(self.form_langopt_key('eh')) + if eh == 'default': args.append('/EHsc') - elif eh.value == 'none': + elif eh == 'none': args.append('/EHs-c-') else: - args.append('/EH' + eh.value) + args.append('/EH' + eh) - if not options[self.form_langopt_key('rtti')].value: + if not options.get_value(self.form_langopt_key('rtti')): args.append('/GR-') - permissive, ver = self.VC_VERSION_MAP[options[key].value] + permissive, ver = self.VC_VERSION_MAP[options.get_value(key)] if ver is not None: args.append(f'/std:c++{ver}') @@ -801,7 +801,7 @@ class CPP11AsCPP14Mixin(CompilerMixinBase): # (i.e., after VS2015U3) # if one is using anything before that point, one cannot set the standard. key = self.form_langopt_key('std') - if options[key].value in {'vc++11', 'c++11'}: + if options.get_value(key) in {'vc++11', 'c++11'}: mlog.warning(self.id, 'does not support C++11;', 'attempting best effort; setting the standard to C++14', once=True, fatal=False) @@ -809,10 +809,10 @@ class CPP11AsCPP14Mixin(CompilerMixinBase): # deepcopy since we're messing with members, and we can't simply # copy the members because the option proxy doesn't support it. options = copy.deepcopy(options) - if options[key].value == 'vc++11': - options[key].value = 'vc++14' + if options.get_value(key) == 'vc++11': + options.set_value(key, 'vc++14') else: - options[key].value = 'c++14' + options.set_value(key, 'c++14') return super().get_option_compile_args(options) @@ -848,10 +848,10 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: key = self.form_langopt_key('std') - if options[key].value != 'none' and version_compare(self.version, '<19.00.24210'): + if options.get_value(key) != 'none' and version_compare(self.version, '<19.00.24210'): mlog.warning('This version of MSVC does not support cpp_std arguments', fatal=False) options = copy.copy(options) - options[key].value = 'none' + options.set_value(key, 'none') args = super().get_option_compile_args(options) @@ -924,10 +924,10 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value == 'c++11': + std = options.get_value(key) + if std == 'c++11': args.append('--cpp11') - elif std.value == 'c++03': + elif std == 'c++03': args.append('--cpp') return args @@ -986,9 +986,9 @@ class TICPPCompiler(TICompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('--' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('--' + std) return args def get_always_args(self) -> T.List[str]: @@ -1027,10 +1027,10 @@ class MetrowerksCPPCompilerARM(MetrowerksCompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': + std = options.get_value(key) + if std != 'none': args.append('-lang') - args.append(std.value) + args.append(std) return args class MetrowerksCPPCompilerEmbeddedPowerPC(MetrowerksCompiler, CPPCompiler): @@ -1056,7 +1056,7 @@ class MetrowerksCPPCompilerEmbeddedPowerPC(MetrowerksCompiler, CPPCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('-lang ' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('-lang ' + std) return args diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index 954040e..dc9cf8a 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -13,7 +13,7 @@ from .. import options from .. import mlog from ..mesonlib import ( EnvironmentException, Popen_safe, - is_windows, LibType, version_compare, + is_windows, LibType, version_compare, OptionKey ) from .compilers import Compiler @@ -549,7 +549,7 @@ class CudaCompiler(Compiler): # Use the -ccbin option, if available, even during sanity checking. # Otherwise, on systems where CUDA does not support the default compiler, # NVCC becomes unusable. - flags += self.get_ccbin_args(env.coredata.options) + flags += self.get_ccbin_args(env.coredata.optstore) # If cross-compiling, we can't run the sanity check, only compile it. if env.need_exe_wrapper(self.for_machine) and not env.has_exe_wrapper(): @@ -655,16 +655,17 @@ class CudaCompiler(Compiler): ''), ) - def _to_host_compiler_options(self, options: 'KeyedOptionDictType') -> 'KeyedOptionDictType': + def _to_host_compiler_options(self, master_options: 'KeyedOptionDictType') -> 'KeyedOptionDictType': """ Convert an NVCC Option set to a host compiler's option set. """ # We must strip the -std option from the host compiler option set, as NVCC has # its own -std flag that may not agree with the host compiler's. - host_options = {key: options.get(key, opt) for key, opt in self.host_compiler.get_options().items()} - std_key = self.form_langopt_key('std') + host_options = {key: master_options.get(key, opt) for key, opt in self.host_compiler.get_options().items()} + std_key = OptionKey('std', machine=self.for_machine, lang=self.host_compiler.language) overrides = {std_key: 'none'} + # To shut up mypy. return coredata.OptionsView(host_options, overrides=overrides) def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: @@ -674,9 +675,9 @@ class CudaCompiler(Compiler): # and attempting to use it will result in a warning: https://stackoverflow.com/a/51272091/741027 if not is_windows(): key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('--std=' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('--std=' + std) return args + self._to_host_flags(self.host_compiler.get_option_compile_args(self._to_host_compiler_options(options))) @@ -792,9 +793,9 @@ class CudaCompiler(Compiler): def get_dependency_link_args(self, dep: 'Dependency') -> T.List[str]: return self._to_host_flags(super().get_dependency_link_args(dep), _Phase.LINKER) - def get_ccbin_args(self, options: 'KeyedOptionDictType') -> T.List[str]: + def get_ccbin_args(self, ccoptions: 'KeyedOptionDictType') -> T.List[str]: key = self.form_langopt_key('ccbindir') - ccbindir = options[key].value + ccbindir = ccoptions.get_value(key) if isinstance(ccbindir, str) and ccbindir != '': return [self._shield_nvcc_list_arg('-ccbin='+ccbindir, False)] else: diff --git a/mesonbuild/compilers/cython.py b/mesonbuild/compilers/cython.py index 76e66c0..7c11286 100644 --- a/mesonbuild/compilers/cython.py +++ b/mesonbuild/compilers/cython.py @@ -84,10 +84,10 @@ class CythonCompiler(Compiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('version') - version = options[key] - args.append(f'-{version.value}') + version = options.get_value(key) + args.append(f'-{version}') key = self.form_langopt_key('language') - lang = options[key] - if lang.value == 'cpp': + lang = options.get_value(key) + if lang == 'cpp': args.append('--cplus') return args diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 66fb466..9b288e9 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -154,9 +154,9 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('-std=' + std) return args def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: @@ -291,10 +291,10 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] + std = options.get_value(key) stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'} - if std.value != 'none': - args.append('-stand=' + stds[std.value]) + if std != 'none': + args.append('-stand=' + stds[std]) return args def get_preprocess_only_args(self) -> T.List[str]: @@ -346,10 +346,10 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] key = self.form_langopt_key('std') - std = options[key] + std = options.get_value(key) stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'} - if std.value != 'none': - args.append('/stand:' + stds[std.value]) + if std != 'none': + args.append('/stand:' + stds[std]) return args def get_werror_args(self) -> T.List[str]: diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index d273015..70e81a4 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -26,7 +26,7 @@ from ... import arglist from ... import mesonlib from ... import mlog from ...linkers.linkers import GnuLikeDynamicLinkerMixin, SolarisDynamicLinker, CompCertDynamicLinker -from ...mesonlib import LibType, OptionKey +from ...mesonlib import LibType from .. import compilers from ..compilers import CompileCheckMode from .visualstudio import VisualStudioLikeCompiler @@ -376,8 +376,8 @@ class CLikeCompiler(Compiler): # linking with static libraries since MSVC won't select a CRT for # us in that case and will error out asking us to pick one. try: - crt_val = env.coredata.options[OptionKey('b_vscrt')].value - buildtype = env.coredata.options[OptionKey('buildtype')].value + crt_val = env.coredata.optstore.get_value('b_vscrt') + buildtype = env.coredata.optstore.get_value('buildtype') cargs += self.get_crt_compile_args(crt_val, buildtype) except (KeyError, AttributeError): pass diff --git a/mesonbuild/compilers/mixins/elbrus.py b/mesonbuild/compilers/mixins/elbrus.py index 27cba80..10df3de 100644 --- a/mesonbuild/compilers/mixins/elbrus.py +++ b/mesonbuild/compilers/mixins/elbrus.py @@ -84,9 +84,9 @@ class ElbrusCompiler(GnuLikeCompiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args: T.List[str] = [] - std = options[OptionKey('std', lang=self.language, machine=self.for_machine)] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(OptionKey('std', lang=self.language, machine=self.for_machine)) + if std != 'none': + args.append('-std=' + std) return args def openmp_flags(self) -> T.List[str]: diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py index 110dbc6..6b7f087 100644 --- a/mesonbuild/compilers/mixins/emscripten.py +++ b/mesonbuild/compilers/mixins/emscripten.py @@ -51,7 +51,7 @@ class EmscriptenMixin(Compiler): def thread_link_flags(self, env: 'Environment') -> T.List[str]: args = ['-pthread'] - count: int = env.coredata.options[OptionKey('thread_count', lang=self.language, machine=self.for_machine)].value + count: int = env.coredata.optstore.get_value(OptionKey('thread_count', lang=self.language, machine=self.for_machine)) if count: args.append(f'-sPTHREAD_POOL_SIZE={count}') return args diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py index 4d33ec8..c63f288 100644 --- a/mesonbuild/compilers/objc.py +++ b/mesonbuild/compilers/objc.py @@ -90,9 +90,9 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler): def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]: args = [] - std = options[OptionKey('std', machine=self.for_machine, lang='c')] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(OptionKey('std', machine=self.for_machine, lang='c')) + if std != 'none': + args.append('-std=' + std) return args class AppleClangObjCCompiler(ClangObjCCompiler): diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py index e28e3ed..e24406c 100644 --- a/mesonbuild/compilers/objcpp.py +++ b/mesonbuild/compilers/objcpp.py @@ -92,9 +92,9 @@ class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler): def get_option_compile_args(self, options: 'coredata.KeyedOptionDictType') -> T.List[str]: args = [] - std = options[OptionKey('std', machine=self.for_machine, lang='cpp')] - if std.value != 'none': - args.append('-std=' + std.value) + std = options.get_value(OptionKey('std', machine=self.for_machine, lang='cpp')) + if std != 'none': + args.append('-std=' + std) return args diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index 346a3dd..b130c58 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -173,9 +173,9 @@ class RustCompiler(Compiler): def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: args = [] key = self.form_langopt_key('std') - std = options[key] - if std.value != 'none': - args.append('--edition=' + std.value) + std = options.get_value(key) + if std != 'none': + args.append('--edition=' + std) return args def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]: |