summaryrefslogtreecommitdiff
path: root/mesonbuild/ast
diff options
context:
space:
mode:
authorVolker Weißmann <volker.weissmann@gmx.de>2025-03-09 17:15:52 +0100
committerDylan Baker <dylan@pnwbakers.com>2025-05-29 09:20:27 -0700
commit792db9439b30b64449097eb5e5fc940148cacaab (patch)
tree18caa6ae9e1ef35cb479ab42dead3eb79cdc2183 /mesonbuild/ast
parent81558a0e39e969d9059e004088cc0e32b93e5f05 (diff)
downloadmeson-792db9439b30b64449097eb5e5fc940148cacaab.tar.gz
rewriter: Add IntrospectionDependency
To improve type-safety and readability we replace a dictionary with a new class `IntrospectionDependency`.
Diffstat (limited to 'mesonbuild/ast')
-rw-r--r--mesonbuild/ast/interpreter.py10
-rw-r--r--mesonbuild/ast/introspection.py20
2 files changed, 20 insertions, 10 deletions
diff --git a/mesonbuild/ast/interpreter.py b/mesonbuild/ast/interpreter.py
index b462c7e87..cde578a9a 100644
--- a/mesonbuild/ast/interpreter.py
+++ b/mesonbuild/ast/interpreter.py
@@ -65,6 +65,16 @@ if T.TYPE_CHECKING:
_T = T.TypeVar('_T')
_V = T.TypeVar('_V')
+# `IntrospectionDependency` is to the `IntrospectionInterpreter` what `Dependency` is to the normal `Interpreter`.
+@dataclass
+class IntrospectionDependency(MesonInterpreterObject):
+ name: str
+ required: T.Union[bool]
+ version: T.List[str]
+ has_fallback: bool
+ conditional: bool
+ node: FunctionNode
+
# `IntrospectionBuildTarget` is to the `IntrospectionInterpreter` what `BuildTarget` is to the normal `Interpreter`.
@dataclass
class IntrospectionBuildTarget(MesonInterpreterObject):
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index 316b26175..88ca72c84 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -16,7 +16,7 @@ from ..interpreterbase import InvalidArguments, SubProject
from ..mesonlib import MachineChoice
from ..options import OptionKey
from ..mparser import BaseNode, ArithmeticNode, ArrayNode, ElementaryNode, IdNode, FunctionNode, StringNode
-from .interpreter import AstInterpreter, IntrospectionBuildTarget
+from .interpreter import AstInterpreter, IntrospectionBuildTarget, IntrospectionDependency
if T.TYPE_CHECKING:
from ..build import BuildTarget
@@ -66,7 +66,7 @@ class IntrospectionInterpreter(AstInterpreter):
self.default_options = {OptionKey('backend'): self.backend}
self.project_data: T.Dict[str, T.Any] = {}
self.targets: T.List[IntrospectionBuildTarget] = []
- self.dependencies: T.List[T.Dict[str, T.Any]] = []
+ self.dependencies: T.List[IntrospectionDependency] = []
self.project_node: BaseNode = None
self.funcs.update({
@@ -225,14 +225,14 @@ class IntrospectionInterpreter(AstInterpreter):
required = required.value
if not isinstance(required, bool):
required = False
- self.dependencies += [{
- 'name': name,
- 'required': required,
- 'version': version,
- 'has_fallback': has_fallback,
- 'conditional': node.condition_level > 0,
- 'node': node
- }]
+ newdep = IntrospectionDependency(
+ name=name,
+ required=required,
+ version=version,
+ has_fallback=has_fallback,
+ conditional=node.condition_level > 0,
+ node=node)
+ self.dependencies += [newdep]
def build_target(self, node: BaseNode, args: T.List[TYPE_var], kwargs_raw: T.Dict[str, TYPE_var], targetclass: T.Type[BuildTarget]) -> IntrospectionBuildTarget:
args = self.flatten_args(args)