Add choices to OptionProxy

they're probably not strictly needed, but it makes mypy happy.
pull/8080/head
Dylan Baker 4 years ago
parent 615686fd6d
commit bdca05e2e6
  1. 24
      mesonbuild/compilers/c.py
  2. 16
      mesonbuild/compilers/cpp.py
  3. 6
      mesonbuild/compilers/fortran.py
  4. 5
      mesonbuild/mesonlib.py

@ -134,7 +134,7 @@ class _ClangCStds(CompilerMixinBase):
if version_compare(self.version, self._C2X_VERSION):
c_stds += ['c2x']
g_stds += ['gnu2x']
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
opts['std'].choices = ['none'] + c_stds + g_stds
return opts
@ -225,7 +225,7 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts['std'].choices = ['none', 'c90', 'c99', 'c11', 'gnu90', 'gnu99', 'gnu11'] # type: ignore
opts['std'].choices = ['none', 'c90', 'c99', 'c11', 'gnu90', 'gnu99', 'gnu11']
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -267,7 +267,7 @@ class GnuCCompiler(GnuCompiler, CCompiler):
if version_compare(self.version, self._C2X_VERSION):
c_stds += ['c2x']
g_stds += ['gnu2x']
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
opts['std'].choices = ['none'] + c_stds + g_stds
if self.info.is_windows() or self.info.is_cygwin():
opts.update({
'winlibs': coredata.UserArrayOption(
@ -333,7 +333,7 @@ class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
# It does support some various ISO standards and c/gnu 90, 9x, 1x in addition to those which GNU CC supports.
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts['std'].choices = [ # type: ignore
opts['std'].choices = [
'none', 'c89', 'c90', 'c9x', 'c99', 'c1x', 'c11',
'gnu89', 'gnu90', 'gnu9x', 'gnu99', 'gnu1x', 'gnu11',
'iso9899:2011', 'iso9899:1990', 'iso9899:199409', 'iso9899:1999',
@ -374,7 +374,7 @@ class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
g_stds = ['gnu89', 'gnu99']
if version_compare(self.version, '>=16.0.0'):
c_stds += ['c11']
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
opts['std'].choices = ['none'] + c_stds + g_stds
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -436,7 +436,7 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi
if version_compare(self.version, self._C17_VERSION):
c_stds += ['c17', 'c18']
g_stds += ['gnu17', 'gnu18']
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
opts['std'].choices = ['none'] + c_stds + g_stds
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -489,7 +489,7 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
def get_options(self) -> 'OptionDictType':
opts = super().get_options()
opts['std'].choices = ['none', 'c89', 'c99', 'c11'] # type: ignore
opts['std'].choices = ['none', 'c89', 'c99', 'c11']
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -515,7 +515,7 @@ class ArmCCompiler(ArmCompiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts['std'].choices = ['none', 'c89', 'c99', 'c11'] # type: ignore
opts['std'].choices = ['none', 'c89', 'c99', 'c11']
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -542,7 +542,7 @@ class CcrxCCompiler(CcrxCompiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts['std'].choices = ['none', 'c89', 'c99'] # type: ignore
opts['std'].choices = ['none', 'c89', 'c99']
return opts
def get_no_stdinc_args(self) -> T.List[str]:
@ -587,7 +587,7 @@ class Xc16CCompiler(Xc16Compiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts['std'].choices = ['none', 'c89', 'c99', 'gnu89', 'gnu99'] # type: ignore
opts['std'].choices = ['none', 'c89', 'c99', 'gnu89', 'gnu99']
return opts
def get_no_stdinc_args(self) -> T.List[str]:
@ -630,7 +630,7 @@ class CompCertCCompiler(CompCertCompiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts['std'].choices = ['none', 'c89', 'c99'] # type: ignore
opts['std'].choices = ['none', 'c89', 'c99']
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -666,7 +666,7 @@ class C2000CCompiler(C2000Compiler, CCompiler):
def get_options(self) -> 'OptionDictType':
opts = CCompiler.get_options(self)
opts['std'].choices = ['none', 'c89', 'c99', 'c11'] # type: ignore
opts['std'].choices = ['none', 'c89', 'c99', 'c11']
return opts
def get_no_stdinc_args(self) -> T.List[str]:

@ -206,7 +206,7 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
),
'rtti': coredata.UserBooleanOption('Enable RTTI', True),
})
opts['std'].choices = [ # type: ignore
opts['std'].choices = [
'none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z',
'c++2a', 'c++20', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++1z',
'gnu++2a', 'gnu++20',
@ -296,7 +296,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
'default',
),
})
opts['std'].choices = [ # type: ignore
opts['std'].choices = [
'none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'gnu++98',
'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17',
]
@ -345,7 +345,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
False,
)
})
opts['std'].choices = [ # type: ignore
opts['std'].choices = [
'none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z',
'c++2a', 'c++20', 'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17',
'gnu++1z', 'gnu++2a', 'gnu++20',
@ -449,7 +449,7 @@ class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler):
False,
),
})
opts['std'].choices = cpp_stds # type: ignore
opts['std'].choices = cpp_stds
return opts
# Elbrus C++ compiler does not have lchmod, but there is only linker warning, not compiler error.
@ -520,7 +520,7 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
'rtti': coredata.UserBooleanOption('Enable RTTI', True),
'debugstl': coredata.UserBooleanOption('STL debug mode', False),
})
opts['std'].choices = ['none'] + c_stds + g_stds # type: ignore
opts['std'].choices = ['none'] + c_stds + g_stds
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -577,7 +577,7 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase):
msvc_winlibs,
),
})
opts['std'].choices = cpp_stds # type: ignore
opts['std'].choices = cpp_stds
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -721,7 +721,7 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler):
def get_options(self) -> 'OptionDictType':
opts = CPPCompiler.get_options(self)
opts['std'].choices = ['none', 'c++03', 'c++11'] # type: ignore
opts['std'].choices = ['none', 'c++03', 'c++11']
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -779,7 +779,7 @@ class C2000CPPCompiler(C2000Compiler, CPPCompiler):
def get_options(self) -> 'OptionDictType':
opts = CPPCompiler.get_options(self)
opts['std'].choices = ['none', 'c++03'] # type: ignore
opts['std'].choices = ['none', 'c++03']
return opts
def get_always_args(self) -> T.List[str]:

