diff options
Diffstat (limited to 'mesonbuild/msetup.py')
| -rw-r--r-- | mesonbuild/msetup.py | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/mesonbuild/msetup.py b/mesonbuild/msetup.py index e634c05ab..e2646f9e1 100644 --- a/mesonbuild/msetup.py +++ b/mesonbuild/msetup.py @@ -27,6 +27,7 @@ if T.TYPE_CHECKING: builddir: str sourcedir: str pager: bool + unset_opts: T.List[str] git_ignore_file = '''# This file is autogenerated by Meson. If you change or delete it, it won't be recreated. * @@ -187,6 +188,44 @@ class MesonApp: with mesonlib.BuildDirLock(self.build_dir): return self._generate(env, capture, vslite_ctx) + def check_unused_options(self, coredata: 'coredata.CoreData', cmd_line_options: T.Any, all_subprojects: T.Any) -> None: + pending = coredata.optstore.pending_project_options + errlist: T.List[str] = [] + permitted_unknowns = ['b_vscrt', 'b_lto', 'b_lundef'] + permitlist: T.List[str] = [] + for opt in pending: + # Due to backwards compatibility setting build options in non-cross + # builds is permitted and is a no-op. This should be made + # a hard error. + if not coredata.is_cross_build() and opt.is_for_build(): + continue + # It is not an error to set wrong option for unknown subprojects or + # language because we don't have control on which one will be selected. + if opt.subproject and opt.subproject not in all_subprojects: + continue + if coredata.optstore.is_compiler_option(opt): + continue + if opt.name in permitted_unknowns: + permitlist.append(opt.name) + continue + keystr = str(opt) + if keystr in cmd_line_options: + errlist.append(f'"{keystr}"') + if errlist: + errstr = ', '.join(errlist) + raise MesonException(f'Unknown options: {errstr}') + if permitlist: + # This is needed due to backwards compatibility. + # It was permitted to define some command line options that + # were not used. This can be seen as a bug, since + # if you define -Db_lto but the compiler class does not + # support it, this option gets silently swallowed. + # So at least print a message about it. + optstr = ','.join(permitlist) + mlog.warning(f'Some command line options went unused: {optstr}', fatal=False) + + coredata.optstore.clear_pending() + def _generate(self, env: environment.Environment, capture: bool, vslite_ctx: T.Optional[dict]) -> T.Optional[dict]: # Get all user defined options, including options that have been defined # during a previous invocation or using meson configure. @@ -242,6 +281,9 @@ class MesonApp: cdf = env.dump_coredata() self.finalize_postconf_hooks(b, intr) + self.check_unused_options(env.coredata, + intr.user_defined_options.cmd_line_options, + intr.subprojects) if self.options.profile: localvars = locals() fname = f'profile-{intr.backend.name}-backend.log' @@ -275,9 +317,9 @@ class MesonApp: # collect warnings about unsupported build configurations; must be done after full arg processing # by Interpreter() init, but this is most visible at the end - if env.coredata.optstore.get_value('backend') == 'xcode': + if env.coredata.optstore.get_value_for('backend') == 'xcode': mlog.warning('xcode backend is currently unmaintained, patches welcome') - if env.coredata.optstore.get_value('layout') == 'flat': + if env.coredata.optstore.get_value_for('layout') == 'flat': mlog.warning('-Dlayout=flat is unsupported and probably broken. It was a failed experiment at ' 'making Windows build artifacts runnable while uninstalled, due to PATH considerations, ' 'but was untested by CI and anyways breaks reasonable use of conflicting targets in different subdirs. ' @@ -321,17 +363,17 @@ def run_genvslite_setup(options: CMDOptions) -> None: # invoke the appropriate 'meson compile ...' build commands upon the normal visual studio build/rebuild/clean actions, instead of using # the native VS/msbuild system. builddir_prefix = options.builddir - genvsliteval = options.cmd_line_options.pop(OptionKey('genvslite')) + genvsliteval = options.cmd_line_options.pop('genvslite') # type: ignore [call-overload] # The command line may specify a '--backend' option, which doesn't make sense in conjunction with # '--genvslite', where we always want to use a ninja back end - - k_backend = OptionKey('backend') + k_backend = 'backend' if k_backend in options.cmd_line_options.keys(): - if options.cmd_line_options[k_backend] != 'ninja': + if options.cmd_line_options[k_backend] != 'ninja': # type: ignore [index] raise MesonException('Explicitly specifying a backend option with \'genvslite\' is not necessary ' '(the ninja backend is always used) but specifying a non-ninja backend ' 'conflicts with a \'genvslite\' setup') else: - options.cmd_line_options[k_backend] = 'ninja' + options.cmd_line_options[k_backend] = 'ninja' # type: ignore [index] buildtypes_list = coredata.get_genvs_default_buildtype_list() vslite_ctx = {} @@ -358,7 +400,7 @@ def run(options: T.Union[CMDOptions, T.List[str]]) -> int: # lie options.pager = False - if OptionKey('genvslite') in options.cmd_line_options.keys(): + if 'genvslite' in options.cmd_line_options.keys(): run_genvslite_setup(options) else: app = MesonApp(options) |
