Skip to content

Commit

Permalink
msetup: remove bad warning about unused options
Browse files Browse the repository at this point in the history
This is just a bad warning, while it *could* give the user useful
information, it often doesn't since it can get values to warn about
from:

  - environment variables
  - the command line
  - machine files
  - `project(default_options : ...)`
  - `subproject(default_options : ...)`
  - `dependency(default_options : ...)`

The problem of course is that user may have no control over these
values. 3 of them are hardcoded into the meson.build files, so the user
can't do anything about them. And there are legitimate reasons to have
unused values in those, like setting defaults for a language only used
on specific platforms.

Environment variables may be set by the distro (NixOS sets them for any
enabled language, so just having a D compiler causes `DFLAGS` to be set,
for example). They likely don't want to special case "only set the
environment variables if the project is going to use them".

For machine files it limits the utility of the files, since the user
needs to be sure that they don't include any options that wont be used.

Finally, the command line could be altered by wrapper scripts, or simply
programmed to insert options that *may* be used but aren't required.
like setting `objc_args` regardless of whether ObjectivC bindings are
generated.

Importantly this causes several unit tests to unconditionally fail for
me because of the NixOS case, because the tests assert that "WARNING" is
not generated, but I will *always* hit this warning.
  • Loading branch information
dcbaker committed Mar 3, 2025
1 parent 7130468 commit e1a2415
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions mesonbuild/msetup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2016-2018 The Meson development team
# Copyright © 2023-2024 Intel Corporation
# Copyright © 2023-2025 Intel Corporation

from __future__ import annotations

Expand Down Expand Up @@ -191,7 +191,6 @@ def generate(self, capture: bool = False, vslite_ctx: T.Optional[dict] = None) -
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] = []
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
Expand All @@ -202,28 +201,14 @@ def check_unused_options(self, coredata: 'coredata.CoreData', cmd_line_options:
# 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):
permitlist.append(opt.name)
continue
# Ditto for base options.
if coredata.optstore.is_base_option(opt):
permitlist.append(opt.name)
if coredata.optstore.is_compiler_option(opt) or coredata.optstore.is_base_option(opt):
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'The following command line option(s) were not used: {optstr}', fatal=False)

coredata.optstore.clear_pending()

Expand Down

0 comments on commit e1a2415

Please sign in to comment.