summaryrefslogtreecommitdiff
path: root/mesonbuild
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
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')
-rw-r--r--mesonbuild/ast/interpreter.py10
-rw-r--r--mesonbuild/ast/introspection.py20
-rw-r--r--mesonbuild/mintro.py19
-rw-r--r--mesonbuild/rewriter.py11
4 files changed, 35 insertions, 25 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)
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py
index ed4ccb7e2..94ecaf9d0 100644
--- a/mesonbuild/mintro.py
+++ b/mesonbuild/mintro.py
@@ -380,17 +380,16 @@ def list_compilers(coredata: cdata.CoreData) -> T.Dict[str, T.Dict[str, T.Dict[s
}
return compilers
-def list_deps_from_source(intr: IntrospectionInterpreter) -> T.List[T.Dict[str, T.Union[str, bool]]]:
- result: T.List[T.Dict[str, T.Union[str, bool]]] = []
+def list_deps_from_source(intr: IntrospectionInterpreter) -> T.List[T.Dict[str, T.Union[str, bool, T.List[str]]]]:
+ result: T.List[T.Dict[str, T.Union[str, bool, T.List[str]]]] = []
for i in intr.dependencies:
- keys = [
- 'name',
- 'required',
- 'version',
- 'has_fallback',
- 'conditional',
- ]
- result += [{k: v for k, v in i.items() if k in keys}]
+ result += [{
+ 'name': i.name,
+ 'required': i.required,
+ 'version': i.version,
+ 'has_fallback': i.has_fallback,
+ 'conditional': i.conditional,
+ }]
return result
def list_deps(coredata: cdata.CoreData, backend: backends.Backend) -> T.List[T.Dict[str, T.Union[str, T.List[str]]]]:
diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py
index 6df155b00..253e3f2fb 100644
--- a/mesonbuild/rewriter.py
+++ b/mesonbuild/rewriter.py
@@ -10,6 +10,7 @@
from __future__ import annotations
from .ast import IntrospectionInterpreter, BUILD_TARGET_FUNCTIONS, AstConditionLevel, AstIDGenerator, AstIndentationGenerator, AstPrinter
+from .ast.interpreter import IntrospectionDependency
from mesonbuild.mesonlib import MesonException, setup_vsenv
from . import mlog, environment
from functools import wraps
@@ -427,10 +428,10 @@ class Rewriter:
return tgt
- def find_dependency(self, dependency: str):
+ def find_dependency(self, dependency: str) -> T.Optional[IntrospectionDependency]:
def check_list(name: str):
for i in self.interpreter.dependencies:
- if name == i['name']:
+ if name == i.name:
return i
return None
@@ -521,9 +522,9 @@ class Rewriter:
node = tmp_tgt.node
arg_node = node.args
elif cmd['function'] == 'dependency':
- tmp = self.find_dependency(cmd['id'])
- if tmp:
- node = tmp['node']
+ tmp_dep = self.find_dependency(cmd['id'])
+ if tmp_dep:
+ node = tmp_dep.node
arg_node = node.args
if not node:
mlog.error('Unable to find the function node')