aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/build.py
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-03-22 21:20:15 -0400
committerXavier Claessens <xclaesse@gmail.com>2022-03-29 16:10:28 -0400
commit90310116ab683f8b7869836b5ae9b6504f87bcf4 (patch)
tree3032c1385aa2865b6e8b53182da13ded444215e5 /mesonbuild/build.py
parente33ec88ac714b1d41cbfec28e80ee6bc046200eb (diff)
downloadmeson-90310116ab683f8b7869836b5ae9b6504f87bcf4.zip
meson-90310116ab683f8b7869836b5ae9b6504f87bcf4.tar.gz
meson-90310116ab683f8b7869836b5ae9b6504f87bcf4.tar.bz2
Replace backend.get_option_for_target() with target.get_option()
That method had nothing specific to the backend, it's purely a Target method. This allows to cache the OptionOverrideProxy object on the Target instance instead of creating a new one for each option lookup.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r--mesonbuild/build.py37
1 files changed, 21 insertions, 16 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 24eeb08..72f5950 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -35,7 +35,7 @@ from .mesonlib import (
File, MesonException, MachineChoice, PerMachine, OrderedSet, listify,
extract_as_list, typeslistify, stringlistify, classify_unity_sources,
get_filenames_templates_dict, substitute_values, has_path_sep,
- OptionKey, PerMachineDefaultable,
+ OptionKey, PerMachineDefaultable, OptionOverrideProxy,
MesonBugException
)
from .compilers import (
@@ -578,7 +578,7 @@ class Target(HoldableObject):
'''))
self.install = False
self.build_always_stale = False
- self.option_overrides: T.Dict[OptionKey, str] = {}
+ self.options = OptionOverrideProxy({}, self.environment.coredata.options, self.subproject)
self.extra_files = [] # type: T.List[File]
if not hasattr(self, 'typename'):
raise RuntimeError(f'Target type is not set for target class "{type(self).__name__}". This is a bug')
@@ -682,13 +682,25 @@ class Target(HoldableObject):
# set, use the value of 'install' if it's enabled.
self.build_by_default = True
- option_overrides = self.parse_overrides(kwargs)
+ self.set_option_overrides(self.parse_overrides(kwargs))
+ def set_option_overrides(self, option_overrides: T.Dict[OptionKey, str]) -> None:
+ self.options.overrides = {}
for k, v in option_overrides.items():
if k.lang:
- self.option_overrides[k.evolve(machine=self.for_machine)] = v
- continue
- self.option_overrides[k] = v
+ self.options.overrides[k.evolve(machine=self.for_machine)] = v
+ else:
+ self.options.overrides[k] = v
+
+ def get_options(self) -> OptionOverrideProxy:
+ return self.options
+
+ def get_option(self, key: 'OptionKey') -> T.Union[str, int, bool, 'WrapMode']:
+ # We don't actually have wrapmode here to do an assert, so just do a
+ # cast, we know what's in coredata anyway.
+ # TODO: if it's possible to annotate get_option or validate_option_value
+ # in the future we might be able to remove the cast here
+ return T.cast('T.Union[str, int, bool, WrapMode]', self.options[key].value)
@staticmethod
def parse_overrides(kwargs: T.Dict[str, T.Any]) -> T.Dict[OptionKey, str]:
@@ -959,10 +971,8 @@ class BuildTarget(Target):
self.compilers['c'] = self.all_compilers['c']
if 'cython' in self.compilers:
key = OptionKey('language', machine=self.for_machine, lang='cython')
- if key in self.option_overrides:
- value = self.option_overrides[key]
- else:
- value = self.environment.coredata.options[key].value
+ value = self.get_option(key)
+
try:
self.compilers[value] = self.all_compilers[value]
except KeyError:
@@ -2450,12 +2460,7 @@ class CustomTarget(Target, CommandBase):
self.install_tag = _install_tag
self.name = name if name else self.outputs[0]
- if override_options:
- for k, v in override_options.items():
- if k.lang:
- self.option_overrides_compiler[k.evolve(machine=self.for_machine)] = v
- else:
- self.option_overrides_base[k] = v
+ self.set_option_overrides(override_options or {})
# Whether to use absolute paths for all files on the commandline
self.absolute_paths = absolute_paths