diff options
| author | Charles Brunet <charles.brunet@optelgroup.com> | 2024-01-11 15:20:44 -0500 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2024-03-15 09:23:46 -0700 |
| commit | dacb25db101e7ede60b6ba3dd5a7d1935dc5ff73 (patch) | |
| tree | eef37958f0c54683829453d03d4e13bf5e02377f /mesonbuild/compilers/cpp.py | |
| parent | d08ef2c08bb0120f0ba20dbc10575b7e15577349 (diff) | |
| download | meson-dacb25db101e7ede60b6ba3dd5a7d1935dc5ff73.tar.gz | |
Improve error messages for invalid option values
By adding the option name to UserOption object, it is now possible to
display the name of the affected option when the given option value is
not valid.
Fixes #12635
Diffstat (limited to 'mesonbuild/compilers/cpp.py')
| -rw-r--r-- | mesonbuild/compilers/cpp.py | 173 |
1 files changed, 98 insertions, 75 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 5e412e7a5..540dedb18 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -237,18 +237,22 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): def get_options(self) -> 'MutableKeyedOptionDictType': opts = CPPCompiler.get_options(self) key = OptionKey('key', machine=self.for_machine, lang=self.language) - opts.update({ - key.evolve('debugstl'): coredata.UserBooleanOption( - 'STL debug mode', - False, - ), - key.evolve('eh'): coredata.UserComboOption( - 'C++ exception handling type.', - ['none', 'default', 'a', 's', 'sc'], - 'default', - ), - key.evolve('rtti'): coredata.UserBooleanOption('Enable RTTI', True), - }) + self.update_options( + opts, + self.create_option(coredata.UserComboOption, + key.evolve('eh'), + 'C++ exception handling type.', + ['none', 'default', 'a', 's', 'sc'], + 'default'), + self.create_option(coredata.UserBooleanOption, + key.evolve('rtti'), + 'Enable RTTI', + True), + self.create_option(coredata.UserBooleanOption, + key.evolve('debugstl'), + 'STL debug mode', + False), + ) cppstd_choices = [ 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z', 'c++2a', 'c++20', ] @@ -260,12 +264,13 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): assert isinstance(std_opt, coredata.UserStdOption), 'for mypy' std_opt.set_versions(cppstd_choices, gnu=True) if self.info.is_windows() or self.info.is_cygwin(): - opts.update({ - key.evolve('winlibs'): coredata.UserArrayOption( - 'Standard Win libraries to link against', - gnu_winlibs, - ), - }) + self.update_options( + opts, + self.create_option(coredata.UserArrayOption, + key.evolve('winlibs'), + 'Standard Win libraries to link against', + gnu_winlibs), + ) return opts def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: @@ -378,13 +383,14 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler): def get_options(self) -> 'MutableKeyedOptionDictType': opts = CPPCompiler.get_options(self) key = OptionKey('std', machine=self.for_machine, lang=self.language) - opts.update({ - key.evolve('eh'): coredata.UserComboOption( - 'C++ exception handling type.', - ['none', 'default', 'a', 's', 'sc'], - 'default', - ), - }) + self.update_options( + opts, + self.create_option(coredata.UserComboOption, + key.evolve('eh'), + 'C++ exception handling type.', + ['none', 'default', 'a', 's', 'sc'], + 'default'), + ) std_opt = opts[key] assert isinstance(std_opt, coredata.UserStdOption), 'for mypy' std_opt.set_versions(['c++98', 'c++03', 'c++11', 'c++14', 'c++17'], gnu=True) @@ -426,18 +432,22 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): def get_options(self) -> 'MutableKeyedOptionDictType': key = OptionKey('std', machine=self.for_machine, lang=self.language) opts = CPPCompiler.get_options(self) - opts.update({ - key.evolve('eh'): coredata.UserComboOption( - 'C++ exception handling type.', - ['none', 'default', 'a', 's', 'sc'], - 'default', - ), - key.evolve('rtti'): coredata.UserBooleanOption('Enable RTTI', True), - key.evolve('debugstl'): coredata.UserBooleanOption( - 'STL debug mode', - False, - ) - }) + self.update_options( + opts, + self.create_option(coredata.UserComboOption, + key.evolve('eh'), + 'C++ exception handling type.', + ['none', 'default', 'a', 's', 'sc'], + 'default'), + self.create_option(coredata.UserBooleanOption, + key.evolve('rtti'), + 'Enable RTTI', + True), + self.create_option(coredata.UserBooleanOption, + key.evolve('debugstl'), + 'STL debug mode', + False), + ) cppstd_choices = [ 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z', 'c++2a', 'c++20', @@ -450,12 +460,13 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): assert isinstance(std_opt, coredata.UserStdOption), 'for mypy' std_opt.set_versions(cppstd_choices, gnu=True) if self.info.is_windows() or self.info.is_cygwin(): - opts.update({ - key.evolve('winlibs'): coredata.UserArrayOption( - 'Standard Win libraries to link against', - gnu_winlibs, - ), - }) + self.update_options( + opts, + self.create_option(coredata.UserArrayOption, + key.evolve('winlibs'), + 'Standard Win libraries to link against', + gnu_winlibs), + ) return opts def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: @@ -550,17 +561,18 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler): cpp_stds += ['c++20'] key = OptionKey('std', machine=self.for_machine, lang=self.language) - opts.update({ - key.evolve('eh'): coredata.UserComboOption( - 'C++ exception handling type.', - ['none', 'default', 'a', 's', 'sc'], - 'default', - ), - key.evolve('debugstl'): coredata.UserBooleanOption( - 'STL debug mode', - False, - ), - }) + self.update_options( + opts, + self.create_option(coredata.UserComboOption, + key.evolve('eh'), + 'C++ exception handling type.', + ['none', 'default', 'a', 's', 'sc'], + 'default'), + self.create_option(coredata.UserBooleanOption, + key.evolve('debugstl'), + 'STL debug mode', + False), + ) std_opt = opts[key] assert isinstance(std_opt, coredata.UserStdOption), 'for mypy' std_opt.set_versions(cpp_stds, gnu=True) @@ -628,15 +640,22 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler): g_stds += ['gnu++2a'] key = OptionKey('std', machine=self.for_machine, lang=self.language) - opts.update({ - key.evolve('eh'): coredata.UserComboOption( - 'C++ exception handling type.', - ['none', 'default', 'a', 's', 'sc'], - 'default', - ), - key.evolve('rtti'): coredata.UserBooleanOption('Enable RTTI', True), - key.evolve('debugstl'): coredata.UserBooleanOption('STL debug mode', False), - }) + self.update_options( + opts, + self.create_option(coredata.UserComboOption, + key.evolve('eh'), + 'C++ exception handling type.', + ['none', 'default', 'a', 's', 'sc'], + 'default'), + self.create_option(coredata.UserBooleanOption, + key.evolve('rtti'), + 'Enable RTTI', + True), + self.create_option(coredata.UserBooleanOption, + key.evolve('debugstl'), + 'STL debug mode', + False), + ) std_opt = opts[key] assert isinstance(std_opt, coredata.UserStdOption), 'for mypy' std_opt.set_versions(c_stds + g_stds) @@ -694,18 +713,22 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase): def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List[str]) -> 'MutableKeyedOptionDictType': key = OptionKey('std', machine=self.for_machine, lang=self.language) - opts.update({ - key.evolve('eh'): coredata.UserComboOption( - 'C++ exception handling type.', - ['none', 'default', 'a', 's', 'sc'], - 'default', - ), - key.evolve('rtti'): coredata.UserBooleanOption('Enable RTTI', True), - key.evolve('winlibs'): coredata.UserArrayOption( - 'Windows libs to link against.', - msvc_winlibs, - ), - }) + self.update_options( + opts, + self.create_option(coredata.UserComboOption, + key.evolve('eh'), + 'C++ exception handling type.', + ['none', 'default', 'a', 's', 'sc'], + 'default'), + self.create_option(coredata.UserBooleanOption, + key.evolve('rtti'), + 'Enable RTTI', + True), + self.create_option(coredata.UserArrayOption, + key.evolve('winlibs'), + 'Windows libs to link against.', + msvc_winlibs), + ) std_opt = opts[key] assert isinstance(std_opt, coredata.UserStdOption), 'for mypy' std_opt.set_versions(cpp_stds) |