@ -186,7 +186,7 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
fortran_stds += ['f2008']
if version_compare(self.version, '>=8.0.0'):
fortran_stds += ['f2018']
opts['std'].choices = ['none'] + fortran_stds # type: ignore
opts['std'].choices = ['none'] + fortran_stds
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -315,7 +315,7 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
def get_options(self) -> 'OptionDictType':
opts = FortranCompiler.get_options(self)
opts['std'].choices = ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018'] # type: ignore
opts['std'].choices = ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018']
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:
@ -365,7 +365,7 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
def get_options(self) -> 'OptionDictType':
opts = FortranCompiler.get_options(self)
opts['std'].choices = ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018'] # type: ignore
opts['std'].choices = ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018']
return opts
def get_option_compile_args(self, options: 'OptionDictType') -> T.List[str]:

@ -1738,8 +1738,9 @@ def run_once(func: T.Callable[..., _T]) -> T.Callable[..., _T]:
class OptionProxy(T.Generic[_T]):
def __init__(self, value: _T):
def __init__(self, value: _T, choices: T.Optional[T.List[str]] = None):
self.value = value
self.choices = choices
class OptionOverrideProxy(collections.abc.MutableMapping):
@ -1761,7 +1762,7 @@ class OptionOverrideProxy(collections.abc.MutableMapping):
if key in self.options:
opt = self.options[key]
if key in self.overrides:
return OptionProxy(opt.validate_value(self.overrides[key]))
return OptionProxy(opt.validate_value(self.overrides[key]), getattr(opt, 'choices', None))
return opt
raise KeyError('Option not found', key)

Loading…
Cancel
Save