summaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-04-29 19:26:05 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2025-05-01 22:24:00 +0300
commite22fba20dbd9010333b150be2564e70866aa3676 (patch)
treec7be013c0b792c0c4c0827a0d71bcd7fa5676d13 /mesonbuild
parentd241394f8b8c5f24b5ffde56a9956eee93e611e4 (diff)
downloadmeson-e22fba20dbd9010333b150be2564e70866aa3676.tar.gz
options: extract validation of command line options
Which command line options are valid is not entirely known until the backend option is processed. Split the validation to a separate function so that it can be done later, and while at it mention all unknown options instead of just the first. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/interpreter/interpreter.py1
-rw-r--r--mesonbuild/options.py28
2 files changed, 21 insertions, 8 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index bf41bfb55..b32b8c6e7 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -1201,6 +1201,7 @@ class Interpreter(InterpreterBase, HoldableObject):
self.coredata.initialized_subprojects.add(self.subproject)
if not self.is_subproject():
+ self.coredata.optstore.validate_cmd_line_options(self.user_defined_options.cmd_line_options)
self.build.project_name = proj_name
self.active_projectname = proj_name
diff --git a/mesonbuild/options.py b/mesonbuild/options.py
index 043a0fbf8..3b7d8b2c0 100644
--- a/mesonbuild/options.py
+++ b/mesonbuild/options.py
@@ -1370,16 +1370,28 @@ class OptionStore:
if proj_key in self.options:
self.set_option(proj_key, valstr, True)
else:
- # Fail on unknown options that we can know must
- # exist at this point in time. Subproject and compiler
- # options are resolved later.
- #
- # Some base options (sanitizers etc) might get added later.
- # Permitting them all is not strictly correct.
- if key.subproject is None and not self.is_compiler_option(key) and not self.is_base_option(key):
- raise MesonException(f'Unknown options: "{keystr}"')
self.pending_options[key] = valstr
+ def validate_cmd_line_options(self, cmd_line_options: OptionStringLikeDict) -> None:
+ unknown_options = []
+ for keystr, valstr in cmd_line_options.items():
+ if isinstance(keystr, str):
+ key = OptionKey.from_string(keystr)
+ else:
+ key = keystr
+ # Fail on unknown options that we can know must exist at this point in time.
+ # Subproject and compiler options are resolved later.
+ #
+ # Some base options (sanitizers etc) might get added later.
+ # Permitting them all is not strictly correct.
+ if key.subproject is None and not self.is_compiler_option(key) and not self.is_base_option(key) and \
+ key in self.pending_options:
+ unknown_options.append(f'"{key}"')
+
+ if unknown_options:
+ keys = ', '.join(unknown_options)
+ raise MesonException(f'Unknown options: {keys}')
+
def hacky_mchackface_back_to_list(self, optdict: T.Dict[str, str]) -> T.List[str]:
if isinstance(optdict, dict):
return [f'{k}={v}' for k, v in optdict.items()]