summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-02-26 10:52:39 -0800
committerJussi Pakkanen <jpakkane@gmail.com>2025-02-27 23:33:39 +0200
commit3f430886dc29f2f80ca1556b9e0518f2a182f988 (patch)
treeaa57d40231107983cae215f4f71cd6496196c840
parentd9f3f6c0b27476edc84ccddecb373af88fde1053 (diff)
downloadmeson-3f430886dc29f2f80ca1556b9e0518f2a182f988.tar.gz
coredata: delete the OptionsView
This also makes KeyedOptionDictType obsolete and it's removed
-rw-r--r--mesonbuild/compilers/compilers.py4
-rw-r--r--mesonbuild/compilers/mixins/islinker.py4
-rw-r--r--mesonbuild/coredata.py71
-rw-r--r--mesonbuild/mconf.py6
-rw-r--r--mesonbuild/mintro.py2
5 files changed, 11 insertions, 76 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 7e061ba47..14f0a330d 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -26,7 +26,7 @@ from ..arglist import CompilerArgs
if T.TYPE_CHECKING:
from .. import coredata
from ..build import BuildTarget, DFeatures
- from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType
+ from ..coredata import MutableKeyedOptionDictType
from ..envconfig import MachineInfo
from ..environment import Environment
from ..linkers import RSPFileSyntax
@@ -272,7 +272,7 @@ def option_enabled(boptions: T.Set[OptionKey],
return False
-def get_option_value(options: 'KeyedOptionDictType', opt: OptionKey, fallback: '_T') -> '_T':
+def get_option_value(options: options.OptionStore, opt: OptionKey, fallback: '_T') -> '_T':
"""Get the value of an option, or the fallback value."""
try:
v: '_T' = options.get_value(opt) # type: ignore [assignment]
diff --git a/mesonbuild/compilers/mixins/islinker.py b/mesonbuild/compilers/mixins/islinker.py
index 6c9daf3fc..44040a7a2 100644
--- a/mesonbuild/compilers/mixins/islinker.py
+++ b/mesonbuild/compilers/mixins/islinker.py
@@ -16,10 +16,10 @@ import typing as T
from ...mesonlib import EnvironmentException, MesonException, is_windows
if T.TYPE_CHECKING:
- from ...coredata import KeyedOptionDictType
from ...environment import Environment
from ...compilers.compilers import Compiler
from ...build import BuildTarget
+ from ...options import OptionStore
else:
# This is a bit clever, for mypy we pretend that these mixins descend from
# Compiler, so we get all of the methods and attributes defined for us, but
@@ -71,7 +71,7 @@ class BasicLinkerIsCompilerMixin(Compiler):
def get_std_shared_lib_link_args(self) -> T.List[str]:
return []
- def get_std_shared_module_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
+ def get_std_shared_module_args(self, options: OptionStore) -> T.List[str]:
return self.get_std_shared_lib_link_args()
def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index f41b5aef2..ef761f54f 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -10,8 +10,7 @@ from . import mlog, options
import pickle, os, uuid
import sys
from itertools import chain
-from collections import OrderedDict, abc
-import dataclasses
+from collections import OrderedDict
import textwrap
from .mesonlib import (
@@ -60,9 +59,8 @@ if T.TYPE_CHECKING:
cross_file: T.List[str]
native_file: T.List[str]
- OptionDictType = T.Union[T.Dict[str, options.AnyOptionType], 'OptionsView']
+ OptionDictType = T.Dict[str, options.AnyOptionType]
MutableKeyedOptionDictType = T.Dict['OptionKey', options.AnyOptionType]
- KeyedOptionDictType = T.Union['options.OptionStore', 'OptionsView']
CompilerCheckCacheKey = T.Tuple[T.Tuple[str, ...], str, FileOrString, T.Tuple[str, ...], CompileCheckMode]
# code, args
RunCheckCacheKey = T.Tuple[str, T.Tuple[str, ...]]
@@ -146,7 +144,7 @@ class DependencyCache:
successfully lookup by providing a simple get/put interface.
"""
- def __init__(self, builtins: 'KeyedOptionDictType', for_machine: MachineChoice):
+ def __init__(self, builtins: options.OptionStore, for_machine: MachineChoice):
self.__cache: T.MutableMapping[TV_DepID, DependencySubCache] = OrderedDict()
self.__builtins = builtins
self.__pkg_conf_key = options.OptionKey('pkg_config_path')
@@ -900,69 +898,6 @@ def parse_cmd_line_options(args: SharedCMDOptions) -> None:
args.cmd_line_options[key.name] = value
delattr(args, name)
-@dataclasses.dataclass
-class OptionsView(abc.Mapping):
- '''A view on an options dictionary for a given subproject and with overrides.
- '''
-
- # TODO: the typing here could be made more explicit using a TypeDict from
- # python 3.8 or typing_extensions
- original_options: T.Union[KeyedOptionDictType, 'dict[OptionKey, options.AnyOptionType]']
- subproject: T.Optional[str] = None
- overrides: T.Optional[T.Mapping[OptionKey, ElementaryOptionValues]] = dataclasses.field(default_factory=dict)
-
- def __getitem__(self, key: OptionKey) -> options.UserOption:
- # 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 isinstance(self.original_options, options.OptionStore):
- # This is only used by CUDA currently.
- # This entire class gets removed when option refactor
- # is finished.
- if '_' in key.name or key.lang is not None:
- is_project_option = False
- else:
- sys.exit(f'FAIL {key}.')
- else:
- is_project_option = self.original_options.is_project_option(key)
- if not is_project_option:
- opt = self.original_options.get(key)
- if opt is None or opt.yielding:
- key2 = key.as_root()
- # This hack goes away once wi start using OptionStore
- # to hold overrides.
- if isinstance(self.original_options, options.OptionStore):
- if key2 not in self.original_options:
- raise KeyError(f'{key} {key2}')
- opt = self.original_options.get_value_object(key2)
- else:
- opt = self.original_options[key2]
- else:
- opt = self.original_options[key]
- if opt.yielding:
- opt = self.original_options.get(key.as_root(), opt)
- if self.overrides:
- 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 get_value(self, key: T.Union[str, OptionKey]):
- if isinstance(key, str):
- key = OptionKey(key)
- return self[key].value
-
- def set_value(self, key: T.Union[str, OptionKey], value: ElementaryOptionValues):
- if isinstance(key, str):
- key = OptionKey(key)
- self.overrides[key] = value
-
- def __iter__(self) -> T.Iterator[OptionKey]:
- return iter(self.original_options)
-
- def __len__(self) -> int:
- return len(self.original_options)
FORBIDDEN_TARGET_NAMES = frozenset({
'clean',
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index e486df7c1..3fb759bf8 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2014-2016 The Meson development team
-# Copyright © 2023-2024 Intel Corporation
+# Copyright © 2023-2025 Intel Corporation
from __future__ import annotations
@@ -190,7 +190,7 @@ class Conf:
items = [l[i] if l[i] else ' ' * four_column[i] for i in range(4)]
mlog.log(*items)
- def split_options_per_subproject(self, options: T.Union[coredata.MutableKeyedOptionDictType, coredata.KeyedOptionDictType]) -> T.Dict[str, 'coredata.MutableKeyedOptionDictType']:
+ def split_options_per_subproject(self, options: T.Union[coredata.MutableKeyedOptionDictType, options.OptionStore]) -> T.Dict[str, 'coredata.MutableKeyedOptionDictType']:
result: T.Dict[str, 'coredata.MutableKeyedOptionDictType'] = {}
for k, o in options.items():
if k.subproject:
@@ -228,7 +228,7 @@ class Conf:
self._add_line(mlog.normal_yellow(section + ':'), '', '', '')
self.print_margin = 2
- def print_options(self, title: str, opts: T.Union[coredata.MutableKeyedOptionDictType, coredata.KeyedOptionDictType]) -> None:
+ def print_options(self, title: str, opts: T.Union[coredata.MutableKeyedOptionDictType, options.OptionStore]) -> None:
if not opts:
return
if title:
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index 8ec2b1f11..55cf53d06 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -304,7 +304,7 @@ def list_buildoptions(coredata: cdata.CoreData, subprojects: T.Optional[T.List[s
for s in subprojects:
core_options[k.evolve(subproject=s)] = v
- def add_keys(opts: T.Union[cdata.MutableKeyedOptionDictType, cdata.KeyedOptionDictType], section: str) -> None:
+ def add_keys(opts: T.Union[cdata.MutableKeyedOptionDictType, options.OptionStore], section: str) -> None:
for key, opt in sorted(opts.items()):
optdict = {'name': str(key), 'value': opt.value, 'section': section,
'machine': key.machine.get_lower_case_name() if coredata.is_per_machine_option(key) else 'any'}