summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2025-06-18 12:08:31 +0200
committerDylan Baker <dylan@pnwbakers.com>2025-10-06 14:44:31 -0700
commitbfe7445d87019ce5fbf5118473307404cea95d21 (patch)
treeea65a2574de20e70adae94318e99cadcb12ebcc7
parent844c9e64121312688325fc97c6a322ffbed5008c (diff)
downloadmeson-bfe7445d87019ce5fbf5118473307404cea95d21.tar.gz
interpreter: unify and specialize code to set backend options
Avoid different but equivalent code between ast and regular interpreter, and avoid using coredata.set_options since all options are known to be backend options. Move to environment since it uses environment.options. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--mesonbuild/ast/introspection.py4
-rw-r--r--mesonbuild/environment.py11
-rw-r--r--mesonbuild/interpreter/interpreter.py8
3 files changed, 13 insertions, 10 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index e610b536d..b4cf8203c 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -128,10 +128,8 @@ class IntrospectionInterpreter(AstInterpreter):
if os.path.isdir(os.path.join(subprojects_dir, i)):
self.do_subproject(SubProject(i))
- self.coredata.init_backend_options(self.backend)
- options = {k: v for k, v in self.environment.options.items() if self.environment.coredata.optstore.is_backend_option(k)}
+ self.environment.init_backend_options(self.backend)
- self.coredata.set_options(options)
self._add_languages(proj_langs, True, MachineChoice.HOST)
self._add_languages(proj_langs, True, MachineChoice.BUILD)
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 689508f09..7d1511633 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -906,6 +906,17 @@ class Environment:
self.coredata = coredata.CoreData(options, self.scratch_dir, meson_command)
self.first_invocation = True
+ def init_backend_options(self, backend_name: str) -> None:
+ # Only init backend options on first invocation otherwise it would
+ # override values previously set from command line.
+ if not self.first_invocation:
+ return
+
+ self.coredata.init_backend_options(backend_name)
+ for k, v in self.options.items():
+ if self.coredata.optstore.is_backend_option(k):
+ self.coredata.optstore.set_option(k, v)
+
def is_cross_build(self, when_building_for: MachineChoice = MachineChoice.HOST) -> bool:
return self.coredata.is_cross_build(when_building_for)
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index e7560f863..73be40eec 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -1155,13 +1155,7 @@ class Interpreter(InterpreterBase, HoldableObject):
raise MesonBugException(f'Backend changed from {backend_name} to {self.backend.name}')
self.coredata.optstore.set_option(OptionKey('backend'), self.backend.name, first_invocation=True)
- # Only init backend options on first invocation otherwise it would
- # override values previously set from command line.
- if self.environment.first_invocation:
- self.coredata.init_backend_options(backend_name)
-
- options = {k: v for k, v in self.environment.options.items() if self.environment.coredata.optstore.is_backend_option(k)}
- self.coredata.set_options(options)
+ self.environment.init_backend_options(backend_name)
@typed_pos_args('project', str, varargs=str)
@typed_kwargs(