aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2021-10-12 22:40:19 -0400
committerXavier Claessens <xclaesse@gmail.com>2022-03-22 17:20:48 -0400
commit34f442a365cabdec884b7e9c9631bef434b7f989 (patch)
tree9987fd4a76247ad67e99db074de3bdab66502266
parent06d12064d0ccb1477fadf1d62492a493fb2fb947 (diff)
downloadmeson-34f442a365cabdec884b7e9c9631bef434b7f989.zip
meson-34f442a365cabdec884b7e9c9631bef434b7f989.tar.gz
meson-34f442a365cabdec884b7e9c9631bef434b7f989.tar.bz2
OptionOverrideProxy: Handle per-subproject options
-rw-r--r--mesonbuild/backend/backends.py13
-rw-r--r--mesonbuild/mesonlib/universal.py29
2 files changed, 25 insertions, 17 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 2a955db..b15cfd0 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -312,19 +312,16 @@ class Backend:
def get_options_for_target(self, target: build.BuildTarget) -> OptionOverrideProxy:
return OptionOverrideProxy(target.option_overrides,
- self.environment.coredata.options)
+ self.environment.coredata.options,
+ target.subproject)
- def get_option_for_target(self, option_name: 'OptionKey', target: build.BuildTarget) -> T.Union[str, int, bool, 'WrapMode']:
- if option_name in target.option_overrides_base:
- override = target.option_overrides_base[option_name]
- v = self.environment.coredata.validate_option_value(option_name, override)
- else:
- v = self.environment.coredata.get_option(option_name.evolve(subproject=target.subproject))
+ def get_option_for_target(self, key: 'OptionKey', target: build.BuildTarget) -> T.Union[str, int, bool, 'WrapMode']:
+ options = self.get_options_for_target(target)
# 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]', v)
+ return T.cast('T.Union[str, int, bool, WrapMode]', options[key].value)
def get_source_dir_include_args(self, target: build.BuildTarget, compiler: 'Compiler', *, absolute_path: bool = False) -> T.List[str]:
curdir = target.get_subdir()
diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py
index f0253b2..dd8473e 100644
--- a/mesonbuild/mesonlib/universal.py
+++ b/mesonbuild/mesonlib/universal.py
@@ -1946,18 +1946,29 @@ class OptionOverrideProxy(collections.abc.Mapping):
# TODO: the typing here could be made more explicit using a TypeDict from
# python 3.8 or typing_extensions
- def __init__(self, overrides: T.Dict['OptionKey', T.Any], options: 'KeyedOptionDictType'):
+ def __init__(self, overrides: T.Dict['OptionKey', T.Any], options: 'KeyedOptionDictType',
+ subproject: T.Optional[str] = None):
self.overrides = overrides
self.options = options
+ self.subproject = subproject
def __getitem__(self, key: 'OptionKey') -> 'UserOption':
- if key in self.options:
+ # FIXME: This is fundamentally the same algorithm than interpreter.get_option_internal().
+ # We should try to share the code somehow.
+ key = key.evolve(subproject=self.subproject)
+ if not key.is_project():
+ opt = self.options.get(key)
+ if opt is None or opt.yielding:
+ opt = self.options[key.as_root()]
+ else:
opt = self.options[key]
- if key in self.overrides:
- opt = copy.copy(opt)
- opt.set_value(self.overrides[key])
- return opt
- raise KeyError('Option not found', key)
+ if opt.yielding:
+ opt = self.options.get(key.as_root(), opt)
+ override_value = self.overrides.get(key.as_root())
+ if override_value is not None :
+ opt = copy.copy(opt)
+ opt.set_value(override_value)
+ return opt
def __iter__(self) -> T.Iterator['OptionKey']:
return iter(self.options)
@@ -1968,8 +1979,8 @@ class OptionOverrideProxy(collections.abc.Mapping):
def __eq__(self, other: object) -> bool:
if not isinstance(other, OptionOverrideProxy):
return NotImplemented
- t1 = (self.overrides, self.options)
- t2 = (other.overrides, other.options)
+ t1 = (self.overrides, self.subproject, self.options)
+ t2 = (other.overrides, other.subproject, other.options)
return t1 == t2